Skip to content

Commit

Permalink
add brave_payments_enabled flag and disable on windows for now
Browse files Browse the repository at this point in the history
  • Loading branch information
bridiver committed Jul 6, 2018
1 parent 88efc80 commit 0fada47
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 21 deletions.
27 changes: 26 additions & 1 deletion browser/payments/BUILD.gn
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
]
Expand Down
11 changes: 3 additions & 8 deletions browser/payments/payments_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 1 addition & 10 deletions browser/payments/payments_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,16 @@
#include "base/macros.h"
#include "components/keyed_service/core/keyed_service.h"

namespace braveledger_ledger {
class Ledger;
}

namespace payments {

class PaymentsService : public KeyedService {
public:
PaymentsService();
~PaymentsService() override;

// KeyedService:
void Shutdown() override;

void CreateWallet();
virtual void CreateWallet();

private:
std::unique_ptr<braveledger_ledger::Ledger> ledger_;

DISALLOW_COPY_AND_ASSIGN(PaymentsService);
};

Expand Down
16 changes: 14 additions & 2 deletions browser/payments/payments_service_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -35,14 +39,22 @@ PaymentsServiceFactory::~PaymentsServiceFactory() {

KeyedService* PaymentsServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
#if defined(BRAVE_PAYMENTS_ENABLED)
std::unique_ptr<payments::PaymentsService> 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 {
Expand Down
25 changes: 25 additions & 0 deletions browser/payments/payments_service_impl.cc
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions browser/payments/payments_service_impl.h
Original file line number Diff line number Diff line change
@@ -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 <memory>

#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<braveledger_ledger::Ledger> ledger_;

DISALLOW_COPY_AND_ASSIGN(PaymentsServiceImpl);
};

} // namespace history

#endif // BRAVE_BROWSER_PAYMENTS_PAYMENTS_SERVICE_IMPL_

0 comments on commit 0fada47

Please sign in to comment.