Skip to content

Commit

Permalink
Remove region support for Ads as CDN now controls catalog for each re…
Browse files Browse the repository at this point in the history
…gion
  • Loading branch information
tmancey committed Mar 20, 2019
1 parent 51a8f36 commit b6d388a
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 82 deletions.
18 changes: 1 addition & 17 deletions components/brave_ads/browser/ads_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,13 @@ std::string LoadOnFileTaskRunner(
}

std::vector<ads::AdInfo> GetAdsForCategoryOnFileTaskRunner(
const std::string region,
const std::string category,
BundleStateDatabase* backend) {
std::vector<ads::AdInfo> ads;
if (!backend)
return ads;

backend->GetAdsForCategory(region, category, ads);
backend->GetAdsForCategory(category, ads);

return ads;
}
Expand Down Expand Up @@ -374,12 +373,6 @@ void AdsServiceImpl::Start() {
if (command_line.HasSwitch(switches::kTesting)) {
is_testing = true;
}
if (command_line.HasSwitch(switches::kLocale)) {
std::string locale = command_line.GetSwitchValueASCII(switches::kLocale);
if (!locale.empty()) {
command_line_switch_ads_locale_ = locale;
}
}

bat_ads_service_->SetProduction(is_production, base::NullCallback());
bat_ads_service_->SetDebug(is_debug, base::NullCallback());
Expand Down Expand Up @@ -709,31 +702,26 @@ void AdsServiceImpl::OnReset(const ads::OnResetCallback& callback,
}

void AdsServiceImpl::GetAds(
const std::string& region,
const std::string& category,
ads::OnGetAdsCallback callback) {
base::PostTaskAndReplyWithResult(file_task_runner_.get(), FROM_HERE,
base::BindOnce(&GetAdsForCategoryOnFileTaskRunner,
region,
category,
bundle_state_backend_.get()),
base::BindOnce(&AdsServiceImpl::OnGetAdsForCategory,
AsWeakPtr(),
std::move(callback),
region,
category));
}

void AdsServiceImpl::OnGetAdsForCategory(
const ads::OnGetAdsCallback& callback,
const std::string& region,
const std::string& category,
const std::vector<ads::AdInfo>& ads) {
if (!connected())
return;

callback(ads.empty() ? ads::Result::FAILED : ads::Result::SUCCESS,
region,
category,
ads);
}
Expand Down Expand Up @@ -868,10 +856,6 @@ const std::vector<std::string> AdsServiceImpl::GetLocales() const {
}

const std::string AdsServiceImpl::GetAdsLocale() const {
if (!command_line_switch_ads_locale_.empty()) {
return command_line_switch_ads_locale_;
}

return g_browser_process->GetApplicationLocale();
}

Expand Down
4 changes: 0 additions & 4 deletions components/brave_ads/browser/ads_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ class AdsServiceImpl : public AdsService,
void Reset(const std::string& name,
ads::OnResetCallback callback) override;
void GetAds(
const std::string& region,
const std::string& category,
ads::OnGetAdsCallback callback) override;
void LoadSampleBundle(ads::OnLoadSampleBundleCallback callback) override;
Expand Down Expand Up @@ -159,7 +158,6 @@ class AdsServiceImpl : public AdsService,
void OnForeground() override;

void OnGetAdsForCategory(const ads::OnGetAdsCallback& callback,
const std::string& region,
const std::string& category,
const std::vector<ads::AdInfo>& ads);
void OnSaveBundleState(const ads::OnSaveCallback& callback, bool success);
Expand Down Expand Up @@ -204,8 +202,6 @@ class AdsServiceImpl : public AdsService,
NotificationInfoMap notification_ids_;
std::map<const net::URLFetcher*, ads::URLRequestCallback> fetchers_;

std::string command_line_switch_ads_locale_;

DISALLOW_COPY_AND_ASSIGN(AdsServiceImpl);
};

Expand Down
8 changes: 3 additions & 5 deletions components/brave_ads/browser/bundle_state_database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,9 @@ bool BundleStateDatabase::InsertOrUpdateAdInfoCategory(
return ad_info_statement.Run();
}

bool BundleStateDatabase::GetAdsForCategory(const std::string& region,
const std::string& category,
std::vector<ads::AdInfo>& ads) {
bool BundleStateDatabase::GetAdsForCategory(
const std::string& category,
std::vector<ads::AdInfo>& ads) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

bool initialized = Init();
Expand All @@ -348,13 +348,11 @@ bool BundleStateDatabase::GetAdsForCategory(const std::string& region,
"INNER JOIN ad_info_category AS aic "
"ON aic.ad_info_uuid = ai.uuid "
"WHERE aic.category_name = ? and "
"ai.region = ? and "
"ai.start_timestamp <= strftime('%Y-%m-%d %H:%M', "
"datetime('now','localtime')) and "
"ai.end_timestamp >= strftime('%Y-%m-%d %H:%M', "
"datetime('now','localtime'));"));
info_sql.BindString(0, category);
info_sql.BindString(1, region);

