-
Notifications
You must be signed in to change notification settings - Fork 893
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4075 from brave/ntp-sbw
New Tab Page Branded Wallpapers (desktop)
- Loading branch information
Showing
99 changed files
with
3,961 additions
and
693 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
source_set("ntp_sponsored_images") { | ||
sources = [ | ||
"view_counter_service_factory.cc", | ||
"view_counter_service_factory.h", | ||
] | ||
|
||
deps = [ | ||
"//base", | ||
"//brave/components/ntp_sponsored_images/browser", | ||
"//brave/common", | ||
"//brave/components/brave_ads/browser", | ||
"//chrome/common", | ||
"//content/public/browser", | ||
"//components/keyed_service/content", | ||
"//components/prefs", | ||
"//components/pref_registry", | ||
] | ||
} |
82 changes: 82 additions & 0 deletions
82
browser/ntp_sponsored_images/view_counter_service_factory.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright (c) 2020 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// you can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#include "brave/browser/ntp_sponsored_images/view_counter_service_factory.h" | ||
|
||
#include "brave/browser/brave_browser_process_impl.h" | ||
#include "brave/common/pref_names.h" | ||
#include "brave/components/brave_ads/browser/ads_service.h" | ||
#include "brave/components/brave_ads/browser/ads_service_factory.h" | ||
#include "brave/components/ntp_sponsored_images/browser/features.h" | ||
#include "brave/components/ntp_sponsored_images/browser/ntp_sponsored_images_service.h" | ||
#include "brave/components/ntp_sponsored_images/browser/view_counter_service.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "chrome/common/chrome_features.h" | ||
#include "content/public/browser/browser_context.h" | ||
#include "components/keyed_service/content/browser_context_dependency_manager.h" | ||
#include "components/keyed_service/content/browser_context_keyed_service_factory.h" | ||
#include "components/pref_registry/pref_registry_syncable.h" | ||
#include "components/prefs/pref_service.h" | ||
|
||
namespace ntp_sponsored_images { | ||
|
||
// static | ||
ViewCounterService* ViewCounterServiceFactory::GetForProfile(Profile* profile) { | ||
if (base::FeatureList::IsEnabled(features::kBraveNTPBrandedWallpaper)) | ||
return static_cast<ViewCounterService*>( | ||
GetInstance()->GetServiceForBrowserContext(profile, true)); | ||
|
||
return nullptr; | ||
} | ||
|
||
// static | ||
ViewCounterServiceFactory* ViewCounterServiceFactory::GetInstance() { | ||
return base::Singleton<ViewCounterServiceFactory>::get(); | ||
} | ||
|
||
ViewCounterServiceFactory::ViewCounterServiceFactory() | ||
: BrowserContextKeyedServiceFactory( | ||
"ViewCounterService", | ||
BrowserContextDependencyManager::GetInstance()) { | ||
DependsOn(brave_ads::AdsServiceFactory::GetInstance()); | ||
} | ||
|
||
ViewCounterServiceFactory::~ViewCounterServiceFactory() {} | ||
|
||
KeyedService* ViewCounterServiceFactory::BuildServiceInstanceFor( | ||
content::BrowserContext* browser_context) const { | ||
Profile* profile = Profile::FromBrowserContext(browser_context); | ||
|
||
bool is_supported_locale = false; | ||
auto* ads_service = brave_ads::AdsServiceFactory::GetForProfile(profile); | ||
if (!ads_service) { | ||
LOG(ERROR) << "Ads service was disabled at build time!"; | ||
} else { | ||
is_supported_locale = ads_service->IsSupportedLocale(); | ||
} | ||
|
||
auto* service = g_brave_browser_process->ntp_sponsored_images_service(); | ||
service->AddDataSource(browser_context); | ||
|
||
ViewCounterService* instance = new ViewCounterService( | ||
service, | ||
profile->GetPrefs(), | ||
is_supported_locale); | ||
return instance; | ||
} | ||
|
||
void ViewCounterServiceFactory::RegisterProfilePrefs( | ||
user_prefs::PrefRegistrySyncable* registry) { | ||
registry->RegisterBooleanPref( | ||
kBrandedWallpaperNotificationDismissed, false); | ||
registry->RegisterBooleanPref( | ||
kNewTabPageShowBrandedBackgroundImage, true); | ||
} | ||
|
||
bool ViewCounterServiceFactory::ServiceIsCreatedWithBrowserContext() const { | ||
return true; | ||
} | ||
|
||
} // namespace ntp_sponsored_images |
50 changes: 50 additions & 0 deletions
50
browser/ntp_sponsored_images/view_counter_service_factory.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* Copyright (c) 2019 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_BROWSER_NTP_SPONSORED_IMAGES_VIEW_COUNTER_SERVICE_FACTORY_H_ | ||
#define BRAVE_BROWSER_NTP_SPONSORED_IMAGES_VIEW_COUNTER_SERVICE_FACTORY_H_ | ||
|
||
#include "base/macros.h" | ||
#include "base/memory/singleton.h" | ||
#include "components/keyed_service/content/browser_context_keyed_service_factory.h" | ||
|
||
class Profile; | ||
|
||
namespace content { | ||
class BrowserContext; | ||
} | ||
|
||
namespace user_prefs { | ||
class PrefRegistrySyncable; | ||
} | ||
|
||
namespace ntp_sponsored_images { | ||
|
||
class ViewCounterService; | ||
|
||
class ViewCounterServiceFactory : public BrowserContextKeyedServiceFactory { | ||
public: | ||
static ViewCounterService* GetForProfile(Profile* profile); | ||
static ViewCounterServiceFactory* GetInstance(); | ||
|
||
private: | ||
friend struct base::DefaultSingletonTraits<ViewCounterServiceFactory>; | ||
|
||
ViewCounterServiceFactory(); | ||
~ViewCounterServiceFactory() override; | ||
|
||
// BrowserContextKeyedServiceFactory: | ||
KeyedService* BuildServiceInstanceFor( | ||
content::BrowserContext* context) const override; | ||
bool ServiceIsCreatedWithBrowserContext() const override; | ||
void RegisterProfilePrefs( | ||
user_prefs::PrefRegistrySyncable* registry) override; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(ViewCounterServiceFactory); | ||
}; | ||
|
||
} // namespace ntp_sponsored_images | ||
|
||
#endif // BRAVE_BROWSER_NTP_SPONSORED_IMAGES_VIEW_COUNTER_SERVICE_FACTORY_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.