Skip to content

Commit

Permalink
Migrate brave-core changes from Android Ads
Browse files Browse the repository at this point in the history
Fixes brave/brave-browser#5160

* Added id to NotificationInfo data structure
* Refactored debug logging
* Refactored TabUpdated/TabClosed
* Refactored unseen ads to available ads and decoupled frequency capping
* Refactored background helper and fixed linter errors
* Implemented background helper for Android
* Refactored locale helper
* Implemented locale helper for Android
* Implemented notification helper
* Refactored OnMediaPlaying/OnMediaStopped
* Only show ad notifications on mobile if the app is in the foreground
* Bumped Challenge Bypass Ristretto dependencies
* Refactored GenerateGUID to use base::GenerateGUID
* Enabled Brave ads for Android
* Allow reinitialization of the bundle state database if the file was removed from storage
* Refactored check for network connection
* Implemented ChangeLocale
* Stop collecting activity, delivering notifications and sustaining ad interaction when destroying AdsImpl
* Refactored Client to use callbacks
* Implemented notifications state
* Refactored Initialize and RemoveAllHistory to use callbacks
* Implemented close notification
* Implemented My First Ad
* Refactored notifications
* Updated README.md
* General refactoring
  • Loading branch information
tmancey authored Jul 18, 2019
1 parent 805bf64 commit e6f0035
Show file tree
Hide file tree
Showing 83 changed files with 2,241 additions and 790 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ deps = {
"components/brave_sync/extension/brave-sync": "https://github.com/brave/sync.git@e97e9e912552cd789cb2c1b1f327c77b32175317",
"components/brave_sync/extension/brave-crypto": "https://github.com/brave/crypto@c1abcd4d6eb7d5cb581804cb3ad9da30d4439022",
"vendor/bat-native-usermodel": "https://github.com/brave-intl/bat-native-usermodel.git@c1745b906079285fc01e3079ac49b0e65fde0f98",
"vendor/challenge_bypass_ristretto_ffi": "https://github.com/brave-intl/challenge-bypass-ristretto-ffi.git@2c0e28f76e4b6f53947bf4faa5afd93614f96aca",
"vendor/challenge_bypass_ristretto_ffi": "https://github.com/brave-intl/challenge-bypass-ristretto-ffi.git@f88d942ddfaf61a4a6703355a77c4ef71bc95c35",
}

hooks = [
Expand Down
24 changes: 24 additions & 0 deletions components/brave_ads/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ source_set("browser") {
"ads_service_impl.h",
"background_helper.cc",
"background_helper.h",
"background_helper_android.cc",
"background_helper_android.h",
"background_helper_linux.cc",
"background_helper_linux.h",
"background_helper_mac.mm",
Expand All @@ -56,8 +58,20 @@ source_set("browser") {
"locale_helper_mac.h",
"locale_helper_win.cc",
"locale_helper_win.h",
"locale_helper_android.cc",
"locale_helper_android.h",
"bundle_state_database.cc",
"bundle_state_database.h",
"notification_helper.cc",
"notification_helper.h",
"notification_helper_android.cc",
"notification_helper_android.h",
"notification_helper_linux.cc",
"notification_helper_linux.h",
"notification_helper_mac.cc",
"notification_helper_mac.h",
"notification_helper_win.cc",
"notification_helper_win.h",
]

deps += [
Expand All @@ -80,6 +94,12 @@ source_set("browser") {
"//ui/gfx",
]
}

if (is_android) {
deps += [
"//chrome/android:jni_headers",
]
}
}
}

Expand Down Expand Up @@ -118,4 +138,8 @@ source_set("testutil") {
"test_util.cc",
"test_util.h",
]

if (is_android) {
deps += [ "//chrome/android:test_support_jni_headers" ]
}
}
15 changes: 7 additions & 8 deletions components/brave_ads/browser/ad_notification.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
/* 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/. */

