Skip to content

Commit af8250f

Browse files
authored
Merge pull request #8220 from brave/rewards-fix-crash-starting-rewards
Onboarding should start process if necessary
2 parents 2f9680a + 23fae3b commit af8250f

File tree

10 files changed

+85
-152
lines changed

10 files changed

+85
-152
lines changed

browser/brave_rewards/android/brave_rewards_native_worker.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,7 @@ void BraveRewardsNativeWorker::StartProcess(JNIEnv* env) {
271271
}
272272
}
273273

274-
void BraveRewardsNativeWorker::OnStartProcess(
275-
const ledger::type::Result result) {
274+
void BraveRewardsNativeWorker::OnStartProcess() {
276275
JNIEnv* env = base::android::AttachCurrentThread();
277276
Java_BraveRewardsNativeWorker_OnStartProcess(
278277
env, weak_java_brave_rewards_native_worker_.get(env));

browser/brave_rewards/android/brave_rewards_native_worker.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,17 @@ class BraveRewardsNativeWorker : public brave_rewards::RewardsServiceObserver,
214214
JNIEnv* env,
215215
bool isAutoContributeEnabled);
216216
void StartProcess(JNIEnv* env);
217-
void OnStartProcess(const ledger::type::Result result);
217+
218218
private:
219219
std::string StdStrStrMapToJsonString(
220220
const base::flat_map<std::string, std::string>& args);
221221

222222
void OnBalance(
223223
const ledger::type::Result result,
224224
ledger::type::BalancePtr balance);
225+
226+
void OnStartProcess();
227+
225228
JavaObjectWeakGlobalRef weak_java_brave_rewards_native_worker_;
226229
brave_rewards::RewardsService* brave_rewards_service_;
227230
ledger::type::RewardsParameters parameters_;

browser/extensions/api/brave_rewards_api.cc

+16-25
Original file line numberDiff line numberDiff line change
@@ -313,29 +313,20 @@ ExtensionFunction::ResponseAction BraveRewardsTipUserFunction::Run() {
313313
->AddRewardsExtension();
314314

315315
rewards_service->StartProcess(
316-
base::BindOnce(
317-
&BraveRewardsTipUserFunction::OnTipUserStartProcess,
318-
this,
319-
params->publisher_key));
316+
base::BindOnce(&BraveRewardsTipUserFunction::OnProcessStarted, this,
317+
params->publisher_key));
320318

321319
return RespondNow(NoArguments());
322320
}
323321

