Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native ledger integration #198

Merged
merged 5 commits into from
Jul 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ deps = {
"vendor/boto": "https://github.com/boto/boto@f7574aa6cc2c819430c1f05e9a1a1a666ef8169b",
"vendor/python-patch": "https://github.com/svn2github/python-patch@a336a458016ced89aba90dfc3f4c8222ae3b1403",
"vendor/sparkle": "https://github.com/brave/Sparkle.git@c0759cce415d7c0feae45005c8a013b1898711f0",
"vendor/bat-native-ledger": "https://github.com/brave-intl/bat-native-ledger@2f1f6480cfa618c6dc2209dbbbfdece1ae8dd377",
"vendor/bat-native-rapidjson": "https://github.com/brave-intl/bat-native-rapidjson.git@744b43313525a047eda4f2e2e689aa88b6c596fa",
"vendor/bip39wally-core-native": "https://github.com/brave-intl/bip39wally-core-native.git@e5aba371a56d3e41f7e80e868312446ce7bd434c",
"vendor/bat-native-anonize": "https://github.com/brave-intl/bat-native-anonize.git@8f60c03329f475959b44cd22838284e19508ec80",
"vendor/bat-native-tweetnacl": "https://github.com/brave-intl/bat-native-tweetnacl.git@d61f0cdc88dd2c4320176d2c514b8dd8dd1f22c2",
}

hooks = [
Expand Down
3 changes: 3 additions & 0 deletions browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ source_set("browser_process") {
"brave_stats_updater_params.h",
"brave_tab_helpers.cc",
"brave_tab_helpers.h",
"browser_context_keyed_service_factories.cc",
"browser_context_keyed_service_factories.h",
"component_updater/brave_component_installer.cc",
"component_updater/brave_component_installer.h",
"component_updater/brave_component_updater_configurator.cc",
Expand All @@ -42,6 +44,7 @@ source_set("browser_process") {
]

deps = [
"//brave/browser/payments",
"//brave/components/brave_shields/browser:brave_shields",
"//brave/components/content_settings/core/browser",
"//brave/common",
Expand Down
15 changes: 15 additions & 0 deletions browser/browser_context_keyed_service_factories.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* 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/browser_context_keyed_service_factories.h"

#include "brave/browser/payments/payments_service_factory.h"

namespace brave {

void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
PaymentsServiceFactory::GetInstance();
}

} // namespace brave
14 changes: 14 additions & 0 deletions browser/browser_context_keyed_service_factories.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef BRAVE_BROWSER_CONTEXT_KEYED_SERVICE_FACTORIES_H_
#define BRAVE_BROWSER_CONTEXT_KEYED_SERVICE_FACTORIES_H_

namespace brave {

void EnsureBrowserContextKeyedServiceFactoriesBuilt();

} // namespace apps

#endif // BRAVE_BROWSER_CONTEXT_KEYED_SERVICE_FACTORIES_H_
47 changes: 47 additions & 0 deletions browser/payments/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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",
"//components/keyed_service/core",
# for profile.h
"//components/domain_reliability",
"//content/public/browser",
"//services/network/public/mojom",
]

if (brave_payments_enabled) {
sources += [
"payments_service_impl.cc",
"payments_service_impl.h",
]

deps += [
"//brave/vendor/bat-native-ledger",
]
}
}
19 changes: 19 additions & 0 deletions browser/payments/payments_service.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* 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.h"

#include "base/logging.h"

namespace payments {

PaymentsService::PaymentsService() {
}

PaymentsService::~PaymentsService() {
}

void PaymentsService::CreateWallet() {
NOTREACHED();
}
} // namespace history
28 changes: 28 additions & 0 deletions browser/payments/payments_service.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* 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_
#define BRAVE_BROWSER_PAYMENTS_PAYMENTS_SERVICE_

#include <memory>

#include "base/macros.h"
#include "components/keyed_service/core/keyed_service.h"

namespace payments {

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

virtual void CreateWallet();

private:
DISALLOW_COPY_AND_ASSIGN(PaymentsService);
};

} // namespace history

#endif // BRAVE_BROWSER_PAYMENTS_PAYMENTS_SERVICE_
62 changes: 62 additions & 0 deletions browser/payments/payments_service_factory.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* 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_factory.h"

#include "brave/browser/payments/payments_service.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#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) {
if (profile->IsOffTheRecord())
return NULL;

return static_cast<payments::PaymentsService*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}

// static
PaymentsServiceFactory* PaymentsServiceFactory::GetInstance() {
return base::Singleton<PaymentsServiceFactory>::get();
}

PaymentsServiceFactory::PaymentsServiceFactory()
: BrowserContextKeyedServiceFactory(
"PaymentsService",
BrowserContextDependencyManager::GetInstance()) {
}

PaymentsServiceFactory::~PaymentsServiceFactory() {
}

KeyedService* PaymentsServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
#if defined(BRAVE_PAYMENTS_ENABLED)
std::unique_ptr<payments::PaymentsService> payments_service(
new payments::PaymentsServiceImpl());
return payments_service.release();
#else
return NULL;
#endif
}

content::BrowserContext* PaymentsServiceFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
if (context->IsOffTheRecord())
return chrome::GetBrowserContextOwnInstanceInIncognito(context);

// use original profile for session profiles
return chrome::GetBrowserContextRedirectedInIncognito(context);
}

bool PaymentsServiceFactory::ServiceIsNULLWhileTesting() const {
return true;
}
39 changes: 39 additions & 0 deletions browser/payments/payments_service_factory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* 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_FACTORY_H_
#define BRAVE_BROWSER_PAYMENTS_PAYMENTS_SERVICE_FACTORY_H_

#include "base/memory/singleton.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"

class Profile;

namespace payments {
class PaymentsService;
}

// Singleton that owns all PaymentsService and associates them with
// Profiles.
class PaymentsServiceFactory : public BrowserContextKeyedServiceFactory {
public:
static payments::PaymentsService* GetForProfile(Profile* profile);

static PaymentsServiceFactory* GetInstance();

private:
friend struct base::DefaultSingletonTraits<PaymentsServiceFactory>;

PaymentsServiceFactory();
~PaymentsServiceFactory() override;

// BrowserContextKeyedServiceFactory:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
bool ServiceIsNULLWhileTesting() const override;
};

#endif // BRAVE_BROWSER_PAYMENTS_PAYMENTS_SERVICE_FACTORY_H_
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_
1 change: 1 addition & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ source_set("ui") {
"//brave/app:command_ids",
"//brave/app/theme:brave_unscaled_resources",
"//brave/app/theme:brave_theme_resources",
"//brave/browser/payments",
"//brave/components/resources:brave_components_resources_grit",
"//chrome/app:command_ids",
]
Expand Down
1 change: 1 addition & 0 deletions browser/ui/brave_pages.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "brave/browser/ui/brave_pages.h"

#include "brave/common/webui_url_constants.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/singleton_tabs.h"
#include "url/gurl.h"

Expand Down
Loading