Expand All @@ -13,16 +14,13 @@ namespace brave_ads {

namespace {

const char kNotifierIdPrefix[] = "service.ads_service.";
const char kNotifierId[] = "service.ads_service";

} // namespace

// static
std::unique_ptr<message_center::Notification> CreateAdNotification(
const ads::NotificationInfo& notification_info,
std::string* notification_id) {
*notification_id = kNotifierIdPrefix + notification_info.uuid;
const ads::NotificationInfo& notification_info) {
message_center::RichNotificationData notification_data;

base::string16 advertiser;
Expand All @@ -42,16 +40,17 @@ std::unique_ptr<message_center::Notification> CreateAdNotification(
notification_data.context_message = base::ASCIIToUTF16(" ");
auto notification = std::make_unique<message_center::Notification>(
message_center::NOTIFICATION_TYPE_SIMPLE,
*notification_id,
notification_info.id,
advertiser,
text,
gfx::Image(),
base::string16(),
GURL("chrome://brave_ads/?" + *notification_id),
GURL("chrome://brave_ads/?" + notification_info.id),
message_center::NotifierId(message_center::NotifierType::SYSTEM_COMPONENT,
kNotifierId),
kNotifierId),
notification_data,
nullptr);

#if !defined(OS_MACOSX) || defined(OFFICIAL_BUILD)
// set_never_timeout uses an XPC service which requires signing
// so for now we don't set this for macos dev builds
Expand Down
12 changes: 6 additions & 6 deletions components/brave_ads/browser/ad_notification.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
/* 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_COMPONENTS_BRAVE_ADS_BROWSER_AD_NOTIFICATION_
#define BRAVE_COMPONENTS_BRAVE_ADS_BROWSER_AD_NOTIFICATION_
#ifndef BRAVE_COMPONENTS_BRAVE_ADS_BROWSER_AD_NOTIFICATION_H_
#define BRAVE_COMPONENTS_BRAVE_ADS_BROWSER_AD_NOTIFICATION_H_

#include <memory>
#include <string>
Expand All @@ -20,9 +21,8 @@ class Notification;
namespace brave_ads {

std::unique_ptr<message_center::Notification> CreateAdNotification(
const ads::NotificationInfo& notification_info,
std::string* notification_id);
const ads::NotificationInfo& notification_info);

} // namespace brave_ads

#endif // BRAVE_COMPONENTS_BRAVE_ADS_BROWSER_AD_NOTIFICATION_
#endif // BRAVE_COMPONENTS_BRAVE_ADS_BROWSER_AD_NOTIFICATION_H_
17 changes: 9 additions & 8 deletions components/brave_ads/browser/ads_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,18 @@ class AdsService : public KeyedService {
virtual void SetAdsPerHour(const uint64_t ads_per_hour) = 0;

// ads::Ads proxy
virtual void TabUpdated(
SessionID tab_id,
const GURL& url,
const bool is_active) = 0;
virtual void TabClosed(SessionID tab_id) = 0;
virtual void OnMediaStart(SessionID tab_id) = 0;
virtual void OnMediaStop(SessionID tab_id) = 0;
virtual void SetConfirmationsIsReady(const bool is_ready) = 0;
virtual void ChangeLocale(const std::string& locale) = 0;
virtual void ClassifyPage(
const std::string& url,
const std::string& page) = 0;
virtual void SetConfirmationsIsReady(const bool is_ready) = 0;
virtual void OnMediaStart(SessionID tab_id) = 0;
virtual void OnMediaStop(SessionID tab_id) = 0;
virtual void OnTabUpdated(
SessionID tab_id,
const GURL& url,
const bool is_active) = 0;
virtual void OnTabClosed(SessionID tab_id) = 0;

private:
DISALLOW_COPY_AND_ASSIGN(AdsService);
Expand Down
2 changes: 2 additions & 0 deletions components/brave_ads/browser/ads_service_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ void AdsServiceFactory::RegisterProfilePrefs(

registry->RegisterIntegerPref(prefs::kIdleThreshold, 15);

registry->RegisterBooleanPref(prefs::kShouldShowMyFirstAdNotification, true);

registry->RegisterBooleanPref(
prefs::kShouldShowFirstLaunchNotification, true);
registry->RegisterBooleanPref(
Expand Down
Loading

0 comments on commit e6f0035

Please sign in to comment.