Cleanup Brave Ads startup
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "brave/components/brave_ads/browser/ads_p2a.h"
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/metrics/histogram_functions.h"
|
||||
#include "brave/components/brave_ads/common/pref_names.h"
|
||||
#include "brave/components/time_period_storage/weekly_storage.h"
|
||||
@@ -125,6 +126,8 @@ void SuspendP2AHistograms() {
|
||||
base::UmaHistogramExactLinear(question_name, INT_MAX,
|
||||
std::size(kIntervalBuckets) + 1);
|
||||
}
|
||||
|
||||
VLOG(1) << "P2A histograms suspended";
|
||||
}
|
||||
|
||||
} // namespace brave_ads
|
||||
|
||||
@@ -293,9 +293,6 @@ class AdsService : public KeyedService {
|
||||
virtual void ToggleFlaggedAd(base::Value::Dict value,
|
||||
ToggleFlaggedAdCallback callback) = 0;
|
||||
|
||||
// Called to wipe all state.
|
||||
virtual void WipeState(bool should_shutdown) = 0;
|
||||
|
||||
protected:
|
||||
base::ObserverList<AdsServiceObserver> observers_;
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -52,6 +52,7 @@ struct NotificationAdInfo;
|
||||
} // namespace ads
|
||||
|
||||
namespace base {
|
||||
class OneShotTimer;
|
||||
class SequencedTaskRunner;
|
||||
} // namespace base
|
||||
|
||||
@@ -103,93 +104,99 @@ class AdsServiceImpl : public AdsService,
|
||||
using SimpleURLLoaderList =
|
||||
std::list<std::unique_ptr<network::SimpleURLLoader>>;
|
||||
|
||||
bool IsBraveNewsEnabled() const;
|
||||
|
||||
bool ShouldStartBatAds() const;
|
||||
|
||||
void InitNotificationsForProfile();
|
||||
void InitializeNotificationsForCurrentProfile() const;
|
||||
|
||||
void MigrateConfirmationState();
|
||||
void OnMigrateConfirmationState(bool success);
|
||||
void GetDeviceId();
|
||||
void OnGetDeviceId(std::string device_id);
|
||||
void DetectUncertainFuture();
|
||||
void OnDetectUncertainFuture(bool is_uncertain_future);
|
||||
|
||||
void InitializePrefChangeRegistrar();
|
||||
bool UserHasOptedIn() const;
|
||||
|
||||
bool CanStartBatAdsService() const;
|
||||
void MaybeStartBatAdsService();
|
||||
void StartBatAdsService();
|
||||
void RestartBatAdsServiceAfterDelay();
|
||||
void CancelRestartBatAdsService();
|
||||
|
||||
void InitializeBasePathDirectory();
|
||||
void OnInitializeBasePathDirectory(bool success);
|
||||
void Initialize();
|
||||
void InitializeDatabase();
|
||||
void InitializeRewardsWallet();
|
||||
void OnInitializeRewardsWallet(ledger::mojom::RewardsWalletPtr wallet);
|
||||
void InitializeBatAds();
|
||||
void OnInitializeBatAds(bool success);
|
||||
|
||||
void ShutdownAndResetState();
|
||||
|
||||
void SetSysInfo();
|
||||
|
||||
void SetBuildChannel();
|
||||
|
||||
void MaybeStartOrStop(bool should_restart);
|
||||
void StartBatAdsService();
|
||||
base::TimeDelta GetBatAdsServiceRestartDelay();
|
||||
void Start(uint32_t number_of_start);
|
||||
|
||||
void GetDeviceId(uint32_t number_of_start);
|
||||
void OnGetDeviceId(uint32_t number_of_start, std::string device_id);
|
||||
|
||||
void DetectUncertainFuture(uint32_t number_of_start);
|
||||
void OnDetectUncertainFuture(uint32_t number_of_start,
|
||||
bool is_uncertain_future);
|
||||
|
||||
void EnsureBaseDirectoryExists(uint32_t number_of_start);
|
||||
void OnEnsureBaseDirectoryExists(uint32_t number_of_start, bool success);
|
||||
|
||||
void CreateBatAdsService(uint32_t number_of_start);
|
||||
void OnCreateBatAdsService();
|
||||
|
||||
bool IsBatAdsServiceBound() const;
|
||||
bool IsBatAdsBound() const;
|
||||
|
||||
void OnInitializeBatAds(bool success);
|
||||
|
||||
void CleanUpOnFirstRun();
|
||||
void RemoveDeprecatedFiles() const;
|
||||
|
||||
void ResetState();
|
||||
|
||||
void OnEnabledPrefChanged();
|
||||
void OnIdleTimeThresholdPrefChanged();
|
||||
void OnWalletBravePrefChanged();
|
||||
void OnBraveTodayOptedInPrefChanged();
|
||||
void OnNewTabPageShowTodayPrefChanged();
|
||||
|
||||
void NotifyPrefChanged(const std::string& path);
|
||||
|
||||
bool ShouldShowOnboardingNotification();
|
||||
void MaybeShowOnboardingNotification();
|
||||
|
||||
void CloseAdaptiveCaptcha();
|
||||
|
||||
void InitializePrefChangeRegistrar();
|
||||
void OnEnabledPrefChanged();
|
||||
void OnIdleTimeThresholdPrefChanged();
|
||||
void OnBraveTodayOptedInPrefChanged();
|
||||
void OnNewTabPageShowTodayPrefChanged();
|
||||
void NotifyPrefChanged(const std::string& path) const;
|
||||
|
||||
void GetRewardsWallet();
|
||||
void OnGetRewardsWallet(ledger::mojom::RewardsWalletPtr wallet);
|
||||
|
||||
void StartCheckIdleStateTimer();
|
||||
// TODO(https://github.com/brave/brave-browser/issues/14666) Decouple idle
|
||||
// state business logic.
|
||||
void CheckIdleStateAfterDelay();
|
||||
void CheckIdleState();
|
||||
void ProcessIdleState(ui::IdleState idle_state, base::TimeDelta idle_time);
|
||||
|
||||
absl::optional<ads::NewTabPageAdInfo> GetPrefetchedNewTabPageAd() override;
|
||||
void OnFailedToPrefetchNewTabPageAd(
|
||||
const std::string& placement_id,
|
||||
const std::string& creative_instance_id) override;
|
||||
|
||||
// TODO(https://github.com/brave/brave-browser/issues/23974) Decouple
|
||||
// notification ad business logic.
|
||||
bool ShouldShowCustomNotificationAds();
|
||||
void StartNotificationAdTimeOutTimer(const std::string& placement_id);
|
||||
bool StopNotificationAdTimeOutTimer(const std::string& placement_id);
|
||||
void NotificationAdTimedOut(const std::string& placement_id);
|
||||
void CloseAllNotificationAds();
|
||||
|
||||
void PrefetchNewTabPageAd() override;
|
||||
// TODO(https://github.com/brave/brave-browser/issues/26192) Decouple new
|
||||
// tab page ad business logic.
|
||||
void OnPrefetchNewTabPageAd(absl::optional<base::Value::Dict> dict);
|
||||
|
||||
void PurgeOrphanedNewTabPageAdEvents();
|
||||
void OnPurgeOrphanedNewTabPageAdEvents(bool success);
|
||||
|
||||
void OpenNewTabWithUrl(const GURL& url);
|
||||
// TODO(https://github.com/brave/brave-browser/issues/26193) Decouple open
|
||||
// new tab with ad business logic.
|
||||
void MaybeOpenNewTabWithAd();
|
||||
void OpenNewTabWithAd(const std::string& placement_id);
|
||||
void OnGetNotificationAd(absl::optional<base::Value::Dict> dict);
|
||||
void OnOpenNewTabWithAd(absl::optional<base::Value::Dict> dict);
|
||||
void RetryOpeningNewTabWithAd(const std::string& placement_id);
|
||||
|
||||
void OpenNewTabWithUrl(const GURL& url);
|
||||
|
||||
// TODO(https://github.com/brave/brave-browser/issues/14676) Decouple URL
|
||||
// request business logic.
|
||||
void OnURLRequest(SimpleURLLoaderList::iterator url_loader_iter,
|
||||
ads::UrlRequestCallback callback,
|
||||
std::unique_ptr<std::string> response_body);
|
||||
|
||||
// TODO(https://github.com/brave/brave-browser/issues/14673) Decouple
|
||||
// migration business logic.
|
||||
bool IsUpgradingFromPreBraveAdsBuild();
|
||||
void MigratePrefs();
|
||||
bool MigratePrefs(int source_version,
|
||||
int dest_version,
|
||||
bool is_dry_run = false);
|
||||
|
||||
void DisableAdsIfUpgradingFromPreBraveAdsBuild();
|
||||
void DisableAdsForUnsupportedCountryCodes(
|
||||
const std::string& country_code,
|
||||
@@ -206,15 +213,6 @@ class AdsServiceImpl : public AdsService,
|
||||
void MigratePrefsVersion10To11();
|
||||
void MigratePrefsVersion11To12();
|
||||
|
||||
void WriteDiagnosticLog(const std::string& file,
|
||||
int line,
|
||||
int verbose_level,
|
||||
const std::string& message);
|
||||
|
||||
void OnURLRequest(SimpleURLLoaderList::iterator url_loader_iter,
|
||||
ads::UrlRequestCallback callback,
|
||||
std::unique_ptr<std::string> response_body);
|
||||
|
||||
// KeyedService:
|
||||
void Shutdown() override;
|
||||
|
||||
@@ -279,6 +277,11 @@ class AdsServiceImpl : public AdsService,
|
||||
const std::string& creative_instance_id,
|
||||
ads::mojom::InlineContentAdEventType event_type) override;
|
||||
|
||||
void PrefetchNewTabPageAd() override;
|
||||
absl::optional<ads::NewTabPageAdInfo> GetPrefetchedNewTabPageAd() override;
|
||||
void OnFailedToPrefetchNewTabPageAd(
|
||||
const std::string& placement_id,
|
||||
const std::string& creative_instance_id) override;
|
||||
void TriggerNewTabPageAdEvent(
|
||||
const std::string& placement_id,
|
||||
const std::string& creative_instance_id,
|
||||
@@ -316,8 +319,6 @@ class AdsServiceImpl : public AdsService,
|
||||
void ToggleFlaggedAd(base::Value::Dict value,
|
||||
ToggleFlaggedAdCallback callback) override;
|
||||
|
||||
void WipeState(bool should_shutdown) override;
|
||||
|
||||
// AdsClient:
|
||||
bool IsNetworkConnectionAvailable() const override;
|
||||
|
||||
@@ -328,7 +329,6 @@ class AdsServiceImpl : public AdsService,
|
||||
bool CanShowNotificationAdsWhileBrowserIsBackgrounded() const override;
|
||||
void ShowNotificationAd(const ads::NotificationAdInfo& ad) override;
|
||||
void CloseNotificationAd(const std::string& placement_id) override;
|
||||
void CloseAllNotificationAds();
|
||||
|
||||
void UpdateAdRewards() override;
|
||||
|
||||
@@ -345,13 +345,20 @@ class AdsServiceImpl : public AdsService,
|
||||
int days_ago,
|
||||
ads::GetBrowsingHistoryCallback callback) override;
|
||||
|
||||
// TODO(https://github.com/brave/brave-browser/issues/14676) Decouple URL
|
||||
// request business logic.
|
||||
void UrlRequest(ads::mojom::UrlRequestInfoPtr url_request,
|
||||
ads::UrlRequestCallback callback) override;
|
||||
|
||||
// TODO(https://github.com/brave/brave-browser/issues/26194) Decouple
|
||||
// load/save file business logic.
|
||||
void Save(const std::string& name,
|
||||
const std::string& value,
|
||||
ads::SaveCallback callback) override;
|
||||
void Load(const std::string& name, ads::LoadCallback callback) override;
|
||||
|
||||
// TODO(https://github.com/brave/brave-browser/issues/26195) Decouple load
|
||||
// resources business logic.
|
||||
void LoadFileResource(const std::string& id,
|
||||
int version,
|
||||
ads::LoadFileCallback callback) override;
|
||||
@@ -368,6 +375,8 @@ class AdsServiceImpl : public AdsService,
|
||||
void RunDBTransaction(ads::mojom::DBTransactionInfoPtr transaction,
|
||||
ads::RunDBTransactionCallback callback) override;
|
||||
|
||||
// TODO(https://github.com/brave/brave-browser/issues/14666) Decouple P2A
|
||||
// business logic.
|
||||
void RecordP2AEvent(const std::string& name,
|
||||
base::Value::List value) override;
|
||||
|
||||
@@ -414,6 +423,7 @@ class AdsServiceImpl : public AdsService,
|
||||
void OnDidUpdateResourceComponent(const std::string& id) override;
|
||||
|
||||
// RewardsServiceObserver:
|
||||
void OnRewardsWalletUpdated() override;
|
||||
void OnCompleteReset(bool success) override;
|
||||
|
||||
bool is_bat_ads_initialized_ = false;
|
||||
@@ -421,14 +431,10 @@ class AdsServiceImpl : public AdsService,
|
||||
bool needs_browser_upgrade_to_serve_ads_ = false;
|
||||
bool is_upgrading_from_pre_brave_ads_build_ = false;
|
||||
|
||||
// This is needed to check if the current ads service becomes stale due to
|
||||
// another ads service being in progress.
|
||||
uint32_t total_number_of_starts_ = 0;
|
||||
|
||||
base::Time last_bat_ads_service_restart_time_;
|
||||
|
||||
PrefChangeRegistrar pref_change_registrar_;
|
||||
|
||||
base::OneShotTimer restart_bat_ads_service_timer_;
|
||||
|
||||
ads::mojom::SysInfo sys_info_;
|
||||
|
||||
std::unique_ptr<ads::Database> database_;
|
||||
|
||||
@@ -25,7 +25,7 @@ BatAdsClientMojoBridge::~BatAdsClientMojoBridge() = default;
|
||||
|
||||
bool BatAdsClientMojoBridge::CanShowNotificationAdsWhileBrowserIsBackgrounded()
|
||||
const {
|
||||
if (!connected()) {
|
||||
if (!bat_ads_client_.is_bound()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ bool BatAdsClientMojoBridge::CanShowNotificationAdsWhileBrowserIsBackgrounded()
|
||||
}
|
||||
|
||||
bool BatAdsClientMojoBridge::IsNetworkConnectionAvailable() const {
|
||||
if (!connected()) {
|
||||
if (!bat_ads_client_.is_bound()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ bool BatAdsClientMojoBridge::IsNetworkConnectionAvailable() const {
|
||||
}
|
||||
|
||||
bool BatAdsClientMojoBridge::IsBrowserActive() const {
|
||||
if (!connected()) {
|
||||
if (!bat_ads_client_.is_bound()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ bool BatAdsClientMojoBridge::IsBrowserActive() const {
|
||||
}
|
||||
|
||||
bool BatAdsClientMojoBridge::IsBrowserInFullScreenMode() const {
|
||||
if (!connected()) {
|
||||
if (!bat_ads_client_.is_bound()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -66,13 +66,13 @@ bool BatAdsClientMojoBridge::IsBrowserInFullScreenMode() const {
|
||||
|
||||
void BatAdsClientMojoBridge::ShowNotificationAd(
|
||||
const ads::NotificationAdInfo& ad) {
|
||||
if (connected()) {
|
||||
if (bat_ads_client_.is_bound()) {
|
||||
bat_ads_client_->ShowNotificationAd(ads::NotificationAdToValue(ad));
|
||||
}
|
||||
}
|
||||
|
||||
bool BatAdsClientMojoBridge::CanShowNotificationAds() {
|
||||
if (!connected()) {
|
||||
if (!bat_ads_client_.is_bound()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ bool BatAdsClientMojoBridge::CanShowNotificationAds() {
|
||||
|
||||
void BatAdsClientMojoBridge::CloseNotificationAd(
|
||||
const std::string& placement_id) {
|
||||
if (connected()) {
|
||||
if (bat_ads_client_.is_bound()) {
|
||||
bat_ads_client_->CloseNotificationAd(placement_id);
|
||||
}
|
||||
}
|
||||
@@ -93,7 +93,7 @@ void BatAdsClientMojoBridge::RecordAdEventForId(
|
||||
const std::string& ad_type,
|
||||
const std::string& confirmation_type,
|
||||
const base::Time time) const {
|
||||
if (connected()) {
|
||||
if (bat_ads_client_.is_bound()) {
|
||||
bat_ads_client_->RecordAdEventForId(id, ad_type, confirmation_type, time);
|
||||
}
|
||||
}
|
||||
@@ -101,7 +101,7 @@ void BatAdsClientMojoBridge::RecordAdEventForId(
|
||||
std::vector<base::Time> BatAdsClientMojoBridge::GetAdEventHistory(
|
||||
const std::string& ad_type,
|
||||
const std::string& confirmation_type) const {
|
||||
if (!connected()) {
|
||||
if (!bat_ads_client_.is_bound()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ std::vector<base::Time> BatAdsClientMojoBridge::GetAdEventHistory(
|
||||
|
||||
void BatAdsClientMojoBridge::ResetAdEventHistoryForId(
|
||||
const std::string& id) const {
|
||||
if (connected()) {
|
||||
if (bat_ads_client_.is_bound()) {
|
||||
bat_ads_client_->ResetAdEventHistoryForId(id);
|
||||
}
|
||||
}
|
||||
@@ -138,7 +138,7 @@ void OnUrlRequest(ads::UrlRequestCallback callback,
|
||||
void BatAdsClientMojoBridge::UrlRequest(
|
||||
ads::mojom::UrlRequestInfoPtr url_request,
|
||||
ads::UrlRequestCallback callback) {
|
||||
if (!connected()) {
|
||||
if (!bat_ads_client_.is_bound()) {
|
||||
ads::mojom::UrlResponseInfo response;
|
||||
response.url = url_request->url;
|
||||
response.status_code = -1;
|
||||
@@ -154,7 +154,7 @@ void BatAdsClientMojoBridge::UrlRequest(
|
||||
void BatAdsClientMojoBridge::Save(const std::string& name,
|
||||
const std::string& value,
|
||||
ads::SaveCallback callback) {
|
||||
if (!connected()) {
|
||||
if (!bat_ads_client_.is_bound()) {
|
||||
std::move(callback).Run(/*success*/ false);
|
||||
return;
|
||||
}
|
||||
@@ -165,7 +165,7 @@ void BatAdsClientMojoBridge::Save(const std::string& name,
|
||||
void BatAdsClientMojoBridge::LoadFileResource(const std::string& id,
|
||||
const int version,
|
||||
ads::LoadFileCallback callback) {
|
||||
if (!connected()) {
|
||||
if (!bat_ads_client_.is_bound()) {
|
||||
std::move(callback).Run(base::File());
|
||||
return;
|
||||
}
|
||||
@@ -177,7 +177,7 @@ void BatAdsClientMojoBridge::GetBrowsingHistory(
|
||||
const int max_count,
|
||||
const int days_ago,
|
||||
ads::GetBrowsingHistoryCallback callback) {
|
||||
if (!connected()) {
|
||||
if (!bat_ads_client_.is_bound()) {
|
||||
std::move(callback).Run({});
|
||||
return;
|
||||
}
|
||||
@@ -187,21 +187,21 @@ void BatAdsClientMojoBridge::GetBrowsingHistory(
|
||||
|
||||
void BatAdsClientMojoBridge::RecordP2AEvent(const std::string& name,
|
||||
base::Value::List value) {
|
||||
if (connected()) {
|
||||
if (bat_ads_client_.is_bound()) {
|
||||
bat_ads_client_->RecordP2AEvent(name, std::move(value));
|
||||
}
|
||||
}
|
||||
|
||||
void BatAdsClientMojoBridge::LogTrainingInstance(
|
||||
std::vector<brave_federated::mojom::CovariateInfoPtr> training_instance) {
|
||||
if (connected()) {
|
||||
if (bat_ads_client_.is_bound()) {
|
||||
bat_ads_client_->LogTrainingInstance(std::move(training_instance));
|
||||
}
|
||||
}
|
||||
|
||||
void BatAdsClientMojoBridge::Load(const std::string& name,
|
||||
ads::LoadCallback callback) {
|
||||
if (!connected()) {
|
||||
if (!bat_ads_client_.is_bound()) {
|
||||
std::move(callback).Run(/*success*/ false, /*value*/ {});
|
||||
return;
|
||||
}
|
||||
@@ -210,7 +210,7 @@ void BatAdsClientMojoBridge::Load(const std::string& name,
|
||||
}
|
||||
|
||||
std::string BatAdsClientMojoBridge::LoadDataResource(const std::string& name) {
|
||||
if (!connected()) {
|
||||
if (!bat_ads_client_.is_bound()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ void BatAdsClientMojoBridge::RunDBTransaction(
|
||||
}
|
||||
|
||||
void BatAdsClientMojoBridge::ClearScheduledCaptcha() {
|
||||
if (connected()) {
|
||||
if (bat_ads_client_.is_bound()) {
|
||||
bat_ads_client_->ClearScheduledCaptcha();
|
||||
}
|
||||
}
|
||||
@@ -235,7 +235,7 @@ void BatAdsClientMojoBridge::ClearScheduledCaptcha() {
|
||||
void BatAdsClientMojoBridge::GetScheduledCaptcha(
|
||||
const std::string& payment_id,
|
||||
ads::GetScheduledCaptchaCallback callback) {
|
||||
if (!connected()) {
|
||||
if (!bat_ads_client_.is_bound()) {
|
||||
return std::move(callback).Run({});
|
||||
}
|
||||
|
||||
@@ -246,14 +246,14 @@ void BatAdsClientMojoBridge::ShowScheduledCaptchaNotification(
|
||||
const std::string& payment_id,
|
||||
const std::string& captcha_id,
|
||||
const bool should_show_tooltip_notification) {
|
||||
if (connected()) {
|
||||
if (bat_ads_client_.is_bound()) {
|
||||
bat_ads_client_->ShowScheduledCaptchaNotification(
|
||||
payment_id, captcha_id, should_show_tooltip_notification);
|
||||
}
|
||||
}
|
||||
|
||||
void BatAdsClientMojoBridge::UpdateAdRewards() {
|
||||
if (connected()) {
|
||||
if (bat_ads_client_.is_bound()) {
|
||||
bat_ads_client_->UpdateAdRewards();
|
||||
}
|
||||
}
|
||||
@@ -262,13 +262,13 @@ void BatAdsClientMojoBridge::Log(const char* file,
|
||||
const int line,
|
||||
const int verbose_level,
|
||||
const std::string& message) {
|
||||
if (connected()) {
|
||||
if (bat_ads_client_.is_bound()) {
|
||||
bat_ads_client_->Log(file, line, verbose_level, message);
|
||||
}
|
||||
}
|
||||
|
||||
bool BatAdsClientMojoBridge::GetBooleanPref(const std::string& path) const {
|
||||
if (!connected()) {
|
||||
if (!bat_ads_client_.is_bound()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -279,13 +279,13 @@ bool BatAdsClientMojoBridge::GetBooleanPref(const std::string& path) const {
|
||||
|
||||
void BatAdsClientMojoBridge::SetBooleanPref(const std::string& path,
|
||||
const bool value) {
|
||||
if (connected()) {
|
||||
if (bat_ads_client_.is_bound()) {
|
||||
bat_ads_client_->SetBooleanPref(path, value);
|
||||
}
|
||||
}
|
||||
|
||||
int BatAdsClientMojoBridge::GetIntegerPref(const std::string& path) const {
|
||||
if (!connected()) {
|
||||
if (!bat_ads_client_.is_bound()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -296,13 +296,13 @@ int BatAdsClientMojoBridge::GetIntegerPref(const std::string& path) const {
|
||||
|
||||
void BatAdsClientMojoBridge::SetIntegerPref(const std::string& path,
|
||||
const int value) {
|
||||
if (connected()) {
|
||||
if (bat_ads_client_.is_bound()) {
|
||||
bat_ads_client_->SetIntegerPref(path, value);
|
||||
}
|
||||
}
|
||||
|
||||
double BatAdsClientMojoBridge::GetDoublePref(const std::string& path) const {
|
||||
if (!connected()) {
|
||||
if (!bat_ads_client_.is_bound()) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
@@ -313,14 +313,14 @@ double BatAdsClientMojoBridge::GetDoublePref(const std::string& path) const {
|
||||
|
||||
void BatAdsClientMojoBridge::SetDoublePref(const std::string& path,
|
||||
const double value) {
|
||||
if (connected()) {
|
||||
if (bat_ads_client_.is_bound()) {
|
||||
bat_ads_client_->SetDoublePref(path, value);
|
||||
}
|
||||
}
|
||||
|
||||
std::string BatAdsClientMojoBridge::GetStringPref(
|
||||
const std::string& path) const {
|
||||
if (!connected()) {
|
||||
if (!bat_ads_client_.is_bound()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -331,13 +331,13 @@ std::string BatAdsClientMojoBridge::GetStringPref(
|
||||
|
||||
void BatAdsClientMojoBridge::SetStringPref(const std::string& path,
|
||||
const std::string& value) {
|
||||
if (connected()) {
|
||||
if (bat_ads_client_.is_bound()) {
|
||||
bat_ads_client_->SetStringPref(path, value);
|
||||
}
|
||||
}
|
||||
|
||||
int64_t BatAdsClientMojoBridge::GetInt64Pref(const std::string& path) const {
|
||||
if (!connected()) {
|
||||
if (!bat_ads_client_.is_bound()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -348,13 +348,13 @@ int64_t BatAdsClientMojoBridge::GetInt64Pref(const std::string& path) const {
|
||||
|
||||
void BatAdsClientMojoBridge::SetInt64Pref(const std::string& path,
|
||||
const int64_t value) {
|
||||
if (connected()) {
|
||||
if (bat_ads_client_.is_bound()) {
|
||||
bat_ads_client_->SetInt64Pref(path, value);
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t BatAdsClientMojoBridge::GetUint64Pref(const std::string& path) const {
|
||||
if (!connected()) {
|
||||
if (!bat_ads_client_.is_bound()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -365,13 +365,13 @@ uint64_t BatAdsClientMojoBridge::GetUint64Pref(const std::string& path) const {
|
||||
|
||||
void BatAdsClientMojoBridge::SetUint64Pref(const std::string& path,
|
||||
const uint64_t value) {
|
||||
if (connected()) {
|
||||
if (bat_ads_client_.is_bound()) {
|
||||
bat_ads_client_->SetUint64Pref(path, value);
|
||||
}
|
||||
}
|
||||
|
||||
base::Time BatAdsClientMojoBridge::GetTimePref(const std::string& path) const {
|
||||
if (!connected()) {
|
||||
if (!bat_ads_client_.is_bound()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -382,14 +382,14 @@ base::Time BatAdsClientMojoBridge::GetTimePref(const std::string& path) const {
|
||||
|
||||
void BatAdsClientMojoBridge::SetTimePref(const std::string& path,
|
||||
const base::Time value) {
|
||||
if (connected()) {
|
||||
if (bat_ads_client_.is_bound()) {
|
||||
bat_ads_client_->SetTimePref(path, value);
|
||||
}
|
||||
}
|
||||
|
||||
absl::optional<base::Value::Dict> BatAdsClientMojoBridge::GetDictPref(
|
||||
const std::string& path) const {
|
||||
if (!connected()) {
|
||||
if (!bat_ads_client_.is_bound()) {
|
||||
return absl::nullopt;
|
||||
}
|
||||
|
||||
@@ -400,14 +400,14 @@ absl::optional<base::Value::Dict> BatAdsClientMojoBridge::GetDictPref(
|
||||
|
||||
void BatAdsClientMojoBridge::SetDictPref(const std::string& path,
|
||||
base::Value::Dict value) {
|
||||
if (connected()) {
|
||||
if (bat_ads_client_.is_bound()) {
|
||||
bat_ads_client_->SetDictPref(path, std::move(value));
|
||||
}
|
||||
}
|
||||
|
||||
absl::optional<base::Value::List> BatAdsClientMojoBridge::GetListPref(
|
||||
const std::string& path) const {
|
||||
if (!connected()) {
|
||||
if (!bat_ads_client_.is_bound()) {
|
||||
return absl::nullopt;
|
||||
}
|
||||
|
||||
@@ -418,19 +418,19 @@ absl::optional<base::Value::List> BatAdsClientMojoBridge::GetListPref(
|
||||
|
||||
void BatAdsClientMojoBridge::SetListPref(const std::string& path,
|
||||
base::Value::List value) {
|
||||
if (connected()) {
|
||||
if (bat_ads_client_.is_bound()) {
|
||||
bat_ads_client_->SetListPref(path, std::move(value));
|
||||
}
|
||||
}
|
||||
|
||||
void BatAdsClientMojoBridge::ClearPref(const std::string& path) {
|
||||
if (connected()) {
|
||||
if (bat_ads_client_.is_bound()) {
|
||||
bat_ads_client_->ClearPref(path);
|
||||
}
|
||||
}
|
||||
|
||||
bool BatAdsClientMojoBridge::HasPrefPath(const std::string& path) const {
|
||||
if (!connected()) {
|
||||
if (!bat_ads_client_.is_bound()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -439,10 +439,4 @@ bool BatAdsClientMojoBridge::HasPrefPath(const std::string& path) const {
|
||||
return value;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool BatAdsClientMojoBridge::connected() const {
|
||||
return bat_ads_client_.is_bound();
|
||||
}
|
||||
|
||||
} // namespace bat_ads
|
||||
|
||||
@@ -127,8 +127,6 @@ class BatAdsClientMojoBridge : public ads::AdsClient {
|
||||
const std::string& message) override;
|
||||
|
||||
private:
|
||||
bool connected() const;
|
||||
|
||||
mojo::AssociatedRemote<mojom::BatAdsClient> bat_ads_client_;
|
||||
};
|
||||
|
||||
|
||||
@@ -73,10 +73,12 @@ void Account::SetWallet(const std::string& id, const std::string& seed) {
|
||||
return;
|
||||
}
|
||||
|
||||
BLOG(1, "Successfully set wallet");
|
||||
|
||||
const WalletInfo& wallet = GetWallet();
|
||||
NotifyWalletDidUpdate(wallet);
|
||||
|
||||
if (wallet.WasUpdated(last_wallet_copy)) {
|
||||
BLOG(1, "Successfully set wallet");
|
||||
NotifyWalletDidUpdate(wallet);
|
||||
}
|
||||
|
||||
if (wallet.HasChanged(last_wallet_copy)) {
|
||||
WalletDidChange(wallet);
|
||||
|
||||
@@ -11,8 +11,12 @@ bool WalletInfo::IsValid() const {
|
||||
return !id.empty() && !secret_key.empty();
|
||||
}
|
||||
|
||||
bool WalletInfo::WasUpdated(const WalletInfo& other) const {
|
||||
return *this != other;
|
||||
}
|
||||
|
||||
bool WalletInfo::HasChanged(const WalletInfo& other) const {
|
||||
return other.IsValid() && (*this != other);
|
||||
return other.IsValid() && WasUpdated(other);
|
||||
}
|
||||
|
||||
bool WalletInfo::operator==(const WalletInfo& other) const {
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace ads {
|
||||
struct WalletInfo final {
|
||||
bool IsValid() const;
|
||||
|
||||
bool WasUpdated(const WalletInfo& other) const;
|
||||
bool HasChanged(const WalletInfo& other) const;
|
||||
|
||||
bool operator==(const WalletInfo& other) const;
|
||||
|
||||
@@ -141,11 +141,11 @@ void Transfer::Cancel(const int32_t tab_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
BLOG(1, "Cancelled ad transfer for creative instance id "
|
||||
BLOG(1, "Canceled ad transfer for creative instance id "
|
||||
<< last_clicked_ad_.creative_instance_id << " with tab id "
|
||||
<< tab_id);
|
||||
|
||||
NotifyCancelledTransfer(last_clicked_ad_, tab_id);
|
||||
NotifyCanceledTransfer(last_clicked_ad_, tab_id);
|
||||
}
|
||||
|
||||
void Transfer::FailedToTransferAd(const AdInfo& ad) const {
|
||||
@@ -167,10 +167,10 @@ void Transfer::NotifyDidTransferAd(const AdInfo& ad) const {
|
||||
}
|
||||
}
|
||||
|
||||
void Transfer::NotifyCancelledTransfer(const AdInfo& ad,
|
||||
const int32_t tab_id) const {
|
||||
void Transfer::NotifyCanceledTransfer(const AdInfo& ad,
|
||||
const int32_t tab_id) const {
|
||||
for (TransferObserver& observer : observers_) {
|
||||
observer.OnCancelledTransfer(ad, tab_id);
|
||||
observer.OnCanceledTransfer(ad, tab_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ class Transfer final : public TabManagerObserver {
|
||||
|
||||
void NotifyWillTransferAd(const AdInfo& ad, base::Time time) const;
|
||||
void NotifyDidTransferAd(const AdInfo& ad) const;
|
||||
void NotifyCancelledTransfer(const AdInfo& ad, int32_t tab_id) const;
|
||||
void NotifyCanceledTransfer(const AdInfo& ad, int32_t tab_id) const;
|
||||
void NotifyFailedToTransferAd(const AdInfo& ad) const;
|
||||
|
||||
// TabManagerObserver:
|
||||
|
||||
@@ -23,8 +23,8 @@ class TransferObserver : public base::CheckedObserver {
|
||||
// Invoked when an ad is transferred
|
||||
virtual void OnDidTransferAd(const AdInfo& ad) {}
|
||||
|
||||
// Invoked when an ad transfer is cancelled
|
||||
virtual void OnCancelledTransfer(const AdInfo& ad, const int32_t tab_id) {}
|
||||
// Invoked when an ad transfer is canceled
|
||||
virtual void OnCanceledTransfer(const AdInfo& ad, const int32_t tab_id) {}
|
||||
|
||||
// Invoked when an ad fails to transfer
|
||||
virtual void OnFailedToTransferAd(const AdInfo& ad) {}
|
||||
|
||||
Reference in New Issue
Block a user