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

Implement staging environment support for Android Ads #2660

Merged
merged 1 commit into from
Jun 11, 2019
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
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() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like this could all be done with just the single function, unless there are other reasons for splitting it out like this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did that originally and due to #if etc. the code was harder to read

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, gotcha.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Eventually this code should be abstracted out of the ads service, this changed was mainly to add support for Android Ads

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