while (info_sql.Step()) {
ads::AdInfo info;
Expand Down
13 changes: 7 additions & 6 deletions components/brave_ads/browser/bundle_state_database.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class BundleStateDatabase {
}

bool SaveBundleState(const ads::BundleState& bundle_state);
bool GetAdsForCategory(const std::string& region,
const std::string& category,
std::vector<ads::AdInfo>& ads);
bool GetAdsForCategory(
const std::string& category,
std::vector<ads::AdInfo>& ads);

// Returns the current version of the publisher info database
static int GetCurrentVersion();
Expand All @@ -50,7 +50,7 @@ class BundleStateDatabase {
private:
bool Init();
void OnMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level);
base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level);

bool CreateCategoryTable();
bool CreateAdInfoTable();
Expand All @@ -63,8 +63,9 @@ class BundleStateDatabase {

bool InsertOrUpdateCategory(const std::string& category);
bool InsertOrUpdateAdInfo(const ads::AdInfo& info);
bool InsertOrUpdateAdInfoCategory(const ads::AdInfo& ad_info,
const std::string& category);
bool InsertOrUpdateAdInfoCategory(
const ads::AdInfo& ad_info,
const std::string& category);

sql::Database& GetDB();
sql::MetaTable& GetMetaTable();
Expand Down
1 change: 0 additions & 1 deletion components/brave_ads/common/switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ const char kStaging[] = "brave-ads-staging";
const char kProduction[] = "brave-ads-production";
const char kDebug[] = "brave-ads-debug";
const char kTesting[] = "brave-ads-testing";
const char kLocale[] = "brave-ads-locale";
} // namespace switches
} // namespace brave_ads
1 change: 0 additions & 1 deletion components/brave_ads/common/switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ extern const char kStaging[];
extern const char kProduction[];
extern const char kDebug[];
extern const char kTesting[];
extern const char kLocale[];
} // namespace switches
} // namespace apps

