From 0fada47b1332d78dd5328d9caa6a281a10e530a4 Mon Sep 17 00:00:00 2001 From: bridiver Date: Fri, 6 Jul 2018 07:54:50 -0700 Subject: [PATCH] add `brave_payments_enabled` flag and disable on windows for now --- browser/payments/BUILD.gn | 27 ++++++++++++++- browser/payments/payments_service.cc | 11 ++---- browser/payments/payments_service.h | 11 +----- browser/payments/payments_service_factory.cc | 16 +++++++-- browser/payments/payments_service_impl.cc | 25 ++++++++++++++ browser/payments/payments_service_impl.h | 36 ++++++++++++++++++++ 6 files changed, 105 insertions(+), 21 deletions(-) create mode 100644 browser/payments/payments_service_impl.cc create mode 100644 browser/payments/payments_service_impl.h diff --git a/browser/payments/BUILD.gn b/browser/payments/BUILD.gn index 652f60d4200e..24dfdde9eb76 100644 --- a/browser/payments/BUILD.gn +++ b/browser/payments/BUILD.gn @@ -1,10 +1,29 @@ +declare_args() { + # anonize doesn't currently build on windows + brave_payments_enabled = is_mac || is_linux +} + +config("external_config") { + visibility = [ ":payments" ] + + defines = [] + if (brave_payments_enabled) { + defines += [ "BRAVE_PAYMENTS_ENABLED" ] + } +} + source_set("payments") { + public_configs = [ + ":external_config" + ] + sources = [ "payments_service.cc", "payments_service.h", "payments_service_factory.cc", "payments_service_factory.h", ] + deps = [ "//base", "//components/keyed_service/content", @@ -14,7 +33,13 @@ source_set("payments") { "//content/public/browser", "//services/network/public/mojom", ] - if (is_mac || is_linux) { + + if (brave_payments_enabled) { + sources += [ + "payments_service_impl.cc", + "payments_service_impl.h", + ] + deps += [ "//brave/vendor/bat-native-ledger", ] diff --git a/browser/payments/payments_service.cc b/browser/payments/payments_service.cc index 6ff422cc4a16..2f707d1cdafc 100644 --- a/browser/payments/payments_service.cc +++ b/browser/payments/payments_service.cc @@ -3,22 +3,17 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "brave/browser/payments/payments_service.h" -#include "bat/ledger/ledger.h" +#include "base/logging.h" namespace payments { - PaymentsService::PaymentsService() : - ledger_(new braveledger_ledger::Ledger()) { + PaymentsService::PaymentsService() { } PaymentsService::~PaymentsService() { } void PaymentsService::CreateWallet() { - ledger_->createWallet(); - } - - void PaymentsService::Shutdown() { - ledger_.reset(); + NOTREACHED(); } } // namespace history diff --git a/browser/payments/payments_service.h b/browser/payments/payments_service.h index e1c69b188a56..ab26540b5acb 100644 --- a/browser/payments/payments_service.h +++ b/browser/payments/payments_service.h @@ -10,10 +10,6 @@ #include "base/macros.h" #include "components/keyed_service/core/keyed_service.h" -namespace braveledger_ledger { -class Ledger; -} - namespace payments { class PaymentsService : public KeyedService { @@ -21,14 +17,9 @@ class PaymentsService : public KeyedService { PaymentsService(); ~PaymentsService() override; - // KeyedService: - void Shutdown() override; - - void CreateWallet(); + virtual void CreateWallet(); private: - std::unique_ptr ledger_; - DISALLOW_COPY_AND_ASSIGN(PaymentsService); }; diff --git a/browser/payments/payments_service_factory.cc b/browser/payments/payments_service_factory.cc index 6e85e7d1aa4e..28c66613b964 100644 --- a/browser/payments/payments_service_factory.cc +++ b/browser/payments/payments_service_factory.cc @@ -9,6 +9,10 @@ #include "chrome/browser/profiles/profile.h" #include "components/keyed_service/content/browser_context_dependency_manager.h" +#if defined(BRAVE_PAYMENTS_ENABLED) +#include "brave/browser/payments/payments_service_impl.h" +#endif + // static payments::PaymentsService* PaymentsServiceFactory::GetForProfile( Profile* profile) { @@ -35,14 +39,22 @@ PaymentsServiceFactory::~PaymentsServiceFactory() { KeyedService* PaymentsServiceFactory::BuildServiceInstanceFor( content::BrowserContext* context) const { +#if defined(BRAVE_PAYMENTS_ENABLED) std::unique_ptr payments_service( - new payments::PaymentsService()); + new payments::PaymentsServiceImpl()); return payments_service.release(); +#else + return NULL; +#endif } content::BrowserContext* PaymentsServiceFactory::GetBrowserContextToUse( content::BrowserContext* context) const { - return chrome::GetBrowserContextOwnInstanceInIncognito(context); + if (context->IsOffTheRecord()) + return chrome::GetBrowserContextOwnInstanceInIncognito(context); + + // use original profile for session profiles + return chrome::GetBrowserContextRedirectedInIncognito(context); } bool PaymentsServiceFactory::ServiceIsNULLWhileTesting() const { diff --git a/browser/payments/payments_service_impl.cc b/browser/payments/payments_service_impl.cc new file mode 100644 index 000000000000..ce085651a135 --- /dev/null +++ b/browser/payments/payments_service_impl.cc @@ -0,0 +1,25 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "brave/browser/payments/payments_service_impl.h" + +#include "bat/ledger/ledger.h" + +namespace payments { + + PaymentsServiceImpl::PaymentsServiceImpl() : + ledger_(new braveledger_ledger::Ledger()) { + } + + PaymentsServiceImpl::~PaymentsServiceImpl() { + } + + void PaymentsServiceImpl::CreateWallet() { + ledger_->createWallet(); + } + + void PaymentsServiceImpl::Shutdown() { + ledger_.reset(); + PaymentsService::Shutdown(); + } +} // namespace history diff --git a/browser/payments/payments_service_impl.h b/browser/payments/payments_service_impl.h new file mode 100644 index 000000000000..d356227b12c0 --- /dev/null +++ b/browser/payments/payments_service_impl.h @@ -0,0 +1,36 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_BROWSER_PAYMENTS_PAYMENTS_SERVICE_IMPL_ +#define BRAVE_BROWSER_PAYMENTS_PAYMENTS_SERVICE_IMPL_ + +#include + +#include "brave/browser/payments/payments_service.h" + +namespace braveledger_ledger { +class Ledger; +} + +namespace payments { + +class PaymentsServiceImpl : public PaymentsService { + public: + PaymentsServiceImpl(); + ~PaymentsServiceImpl() override; + + // KeyedService: + void Shutdown() override; + + void CreateWallet() override; + + private: + std::unique_ptr ledger_; + + DISALLOW_COPY_AND_ASSIGN(PaymentsServiceImpl); +}; + +} // namespace history + +#endif // BRAVE_BROWSER_PAYMENTS_PAYMENTS_SERVICE_IMPL_