Skip to content

Commit

Permalink
Implement staging environment support for Android Ads
Browse files Browse the repository at this point in the history
  • Loading branch information
tmancey authored Jun 11, 2019
1 parent 915e7b7 commit 0e1600a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 16 deletions.
57 changes: 41 additions & 16 deletions components/brave_ads/browser/ads_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -409,37 +409,62 @@ bool AdsServiceImpl::StartService() {
bat_ads_service_.set_connection_error_handler(
base::Bind(&AdsServiceImpl::MaybeStart, AsWeakPtr(), true));

bool is_production = false;
UpdateIsProductionFlag();
UpdateIsDebugFlag();
UpdateIsTestingFlag();

return true;
}

#if defined(OS_ANDROID)
void AdsServiceImpl::UpdateIsProductionFlag() {
auto is_production =
profile_->GetPrefs()->GetBoolean(prefs::kUseRewardsStagingServer);
bat_ads_service_->SetProduction(is_production, base::NullCallback());
}
#else
void AdsServiceImpl::UpdateIsProductionFlag() {
#if defined(OFFICIAL_BUILD)
is_production = true;
#endif
bool is_debug = true;
#if defined(NDEBUG)
is_debug = false;
auto is_production = true;
#else
auto is_production = false;
#endif
bool is_testing = false;

const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();

const auto& command_line = *base::CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kStaging)) {
is_production = false;
}
if (command_line.HasSwitch(switches::kProduction)) {
} else if (command_line.HasSwitch(switches::kProduction)) {
is_production = true;
}

bat_ads_service_->SetProduction(is_production, base::NullCallback());
}
#endif

void AdsServiceImpl::UpdateIsDebugFlag() {
#if defined(NDEBUG)
auto is_debug = false;
#else
auto is_debug = true;
#endif

const auto& command_line = *base::CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kDebug)) {
is_debug = true;
}

bat_ads_service_->SetDebug(is_debug, base::NullCallback());
}

void AdsServiceImpl::UpdateIsTestingFlag() {
auto is_testing = false;

const auto& command_line = *base::CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kTesting)) {
is_testing = true;
}

bat_ads_service_->SetProduction(is_production, base::NullCallback());
bat_ads_service_->SetDebug(is_debug, base::NullCallback());
bat_ads_service_->SetTesting(is_testing, base::NullCallback());

return true;
}

void AdsServiceImpl::Start() {
Expand Down
3 changes: 3 additions & 0 deletions components/brave_ads/browser/ads_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ class AdsServiceImpl : public AdsService,

void Start();
bool StartService();
void UpdateIsProductionFlag();
void UpdateIsDebugFlag();
void UpdateIsTestingFlag();
void Stop();
void ResetTimer();
void CheckIdleState();
Expand Down

0 comments on commit 0e1600a

Please sign in to comment.