Skip to content

Commit

Permalink
Merge pull request #465 from brave/win_brave_rewards_enabled
Browse files Browse the repository at this point in the history
Enabling brave rewards for Windows
  • Loading branch information
bbondy committed Sep 26, 2018
1 parent 6796056 commit 148c270
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 14 deletions.
4 changes: 2 additions & 2 deletions DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ deps = {
"vendor/bat-native-ledger": "https://github.com/brave-intl/bat-native-ledger@29e7547133a0cc5fad697316280bcf96f6d1f2bf",
"vendor/bat-native-rapidjson": "https://github.com/brave-intl/bat-native-rapidjson.git@86aafe2ef89835ae71c9ed7c2527e3bb3000930e",
"vendor/bip39wally-core-native": "https://github.com/brave-intl/bip39wally-core-native.git@9b119931c702d55be994117eb505d56310720b1d",
"vendor/bat-native-anonize": "https://github.com/brave-intl/bat-native-anonize.git@6f5817c5a4dcabb49e22b578ecae4993159e6481",
"vendor/bat-native-tweetnacl": "https://github.com/brave-intl/bat-native-tweetnacl.git@05ed8f82faa03609fe5ae0a4c2d454afbe2ff267",
"vendor/bat-native-anonize": "https://github.com/brave-intl/bat-native-anonize.git@0559543f458a949b83b58035273ef7f8f1a1b111",
"vendor/bat-native-tweetnacl": "https://github.com/brave-intl/bat-native-tweetnacl.git@1b4362968c8f22720bfb75af6f506d4ecc0f3116",
}

hooks = [
Expand Down
3 changes: 1 addition & 2 deletions components/brave_rewards/browser/buildflags/buildflags.gni
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import("//build/config/features.gni")

declare_args() {
# anonize doesn't currently build on windows
brave_rewards_enabled = is_mac || is_linux
brave_rewards_enabled = is_mac || is_linux || is_win
}
2 changes: 1 addition & 1 deletion components/brave_rewards/browser/content_site.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct ContentSite {
std::string provider;
};

typedef std::vector<const ContentSite> ContentSiteList;
typedef std::vector<ContentSite> ContentSiteList;

} // namespace brave_rewards

Expand Down
13 changes: 10 additions & 3 deletions components/brave_rewards/browser/publisher_info_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
#include "brave/components/brave_rewards/browser/publisher_info_backend.h"

#include "base/files/file_util.h"
#include "base/strings/utf_string_conversions.h"
#include "third_party/leveldatabase/env_chromium.h"
#include "third_party/leveldatabase/src/include/leveldb/db.h"
#include "third_party/leveldatabase/src/include/leveldb/iterator.h"
#include "third_party/leveldatabase/src/include/leveldb/options.h"
#include "third_party/leveldatabase/src/include/leveldb/slice.h"
#include "third_party/leveldatabase/src/include/leveldb/status.h"

#include <codecvt>

namespace brave_rewards {

PublisherInfoBackend::PublisherInfoBackend(const base::FilePath& path) :
Expand Down Expand Up @@ -57,7 +60,7 @@ bool PublisherInfoBackend::Get(const std::string& lookup,

bool PublisherInfoBackend::Search(const std::vector<std::string>& prefixes,
uint32_t start, uint32_t limit,
std::vector<const std::string>& results) {
std::vector<std::string>& results) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
bool initialized = EnsureInitialized();
DCHECK(initialized);
Expand All @@ -70,7 +73,7 @@ bool PublisherInfoBackend::Search(const std::vector<std::string>& prefixes,

uint32_t count = 0;
uint32_t position = 0;
for (std::vector<const std::string>::const_iterator prefix =
for (std::vector<std::string>::const_iterator prefix =
prefixes.begin(); prefix != prefixes.end(); ++prefix) {

auto slice = leveldb::Slice(*prefix);
Expand All @@ -94,7 +97,7 @@ bool PublisherInfoBackend::Search(const std::vector<std::string>& prefixes,

bool PublisherInfoBackend::Load(uint32_t start,
uint32_t limit,
std::vector<const std::string>& results) {
std::vector<std::string>& results) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
bool initialized = EnsureInitialized();
DCHECK(initialized);
Expand Down Expand Up @@ -125,7 +128,11 @@ bool PublisherInfoBackend::EnsureInitialized() {

leveldb_env::Options options;
options.create_if_missing = true;
#if defined(OS_WIN)
std::string path = base::UTF16ToUTF8(path_.value());
#else
std::string path = path_.value();
#endif
leveldb::Status status = leveldb_env::OpenDB(options, path, &db_);

if (status.IsCorruption()) {
Expand Down
4 changes: 2 additions & 2 deletions components/brave_rewards/browser/publisher_info_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class PublisherInfoBackend {
bool Get(const std::string& lookup, std::string* value);
bool Search(const std::vector<std::string>& prefixes,
uint32_t start, uint32_t limit,
std::vector<const std::string>& results);
std::vector<std::string>& results);
bool Load(uint32_t start, uint32_t limit,
std::vector<const std::string>& results);
std::vector<std::string>& results);

private:
bool EnsureInitialized();
Expand Down
22 changes: 18 additions & 4 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,30 @@ bool IsMediaLink(const GURL& url,
referrer.spec());
}


//read comment about file pathes at src\base\files\file_path.h
#if defined(OS_WIN)
const base::FilePath::StringType kLedger_state(L"ledger_state");
const base::FilePath::StringType kPublisher_state(L"publisher_state");
const base::FilePath::StringType kPublisher_info_db(L"publisher_info_db");
const base::FilePath::StringType kPublishers_list(L"publishers_list");
#else
const base::FilePath::StringType kLedger_state("ledger_state");
const base::FilePath::StringType kPublisher_state("publisher_state");
const base::FilePath::StringType kPublisher_info_db("publisher_info_db");
const base::FilePath::StringType kPublishers_list("publishers_list");
#endif

RewardsServiceImpl::RewardsServiceImpl(Profile* profile) :
profile_(profile),
ledger_(ledger::Ledger::CreateInstance(this)),
file_task_runner_(base::CreateSequencedTaskRunnerWithTraits(
{base::MayBlock(), base::TaskPriority::BEST_EFFORT,
base::TaskShutdownBehavior::BLOCK_SHUTDOWN})),
ledger_state_path_(profile_->GetPath().Append("ledger_state")),
publisher_state_path_(profile_->GetPath().Append("publisher_state")),
publisher_info_db_path_(profile->GetPath().Append("publisher_info_db")),
publisher_list_path_(profile->GetPath().Append("publishers_list")),
ledger_state_path_(profile_->GetPath().Append(kLedger_state)),
publisher_state_path_(profile_->GetPath().Append(kPublisher_state)),
publisher_info_db_path_(profile->GetPath().Append(kPublisher_info_db)),
publisher_list_path_(profile->GetPath().Append(kPublishers_list)),
publisher_info_backend_(new PublisherInfoDatabase(publisher_info_db_path_)),
next_timer_id_(0) {
// TODO(bridiver) - production/verbose should
Expand Down

0 comments on commit 148c270

Please sign in to comment.