Skip to content

Commit

Permalink
Merge fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Jan 14, 2019
1 parent eafb91b commit d76269c
Show file tree
Hide file tree
Showing 19 changed files with 431 additions and 224 deletions.
9 changes: 2 additions & 7 deletions components/brave_rewards/browser/publisher_info_database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,15 @@ PublisherInfoDatabase::~PublisherInfoDatabase() {
}

bool PublisherInfoDatabase::Init() {
LOG(ERROR) << "INIT 0";
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

LOG(ERROR) << "INIT 1";

if (initialized_) {
return true;
}
LOG(ERROR) << "INIT 2" << db_path_;

if (!db_.Open(db_path_)) {
return false;
}
LOG(ERROR) << "INIT 3";

// TODO - add error delegate
sql::Transaction committer(&db_);
Expand All @@ -67,7 +62,7 @@ bool PublisherInfoDatabase::Init() {
!CreateActivityInfoTable() ||
!CreateMediaPublisherInfoTable() ||
!CreateRecurringDonationTable() ||
!CreatePendingContributionsTable())
!CreatePendingContributionsTable()) {
return false;
}

Expand Down Expand Up @@ -1064,7 +1059,7 @@ sql::InitStatus PublisherInfoDatabase::EnsureCurrentVersion() {

// to version 4
if (old_version < 4 && cur_version < 5) {
if (!MigrateV2toV3()) {
if (!MigrateV3toV4()) {
LOG(ERROR) << "DB: Error with MigrateV3toV4";
}
}
Expand Down
2 changes: 2 additions & 0 deletions components/brave_rewards/browser/publisher_info_database.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ class PublisherInfoDatabase {

bool MigrateV2toV3();

bool MigrateV3toV4();

sql::InitStatus EnsureCurrentVersion();

sql::Database db_;
Expand Down
51 changes: 15 additions & 36 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -252,20 +252,6 @@ void PostWriteCallback(
base::Bind(callback, write_success));
}

void GetContentSiteListInternal(
uint32_t start,
uint32_t limit,
const GetContentSiteListCallback& callback,
const ledger::PublisherInfoList& publisher_list,
uint32_t next_record) {
std::unique_ptr<ContentSiteList> site_list(new ContentSiteList);
for (ledger::PublisherInfoList::const_iterator it =
publisher_list.begin(); it != publisher_list.end(); ++it) {
site_list->push_back(PublisherInfoToContentSite(*it));
}
callback.Run(std::move(site_list), next_record);
}

time_t GetCurrentTimestamp() {
return base::Time::NowFromSystemTime().ToTimeT();
}
Expand Down Expand Up @@ -439,10 +425,6 @@ void RewardsServiceImpl::GetContentSiteList(
uint64_t reconcile_stamp,
bool allow_non_verified,
const GetContentSiteListCallback& callback) {
if (!Connected()) {
return;
}

ledger::ActivityInfoFilter filter;
filter.month = ledger::ACTIVITY_MONTH::ANY;
filter.year = -1;
Expand All @@ -454,29 +436,26 @@ void RewardsServiceImpl::GetContentSiteList(
filter.percent = 1;
filter.non_verified = allow_non_verified;

bat_ledger_->GetActivityInfoList(start, limit,
filter.ToJson(),
base::BindOnce(&RewardsServiceImpl::OnGetPublisherInfoList, AsWeakPtr(),
start,
limit,
callback));
GetActivityInfoList(start, limit,
filter,
std::bind(&RewardsServiceImpl::OnGetContentSiteList,
this,
callback,
std::placeholders::_1,
std::placeholders::_2));
}

void RewardsServiceImpl::OnGetPublisherInfoList(
uint32_t start, uint32_t limit,
void RewardsServiceImpl::OnGetContentSiteList(
const GetContentSiteListCallback& callback,
const std::vector<std::string>& publisher_info_list,
const ledger::PublisherInfoList& list,
uint32_t next_record) {
ledger::PublisherInfoList list;

for (const auto& i : publisher_info_list) {
ledger::PublisherInfo info;
info.loadFromJson(i);
list.push_back(info);
std::unique_ptr<ContentSiteList> site_list(new ContentSiteList);
for (ledger::PublisherInfoList::const_iterator it =
list.begin(); it != list.end(); ++it) {
site_list->push_back(PublisherInfoToContentSite(*it));
}

GetContentSiteListInternal(start, limit, callback, std::move(list),
next_record);
callback.Run(std::move(site_list), next_record);
}

void RewardsServiceImpl::OnLoad(SessionID tab_id, const GURL& url) {
Expand Down Expand Up @@ -1057,7 +1036,7 @@ void RewardsServiceImpl::OnPanelPublisherInfoLoaded(
callback(ledger::Result::LEDGER_OK, std::move(publisher_info));
}

void RewardsServiceImpl::LoadActivityInfoList(
void RewardsServiceImpl::GetActivityInfoList(
uint32_t start,
uint32_t limit,
ledger::ActivityInfoFilter filter,
Expand Down
10 changes: 5 additions & 5 deletions components/brave_rewards/browser/rewards_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ class RewardsServiceImpl : public RewardsService,
uint64_t reconcile_stamp,
bool allow_non_verified,
const GetContentSiteListCallback& callback) override;
void OnGetContentSiteList(
const GetContentSiteListCallback& callback,
const ledger::PublisherInfoList& list,
uint32_t next_record);
void OnLoad(SessionID tab_id, const GURL& url) override;
void OnUnload(SessionID tab_id) override;
void OnShow(SessionID tab_id) override;
Expand Down Expand Up @@ -272,7 +276,7 @@ class RewardsServiceImpl : public RewardsService,
ledger::PublisherInfoCallback callback) override;
void LoadPanelPublisherInfo(ledger::ActivityInfoFilter filter,
ledger::PublisherInfoCallback callback) override;
void LoadActivityInfoList(
void GetActivityInfoList(
uint32_t start,
uint32_t limit,
ledger::ActivityInfoFilter filter,
Expand Down Expand Up @@ -346,10 +350,6 @@ class RewardsServiceImpl : public RewardsService,

// Mojo Proxy methods
void OnPublisherBannerMojoProxy(const std::string& banner);
void OnGetPublisherInfoList(uint32_t start, uint32_t limit,
const GetContentSiteListCallback& callback,
const std::vector<std::string>& publisher_info_list,
uint32_t next_record);
void OnGetAllBalanceReports(
const GetAllBalanceReportsCallback& callback,
const base::flat_map<std::string, std::string>& json_reports);
Expand Down
2 changes: 1 addition & 1 deletion components/brave_rewards/browser/test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class MockLedgerClient : public ledger::Ledger {
MOCK_METHOD0(GetRecurringDonationPublisherInfo,
std::vector<ledger::ContributionInfo>());

MOCK_METHOD4(GetPublisherInfoList, void(
MOCK_METHOD4(GetActivityInfoList, void(
uint32_t start,
uint32_t limit,
const ledger::ActivityInfoFilter& filter,
Expand Down
127 changes: 109 additions & 18 deletions components/services/bat_ledger/bat_ledger_client_mojo_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "brave/components/services/bat_ledger/bat_ledger_client_mojo_proxy.h"

#include <string>

#include "base/logging.h"
#include "mojo/public/cpp/bindings/map.h"

Expand Down Expand Up @@ -311,44 +313,41 @@ void OnLoadPublisherInfo(const ledger::PublisherInfoCallback& callback,
}

void BatLedgerClientMojoProxy::LoadPublisherInfo(
ledger::ActivityInfoFilter filter,
const std::string& publisher_key,
ledger::PublisherInfoCallback callback) {
if (!Connected()) {
callback(ledger::Result::LEDGER_ERROR,
std::unique_ptr<ledger::PublisherInfo>());
return;
}

bat_ledger_client_->LoadPublisherInfo(filter.ToJson(),
bat_ledger_client_->LoadPublisherInfo(publisher_key,
base::BindOnce(&OnLoadPublisherInfo, std::move(callback)));
}

void OnLoadPublisherInfoList(const ledger::PublisherInfoListCallback& callback,
const std::vector<std::string>& publisher_info_list,
uint32_t next_record) {
ledger::PublisherInfoList list;
void OnLoadPanelPublisherInfo(const ledger::PublisherInfoCallback& callback,
int32_t result, const std::string& publisher_info) {
std::unique_ptr<ledger::PublisherInfo> info;

for (const auto& publisher_info : publisher_info_list) {
ledger::PublisherInfo info;
info.loadFromJson(publisher_info);
list.push_back(info);
if (!publisher_info.empty()) {
info.reset(new ledger::PublisherInfo());
info->loadFromJson(publisher_info);
}

callback(list, next_record);
callback(ToLedgerResult(result), std::move(info));
}

void BatLedgerClientMojoProxy::LoadPublisherInfoList(
uint32_t start,
uint32_t limit,
void BatLedgerClientMojoProxy::LoadPanelPublisherInfo(
ledger::ActivityInfoFilter filter,
ledger::PublisherInfoListCallback callback) {
ledger::PublisherInfoCallback callback) {
if (!Connected()) {
callback(std::vector<ledger::PublisherInfo>(), 0);
callback(ledger::Result::LEDGER_ERROR,
std::unique_ptr<ledger::PublisherInfo>());
return;
}

bat_ledger_client_->LoadPublisherInfoList(start, limit, filter.ToJson(),
base::BindOnce(&OnLoadPublisherInfoList, std::move(callback)));
bat_ledger_client_->LoadPanelPublisherInfo(filter.ToJson(),
base::BindOnce(&OnLoadPanelPublisherInfo, std::move(callback)));
}

void OnLoadMediaPublisherInfo(const ledger::PublisherInfoCallback& callback,
Expand Down Expand Up @@ -548,6 +547,98 @@ void BatLedgerClientMojoProxy::SavePendingContribution(
bat_ledger_client_->SavePendingContribution(list.ToJson());
}

void OnLoadActivityInfo(const ledger::PublisherInfoCallback& callback,
int32_t result, const std::string& publisher_info) {
std::unique_ptr<ledger::PublisherInfo> info;
if (!publisher_info.empty()) {
info.reset(new ledger::PublisherInfo());
info->loadFromJson(publisher_info);
}
callback(ToLedgerResult(result), std::move(info));
}

void BatLedgerClientMojoProxy::LoadActivityInfo(
ledger::ActivityInfoFilter filter,
ledger::PublisherInfoCallback callback) {
if (!Connected()) {
callback(ledger::Result::LEDGER_ERROR,
std::unique_ptr<ledger::PublisherInfo>());
return;
}

bat_ledger_client_->LoadPublisherInfo(filter.ToJson(),
base::BindOnce(&OnLoadActivityInfo, std::move(callback)));
}

void OnSaveActivityInfo(const ledger::PublisherInfoCallback& callback,
int32_t result, const std::string& publisher_info) {
std::unique_ptr<ledger::PublisherInfo> info;
if (!publisher_info.empty()) {
info.reset(new ledger::PublisherInfo());
info->loadFromJson(publisher_info);
}
callback(ToLedgerResult(result), std::move(info));
}

void BatLedgerClientMojoProxy::SaveActivityInfo(
std::unique_ptr<ledger::PublisherInfo> publisher_info,
ledger::PublisherInfoCallback callback) {
if (!Connected()) {
callback(ledger::Result::LEDGER_ERROR,
std::unique_ptr<ledger::PublisherInfo>());
return;
}

std::string json_info = publisher_info ? publisher_info->ToJson() : "";
bat_ledger_client_->SaveActivityInfo(json_info,
base::BindOnce(&OnSaveActivityInfo, std::move(callback)));
}

void OnRestorePublishersDone(const ledger::OnRestoreCallback& callback,
bool result) {
callback(result);
}

void BatLedgerClientMojoProxy::OnRestorePublishers(
ledger::OnRestoreCallback callback) {
if (!Connected()) {
callback(false);
return;
}

bat_ledger_client_->OnRestorePublishers(
base::BindOnce(&OnRestorePublishersDone, std::move(callback)));
}

void OnGetActivityInfoList(const ledger::PublisherInfoListCallback& callback,
const std::vector<std::string>& publisher_info_list,
uint32_t next_record) {
ledger::PublisherInfoList list;

for (const auto& publisher_info : publisher_info_list) {
ledger::PublisherInfo info;
info.loadFromJson(publisher_info);
list.push_back(info);
}

callback(list, next_record);
}

void BatLedgerClientMojoProxy::GetActivityInfoList(uint32_t start,
uint32_t limit,
ledger::ActivityInfoFilter filter,
ledger::PublisherInfoListCallback callback) {
if (!Connected()) {
callback(std::vector<ledger::PublisherInfo>(), 0);
return;
}

bat_ledger_client_->GetActivityInfoList(start,
limit,
filter.ToJson(),
base::BindOnce(&OnGetActivityInfoList, std::move(callback)));
}

bool BatLedgerClientMojoProxy::Connected() const {
return bat_ledger_client_.is_bound();
}
Expand Down
22 changes: 16 additions & 6 deletions components/services/bat_ledger/bat_ledger_client_mojo_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,10 @@ class BatLedgerClientMojoProxy : public ledger::LedgerClient,

void SavePublisherInfo(std::unique_ptr<ledger::PublisherInfo> publisher_info,
ledger::PublisherInfoCallback callback) override;
void LoadPublisherInfo(ledger::ActivityInfoFilter filter,
void LoadPublisherInfo(const std::string& publisher_key,
ledger::PublisherInfoCallback callback) override;
void LoadPublisherInfoList(
uint32_t start,
uint32_t limit,
ledger::ActivityInfoFilter filter,
ledger::PublisherInfoListCallback callback) override;
void LoadPanelPublisherInfo(ledger::ActivityInfoFilter filter,
ledger::PublisherInfoCallback callback) override;
void SavePublishersList(const std::string& publishers_list,
ledger::LedgerCallbackHandler* handler) override;
void SetTimer(uint64_t time_offset, uint32_t& timer_id) override;
Expand Down Expand Up @@ -98,6 +95,19 @@ class BatLedgerClientMojoProxy : public ledger::LedgerClient,
void SavePendingContribution(
const ledger::PendingContributionList& list) override;

void LoadActivityInfo(ledger::ActivityInfoFilter filter,
ledger::PublisherInfoCallback callback) override;

void SaveActivityInfo(std::unique_ptr<ledger::PublisherInfo> publisher_info,
ledger::PublisherInfoCallback callback) override;

void OnRestorePublishers(ledger::OnRestoreCallback callback) override;

void GetActivityInfoList(uint32_t start,
uint32_t limit,
ledger::ActivityInfoFilter filter,
ledger::PublisherInfoListCallback callback) override;

private:
bool Connected() const;

Expand Down
Loading

0 comments on commit d76269c

Please sign in to comment.