Skip to content

Commit

Permalink
Merge pull request #7954 from /issues/13889
Browse files Browse the repository at this point in the history
Decouple RPill from Brave Ads
  • Loading branch information
tmancey committed Feb 14, 2021
2 parents eb4b77e + 4ee2b7c commit e44fbd7
Show file tree
Hide file tree
Showing 17 changed files with 142 additions and 215 deletions.
34 changes: 15 additions & 19 deletions components/brave_ads/browser/BUILD.gn
Expand Up @@ -5,9 +5,7 @@ import("//brave/components/brave_rewards/browser/buildflags/buildflags.gni")
source_set("browser") {
# Remove when https://github.com/brave/brave-browser/issues/10639 is resolved
check_includes = false
public_deps = [
"buildflags",
]
public_deps = [ "buildflags" ]

sources = [
"ads_service.cc",
Expand All @@ -23,21 +21,23 @@ source_set("browser") {
"//base",
"//brave/common",
"//brave/components/brave_ads/common",
"//brave/components/brave_rewards/common",
"//brave/components/brave_rewards/browser",
"//brave/components/brave_rewards/common",
"//brave/components/l10n/browser",
"//brave/components/rpill/common",
"//chrome/common:buildflags",
"//components/dom_distiller/content/browser",
"//components/dom_distiller/core",

# for profile.h
"//components/domain_reliability",
"//components/keyed_service/content",
"//components/keyed_service/core",
"//components/prefs",
"//components/pref_registry",
"//components/prefs",
"//components/sessions",
"//url",
# for profile.h
"//components/domain_reliability",
"//content/public/browser",
"//url",
]

if (brave_ads_enabled) {
Expand All @@ -60,10 +60,10 @@ source_set("browser") {

deps += [
"//brave/app:brave_generated_resources_grit",
"//brave/vendor/bat-native-ads",
"//brave/browser/notifications",
"//brave/components/brave_ads/resources",
"//brave/components/services/bat_ads/public/cpp",
"//brave/vendor/bat-native-ads",
"//components/history/core/browser",
"//components/history/core/common",
"//components/wifi",
Expand All @@ -76,12 +76,12 @@ source_set("browser") {

if (is_android) {
sources += [
"//brave/browser/brave_ads/android/brave_ads_native_helper.cc",
"//brave/browser/brave_ads/android/brave_ads_native_helper.h",
"background_helper_android.cc",
"background_helper_android.h",
"notification_helper_android.cc",
"notification_helper_android.h",
"//brave/browser/brave_ads/android/brave_ads_native_helper.cc",
"//brave/browser/brave_ads/android/brave_ads_native_helper.h",
]
deps += [
"//brave/browser/brave_ads/android:jni_headers",
Expand Down Expand Up @@ -117,8 +117,8 @@ source_set("browser") {
"notification_helper_win.h",
]
deps += [
"//ui/views",
"//ui/gfx",
"//ui/views",
]
}
}
Expand All @@ -131,19 +131,15 @@ source_set("testutil") {
":browser",
"//base",
"//brave/components/brave_rewards/browser:browser",
"//content/public/browser",
"//chrome/test:test_support",
"//content/public/browser",
"//testing/gtest",
]

if (brave_ads_enabled) {
deps += [
"//brave/vendor/bat-native-ads",
]
deps += [ "//brave/vendor/bat-native-ads" ]

configs += [
"//brave/vendor/bat-native-ads:internal_config"
]
configs += [ "//brave/vendor/bat-native-ads:internal_config" ]
}

sources = [
Expand Down
15 changes: 8 additions & 7 deletions components/brave_ads/browser/ads_service_impl.cc
Expand Up @@ -54,6 +54,7 @@
#include "brave/components/brave_rewards/common/pref_names.h"
#include "brave/components/l10n/browser/locale_helper.h"
#include "brave/components/l10n/common/locale_util.h"
#include "brave/components/rpill/common/rpill.h"
#include "brave/components/services/bat_ads/public/cpp/ads_client_mojo_bridge.h"
#include "brave/components/services/bat_ads/public/interfaces/bat_ads.mojom.h"
#include "brave/grit/brave_generated_resources.h"
Expand Down Expand Up @@ -728,7 +729,7 @@ void AdsServiceImpl::MaybeStart(const bool should_restart) {
}

void AdsServiceImpl::Start() {
GetHardwareInfo();
DetectUncertainFuture();
}

void AdsServiceImpl::Stop() {
Expand Down Expand Up @@ -782,15 +783,15 @@ void AdsServiceImpl::OnResetAllState(const bool success) {
VLOG(1) << "Successfully reset ads state";
}

void AdsServiceImpl::GetHardwareInfo() {
base::SysInfo::GetHardwareInfo(base::BindOnce(
&AdsServiceImpl::OnGetHardwareInfo, base::Unretained(this)));
void AdsServiceImpl::DetectUncertainFuture() {
auto callback =
base::BindOnce(&AdsServiceImpl::OnDetectUncertainFuture, AsWeakPtr());
brave_rpill::DetectUncertainFuture(base::BindOnce(std::move(callback)));
}

void AdsServiceImpl::OnGetHardwareInfo(base::SysInfo::HardwareInfo hardware) {
void AdsServiceImpl::OnDetectUncertainFuture(const bool is_uncertain_future) {
ads::SysInfoPtr sys_info = ads::SysInfo::New();
sys_info->manufacturer = hardware.manufacturer;
sys_info->model = hardware.model;
sys_info->is_uncertain_future = is_uncertain_future;

bat_ads_service_->SetSysInfo(std::move(sys_info), base::NullCallback());

Expand Down
5 changes: 2 additions & 3 deletions components/brave_ads/browser/ads_service_impl.h
Expand Up @@ -17,7 +17,6 @@
#include "base/containers/flat_set.h"
#include "base/files/file_path.h"
#include "base/memory/weak_ptr.h"
#include "base/system/sys_info.h"
#include "base/timer/timer.h"
#include "bat/ads/ads.h"
#include "bat/ads/ads_client.h"
Expand Down Expand Up @@ -185,8 +184,8 @@ class AdsServiceImpl : public AdsService,
void OnShutdownAndResetBatAds(const int32_t result);
void OnResetAllState(const bool success);

void GetHardwareInfo();
void OnGetHardwareInfo(base::SysInfo::HardwareInfo hardware);
void DetectUncertainFuture();
void OnDetectUncertainFuture(const bool is_uncertain_future);

void EnsureBaseDirectoryExists();
void OnEnsureBaseDirectoryExists(const bool success);
Expand Down
1 change: 0 additions & 1 deletion components/brave_ads/test/BUILD.gn
Expand Up @@ -105,7 +105,6 @@ source_set("brave_ads_unit_tests") {
"//brave/vendor/bat-native-ads/src/bat/ads/internal/privacy/unblinded_tokens/unblinded_tokens_unittest.cc",
"//brave/vendor/bat-native-ads/src/bat/ads/internal/privacy/unblinded_tokens/unblinded_tokens_unittest_util.cc",
"//brave/vendor/bat-native-ads/src/bat/ads/internal/privacy/unblinded_tokens/unblinded_tokens_unittest_util.h",
"//brave/vendor/bat-native-ads/src/bat/ads/internal/rpill/rpill_unittest.cc",
"//brave/vendor/bat-native-ads/src/bat/ads/internal/security/security_util_unittest.cc",
"//brave/vendor/bat-native-ads/src/bat/ads/internal/server/ads_serve_server_util_unittest.cc",
"//brave/vendor/bat-native-ads/src/bat/ads/internal/server/ads_server_util_unittest.cc",
Expand Down
8 changes: 8 additions & 0 deletions components/rpill/common/BUILD.gn
@@ -0,0 +1,8 @@
source_set("common") {
deps = [ "//base" ]

sources = [
"rpill.cc",
"rpill.h",
]
}
79 changes: 79 additions & 0 deletions components/rpill/common/rpill.cc
@@ -0,0 +1,79 @@
/* 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/components/rpill/common/rpill.h"

#include <memory>
#include <string>
#include <utility>

#include "base/barrier_closure.h"
#include "base/callback.h"
#include "base/callback_helpers.h"
#include "base/strings/string_util.h"
#include "base/system/sys_info.h"

namespace brave_rpill {

namespace {

struct DeviceInfo {
std::string manufacturer_name;
std::string model_name;

std::string id() const {
return base::ToLowerASCII(manufacturer_name + model_name);
}
};

bool IsUncertainFuture(DeviceInfo* device_info_ptr) {
DCHECK(device_info_ptr);

const std::string device_id = device_info_ptr->id();

static const char* const kKeywords[] = {"amazon", "virtualbox", "vmware",
"xen"};

for (const char* keyword : kKeywords) {
if (device_id.find(keyword) != std::string::npos) {
return true;
}
}

return false;
}

void OnDeviceInfoReady(IsUncertainFutureCallback callback,
std::unique_ptr<DeviceInfo> device_info) {
const bool is_uncertain_future = IsUncertainFuture(device_info.get());
std::move(callback).Run(is_uncertain_future);
}

void OnHardwareInfoReady(DeviceInfo* device_info_ptr,
base::ScopedClosureRunner done_closure,
base::SysInfo::HardwareInfo hardware_info) {
DCHECK(device_info_ptr);

device_info_ptr->manufacturer_name = std::move(hardware_info.manufacturer);
device_info_ptr->model_name = std::move(hardware_info.model);
}

} // namespace

void DetectUncertainFuture(IsUncertainFutureCallback callback) {
std::unique_ptr<DeviceInfo> device_info = std::make_unique<DeviceInfo>();
DeviceInfo* device_info_ptr = device_info.get();

base::RepeatingClosure done_closure = base::BarrierClosure(
/*num_closures=*/1,
base::BindOnce(&OnDeviceInfoReady, std::move(callback),
std::move(device_info)));

base::SysInfo::GetHardwareInfo(
base::BindOnce(&OnHardwareInfoReady, device_info_ptr,
base::ScopedClosureRunner(done_closure)));
}

} // namespace brave_rpill
21 changes: 21 additions & 0 deletions components/rpill/common/rpill.h
@@ -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/. */

#ifndef BRAVE_COMPONENTS_RPILL_COMMON_RPILL_H_
#define BRAVE_COMPONENTS_RPILL_COMMON_RPILL_H_

#include "base/callback_forward.h"

namespace brave_rpill {

using IsUncertainFutureCallback = base::OnceCallback<void(const bool)>;

// Detects if the future is uncertain or bright. The specified |callback| wil be
// run upon completion with the result.
void DetectUncertainFuture(IsUncertainFutureCallback callback);

} // namespace brave_rpill

#endif // BRAVE_COMPONENTS_RPILL_COMMON_RPILL_H_
3 changes: 1 addition & 2 deletions components/services/bat_ads/bat_ads_service_impl.cc
Expand Up @@ -44,8 +44,7 @@ void BatAdsServiceImpl::SetSysInfo(
ads::SysInfoPtr sys_info,
SetSysInfoCallback callback) {
DCHECK(!is_initialized_);
ads::g_sys_info.manufacturer = sys_info->manufacturer;
ads::g_sys_info.model = sys_info->model;
ads::g_sys_info.is_uncertain_future = sys_info->is_uncertain_future;
std::move(callback).Run();
}

Expand Down
2 changes: 0 additions & 2 deletions vendor/bat-native-ads/BUILD.gn
Expand Up @@ -494,8 +494,6 @@ source_set("ads") {
"src/bat/ads/internal/privacy/unblinded_tokens/unblinded_token_info.h",
"src/bat/ads/internal/privacy/unblinded_tokens/unblinded_tokens.cc",
"src/bat/ads/internal/privacy/unblinded_tokens/unblinded_tokens.h",
"src/bat/ads/internal/rpill/rpill.cc",
"src/bat/ads/internal/rpill/rpill.h",
"src/bat/ads/internal/search_engine/search_provider_info.cc",
"src/bat/ads/internal/search_engine/search_provider_info.h",
"src/bat/ads/internal/search_engine/search_providers.cc",
Expand Down
Expand Up @@ -11,8 +11,7 @@ enum BraveAdsEnvironment {
};

struct BraveAdsSysInfo {
string manufacturer;
string model;
bool is_uncertain_future;
};

struct BraveAdsBuildChannel {
Expand Down
47 changes: 0 additions & 47 deletions vendor/bat-native-ads/src/bat/ads/internal/rpill/rpill.cc

This file was deleted.

15 changes: 0 additions & 15 deletions vendor/bat-native-ads/src/bat/ads/internal/rpill/rpill.h

This file was deleted.

0 comments on commit e44fbd7

Please sign in to comment.