Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anti-Targeting for Brave Ads #8167

Merged
merged 1 commit into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ source_set("browser_process") {
"themes",
"ui",
"//base",
"//brave/browser/brave_ads",
"//brave/browser/brave_ads/notifications",
"//brave/browser/net",
"//brave/browser/translate/buildflags",
Expand Down Expand Up @@ -381,6 +382,8 @@ source_set("browser_process") {
"brave_rewards/android/brave_rewards_native_worker.cc",
"brave_rewards/android/brave_rewards_native_worker.h",
]

deps += [ "brave_ads" ]
} else {
sources += [
"brave_rewards/tip_dialog.cc",
Expand Down
26 changes: 26 additions & 0 deletions browser/brave_ads/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import("//brave/build/config.gni")
import("//brave/components/brave_ads/browser/buildflags/buildflags.gni")

source_set("brave_ads") {
# Remove when https://github.com/brave/brave-browser/issues/10639 is resolved
check_includes = false
Comment on lines +5 to +6
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need these?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should have been removed @moritzhaller


sources = [
"ads_service_factory.cc",
"ads_service_factory.h",
"ads_tab_helper.cc",
"ads_tab_helper.h",
]

deps = [
"//base",
"//brave/browser/profiles:util",
"//brave/components/brave_ads/browser",
"//brave/components/brave_ads/browser/buildflags",
"//components/dom_distiller/content/browser",
"//components/keyed_service/content",
"//components/sessions",
"//content/public/browser",
"//ui/base",
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 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/components/brave_ads/browser/ads_service_factory.h"
#include "brave/browser/brave_ads/ads_service_factory.h"

#include <memory>

Expand All @@ -19,7 +19,9 @@
#include "brave/browser/brave_rewards/rewards_service_factory.h"
#include "brave/components/brave_ads/browser/ads_service_impl.h"
#include "chrome/browser/dom_distiller/dom_distiller_service_factory.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/notifications/notification_display_service_factory.h"
#include "components/history/core/browser/history_service.h"
#endif

namespace brave_ads {
Expand Down Expand Up @@ -57,6 +59,7 @@ AdsServiceFactory::AdsServiceFactory()
DependsOn(NotificationDisplayServiceFactory::GetInstance());
DependsOn(dom_distiller::DomDistillerServiceFactory::GetInstance());
DependsOn(brave_rewards::RewardsServiceFactory::GetInstance());
DependsOn(HistoryServiceFactory::GetInstance());
#endif
}

Expand All @@ -65,8 +68,10 @@ AdsServiceFactory::~AdsServiceFactory() {}
KeyedService* AdsServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
#if BUILDFLAG(BRAVE_ADS_ENABLED)
std::unique_ptr<AdsServiceImpl> ads_service(
new AdsServiceImpl(Profile::FromBrowserContext(context)));
auto* profile = Profile::FromBrowserContext(context);
std::unique_ptr<AdsServiceImpl> ads_service(new AdsServiceImpl(
profile, HistoryServiceFactory::GetInstance()->GetForProfile(
profile, ServiceAccessType::EXPLICIT_ACCESS)));
return ads_service.release();
#else
return nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* 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_COMPONENTS_BRAVE_ADS_BROWSER_ADS_SERVICE_FACTORY_H_
#define BRAVE_COMPONENTS_BRAVE_ADS_BROWSER_ADS_SERVICE_FACTORY_H_
#ifndef BRAVE_BROWSER_BRAVE_ADS_ADS_SERVICE_FACTORY_H_
#define BRAVE_BROWSER_BRAVE_ADS_ADS_SERVICE_FACTORY_H_

#include "base/memory/singleton.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
Expand Down Expand Up @@ -40,4 +40,4 @@ class AdsServiceFactory : public BrowserContextKeyedServiceFactory {

} // namespace brave_ads

#endif // BRAVE_COMPONENTS_BRAVE_ADS_BROWSER_ADS_SERVICE_FACTORY_H_
#endif // BRAVE_BROWSER_BRAVE_ADS_ADS_SERVICE_FACTORY_H_
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
* 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/components/brave_ads/browser/ads_tab_helper.h"
#include "brave/browser/brave_ads/ads_tab_helper.h"

#include <memory>
#include <utility>

#include "brave/browser/brave_ads/ads_service_factory.h"
#include "brave/components/brave_ads/browser/ads_service.h"
#include "brave/components/brave_ads/browser/ads_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "components/dom_distiller/content/browser/distiller_javascript_utils.h"
#include "components/dom_distiller/content/browser/distiller_page_web_contents.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* 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_COMPONENTS_BRAVE_ADS_BROWSER_ADS_TAB_HELPER_H_
#define BRAVE_COMPONENTS_BRAVE_ADS_BROWSER_ADS_TAB_HELPER_H_
#ifndef BRAVE_BROWSER_BRAVE_ADS_ADS_TAB_HELPER_H_
#define BRAVE_BROWSER_BRAVE_ADS_ADS_TAB_HELPER_H_

#include <cstdint>

Expand Down Expand Up @@ -99,4 +99,4 @@ class AdsTabHelper : public content::WebContentsObserver,

} // namespace brave_ads

#endif // BRAVE_COMPONENTS_BRAVE_ADS_BROWSER_ADS_TAB_HELPER_H_
#endif // BRAVE_BROWSER_BRAVE_ADS_ADS_TAB_HELPER_H_
2 changes: 1 addition & 1 deletion browser/brave_ads/android/brave_ads_native_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "brave/browser/brave_ads/ads_service_factory.h"
#include "brave/browser/brave_ads/android/jni_headers/BraveAdsNativeHelper_jni.h"
#include "brave/components/brave_ads/browser/ads_notification_handler.h"
#include "brave/components/brave_ads/browser/ads_service.h"
#include "brave/components/brave_ads/browser/ads_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_android.h"

Expand Down
14 changes: 5 additions & 9 deletions browser/brave_ads/notifications/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
source_set("notifications") {
sources = [
"platform_bridge.cc",
"platform_bridge.h"
"platform_bridge.h",
]

deps = [
"//base",
"//brave/browser/brave_ads",
"//brave/browser/profiles",
"//brave/components/brave_ads/browser",
"//brave/ui/brave_ads",
"//brave/ui/brave_ads/public/cpp",
"//brave/vendor/bat-native-ads",
"//brave/vendor/bat-native-ledger",
"//content/public/browser",
"//brave/browser/profiles",
"//skia",
]

if (is_android) {
deps += [
"//brave/browser/brave_ads/android:jni_headers",
]
deps += [ "//brave/browser/brave_ads/android:jni_headers" ]
}
}
3 changes: 2 additions & 1 deletion browser/brave_ads/notifications/platform_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
#include "base/memory/scoped_refptr.h"
#include "base/run_loop.h"
#include "base/task/post_task.h"
#include "brave/browser/brave_ads/ads_service_factory.h"
#include "brave/browser/profiles/profile_util.h"
#include "brave/components/brave_ads/browser/ads_notification_handler.h"
#include "brave/components/brave_ads/browser/ads_service.h"
#include "brave/components/brave_ads/browser/ads_service_factory.h"
#include "brave/components/brave_ads/browser/ads_service_impl.h"
#include "brave/ui/brave_ads/message_popup_view.h"
#include "brave/ui/brave_ads/public/cpp/notification.h"
Expand Down
1 change: 0 additions & 1 deletion browser/brave_ads/notifications/platform_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <string>

#include "base/macros.h"
#include "brave/browser/profiles/profile_util.h"
#include "brave/components/brave_ads/browser/ads_notification_handler.h"
#include "brave/ui/brave_ads/public/cpp/notification.h"

Expand Down
12 changes: 6 additions & 6 deletions browser/brave_rewards/android/brave_rewards_native_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
#include <vector>
#include <utility>

#include "base/containers/flat_map.h"
#include "base/time/time.h"
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "base/android/jni_array.h"
#include "base/android/jni_string.h"
#include "base/containers/flat_map.h"
#include "base/json/json_writer.h"
#include "brave/components/brave_ads/browser/ads_service.h"
#include "brave/components/brave_ads/browser/ads_service_factory.h"
#include "base/time/time.h"
#include "brave/browser/brave_ads/ads_service_factory.h"
#include "brave/browser/brave_rewards/rewards_service_factory.h"
#include "brave/build/android/jni_headers/BraveRewardsNativeWorker_jni.h"
#include "brave/components/brave_ads/browser/ads_service.h"
#include "brave/components/brave_rewards/browser/rewards_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "content/public/browser/url_data_source.h"
#include "brave/build/android/jni_headers/BraveRewardsNativeWorker_jni.h"

#define DEFAULT_ADS_PER_HOUR 2
#define DEFAULT_AUTO_CONTRIBUTION_AMOUNT 10
Expand Down
2 changes: 1 addition & 1 deletion browser/brave_tab_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

#include "base/command_line.h"
#include "base/feature_list.h"
#include "brave/browser/brave_ads/ads_tab_helper.h"
#include "brave/browser/brave_stats/brave_stats_tab_helper.h"
#include "brave/browser/ephemeral_storage/ephemeral_storage_tab_helper.h"
#include "brave/browser/ui/bookmark/brave_bookmark_tab_helper.h"
#include "brave/components/brave_ads/browser/ads_tab_helper.h"
#include "brave/components/brave_perf_predictor/browser/buildflags.h"
#include "brave/components/brave_rewards/browser/buildflags/buildflags.h"
#include "brave/components/brave_shields/browser/brave_shields_web_contents_observer.h"
Expand Down
2 changes: 1 addition & 1 deletion browser/browser_context_keyed_service_factories.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

#include "brave/browser/browser_context_keyed_service_factories.h"

#include "brave/browser/brave_ads/ads_service_factory.h"
#include "brave/browser/brave_rewards/rewards_service_factory.h"
#include "brave/browser/brave_shields/ad_block_pref_service_factory.h"
#include "brave/browser/brave_shields/cookie_pref_service_factory.h"
#include "brave/browser/ntp_background_images/view_counter_service_factory.h"
#include "brave/browser/search_engines/search_engine_provider_service_factory.h"
#include "brave/browser/search_engines/search_engine_tracker.h"
#include "brave/components/brave_ads/browser/ads_service_factory.h"
#include "brave/components/brave_wallet/common/buildflags/buildflags.h"
#include "brave/components/greaselion/browser/buildflags/buildflags.h"
#include "brave/components/ipfs/buildflags/buildflags.h"
Expand Down
2 changes: 2 additions & 0 deletions browser/extensions/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ source_set("extensions") {
]

deps += [
"//brave/browser/brave_ads",
"//brave/components/brave_ads/browser",
"//brave/components/brave_rewards/browser",
"//brave/vendor/bat-native-ads:headers",
"//brave/vendor/bat-native-ledger:headers",
Expand Down
2 changes: 1 addition & 1 deletion browser/extensions/api/brave_rewards_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

#include "base/bind.h"
#include "base/strings/string_number_conversions.h"
#include "brave/browser/brave_ads/ads_service_factory.h"
#include "brave/browser/brave_rewards/rewards_service_factory.h"
#include "brave/browser/brave_rewards/tip_dialog.h"
#include "brave/browser/extensions/api/brave_action_api.h"
#include "brave/browser/extensions/brave_component_loader.h"
#include "brave/browser/profiles/profile_util.h"
#include "brave/common/extensions/api/brave_rewards.h"
#include "brave/components/brave_ads/browser/ads_service.h"
#include "brave/components/brave_ads/browser/ads_service_factory.h"
#include "brave/components/brave_rewards/browser/rewards_service.h"
#include "chrome/browser/extensions/api/tabs/tabs_constants.h"
#include "chrome/browser/extensions/chrome_extension_function_details.h"
Expand Down
5 changes: 3 additions & 2 deletions browser/ntp_background_images/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ source_set("ntp_background_images") {

deps = [
"//base",
"//brave/components/brave_stats/browser",
"//brave/browser/brave_ads",
"//brave/common",
"//brave/components/brave_ads/browser",
"//brave/components/brave_stats/browser",
"//brave/components/ntp_background_images/browser",
"//brave/components/ntp_background_images/common",
"//chrome/common",
Expand All @@ -27,9 +28,9 @@ source_set("ntp_background_images") {
]

deps += [
"//brave/build/android:jni_headers",
"//components/keyed_service/content",
"//components/keyed_service/core",
"//brave/build/android:jni_headers",
]
}
}
4 changes: 2 additions & 2 deletions browser/ntp_background_images/view_counter_service_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@

#include <memory>

#include "brave/browser/brave_ads/ads_service_factory.h"
#include "brave/browser/brave_browser_process_impl.h"
#include "brave/browser/profiles/profile_util.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_background_images/browser/ntp_background_images_service.h"
#include "brave/components/ntp_background_images/browser/ntp_background_images_source.h"
#include "brave/components/ntp_background_images/browser/view_counter_service.h"
#include "brave/components/ntp_background_images/common/pref_names.h"
#include "chrome/browser/profiles/profile.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"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/url_data_source.h"

namespace ntp_background_images {
Expand Down
26 changes: 23 additions & 3 deletions browser/profiles/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ source_set("profiles") {
"brave_renderer_updater.h",
"brave_renderer_updater_factory.cc",
"brave_renderer_updater_factory.h",
"profile_util.cc",
"profile_util.h",
]

if (is_win) {
Expand All @@ -28,8 +26,11 @@ source_set("profiles") {
]
}

public_deps = [ ":util" ]

deps = [
"//base",
"//brave/browser/brave_ads",
"//brave/browser/gcm_driver",
"//brave/common",
"//brave/common:pref_names",
Expand All @@ -40,7 +41,6 @@ source_set("profiles") {
"//brave/components/content_settings/core/browser",
"//brave/components/decentralized_dns/buildflags",
"//brave/components/ipfs/buildflags",
"//brave/components/ntp_background_images/common",
"//brave/components/tor",
"//brave/content:browser",
"//chrome/common",
Expand All @@ -66,3 +66,23 @@ source_set("profiles") {
deps += [ "//brave/browser/decentralized_dns" ]
}
}

source_set("util") {
# Remove when https://github.com/brave/brave-browser/issues/10648 is resolved
check_includes = false

sources = [
"profile_util.cc",
"profile_util.h",
]

deps = [
"//base",
"//brave/common",
"//brave/components/ntp_background_images/common",
"//brave/components/search_engines",
"//brave/components/tor/buildflags",
"//components/prefs",
"//content/public/browser",
]
}
2 changes: 1 addition & 1 deletion browser/profiles/brave_profile_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
#include <vector>

#include "base/metrics/histogram_macros.h"
#include "brave/browser/brave_ads/ads_service_factory.h"
#include "brave/browser/brave_rewards/rewards_service_factory.h"
#include "brave/browser/profiles/profile_util.h"
#include "brave/common/pref_names.h"
#include "brave/components/brave_ads/browser/ads_service_factory.h"
#include "brave/components/brave_wallet/common/buildflags/buildflags.h"
#include "brave/components/content_settings/core/browser/brave_content_settings_pref_provider.h"
#include "brave/components/decentralized_dns/buildflags/buildflags.h"
Expand Down
2 changes: 1 addition & 1 deletion browser/profiles/brave_profile_manager_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include <vector>

#include "base/strings/utf_string_conversions.h"
#include "brave/browser/brave_ads/ads_service_factory.h"
#include "brave/browser/brave_browser_process_impl.h"
#include "brave/browser/brave_rewards/rewards_service_factory.h"
#include "brave/components/brave_ads/browser/ads_service_factory.h"
#include "brave/components/ipfs/buildflags/buildflags.h"
#include "brave/components/tor/tor_constants.h"
#include "chrome/browser/browser_process.h"
Expand Down
Loading