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

Enabling brave rewards for Windows #465

Merged
merged 3 commits into from
Sep 26, 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
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@bba76f13c7ea4d295bd93e7cfa384801d25311b2",
"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
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
NejcZdovc marked this conversation as resolved.
Show resolved Hide resolved
}
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