Unify media publisher and regular publisher

This commit is contained in:
NejcZdovc
2018-09-05 17:57:00 +02:00
parent 04b6b2b73b
commit 6232d15cab
9 changed files with 60 additions and 64 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ deps = {
"vendor/boto": "https://github.com/boto/boto@f7574aa6cc2c819430c1f05e9a1a1a666ef8169b",
"vendor/python-patch": "https://github.com/svn2github/python-patch@a336a458016ced89aba90dfc3f4c8222ae3b1403",
"vendor/sparkle": "https://github.com/brave/Sparkle.git@c0759cce415d7c0feae45005c8a013b1898711f0",
"vendor/bat-native-ledger": "https://github.com/brave-intl/bat-native-ledger@847899fa0cd9ecc2ddb55f14041c14def35bd31e",
"vendor/bat-native-ledger": "https://github.com/brave-intl/bat-native-ledger@f2687f9a2bb8adcb0313638502296a517617fbd7",
"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",
@@ -7,7 +7,7 @@ namespace brave_rewards {
ContentSite::ContentSite() : percentage(0) {}
ContentSite::ContentSite(const id_type site_id) :
ContentSite::ContentSite(const std::string& site_id) :
id(site_id),
percentage(0),
verified(false) {
@@ -13,13 +13,12 @@
namespace brave_rewards {
struct ContentSite {
typedef std::string id_type;
ContentSite();
ContentSite(const id_type site_id);
ContentSite(const std::string& site_id);
ContentSite(const ContentSite& properties);
~ContentSite();
const id_type id;
std::string id;
double percentage;
bool verified;
std::string name;
@@ -181,12 +181,8 @@ bool PublisherInfoDatabase::CreateMediaPublisherInfoTable() {
sql.append(name);
sql.append(
"("
"publisher_id LONGVARCHAR PRIMARY KEY NOT NULL,"
// just store the raw json because this is just a 1 to 1 mapping
// and we don't need to sort or filter
"data TEXT NOT NULL,"
// schema version for serialized json data
"schema_version INTEGER DEFAULT 1 NOT NULL,"
"media_key TEXT NOT NULL PRIMARY KEY UNIQUE,"
"publisher_id LONGVARCHAR NOT NULL,"
"CONSTRAINT fk_media_publisher_info_publisher_id"
" FOREIGN KEY (publisher_id)"
" REFERENCES publisher_info (publisher_id)"
@@ -278,7 +274,7 @@ bool PublisherInfoDatabase::InsertOrUpdatePublisherInfo(
}
bool PublisherInfoDatabase::InsertOrUpdateMediaPublisherInfo(
const ledger::MediaPublisherInfo& info) {
const std::string& media_key, const std::string& publisher_id) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
bool initialized = Init();
@@ -289,34 +285,41 @@ bool PublisherInfoDatabase::InsertOrUpdateMediaPublisherInfo(
sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
"INSERT OR REPLACE INTO media_publisher_info "
"(publisher_id, data) "
"(media_key, publisher_id) "
"VALUES (?, ?)"));
statement.BindString(0, info.publisher_id_);
statement.BindString(1, info.ToJSON());
statement.BindString(0, media_key);
statement.BindString(1, publisher_id);
return statement.Run();
}
std::unique_ptr<ledger::MediaPublisherInfo>
PublisherInfoDatabase::GetMediaPublisherInfo(const std::string& publisher_id) {
std::unique_ptr<ledger::PublisherInfo>
PublisherInfoDatabase::GetMediaPublisherInfo(const std::string& media_key) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
bool initialized = Init();
DCHECK(initialized);
std::unique_ptr<ledger::MediaPublisherInfo> info;
std::unique_ptr<ledger::PublisherInfo> info;
if (!initialized)
return info;
sql::Statement info_sql(
db_.GetUniqueStatement("SELECT data FROM media_publisher_info WHERE publisher_id=?"));
db_.GetUniqueStatement("SELECT pi.publisher_id, pi.name, pi.url, pi.favIcon "
"FROM media_publisher_info as mpi "
"INNER JOIN publisher_info AS pi ON mpi.publisher_id = pi.publisher_id "
"WHERE mpi.media_key=?"));
info_sql.BindString(0, publisher_id);
info_sql.BindString(0, media_key);
if (info_sql.Step()) {
info = ledger::MediaPublisherInfo::FromJSON(info_sql.ColumnString(0));
info.reset(new ledger::PublisherInfo());
info->id = info_sql.ColumnString(0);
info->name = info_sql.ColumnString(1);
info->url = info_sql.ColumnString(2);
info->favicon_url = info_sql.ColumnString(3);
}
return info;
}
@@ -19,10 +19,6 @@
#include "sql/init_status.h"
#include "sql/meta_table.h"
namespace ledger {
struct MediaPublisherInfo;
}
namespace brave_rewards {
class PublisherInfoDatabase {
@@ -37,14 +33,14 @@ class PublisherInfoDatabase {
}
bool InsertOrUpdatePublisherInfo(const ledger::PublisherInfo& info);
bool InsertOrUpdateMediaPublisherInfo(const ledger::MediaPublisherInfo& info);
bool InsertOrUpdateMediaPublisherInfo(const std::string& media_key, const std::string& publisher_id);
bool Find(int start,
int limit,
const ledger::PublisherInfoFilter& filter,
ledger::PublisherInfoList* list);
std::unique_ptr<ledger::MediaPublisherInfo> GetMediaPublisherInfo(
const std::string& publisher_id);
std::unique_ptr<ledger::PublisherInfo> GetMediaPublisherInfo(
const std::string& media_key);
// Returns the current version of the publisher info database
static int GetCurrentVersion();
@@ -114,23 +114,24 @@ std::string LoadStateOnFileTaskRunner(
}
bool SaveMediaPublisherInfoOnFileTaskRunner(
ledger::MediaPublisherInfo publisher_info,
const std::string& media_key,
const std::string& publisher_id,
PublisherInfoDatabase* backend) {
if (backend && backend->InsertOrUpdateMediaPublisherInfo(publisher_info))
if (backend && backend->InsertOrUpdateMediaPublisherInfo(media_key, publisher_id))
return true;
return false;
}
std::unique_ptr<ledger::MediaPublisherInfo>
std::unique_ptr<ledger::PublisherInfo>
LoadMediaPublisherInfoListOnFileTaskRunner(
const std::string publisher_id,
const std::string media_key,
PublisherInfoDatabase* backend) {
std::unique_ptr<ledger::MediaPublisherInfo> info;
std::unique_ptr<ledger::PublisherInfo> info;
if (!backend)
return info;
info = backend->GetMediaPublisherInfo(publisher_id);
info = backend->GetMediaPublisherInfo(media_key);
return info;
}
@@ -372,19 +373,19 @@ void RewardsServiceImpl::OnXHRLoad(SessionID tab_id,
}
void RewardsServiceImpl::LoadMediaPublisherInfo(
const std::string& publisher_id,
ledger::MediaPublisherInfoCallback callback) {
const std::string& media_key,
ledger::PublisherInfoCallback callback) {
base::PostTaskAndReplyWithResult(file_task_runner_.get(), FROM_HERE,
base::Bind(&LoadMediaPublisherInfoListOnFileTaskRunner,
publisher_id, publisher_info_backend_.get()),
media_key, publisher_info_backend_.get()),
base::Bind(&RewardsServiceImpl::OnMediaPublisherInfoLoaded,
AsWeakPtr(),
callback));
}
void RewardsServiceImpl::OnMediaPublisherInfoLoaded(
ledger::MediaPublisherInfoCallback callback,
std::unique_ptr<ledger::MediaPublisherInfo> info) {
ledger::PublisherInfoCallback callback,
std::unique_ptr<ledger::PublisherInfo> info) {
if (!info) {
callback(ledger::Result::NOT_FOUND, std::move(info));
return;
@@ -394,26 +395,21 @@ void RewardsServiceImpl::OnMediaPublisherInfoLoaded(
}
void RewardsServiceImpl::SaveMediaPublisherInfo(
std::unique_ptr<ledger::MediaPublisherInfo> media_publisher_info,
ledger::MediaPublisherInfoCallback callback) {
const std::string& media_key,
const std::string& publisher_id) {
base::PostTaskAndReplyWithResult(file_task_runner_.get(), FROM_HERE,
base::Bind(&SaveMediaPublisherInfoOnFileTaskRunner,
*media_publisher_info,
media_key,
publisher_id,
publisher_info_backend_.get()),
base::Bind(&RewardsServiceImpl::OnMediaPublisherInfoSaved,
AsWeakPtr(),
callback,
base::Passed(std::move(media_publisher_info))));
AsWeakPtr()));
}
void RewardsServiceImpl::OnMediaPublisherInfoSaved(
ledger::MediaPublisherInfoCallback callback,
std::unique_ptr<ledger::MediaPublisherInfo> info,
bool success) {
callback(success ? ledger::Result::OK
: ledger::Result::ERROR, std::move(info));
TriggerOnContentSiteUpdated();
void RewardsServiceImpl::OnMediaPublisherInfoSaved(bool success) {
if (!success) {
VLOG(1) << "Error in OnMediaPublisherInfoSaved";
}
}
std::string RewardsServiceImpl::URIEncode(const std::string& value) {
@@ -89,11 +89,9 @@ class RewardsServiceImpl : public RewardsService,
uint64_t GetReconcileStamp() const override;
std::map<std::string, std::string> GetAddresses() const override;
void LoadMediaPublisherInfo(
const std::string& publisher_id,
ledger::MediaPublisherInfoCallback callback) override;
void SaveMediaPublisherInfo(
std::unique_ptr<ledger::MediaPublisherInfo> media_publisher_info,
ledger::MediaPublisherInfoCallback callback) override;
const std::string& media_key,
ledger::PublisherInfoCallback callback) override;
void SaveMediaPublisherInfo(const std::string& media_key, const std::string& publisher_id) override;
std::map<std::string, brave_rewards::BalanceReport> GetAllBalanceReports() override;
private:
@@ -122,11 +120,9 @@ class RewardsServiceImpl : public RewardsService,
bool success);
void OnPublisherInfoLoaded(ledger::PublisherInfoCallback callback,
const ledger::PublisherInfoList list);
void OnMediaPublisherInfoSaved(ledger::MediaPublisherInfoCallback callback,
std::unique_ptr<ledger::MediaPublisherInfo> info,
bool success);
void OnMediaPublisherInfoLoaded(ledger::MediaPublisherInfoCallback callback,
std::unique_ptr<ledger::MediaPublisherInfo> info);
void OnMediaPublisherInfoSaved(bool success);
void OnMediaPublisherInfoLoaded(ledger::PublisherInfoCallback callback,
std::unique_ptr<ledger::PublisherInfo> info);
void OnPublisherInfoListLoaded(uint32_t start,
uint32_t limit,
ledger::GetPublisherInfoListCallback callback,
@@ -45,9 +45,14 @@ class ContributeBox extends React.Component<Props, State> {
}
return list.map((item: Rewards.Publisher) => {
let name = item.name
if (item.provider) {
name = `${name} ${getLocale('on')} ${item.provider}`
}
return {
profile: {
name: item.name,
name,
verified: item.verified,
provider: (item.provider ? item.provider : undefined) as Provider,
src: `chrome://favicon/size/48@1x/${item.url}/`
+1
View File
@@ -89,6 +89,7 @@ declare namespace Rewards {
url: string
name: string
provider: string
favIcon: string
}
export interface Report {