Skip to content

Commit

Permalink
Send platform, build channel and country code as part of ad confirmat…
Browse files Browse the repository at this point in the history
…ion calls where it meets privacy standards
  • Loading branch information
tmancey committed Mar 26, 2020
1 parent 0977bb0 commit 22b4e4c
Show file tree
Hide file tree
Showing 43 changed files with 651 additions and 15 deletions.
1 change: 1 addition & 0 deletions browser/brave_stats_updater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "brave/browser/brave_stats_updater_params.h"
#include "brave/browser/brave_stats_updater_util.h"
#include "brave/browser/version_info.h"
#include "brave/common/brave_channel_info.h"
#include "brave/common/pref_names.h"
#include "brave/components/brave_referrals/buildflags/buildflags.h"
#include "chrome/browser/browser_process.h"
Expand Down
8 changes: 0 additions & 8 deletions browser/brave_stats_updater_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "base/strings/string_piece.h"
#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
#include "chrome/common/channel_info.h"

namespace brave {

Expand All @@ -22,13 +21,6 @@ std::string GetDateAsYMD(const base::Time& time) {
exploded.day_of_month);
}

std::string GetChannelName() {
std::string channel = chrome::GetChannelName();
if (channel.empty())
channel = "release";
return channel;
}

std::string GetPlatformIdentifier() {
#if defined(OS_WIN)
if (base::SysInfo::OperatingSystemArchitecture() == "x86")
Expand Down
2 changes: 0 additions & 2 deletions browser/brave_stats_updater_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ namespace brave {

std::string GetDateAsYMD(const base::Time& time);

std::string GetChannelName();

std::string GetPlatformIdentifier();

int GetIsoWeekNumber(const base::Time& time);
Expand Down
2 changes: 2 additions & 0 deletions common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ source_set("switches") {

source_set("common") {
sources = [
"brave_channel_info.cc",
"brave_channel_info.h",
"brave_content_client.cc",
"brave_content_client.h",
"brave_features.cc",
Expand Down
21 changes: 21 additions & 0 deletions common/brave_channel_info.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/common/brave_channel_info.h"

#include "chrome/common/channel_info.h"

namespace brave {

std::string GetChannelName() {
std::string channel_name = chrome::GetChannelName();
if (channel_name.empty()) {
channel_name = "release";
}

return channel_name;
}

} // namespace brave
18 changes: 18 additions & 0 deletions common/brave_channel_info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_COMMON_BRAVE_CHANNEL_INFO_H_
#define BRAVE_COMMON_BRAVE_CHANNEL_INFO_H_

#include <string>

namespace brave {

std::string GetChannelName();

}

#endif // BRAVE_COMMON_BRAVE_CHANNEL_INFO_H_

2 changes: 2 additions & 0 deletions components/brave_rewards/browser/android_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@

#include "base/json/json_reader.h"
#include "brave/components/brave_rewards/browser/android_util.h"
#include "brave/common/brave_channel_info.h"

namespace android_util {

ledger::ClientInfoPtr GetAndroidClientInfo() {
auto info = ledger::ClientInfo::New();
info->platform = ledger::Platform::ANDROID_R;
info->os = ledger::OperatingSystem::UNDEFINED;
info->channel = brave::GetChannelName();
return info;
}

Expand Down
3 changes: 3 additions & 0 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "brave/base/containers/utils.h"
#include "brave/browser/ui/webui/brave_rewards_source.h"
#include "brave/components/brave_rewards/common/pref_names.h"
#include "brave/common/brave_channel_info.h"
#include "brave/common/pref_names.h"
#include "brave/components/brave_ads/browser/ads_service.h"
#include "brave/components/brave_ads/browser/ads_service_factory.h"
Expand Down Expand Up @@ -3273,6 +3274,8 @@ ledger::ClientInfoPtr GetDesktopClientInfo() {
info->os = ledger::OperatingSystem::UNDEFINED;
#endif

info->channel = brave::GetChannelName();

return info;
}

Expand Down
1 change: 1 addition & 0 deletions components/p3a/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ source_set("p3a") {
]

deps = [
"//brave/common",
"//brave/components/p3a:buildflags",
"//brave/components/brave_prochlo",
"//brave/components/brave_prochlo:prochlo_proto",
Expand Down
1 change: 1 addition & 0 deletions components/p3a/brave_p3a_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "base/trace_event/trace_event.h"
#include "brave/browser/brave_stats_updater_util.h"
#include "brave/browser/version_info.h"
#include "brave/common/brave_channel_info.h"
#include "brave/common/pref_names.h"
#include "brave/components/brave_prochlo/prochlo_message.pb.h"
#include "brave/components/p3a/brave_p3a_log_store.h"
Expand Down
1 change: 1 addition & 0 deletions test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ test("brave_unit_tests") {
"//brave/vendor/bat-native-ads/src/bat/ads/internal/ads_tabs_unittest.cc",
"//brave/vendor/bat-native-ads/src/bat/ads/internal/ads_client_mock.cc",
"//brave/vendor/bat-native-ads/src/bat/ads/internal/ads_client_mock.h",
"//brave/vendor/bat-native-confirmations/src/bat/confirmations/internal/platform_helper_mock.h",
"//brave/vendor/bat-native-confirmations/src/bat/confirmations/internal/ad_grants_unittest.cc",
"//brave/vendor/bat-native-confirmations/src/bat/confirmations/internal/payments_unittest.cc",
"//brave/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmations_create_confirmation_request_unittest.cc",
Expand Down
1 change: 1 addition & 0 deletions vendor/bat-native-ads/include/bat/ads/ad_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct ADS_EXPORT AdInfo {
std::string creative_set_id;
std::string category;
std::string target_url;
std::string geo_target;
};

} // namespace ads
Expand Down
7 changes: 7 additions & 0 deletions vendor/bat-native-ads/src/bat/ads/ad_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ Result AdInfo::FromJson(
target_url = document["url"].GetString();
}

if (document.HasMember("geo_target")) {
geo_target = document["geo_target"].GetString();
}

return SUCCESS;
}

Expand All @@ -71,6 +75,9 @@ void SaveToJson(
writer->String("url");
writer->String(info.target_url.c_str());

writer->String("geo_target");
writer->String(info.geo_target.c_str());

writer->EndObject();
}

Expand Down
3 changes: 3 additions & 0 deletions vendor/bat-native-ads/src/bat/ads/ad_notification_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ void SaveToJson(
writer->String("url");
writer->String(info.target_url.c_str());

writer->String("geo_target");
writer->String(info.geo_target.c_str());

writer->EndObject();
}

Expand Down
11 changes: 11 additions & 0 deletions vendor/bat-native-ads/src/bat/ads/internal/ad_notifications.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const char kNotificationCategoryKey[] = "category";
const char kNotificationTitleKey[] = "advertiser";
const char kNotificationBodyKey[] = "text";
const char kNotificationTargetUrlKey[] = "url";
const char kNotificationGeoTargetKey[] = "geo_target";

AdNotifications::AdNotifications(
AdsImpl* ads,
Expand Down Expand Up @@ -214,6 +215,10 @@ bool AdNotifications::GetNotificationFromDictionary(
return false;
}

if (!GetGeoTargetFromDictionary(dictionary, &notification_info.geo_target)) {
return false;
}

*info = notification_info;

return true;
Expand Down Expand Up @@ -269,6 +274,12 @@ bool AdNotifications::GetTargetUrlFromDictionary(
return GetStringFromDictionary(kNotificationTargetUrlKey, dictionary, value);
}

bool AdNotifications::GetGeoTargetFromDictionary(
base::DictionaryValue* dictionary,
std::string* value) const {
return GetStringFromDictionary(kNotificationGeoTargetKey, dictionary, value);
}

bool AdNotifications::GetStringFromDictionary(
const std::string& key,
base::DictionaryValue* dictionary,
Expand Down
3 changes: 3 additions & 0 deletions vendor/bat-native-ads/src/bat/ads/internal/ad_notifications.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class AdNotifications {
bool GetTargetUrlFromDictionary(
base::DictionaryValue* dictionary,
std::string* value) const;
bool GetGeoTargetFromDictionary(
base::DictionaryValue* dictionary,
std::string* value) const;

bool GetStringFromDictionary(
const std::string& key,
Expand Down
1 change: 1 addition & 0 deletions vendor/bat-native-ads/src/bat/ads/internal/ads_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,7 @@ bool AdsImpl::ShowAdNotification(
ad_notification->title = info.title;
ad_notification->body = info.body;
ad_notification->target_url = helper::Uri::GetUri(info.target_url);
ad_notification->geo_target = info.geo_targets.at(0);

BLOG(INFO) << "Ad notification shown:"
<< std::endl << " uuid: " << ad_notification->uuid
Expand Down
37 changes: 37 additions & 0 deletions vendor/bat-native-confirmations/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ source_set("bat-native-confirmations") {
"src/bat/confirmations/internal/ledger_serve_helper.cc",
"src/bat/confirmations/internal/ledger_serve_helper.h",
"src/bat/confirmations/internal/logging.h",
"src/bat/confirmations/internal/platform_helper.cc",
"src/bat/confirmations/internal/platform_helper.h",
"src/bat/confirmations/internal/payment_info.h",
"src/bat/confirmations/internal/payments.cc",
"src/bat/confirmations/internal/payments.h",
Expand All @@ -100,6 +102,41 @@ source_set("bat-native-confirmations") {
"src/bat/confirmations/internal/unblinded_tokens.h",
]

if (is_android) {
sources += [
"src/bat/confirmations/internal/platform_helper_android.cc",
"src/bat/confirmations/internal/platform_helper_android.h",
]
}

if (is_linux) {
sources += [
"src/bat/confirmations/internal/platform_helper_linux.cc",
"src/bat/confirmations/internal/platform_helper_linux.h",
]
}

if (is_mac) {
sources += [
"src/bat/confirmations/internal/platform_helper_mac.mm",
"src/bat/confirmations/internal/platform_helper_mac.h",
]
}

if (is_ios) {
sources += [
"src/bat/confirmations/internal/platform_helper_ios.mm",
"src/bat/confirmations/internal/platform_helper_ios.h",
]
}

if (is_win) {
sources += [
"src/bat/confirmations/internal/platform_helper_win.cc",
"src/bat/confirmations/internal/platform_helper_win.h",
]
}

public_deps = [
":challenge_bypass_libs",
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct CONFIRMATIONS_EXPORT AdInfo {
std::string creative_set_id;
std::string category;
std::string target_url;
std::string geo_target;
};

} // namespace confirmations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct ConfirmationInfo {
BlindedToken blinded_payment_token;
std::string credential;
uint64_t timestamp_in_seconds;
std::string country_code;
bool created;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ ConfirmationsImpl::~ConfirmationsImpl() {
StopPayingOutRedeemedTokens();
}

ConfirmationsClient* ConfirmationsImpl::get_client() const {
return confirmations_client_;
}

void ConfirmationsImpl::Initialize(
OnInitializeCallback callback) {
BLOG(INFO) << "Initializing confirmations";
Expand Down Expand Up @@ -1143,6 +1147,7 @@ void ConfirmationsImpl::ConfirmAd(
<< std::endl << " creativeSetId: " << info.creative_set_id
<< std::endl << " category: " << info.category
<< std::endl << " targetUrl: " << info.target_url
<< std::endl << " geoTarget: " << info.geo_target
<< std::endl << " confirmationType: " << std::string(confirmation_type);

redeem_token_->Redeem(info, confirmation_type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class ConfirmationsImpl : public Confirmations {
explicit ConfirmationsImpl(ConfirmationsClient* confirmations_client);
~ConfirmationsImpl() override;

ConfirmationsClient* get_client() const;

void Initialize(OnInitializeCallback callback) override;

// Wallet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@
#include "bat/confirmations/internal/token_info.h"
#include "bat/confirmations/internal/create_confirmation_request.h"
#include "bat/confirmations/internal/ads_serve_helper.h"
#include "bat/confirmations/internal/platform_helper.h"
#include "bat/confirmations/internal/security_helper.h"
#include "bat/confirmations/internal/static_values.h"
#include "base/logging.h"
#include "base/json/json_writer.h"
#include "base/values.h"

namespace confirmations {

CreateConfirmationRequest::CreateConfirmationRequest() = default;
CreateConfirmationRequest::CreateConfirmationRequest(
ConfirmationsImpl* confirmations)
: confirmations_(confirmations) {
DCHECK(confirmations_);
}

CreateConfirmationRequest::~CreateConfirmationRequest() = default;

Expand Down Expand Up @@ -79,6 +85,28 @@ std::string CreateConfirmationRequest::CreateConfirmationRequestDTO(
auto type = std::string(info.type);
payload.SetKey("type", base::Value(type));

std::string country_code = info.country_code;
const auto iter = kLargeAnonymityCountryCodes.find(country_code);
if (iter != kLargeAnonymityCountryCodes.end()) {
const bool large_anonymity_country_code = iter->second;
if (large_anonymity_country_code) {
const auto iter = kPrivacyCountryCodes.find(country_code);
if (iter != kPrivacyCountryCodes.end()) {
country_code = "??";
}

payload.SetKey("countryCode", base::Value(country_code));
}
}

const std::string platform = PlatformHelper::GetInstance()->GetPlatformName();
if (!platform.empty()) {
payload.SetKey("platform", base::Value(platform));
}

const auto client_info = confirmations_->get_client()->GetClientInfo();
payload.SetKey("channelName", base::Value(client_info->channel));

std::string json;
base::JSONWriter::Write(payload, &json);

Expand Down
Loading

0 comments on commit 22b4e4c

Please sign in to comment.