324-
void BraveRewardsTipUserFunction::OnTipUserStartProcess(
325-
const std::string& publisher_key,
326-
ledger::type::Result result) {
327-
if (result != ledger::type::Result::LEDGER_OK) {
328-
Release();
329-
return;
330-
}
331-
322+
void BraveRewardsTipUserFunction::OnProcessStarted(
323+
const std::string& publisher_key) {
332324
Profile* profile = Profile::FromBrowserContext(browser_context());
333325
auto* rewards_service = RewardsServiceFactory::GetForProfile(profile);
334326
if (!rewards_service) {
335327
Release();
336328
return;
337329
}
338-
339330
rewards_service->GetPublisherInfo(
340331
publisher_key,
341332
base::Bind(&BraveRewardsTipUserFunction::OnTipUserGetPublisherInfo,
@@ -677,15 +668,15 @@ ExtensionFunction::ResponseAction BraveRewardsSaveAdsSettingFunction::Run() {
677668
Profile* profile = Profile::FromBrowserContext(browser_context());
678669
RewardsService* rewards_service =
679670
RewardsServiceFactory::GetForProfile(profile);
680-
AdsService* ads_service_ = AdsServiceFactory::GetForProfile(profile);
671+
AdsService* ads_service = AdsServiceFactory::GetForProfile(profile);
681672

682-
if (!rewards_service || !ads_service_) {
673+
if (!rewards_service || !ads_service) {
683674
return RespondNow(Error("Service is not initialized"));
684675
}
685676

686677
if (params->key == "adsEnabled") {
687678
const auto is_enabled =
688-
params->value == "true" && ads_service_->IsSupportedLocale();
679+
params->value == "true" && ads_service->IsSupportedLocale();
689680
rewards_service->SetAdsEnabled(is_enabled);
690681
}
691682

@@ -1105,14 +1096,14 @@ BraveRewardsGetAdsEnabledFunction::
11051096
ExtensionFunction::ResponseAction
11061097
BraveRewardsGetAdsEnabledFunction::Run() {
11071098
Profile* profile = Profile::FromBrowserContext(browser_context());
1108-
AdsService* ads_service_ =
1099+
AdsService* ads_service =
11091100
AdsServiceFactory::GetForProfile(profile);
11101101

1111-
if (!ads_service_) {
1102+
if (!ads_service) {
11121103
return RespondNow(Error("Ads service is not initialized"));
11131104
}
11141105

1115-
const bool enabled = ads_service_->IsEnabled();
1106+
const bool enabled = ads_service->IsEnabled();
11161107
return RespondNow(OneArgument(base::Value(enabled)));
11171108
}
11181109

@@ -1122,16 +1113,16 @@ BraveRewardsGetAdsAccountStatementFunction::
11221113
ExtensionFunction::ResponseAction
11231114
BraveRewardsGetAdsAccountStatementFunction::Run() {
11241115
Profile* profile = Profile::FromBrowserContext(browser_context());
1125-
AdsService* ads_service_ =
1116+
AdsService* ads_service =
11261117
AdsServiceFactory::GetForProfile(profile);
11271118

1128-
if (!ads_service_) {
1119+
if (!ads_service) {
11291120
return RespondNow(Error("Ads service is not initialized"));
11301121
}
11311122

11321123
AddRef(); // Balanced in OnGetAdsAccountStatement().
11331124

1134-
ads_service_->GetAccountStatement(base::BindOnce(
1125+
ads_service->GetAccountStatement(base::BindOnce(
11351126
&BraveRewardsGetAdsAccountStatementFunction::OnGetAdsAccountStatement,
11361127
this));
11371128
return RespondLater();
@@ -1170,14 +1161,14 @@ BraveRewardsGetAdsSupportedFunction::
11701161
ExtensionFunction::ResponseAction
11711162
BraveRewardsGetAdsSupportedFunction::Run() {
11721163
Profile* profile = Profile::FromBrowserContext(browser_context());
1173-
AdsService* ads_service_ =
1164+
AdsService* ads_service =
11741165
AdsServiceFactory::GetForProfile(profile);
11751166

1176-
if (!ads_service_) {
1167+
if (!ads_service) {
11771168
return RespondNow(Error("Ads service is not initialized"));
11781169
}
11791170

1180-
const bool supported = ads_service_->IsSupportedLocale();
1171+
const bool supported = ads_service->IsSupportedLocale();
11811172
return RespondNow(OneArgument(base::Value(supported)));
11821173
}
11831174

browser/extensions/api/brave_rewards_api.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@ class BraveRewardsTipUserFunction : public ExtensionFunction {
102102
ResponseAction Run() override;
103103

104104
private:
105-
void OnTipUserStartProcess(
106-
const std::string& publisher_key,
107-
ledger::type::Result result);
105+
void OnProcessStarted(const std::string& publisher_key);
108106
void OnTipUserGetPublisherInfo(
109107
const ledger::type::Result result,
110108
ledger::type::PublisherInfoPtr info);

components/brave_ads/browser/ads_service_impl_unittest.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ class MockRewardsService : public RewardsService {
238238

239239
MOCK_METHOD1(CreateWallet, void(brave_rewards::CreateWalletCallback));
240240

241-
MOCK_METHOD1(StartProcess, void(brave_rewards::StartProcessCallback));
241+
MOCK_METHOD1(StartProcess, void(base::OnceClosure));
242242

243243
MOCK_METHOD1(GetWalletPassphrase,
244244
void(brave_rewards::GetWalletPassphraseCallback));

components/brave_new_tab_ui/containers/newTab/index.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,7 @@ class NewTabPage extends React.Component<Props, State> {
389389
}
390390

391391
startRewards = () => {
392-
chrome.braveRewards.saveAdsSetting('adsEnabled', 'true')
393-
chrome.braveRewards.setAutoContributeEnabled(true)
392+
chrome.braveRewards.saveOnboardingResult('opted-in')
394393
}
395394

396395
dismissBrandedWallpaperNotification = (isUserAction: boolean) => {

components/brave_rewards/browser/rewards_service.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,6 @@ using GetEventLogsCallback =
130130
using GetBraveWalletCallback =
131131
base::OnceCallback<void(ledger::type::BraveWalletPtr wallet)>;
132132

133-
using StartProcessCallback =
134-
base::OnceCallback<void(ledger::type::Result result)>;
135-
136133
using GetWalletPassphraseCallback = base::Callback<void(const std::string&)>;
137134

138135
enum class OnboardingResult {
@@ -365,7 +362,7 @@ class RewardsService : public KeyedService {
365362

366363
virtual void GetBraveWallet(GetBraveWalletCallback callback) = 0;
367364

368-
virtual void StartProcess(StartProcessCallback callback) = 0;
365+
virtual void StartProcess(base::OnceClosure callback) = 0;
369366

370367
virtual void GetWalletPassphrase(GetWalletPassphraseCallback callback) = 0;
371368

0 commit comments

Comments
 (0)