Expand Down
13 changes: 5 additions & 8 deletions components/services/bat_ads/bat_ads_client_mojo_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ void BatAdsClientMojoBridge::Reset(const std::string& name,

void OnGetAds(const ads::OnGetAdsCallback& callback,
int32_t result,
const std::string& region,
const std::string& category,
const std::vector<std::string>& ad_info_json_list) {
std::vector<ads::AdInfo> ad_info_list;
Expand All @@ -301,26 +300,24 @@ void OnGetAds(const ads::OnGetAdsCallback& callback,
if (ad_info.FromJson(it) == ads::Result::SUCCESS) {
ad_info_list.push_back(ad_info);
} else {
callback(
ads::Result::FAILED, region, category, std::vector<ads::AdInfo>());
callback(ads::Result::FAILED, category, std::vector<ads::AdInfo>());
return;
}
}

callback(ToAdsResult(result), region, category, ad_info_list);
callback(ToAdsResult(result), category, ad_info_list);
}

void BatAdsClientMojoBridge::GetAds(
const std::string& region,
const std::string& category,
ads::OnGetAdsCallback callback) {
if (!connected()) {
callback(ads::Result::FAILED, region, category, std::vector<ads::AdInfo>());
callback(ads::Result::FAILED, category, std::vector<ads::AdInfo>());
return;
}

bat_ads_client_->GetAds(region, category,
base::BindOnce(&OnGetAds, std::move(callback)));
bat_ads_client_->GetAds(category, base::BindOnce(&OnGetAds,
std::move(callback)));
}

void OnLoadSampleBundle(const ads::OnLoadSampleBundleCallback& callback,
Expand Down
1 change: 0 additions & 1 deletion components/services/bat_ads/bat_ads_client_mojo_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class BatAdsClientMojoBridge : public ads::AdsClient {
void Reset(const std::string& name,
ads::OnResetCallback callback) override;
void GetAds(
const std::string& region,
const std::string& category,
ads::OnGetAdsCallback callback) override;
void LoadSampleBundle(ads::OnLoadSampleBundleCallback callback) override;
Expand Down
18 changes: 9 additions & 9 deletions components/services/bat_ads/public/cpp/ads_client_mojo_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
#include "base/containers/flat_map.h"
#include "bat/ads/ads.h"

using namespace std::placeholders;
using std::placeholders::_1;
using std::placeholders::_2;
using std::placeholders::_3;

namespace bat_ads {

Expand Down Expand Up @@ -351,29 +353,27 @@ void AdsClientMojoBridge::SaveBundleState(const std::string& bundle_state_json,
void AdsClientMojoBridge::OnGetAds(
CallbackHolder<GetAdsCallback>* holder,
ads::Result result,
const std::string& region,
const std::string& category,
const std::vector<ads::AdInfo>& ad_info) {
if (holder->is_valid()) {
std::vector<std::string> ad_info_json;
for (const auto it : ad_info) {
ad_info_json.push_back(it.ToJson());
}
std::move(holder->get()).Run(
ToMojomResult(result), region, category, ad_info_json);
std::move(holder->get()).Run(ToMojomResult(result), category, ad_info_json);
}
delete holder;
}

void AdsClientMojoBridge::GetAds(const std::string& region,
const std::string& category,
GetAdsCallback callback) {
void AdsClientMojoBridge::GetAds(
const std::string& category,
GetAdsCallback callback) {
// this gets deleted in OnSaveBundleState
auto* holder = new CallbackHolder<GetAdsCallback>(
AsWeakPtr(), std::move(callback));

ads_client_->GetAds(region, category,
std::bind(AdsClientMojoBridge::OnGetAds, holder, _1, _2, _3, _4));
ads_client_->GetAds(category, std::bind(AdsClientMojoBridge::OnGetAds,
holder, _1, _2, _3));
}

} // namespace bat_ads
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ class AdsClientMojoBridge : public mojom::BatAdsClient,
void ConfirmAd(const std::string& notification_info) override;
void SaveBundleState(const std::string& bundle_state,
SaveBundleStateCallback callback) override;
void GetAds(const std::string& region,
const std::string& category,
void GetAds(const std::string& category,
GetAdsCallback callback) override;

private:
Expand Down Expand Up @@ -123,7 +122,6 @@ class AdsClientMojoBridge : public mojom::BatAdsClient,
static void OnGetAds(
CallbackHolder<GetAdsCallback>* holder,
ads::Result result,
const std::string& region,
const std::string& category,
const std::vector<ads::AdInfo>& ad_info);

Expand Down
4 changes: 2 additions & 2 deletions components/services/bat_ads/public/interfaces/bat_ads.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ interface BatAdsClient {
SetCatalogIssuers(string issuers_info);
ConfirmAd(string notification_info);
SaveBundleState(string bundle_state) => (int32 result);
GetAds(string region, string category) =>
(int32 result, string region, string category, array<string> ad_info);
GetAds(string category) =>
(int32 result, string category, array<string> ad_info);
};

interface BatAds {
Expand Down
9 changes: 1 addition & 8 deletions vendor/bat-native-ads/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,9 @@ void LoadSampleBundle(OnLoadSampleBundleCallback callback)
void Reset(const std::string& name, OnResetCallback callback)
```

`GetAds` should get Ads for the specified region and category from the previously persisted bundle state
`GetAds` should get Ads for the specified category from the previously persisted bundle state
```
void GetAds(
const std::string& region,
const std::string& category,
OnGetAdsCallback callback)
```
Expand Down Expand Up @@ -302,12 +301,6 @@ Use staging Ads Serve as defined by `STAGING_SERVER` in `static_values.h`. Defau
--brave-ads-staging
```

Change locale. Default is locale of operating system. Where `{locale}`, i.e. `en_US`

```
--brave-ads-locale={locale}
```

Collect initial activity after 25 seconds instead of 1 hour as defined by `kDebugOneHourInSeconds` in `static_values.h`

```
Expand Down
13 changes: 6 additions & 7 deletions vendor/bat-native-ads/include/bat/ads/ads_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ using OnLoadCallback = std::function<void(const Result, const std::string&)>;

using OnResetCallback = std::function<void(const Result)>;

using OnGetAdsCallback = std::function<void(const Result,
const std::string&, const std::string&, const std::vector<AdInfo>&)>;
using OnGetAdsCallback = std::function<void(const Result, const std::string&,
const std::vector<AdInfo>&)>;

using OnLoadSampleBundleCallback = std::function<void(const Result,
const std::string&)>;
const std::string&)>;

using URLRequestCallback = std::function<void(const int, const std::string&,
const std::map<std::string, std::string>& headers)>;
const std::map<std::string, std::string>& headers)>;

class ADS_EXPORT AdsClient {
public:
Expand Down Expand Up @@ -155,10 +155,9 @@ class ADS_EXPORT AdsClient {
// storage
virtual void Reset(const std::string& name, OnResetCallback callback) = 0;

// Should get ads for the specified region and category from the previously
// persisted bundle state
// Should get ads for the specified category from the previously persisted
// bundle state
virtual void GetAds(
const std::string& region,
const std::string& category,
OnGetAdsCallback callback) = 0;

Expand Down
Loading

0 comments on commit b6d388a

Please sign in to comment.