Skip to content

Commit c18061d

Browse files
authored
Merge pull request #9744 from /issues/14236
Refactored Brave Ads Result to bool
2 parents 0e0d447 + 8b2db3d commit c18061d

File tree

130 files changed

+665
-771
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+665
-771
lines changed

components/brave_ads/browser/ads_service_impl.cc

+12-12
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,8 @@ void AdsServiceImpl::OnCreate() {
680680
bat_ads_->Initialize(base::BindOnce(std::move(callback)));
681681
}
682682

683-
void AdsServiceImpl::OnInitialize(const int32_t result) {
684-
if (result != ads::Result::SUCCESS) {
683+
void AdsServiceImpl::OnInitialize(const bool success) {
684+
if (!success) {
685685
VLOG(0) << "Failed to initialize ads";
686686

687687
is_initialized_ = false;
@@ -706,10 +706,10 @@ void AdsServiceImpl::ShutdownBatAds() {
706706
base::BindOnce(&AdsServiceImpl::OnShutdownBatAds, AsWeakPtr()));
707707
}
708708

709-
void AdsServiceImpl::OnShutdownBatAds(const int32_t result) {
709+
void AdsServiceImpl::OnShutdownBatAds(const bool success) {
710710
DCHECK(is_initialized_);
711711

712-
if (result != ads::Result::SUCCESS) {
712+
if (!success) {
713713
VLOG(0) << "Failed to shutdown ads";
714714
return;
715715
}
@@ -807,10 +807,10 @@ void AdsServiceImpl::ResetAllState(const bool should_shutdown) {
807807
base::BindOnce(&AdsServiceImpl::OnShutdownAndResetBatAds, AsWeakPtr()));
808808
}
809809

810-
void AdsServiceImpl::OnShutdownAndResetBatAds(const int32_t result) {
810+
void AdsServiceImpl::OnShutdownAndResetBatAds(const bool success) {
811811
DCHECK(is_initialized_);
812812

813-
if (result != ads::Result::SUCCESS) {
813+
if (!success) {
814814
VLOG(0) << "Failed to shutdown and reset ads state";
815815
return;
816816
}
@@ -1346,8 +1346,8 @@ void AdsServiceImpl::OnGetAdDiagnostics(GetAdDiagnosticsCallback callback,
13461346
std::move(callback).Run(success, json);
13471347
}
13481348

1349-
void AdsServiceImpl::OnRemoveAllHistory(const int32_t result) {
1350-
if (result != ads::Result::SUCCESS) {
1349+
void AdsServiceImpl::OnRemoveAllHistory(const bool success) {
1350+
if (!success) {
13511351
VLOG(0) << "Failed to remove ads history";
13521352
return;
13531353
}
@@ -1401,9 +1401,9 @@ void AdsServiceImpl::OnLoaded(const ads::LoadCallback& callback,
14011401
}
14021402

14031403
if (value.empty())
1404-
callback(ads::Result::FAILED, value);
1404+
callback(/* success */ false, value);
14051405
else
1406-
callback(ads::Result::SUCCESS, value);
1406+
callback(/* success */ true, value);
14071407
}
14081408

14091409
void AdsServiceImpl::OnSaved(const ads::ResultCallback& callback,
@@ -1412,7 +1412,7 @@ void AdsServiceImpl::OnSaved(const ads::ResultCallback& callback,
14121412
return;
14131413
}
14141414

1415-
callback(success ? ads::Result::SUCCESS : ads::Result::FAILED);
1415+
callback(success);
14161416
}
14171417

14181418
void AdsServiceImpl::MigratePrefs() {
@@ -2047,7 +2047,7 @@ void AdsServiceImpl::LoadAdsResource(const std::string& id,
20472047
g_brave_browser_process->resource_component()->GetPath(id, version);
20482048

20492049
if (!path) {
2050-
callback(ads::Result::FAILED, "");
2050+
callback(/* success */ false, "");
20512051
return;
20522052
}
20532053

components/brave_ads/browser/ads_service_impl.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,10 @@ class AdsServiceImpl : public AdsService,
200200

201201
void OnCreate();
202202

203-
void OnInitialize(const int32_t result);
203+
void OnInitialize(const bool success);
204204

205205
void ShutdownBatAds();
206-
void OnShutdownBatAds(const int32_t result);
206+
void OnShutdownBatAds(const bool success);
207207

208208
bool StartService();
209209

@@ -212,7 +212,7 @@ class AdsServiceImpl : public AdsService,
212212
void Stop();
213213

214214
void ResetState();
215-
void OnShutdownAndResetBatAds(const int32_t result);
215+
void OnShutdownAndResetBatAds(const bool success);
216216
void OnResetAllState(const bool success);
217217

218218
void DetectUncertainFuture();
@@ -272,7 +272,7 @@ class AdsServiceImpl : public AdsService,
272272
const bool success,
273273
const std::string& json);
274274

275-
void OnRemoveAllHistory(const int32_t result);
275+
void OnRemoveAllHistory(const bool success);
276276

277277
void OnToggleAdThumbUp(OnToggleAdThumbUpCallback callback,
278278
const std::string& creative_instance_id,

components/brave_ads/browser/notification_helper_android.cc

+5-3
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,15 @@ bool NotificationHelperAndroid::CanShowNativeNotifications() {
5555
const bool is_notification_channel_enabled =
5656
IsBraveAdsNotificationChannelEnabled(is_foreground);
5757

58-
bool result = is_notifications_enabled && is_notification_channel_enabled;
58+
bool can_show_native_notifications =
59+
is_notifications_enabled && is_notification_channel_enabled;
5960

6061
if (!is_foreground) {
61-
result = result && CanShowBackgroundNotifications();
62+
can_show_native_notifications =
63+
can_show_native_notifications && CanShowBackgroundNotifications();
6264
}
6365

64-
return result;
66+
return can_show_native_notifications;
6567
}
6668

6769
bool NotificationHelperAndroid::ShowMyFirstAdNotification() {

components/services/bat_ads/bat_ads_client_mojo_bridge.cc

+11-25
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,6 @@
1313

1414
namespace bat_ads {
1515

16-
namespace {
17-
18-
ads::Result ToAdsResult(
19-
const int32_t result) {
20-
return (ads::Result)result;
21-
}
22-
23-
} // namespace
24-
25-
///////////////////////////////////////////////////////////////////////////////
26-
2716
BatAdsClientMojoBridge::BatAdsClientMojoBridge(
2817
mojo::PendingAssociatedRemote<mojom::BatAdsClient> client_info) {
2918
bat_ads_client_.Bind(std::move(client_info));
@@ -159,18 +148,16 @@ void BatAdsClientMojoBridge::UrlRequest(ads::mojom::UrlRequestPtr url_request,
159148
base::BindOnce(&OnUrlRequest, std::move(callback)));
160149
}
161150

162-
void OnSave(
163-
const ads::ResultCallback& callback,
164-
const int32_t result) {
165-
callback(ToAdsResult(result));
151+
void OnSave(const ads::ResultCallback& callback, const bool success) {
152+
callback(success);
166153
}
167154

168155
void BatAdsClientMojoBridge::Save(
169156
const std::string& name,
170157
const std::string& value,
171158
ads::ResultCallback callback) {
172159
if (!connected()) {
173-
callback(ads::Result::FAILED);
160+
callback(/* success */ false);
174161
return;
175162
}
176163

@@ -179,16 +166,16 @@ void BatAdsClientMojoBridge::Save(
179166
}
180167

181168
void OnLoadAdsResource(const ads::LoadCallback& callback,
182-
const int32_t result,
169+
const bool success,
183170
const std::string& value) {
184-
callback(ToAdsResult(result), value);
171+
callback(success, value);
185172
}
186173

187174
void BatAdsClientMojoBridge::LoadAdsResource(const std::string& id,
188175
const int version,
189176
ads::LoadCallback callback) {
190177
if (!connected()) {
191-
callback(ads::Result::FAILED, "");
178+
callback(/* success */ false, "");
192179
return;
193180
}
194181

@@ -225,18 +212,17 @@ void BatAdsClientMojoBridge::RecordP2AEvent(const std::string& name,
225212
bat_ads_client_->RecordP2AEvent(name, type, value);
226213
}
227214

228-
void OnLoad(
229-
const ads::LoadCallback& callback,
230-
const int32_t result,
231-
const std::string& value) {
232-
callback(ToAdsResult(result), value);
215+
void OnLoad(const ads::LoadCallback& callback,
216+
const bool success,
217+
const std::string& value) {
218+
callback(success, value);
233219
}
234220

235221
void BatAdsClientMojoBridge::Load(
236222
const std::string& name,
237223
ads::LoadCallback callback) {
238224
if (!connected()) {
239-
callback(ads::Result::FAILED, "");
225+
callback(/* success */ false, "");
240226
return;
241227
}
242228

components/services/bat_ads/bat_ads_impl.cc

+8-10
Original file line numberDiff line numberDiff line change
@@ -289,21 +289,19 @@ void BatAdsImpl::OnResourceComponentUpdated(const std::string& id) {
289289

290290
///////////////////////////////////////////////////////////////////////////////
291291

292-
void BatAdsImpl::OnInitialize(
293-
CallbackHolder<InitializeCallback>* holder,
294-
const int32_t result) {
292+
void BatAdsImpl::OnInitialize(CallbackHolder<InitializeCallback>* holder,
293+
const bool success) {
295294
if (holder->is_valid()) {
296-
std::move(holder->get()).Run((ads::Result)result);
295+
std::move(holder->get()).Run(success);
297296
}
298297

299298
delete holder;
300299
}
301300

302-
void BatAdsImpl::OnShutdown(
303-
CallbackHolder<ShutdownCallback>* holder,
304-
const int32_t result) {
301+
void BatAdsImpl::OnShutdown(CallbackHolder<ShutdownCallback>* holder,
302+
const bool success) {
305303
if (holder->is_valid()) {
306-
std::move(holder->get()).Run((ads::Result)result);
304+
std::move(holder->get()).Run(success);
307305
}
308306

309307
delete holder;
@@ -323,9 +321,9 @@ void BatAdsImpl::OnGetInlineContentAd(
323321

324322
void BatAdsImpl::OnRemoveAllHistory(
325323
CallbackHolder<RemoveAllHistoryCallback>* holder,
326-
const int32_t result) {
324+
const bool success) {
327325
if (holder->is_valid()) {
328-
std::move(holder->get()).Run((ads::Result)result);
326+
std::move(holder->get()).Run(success);
329327
}
330328

331329
delete holder;

components/services/bat_ads/bat_ads_impl.h

+28-30
Original file line numberDiff line numberDiff line change
@@ -178,36 +178,34 @@ class BatAdsImpl :
178178
Callback callback_;
179179
};
180180

181-
static void OnInitialize(
182-
CallbackHolder<InitializeCallback>* holder,
183-
const int32_t result);
184-
185-
static void OnShutdown(
186-
CallbackHolder<ShutdownCallback>* holder,
187-
const int32_t result);
188-
189-
static void OnGetInlineContentAd(
190-
CallbackHolder<GetInlineContentAdCallback>* holder,
191-
const bool success,
192-
const std::string& dimensions,
193-
const ads::InlineContentAdInfo& ad);
194-
195-
static void OnRemoveAllHistory(
196-
CallbackHolder<RemoveAllHistoryCallback>* holder,
197-
const int32_t result);
198-
199-
static void OnGetAccountStatement(
200-
CallbackHolder<GetAccountStatementCallback>* holder,
201-
const bool success,
202-
const ads::StatementInfo& statement);
203-
204-
static void OnGetAdDiagnostics(
205-
CallbackHolder<GetAdDiagnosticsCallback>* holder,
206-
const bool success,
207-
const std::string& json);
208-
209-
std::unique_ptr<BatAdsClientMojoBridge> bat_ads_client_mojo_proxy_;
210-
std::unique_ptr<ads::Ads> ads_;
181+
static void OnInitialize(CallbackHolder<InitializeCallback>* holder,
182+
const bool success);
183+
184+
static void OnShutdown(CallbackHolder<ShutdownCallback>* holder,
185+
const bool success);
186+
187+
static void OnGetInlineContentAd(
188+
CallbackHolder<GetInlineContentAdCallback>* holder,
189+
const bool success,
190+
const std::string& dimensions,
191+
const ads::InlineContentAdInfo& ad);
192+
193+
static void OnRemoveAllHistory(
194+
CallbackHolder<RemoveAllHistoryCallback>* holder,
195+
const bool success);
196+
197+
static void OnGetAccountStatement(
198+
CallbackHolder<GetAccountStatementCallback>* holder,
199+
const bool success,
200+
const ads::StatementInfo& statement);
201+
202+
static void OnGetAdDiagnostics(
203+
CallbackHolder<GetAdDiagnosticsCallback>* holder,
204+
const bool success,
205+
const std::string& json);
206+
207+
std::unique_ptr<BatAdsClientMojoBridge> bat_ads_client_mojo_proxy_;
208+
std::unique_ptr<ads::Ads> ads_;
211209
};
212210

213211
} // namespace bat_ads

components/services/bat_ads/public/cpp/ads_client_mojo_bridge.cc

+10-12
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ void AdsClientMojoBridge::Log(
126126
// static
127127
void AdsClientMojoBridge::OnLoadAdsResource(
128128
CallbackHolder<LoadCallback>* holder,
129-
const ads::Result result,
129+
const bool success,
130130
const std::string& value) {
131131
DCHECK(holder);
132132

133133
if (holder->is_valid()) {
134-
std::move(holder->get()).Run((int32_t)result, std::move(value));
134+
std::move(holder->get()).Run(success, std::move(value));
135135
}
136136

137137
delete holder;
@@ -180,14 +180,13 @@ void AdsClientMojoBridge::RecordP2AEvent(const std::string& name,
180180
}
181181

182182
// static
183-
void AdsClientMojoBridge::OnLoad(
184-
CallbackHolder<LoadCallback>* holder,
185-
const ads::Result result,
186-
const std::string& value) {
183+
void AdsClientMojoBridge::OnLoad(CallbackHolder<LoadCallback>* holder,
184+
const bool success,
185+
const std::string& value) {
187186
DCHECK(holder);
188187

189188
if (holder->is_valid()) {
190-
std::move(holder->get()).Run((int32_t)result, std::move(value));
189+
std::move(holder->get()).Run(success, std::move(value));
191190
}
192191

193192
delete holder;
@@ -204,13 +203,12 @@ void AdsClientMojoBridge::Load(
204203
}
205204

206205
// static
207-
void AdsClientMojoBridge::OnSave(
208-
CallbackHolder<SaveCallback>* holder,
209-
const ads::Result result) {
206+
void AdsClientMojoBridge::OnSave(CallbackHolder<SaveCallback>* holder,
207+
const bool success) {
210208
DCHECK(holder);
211209

212210
if (holder->is_valid()) {
213-
std::move(holder->get()).Run((int32_t)result);
211+
std::move(holder->get()).Run(success);
214212
}
215213

216214
delete holder;
@@ -253,7 +251,7 @@ void AdsClientMojoBridge::UrlRequest(ads::mojom::UrlRequestPtr url_request,
253251
void AdsClientMojoBridge::ShowNotification(
254252
const std::string& json) {
255253
ads::AdNotificationInfo ad_notification;
256-
if (ad_notification.FromJson(json) != ads::Result::SUCCESS) {
254+
if (!ad_notification.FromJson(json)) {
257255
return;
258256
}
259257

0 commit comments

Comments
 (0)