Skip to content

Commit

Permalink
Merge pull request #989 from brave/rewards_oop2
Browse files Browse the repository at this point in the history
Rewards on utility process
  • Loading branch information
NejcZdovc authored Dec 31, 2018
2 parents 6cb7f92 + 08555c3 commit 3a4c91a
Show file tree
Hide file tree
Showing 72 changed files with 4,351 additions and 1,111 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ deps = {
"vendor/sparkle": "https://github.com/brave/Sparkle.git@c0759cce415d7c0feae45005c8a013b1898711f0",
"vendor/bat-native-rapidjson": "https://github.com/brave-intl/bat-native-rapidjson.git@86aafe2ef89835ae71c9ed7c2527e3bb3000930e",
"vendor/bip39wally-core-native": "https://github.com/brave-intl/bip39wally-core-native.git@9b119931c702d55be994117eb505d56310720b1d",
"vendor/bat-native-anonize": "https://github.com/brave-intl/bat-native-anonize.git@adeff3254bb90ccdc9699040d5a4e1cd6b8393b7",
"vendor/bat-native-anonize": "https://github.com/brave-intl/bat-native-anonize.git@19fb43fd58b852fd2c6e4d4c68daa99c835f5182",
"vendor/bat-native-tweetnacl": "https://github.com/brave-intl/bat-native-tweetnacl.git@1b4362968c8f22720bfb75af6f506d4ecc0f3116",
"components/brave_sync/extension/brave-sync": "https://github.com/brave/sync.git@249a663a6f163f8fe5d2e96f9605760fb7627da0",
"components/brave_sync/extension/brave-crypto": "https://github.com/brave/crypto@7e391cec6975106fa9f686016f494cb8a782afcd",
Expand Down
3 changes: 3 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
<message name="IDS_SERVICE_BAT_ADS" desc="The bat ads utility process">
Bat Ads Service
</message>
<message name="IDS_UTILITY_PROCESS_LEDGER_NAME" desc="The utility process running ledger">
Bat Ledger Service
</message>
<!-- Brave Shields Defaults -->
<message name="IDS_SETTINGS_BRAVE_SHIELDS_DEFAULTS_TITLE" desc="The title for Brave shields defaults in settings">
Brave shields defaults
Expand Down
1 change: 1 addition & 0 deletions browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ source_set("browser") {
"//base",
"//brave/components/brave_ads/browser",
"//brave/components/brave_referrals/browser",
"//brave/components/brave_rewards/browser",
"//brave/components/brave_shields/browser:brave_shields",
"//brave/components/brave_webtorrent/browser",
"//brave/components/resources",
Expand Down
9 changes: 9 additions & 0 deletions browser/brave_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "brave/common/tor/tor_launcher.mojom.h"
#include "brave/common/tor/switches.h"
#include "brave/components/brave_ads/browser/buildflags/buildflags.h"
#include "brave/components/brave_rewards/browser/buildflags/buildflags.h"
#include "brave/components/brave_shields/browser/brave_shields_util.h"
#include "brave/components/brave_shields/browser/brave_shields_web_contents_observer.h"
#include "brave/components/brave_shields/common/brave_shield_constants.h"
Expand Down Expand Up @@ -49,6 +50,10 @@ using brave_shields::BraveShieldsWebContentsObserver;
#include "brave/components/services/bat_ads/public/interfaces/bat_ads.mojom.h"
#endif

#if BUILDFLAG(BRAVE_REWARDS_ENABLED)
#include "brave/components/services/bat_ledger/public/interfaces/bat_ledger.mojom.h"
#endif

#if BUILDFLAG(ENABLE_EXTENSIONS)
using extensions::ChromeContentBrowserClientExtensionsPart;
#endif
Expand Down Expand Up @@ -194,6 +199,10 @@ void BraveContentBrowserClient::RegisterOutOfProcessServices(
(*services)[bat_ads::mojom::kServiceName] = base::BindRepeating(
l10n_util::GetStringUTF16, IDS_SERVICE_BAT_ADS);
#endif
#if BUILDFLAG(BRAVE_REWARDS_ENABLED)
(*services)[bat_ledger::mojom::kServiceName] = base::BindRepeating(
l10n_util::GetStringUTF16, IDS_UTILITY_PROCESS_LEDGER_NAME);
#endif
}

std::unique_ptr<content::NavigationUIData>
Expand Down
1 change: 1 addition & 0 deletions browser/extensions/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ source_set("extensions") {
]

deps = [
"//base",
"//brave/browser/resources:brave_extension_grit",
"//brave/common/extensions/api",
"//brave/components/brave_rewards/resources/extension:extension_generated_resources",
Expand Down
16 changes: 13 additions & 3 deletions browser/extensions/api/brave_rewards_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <string>

#include "base/bind.h"
#include "brave/browser/brave_rewards/donations_dialog.h"
#include "brave/common/extensions/api/brave_rewards.h"
#include "brave/components/brave_rewards/browser/rewards_service.h"
Expand Down Expand Up @@ -177,11 +178,20 @@ BraveRewardsGetNonVerifiedSettingsFunction::Run() {
RewardsServiceFactory::GetForProfile(profile);
bool non_verified = true;

if (rewards_service_) {
non_verified = rewards_service_->GetPublisherAllowNonVerified();
if (!rewards_service_) {
return RespondNow(OneArgument(
std::make_unique<base::Value>(non_verified)));
}

return RespondNow(OneArgument(std::make_unique<base::Value>(non_verified)));
rewards_service_->GetPublisherAllowNonVerified(base::Bind(
&BraveRewardsGetNonVerifiedSettingsFunction::OnGetAllowNonVerified,
this));
return RespondLater();
}

void BraveRewardsGetNonVerifiedSettingsFunction::OnGetAllowNonVerified(
bool non_verified) {
Respond(OneArgument(std::make_unique<base::Value>(non_verified)));
}

} // namespace api
Expand Down
3 changes: 3 additions & 0 deletions browser/extensions/api/brave_rewards_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ class BraveRewardsGetNonVerifiedSettingsFunction : public UIThreadExtensionFunct
~BraveRewardsGetNonVerifiedSettingsFunction() override;

ResponseAction Run() override;

private:
void OnGetAllowNonVerified(bool non_verified);
};

} // namespace api
Expand Down
6 changes: 5 additions & 1 deletion browser/importer/brave_profile_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,13 @@ void BraveProfileWriter::UpdateLedger(const BraveLedger& ledger) {
}

ledger_ = BraveLedger(ledger);
rewards_service_->IsWalletCreated(
base::Bind(&BraveProfileWriter::OnIsWalletCreated, AsWeakPtr()));
}

