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

Send platform, build channel and country code as part of ad confirmation calls where it meets privacy standards #5067

Merged
merged 1 commit into from
Apr 17, 2020
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
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
25 changes: 25 additions & 0 deletions common/brave_channel_info.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* 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() {
#if defined(OFFICIAL_BUILD)
std::string channel_name = chrome::GetChannelName();
if (channel_name.empty()) {
channel_name = "release";
}

return channel_name;
#else // OFFICIAL_BUILD
return "developer";
#endif // !OFFICIAL_BUILD
}

} // 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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorting

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raised brave/brave-browser#9166 to resolve across Brave Ads


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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when this is fixed to use chrome::GetChannelName the layering violation here needs to be fixed as well. You cannot use brave/common or chrome/common in components

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @aseren FYI for the refactoring we spoke about

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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chrome::GetChannelName should be passed to RewardsServiceImpl in the factory to eliminate this layering violation

Copy link
Collaborator Author

@tmancey tmancey Nov 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is actually a layering violation, but it always has been there :( I'll fix it in some other PR

"//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 @@ -366,6 +366,7 @@ test("brave_unit_tests") {
"//brave/vendor/bat-native-ads/src/bat/ads/internal/ads_is_mobile_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 @@ -1295,6 +1295,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
5 changes: 5 additions & 0 deletions vendor/bat-native-ads/src/bat/ads/internal/static_values.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ const uint64_t kRetryDownloadingCatalogAfterSeconds =
const std::map<int, std::vector<std::string>> kSupportedRegionsSchemas = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

global objects with non-trivial destructor are prohibited by the style guide (see examples utilizing base::NoDestrutor in the code)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As unrelated to this ticket, I have raised brave/brave-browser#9164, thanks

// Append newly supported regions with a new schema version and update
// |kSupportedRegionsSchemaVersionNumber| to match the new version

// |kLargeAnonymityCountryCodes| and |kOtherCountryCodes| in
// bat-native-confirmations/src/bat/confirmations/internal/static_values.h
// must be updated to reflect newly supported regions

//
// Format: { schema_version : { region... } }
{
Expand Down
31 changes: 31 additions & 0 deletions vendor/bat-native-confirmations/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ source_set("bat-native-confirmations") {
"src/bat/confirmations/internal/grant_rewards_serve_helper.cc",
"src/bat/confirmations/internal/grant_rewards_serve_helper.h",
"src/bat/confirmations/internal/logging.h",
"src/bat/confirmations/internal/platform_info.h",
"src/bat/confirmations/internal/payment_info.h",
"src/bat/confirmations/internal/payments.cc",
"src/bat/confirmations/internal/payments.h",
Expand Down Expand Up @@ -104,6 +105,36 @@ source_set("bat-native-confirmations") {
"src/bat/confirmations/internal/unblinded_tokens.h",
]

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

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

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

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

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

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
Loading