-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #198 from brave/native-ledger
Native ledger integration
- Loading branch information
Showing
25 changed files
with
635 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.