void BraveProfileWriter::OnIsWalletCreated(bool created) {
// If a wallet doesn't exist, we need to create one (needed for RecoverWallet)
if (!rewards_service_->IsWalletCreated()) {
if (!created) {
rewards_service_->AddObserver(this);
LOG(INFO) << "Creating wallet to use for import...";
rewards_service_->CreateWallet();
Expand Down
6 changes: 5 additions & 1 deletion browser/importer/brave_profile_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <vector>

#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/importer/profile_writer.h"
#include "net/cookies/canonical_cookie.h"
#include "brave/components/brave_rewards/browser/rewards_service_observer.h"
Expand All @@ -19,7 +20,8 @@ class BraveInProcessImporterBridge;
struct ImportedWindowState;

class BraveProfileWriter : public ProfileWriter,
public brave_rewards::RewardsServiceObserver {
public brave_rewards::RewardsServiceObserver,
public base::SupportsWeakPtr<BraveProfileWriter>{
public:
explicit BraveProfileWriter(Profile* profile);

Expand All @@ -32,6 +34,8 @@ class BraveProfileWriter : public ProfileWriter,

void SetBridge(BraveInProcessImporterBridge* bridge);

void OnIsWalletCreated(bool created);

// brave_rewards::RewardsServiceObserver:
void OnWalletInitialized(brave_rewards::RewardsService* rewards_service,
int error_code) override;
Expand Down
1 change: 1 addition & 0 deletions browser/profiles/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ source_set("profiles") {
"//brave/common/tor",
"//brave/components/brave_ads/browser",
"//brave/components/brave_sync",
"//brave/components/brave_rewards/browser",
"//ui/base",
]
}
2 changes: 2 additions & 0 deletions browser/profiles/brave_profile_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "brave/common/tor/pref_names.h"
#include "brave/common/tor/tor_constants.h"
#include "brave/components/brave_ads/browser/ads_service_factory.h"
#include "brave/components/brave_rewards/browser/rewards_service_factory.h"
#include "brave/components/brave_sync/brave_sync_service_factory.h"
#include "chrome/browser/browser_process.h"
#include "chrome/common/chrome_constants.h"
Expand Down Expand Up @@ -98,6 +99,7 @@ void BraveProfileManager::DoFinalInitForServices(Profile* profile,
// it will only be constructed only when we open chrome:/sync/
brave_sync::BraveSyncServiceFactory::GetForProfile(profile);
brave_ads::AdsServiceFactory::GetForProfile(profile);
brave_rewards::RewardsServiceFactory::GetForProfile(profile);
}

void BraveProfileManager::LaunchTorProcess(Profile* profile) {
Expand Down
Loading

0 comments on commit 3a4c91a

Please sign in to comment.