Skip to content

Commit

Permalink
Merge pull request #11 from brave-intl/chromium-fixes-pt2
Browse files Browse the repository at this point in the history
Chromium fixes pt2
  • Loading branch information
gdregalo authored Jul 9, 2018
2 parents 2f1f648 + 463e6e8 commit 1d40e62
Show file tree
Hide file tree
Showing 32 changed files with 1,270 additions and 1,260 deletions.
19 changes: 12 additions & 7 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ source_set("bat-native-ledger") {

sources = [
"include/bat/ledger/ledger.h",
"src/bat_balance.cc",
"src/bat_balance.h",
"include/bat/ledger/ledger_callback_handler.h",
"include/bat/ledger/ledger_client.h",
"include/bat/ledger/ledger_url_loader.h",
"include/bat/ledger/ledger_task_runner.h",
"src/bat/ledger/ledger.cc",
"src/bat_client.cc",
"src/bat_client_webrequest.cc",
"src/bat_client_webrequest.h",
"src/bat_client_webrequest_chromium.cc",
"src/bat_client_webrequest_chromium.h",
"src/bat_client.h",
"src/bat_get_media.cc",
"src/bat_get_media.h",
"src/bat_helper.cc",
Expand All @@ -40,7 +40,12 @@ source_set("bat-native-ledger") {
"src/bat_helper_platform.h",
"src/bat_publishers.cc",
"src/bat_publishers.h",
"src/ledger.cc",
"src/ledger_impl.cc",
"src/ledger_impl.h",
"src/ledger_task_runner_impl.cc",
"src/ledger_task_runner_impl.h",
"src/url_request_handler.cc",
"src/url_request_handler.h",
]

deps = [
Expand Down
81 changes: 29 additions & 52 deletions include/bat/ledger/ledger.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,70 +5,47 @@
#ifndef BAT_LEDGER_LEDGER_H_
#define BAT_LEDGER_LEDGER_H_

#include <memory>
#include <map>
#include <string>

namespace braveledger_bat_client {
class BatClient;
}
#include "bat/ledger/ledger_client.h"

namespace braveledger_bat_helper {
struct FETCH_CALLBACK_EXTRA_DATA_ST;
struct MEDIA_PUBLISHER_INFO;
}

namespace braveledger_bat_get_media {
class BatGetMedia;
}

namespace braveledger_bat_publishers {
class BatPublishers;
}

namespace braveledger_ledger {
namespace ledger {

class Ledger {
public:
Ledger();
~Ledger();
Ledger() = default;
virtual ~Ledger() = default;

// Not copyable, not assignable
Ledger(const Ledger&) = delete;
Ledger& operator=(const Ledger&) = delete;
void createWallet();
void initSynopsis();
void saveVisit(const std::string& publisher, const uint64_t& duration, bool ignoreMinTime);
void saveVisitCallback(const std::string& publisher, const uint64_t& verifiedTimestamp);
void favIconUpdated(const std::string& publisher, const std::string& favicon_url);
void setPublisherInclude(const std::string& publisher, const bool& include);
void setPublisherDeleted(const std::string& publisher, const bool& deleted);
void setPublisherPinPercentage(const std::string& publisher, const bool& pinPercentage);
void setPublisherMinVisitTime(const uint64_t& duration); // In milliseconds
void setPublisherMinVisits(const unsigned int& visits);
void setPublisherAllowNonVerified(const bool& allow);
void setContributionAmount(const double& amount);
void OnMediaRequest(const std::string& url, const std::string& urlQuery, const std::string& type, bool privateTab);
std::string getBATAddress();
std::string getBTCAddress();
std::string getETHAddress();
std::string getLTCAddress();
void getBalance();
void run(const uint64_t& delayTime);

private:
bool isBatClientExist();
bool isBatPublisherExist();
void publisherInfoCallback(bool result, const std::string& response, const braveledger_bat_helper::FETCH_CALLBACK_EXTRA_DATA_ST& extraData);
void walletPropertiesCallback(bool result, const std::string& response, const braveledger_bat_helper::FETCH_CALLBACK_EXTRA_DATA_ST& extraData);
void reconcileCallback(const std::string& viewingId);
void OnMediaRequestCallback(const uint64_t& duration, const braveledger_bat_helper::MEDIA_PUBLISHER_INFO& mediaPublisherInfo);
void processMedia(const std::map<std::string, std::string>& parts, std::string type);
std::unique_ptr<braveledger_bat_client::BatClient> bat_client_;
std::unique_ptr<braveledger_bat_publishers::BatPublishers> bat_publishers_;
std::unique_ptr<braveledger_bat_get_media::BatGetMedia> bat_get_media_;
static Ledger* CreateInstance(LedgerClient* client);

virtual void CreateWallet() = 0;
virtual void Reconcile() = 0;
virtual void SaveVisit(const std::string& publisher,
uint64_t duration,
bool ignoreMinTime) = 0;
virtual void OnMediaRequest(const std::string& url,
const std::string& urlQuery,
const std::string& type) = 0;
virtual void SetPublisherInclude(const std::string& publisher,
bool include) = 0;
virtual void SetPublisherDeleted(const std::string& publisher,
bool deleted) = 0;
virtual void SetPublisherPinPercentage(const std::string& publisher,
bool pinPercentage) = 0;
virtual void SetPublisherMinVisitTime(uint64_t duration_in_milliseconds) = 0;
virtual void SetPublisherMinVisits(unsigned int visits) = 0;
virtual void SetPublisherAllowNonVerified(bool allow) = 0;
virtual void SetContributionAmount(double amount) = 0;
virtual const std::string& GetBATAddress() const = 0;
virtual const std::string& GetBTCAddress() const = 0;
virtual const std::string& GetETHAddress() const = 0;
virtual const std::string& GetLTCAddress() const = 0;
};

} // namespace braveledger_ledger
} // namespace ledger

#endif // BAT_LEDGER_LEDGER_H_
36 changes: 36 additions & 0 deletions include/bat/ledger/ledger_callback_handler.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 BAT_LEDGER_LEDGER_CALLBACK_HANDLER_
#define BAT_LEDGER_LEDGER_CALLBACK_HANDLER_

#include <string>

namespace ledger {

enum Result {
OK = 0,
ERROR = 1,
// some more useful result codes should go here
};

// LedgerCallbackHandler must not be destroyed if they have pending callbacks
class LedgerCallbackHandler {
public:
virtual ~LedgerCallbackHandler() = default;

virtual void OnLedgerStateLoaded(Result result,
const std::string& data) {};
virtual void OnPublisherStateLoaded(Result result,
const std::string& data) {};
virtual void OnPublisherStateSaved(Result result) {};
virtual void OnLedgerStateSaved(Result result) {};
virtual void OnURLRequestResponse(uint64_t request_id,
int response_code,
const std::string& response) {};
};

} // namespace ledger

#endif // BAT_LEDGER_LEDGER_CALLBACK_HANDLER_
54 changes: 54 additions & 0 deletions include/bat/ledger/ledger_client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* 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 BAT_LEDGER_LEDGER_CLIENT_H_
#define BAT_LEDGER_LEDGER_CLIENT_H_

#include <memory>

#include "bat/ledger/ledger_callback_handler.h"
#include "bat/ledger/ledger_task_runner.h"
#include "bat/ledger/ledger_url_loader.h"

namespace ledger {

enum URL_METHOD {
GET = 0,
PUT = 1,
POST = 2
};

class LedgerClient {
public:
virtual ~LedgerClient() = default;

// called when the wallet creation has completed
virtual std::string GenerateGUID() const = 0;
virtual void OnWalletCreated(Result result) = 0;
virtual void OnReconcileComplete(Result result,
const std::string& viewing_id) = 0;
virtual void LoadLedgerState(LedgerCallbackHandler* handler) = 0;
virtual void LoadPublisherState(LedgerCallbackHandler* handler) = 0;
virtual void SaveLedgerState(const std::string& ledger_state,
LedgerCallbackHandler* handler) = 0;
virtual void SavePublisherState(const std::string& publisher_state,
LedgerCallbackHandler* handler) = 0;
virtual std::unique_ptr<ledger::LedgerURLLoader> LoadURL(const std::string& url,
const std::vector<std::string>& headers,
const std::string& content,
const std::string& contentType,
const ledger::URL_METHOD& method,
ledger::LedgerCallbackHandler* handler) = 0;
// RunIOTask and RunTask are temporary workarounds for leveldb
// and we should replace them with a ledger_client api for reading/writing
// individual records
virtual void RunIOTask(std::unique_ptr<LedgerTaskRunner> task) = 0;
// If any callbacks are made from inside RunIOTask you must use
// RunTask to return back to the calling thread
virtual void RunTask(std::unique_ptr<LedgerTaskRunner> task) = 0;
};

} // namespace ledger

#endif // BAT_LEDGER_LEDGER_CLIENT_H_
20 changes: 20 additions & 0 deletions include/bat/ledger/ledger_task_runner.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* 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 BAT_LEDGER_LEDGER_TASK_RUNNER_
#define BAT_LEDGER_LEDGER_TASK_RUNNER_

#include <string>

namespace ledger {

class LedgerTaskRunner {
public:
virtual ~LedgerTaskRunner() = default;
virtual void Run() = 0;
};

} // namespace ledger

#endif // BAT_LEDGER_LEDGER_TASK_RUNNER_
21 changes: 21 additions & 0 deletions include/bat/ledger/ledger_url_loader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* 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 BAT_LEDGER_LEDGER_URL_LOADER_
#define BAT_LEDGER_LEDGER_URL_LOADER_

#include <string>

namespace ledger {

class LedgerURLLoader {
public:
virtual ~LedgerURLLoader() = default;
virtual void Start() = 0;
virtual uint64_t request_id() = 0;
};

} // namespace ledger

#endif // BAT_LEDGER_LEDGER_URL_LOADER_
16 changes: 16 additions & 0 deletions src/bat/ledger/ledger.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* 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 "bat/ledger/ledger.h"

#include "ledger_impl.h"

namespace ledger {

// static
ledger::Ledger* Ledger::CreateInstance(LedgerClient* client) {
return new bat_ledger::LedgerImpl(client);
}

}
30 changes: 0 additions & 30 deletions src/bat_balance.cc

This file was deleted.

32 changes: 0 additions & 32 deletions src/bat_balance.h

This file was deleted.

Loading

0 comments on commit 1d40e62

Please sign in to comment.