move BraveComponentUpdaterDelegate and BraveComponentInstaller to components

This commit is contained in:
bridiver
2023-08-14 15:18:21 -07:00
parent b6c4e527a0
commit 6448c20b70
15 changed files with 109 additions and 100 deletions
+3 -3
View File
@@ -17,13 +17,13 @@
#include "brave/browser/brave_shields/ad_block_subscription_download_manager_getter.h"
#include "brave/browser/brave_stats/brave_stats_updater.h"
#include "brave/browser/component_updater/brave_component_updater_configurator.h"
#include "brave/browser/component_updater/brave_component_updater_delegate.h"
#include "brave/browser/misc_metrics/process_misc_metrics.h"
#include "brave/browser/net/brave_system_request_handler.h"
#include "brave/browser/profiles/brave_profile_manager.h"
#include "brave/browser/themes/brave_dark_mode_utils.h"
#include "brave/common/brave_channel_info.h"
#include "brave/components/brave_ads/browser/component_updater/resource_component.h"
#include "brave/components/brave_component_updater/browser/brave_component_updater_delegate.h"
#include "brave/components/brave_component_updater/browser/brave_on_demand_updater.h"
#include "brave/components/brave_component_updater/browser/local_data_files_service.h"
#include "brave/components/brave_referrals/browser/brave_referrals_service.h"
@@ -197,9 +197,9 @@ brave_component_updater::BraveComponent::Delegate*
BraveBrowserProcessImpl::brave_component_updater_delegate() {
if (!brave_component_updater_delegate_) {
brave_component_updater_delegate_ =
std::make_unique<brave::BraveComponentUpdaterDelegate>();
std::make_unique<brave::BraveComponentUpdaterDelegate>(
component_updater(), local_state(), GetApplicationLocale());
}
return brave_component_updater_delegate_.get();
}
+20 -9
View File
@@ -5,27 +5,38 @@
source_set("component_updater") {
sources = [
"brave_component_installer.cc",
"brave_component_installer.h",
"brave_component_updater_delegate.cc",
"brave_component_updater_delegate.h",
"brave_component_updater_configurator.cc",
"brave_component_updater_configurator.h",
]
deps = [
"//base",
"//brave/components/brave_component_updater/browser",
"//chrome/browser:browser_process",
"//brave/components/constants",
"//chrome/common",
"//components/component_updater",
"//components/crx_file",
"//components/prefs",
"//components/services/patch/content",
"//components/services/unzip/content",
"//components/update_client",
"//crypto",
"//components/update_client:network_impl",
"//components/update_client:patch_impl",
"//components/update_client:unzip_impl",
"//content/public/browser",
"//services/network/public/cpp",
]
if (is_win) {
deps += [ "//chrome/installer/util:with_no_strings" ]
}
if (is_android) {
sources += [
"brave_component_updater_android.cc",
"brave_component_updater_android.h",
]
deps += [ "//brave/build/android:jni_headers" ]
deps += [
"//brave/build/android:jni_headers",
"//chrome/browser:browser_process",
]
}
}
@@ -9,6 +9,7 @@
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/command_line.h"
@@ -17,8 +18,6 @@
#include "base/version.h"
#include "brave/components/constants/brave_switches.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/net/system_network_context_manager.h"
#include "chrome/common/pref_names.h"
#include "components/component_updater/component_updater_command_line_config_policy.h"
#include "components/prefs/pref_registry_simple.h"
@@ -48,12 +47,12 @@ namespace component_updater {
// a custom message signing protocol and it does not depend on using HTTPS.
BraveConfigurator::BraveConfigurator(
const base::CommandLine* cmdline,
PrefService* pref_service)
PrefService* pref_service,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory)
: configurator_impl_(ComponentUpdaterCommandLineConfigPolicy(cmdline),
false),
pref_service_(pref_service) {
DCHECK(pref_service_);
}
false),
pref_service_(raw_ref<PrefService>::from_ptr(pref_service)),
url_loader_factory_(std::move(url_loader_factory)) {}
BraveConfigurator::~BraveConfigurator() = default;
@@ -125,8 +124,7 @@ BraveConfigurator::GetNetworkFetcherFactory() {
if (!network_fetcher_factory_) {
network_fetcher_factory_ =
base::MakeRefCounted<update_client::NetworkFetcherChromiumFactory>(
g_browser_process->system_network_context_manager()
->GetSharedURLLoaderFactory(),
url_loader_factory_,
// Never send cookies for component update downloads.
base::BindRepeating([](const GURL& url) { return false; }));
}
@@ -175,7 +173,7 @@ bool BraveConfigurator::EnabledCupSigning() const {
}
PrefService* BraveConfigurator::GetPrefService() const {
return pref_service_;
return base::to_address(pref_service_);
}
update_client::ActivityDataService* BraveConfigurator::GetActivityDataService()
@@ -10,7 +10,7 @@
#include <string>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "base/memory/raw_ref.h"
#include "base/memory/ref_counted.h"
#include "base/time/time.h"
#include "components/component_updater/configurator_impl.h"
@@ -29,12 +29,17 @@ namespace net {
class URLRequestContextGetter;
}
namespace component_updater {
namespace network {
class SharedURLLoaderFactory;
}
namespace component_updater {
class BraveConfigurator : public update_client::Configurator {
public:
BraveConfigurator(const base::CommandLine* cmdline,
PrefService* pref_service);
BraveConfigurator(
const base::CommandLine* cmdline,
PrefService* pref_service,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory);
// update_client::Configurator overrides.
base::TimeDelta InitialDelay() const override;
@@ -72,8 +77,9 @@ class BraveConfigurator : public update_client::Configurator {
friend class base::RefCountedThreadSafe<BraveConfigurator>;
ConfiguratorImpl configurator_impl_;
raw_ptr<PrefService> pref_service_ =
nullptr; // This member is not owned by this class.
const raw_ref<PrefService>
pref_service_; // This member is not owned by this class.
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
scoped_refptr<update_client::NetworkFetcherFactory> network_fetcher_factory_;
scoped_refptr<update_client::CrxDownloaderFactory> crx_downloader_factory_;
scoped_refptr<update_client::UnzipperFactory> unzip_factory_;
-26
View File
@@ -1,26 +0,0 @@
# Copyright (c) 2021 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/. */
brave_browser_component_updater_sources = [
"//brave/browser/component_updater/brave_component_updater_configurator.cc",
"//brave/browser/component_updater/brave_component_updater_configurator.h",
]
brave_browser_component_updater_deps = [
"//base",
"//brave/components/constants",
"//chrome/browser:browser_process",
"//components/component_updater",
"//components/crx_file",
"//components/prefs",
"//components/services/patch/content",
"//components/services/unzip/content",
"//components/update_client",
"//components/update_client:network_impl",
"//components/update_client:patch_impl",
"//components/update_client:unzip_impl",
"//content/public/browser",
"//services/network/public/cpp",
]
+1 -1
View File
@@ -11,7 +11,7 @@
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "brave/browser/brave_rewards/rewards_util.h"
#include "brave/browser/component_updater/brave_component_installer.h"
#include "brave/components/brave_component_updater/browser/brave_component_installer.h"
#include "brave/components/brave_component_updater/browser/brave_on_demand_updater.h"
#include "brave/components/brave_extension/grit/brave_extension.h"
#include "brave/components/brave_webtorrent/grit/brave_webtorrent_resources.h"
@@ -69,11 +69,12 @@ class TestingBraveComponentUpdaterDelegate : public BraveComponent::Delegate {
return base::SingleThreadTaskRunner::GetCurrentDefault();
}
const std::string locale() const override { return "en"; }
const std::string& locale() const override { return locale_; }
PrefService* local_state() override { return local_state_; }
private:
raw_ptr<PrefService> local_state_ = nullptr;
const std::string locale_ = "en";
};
} // namespace
-3
View File
@@ -15,7 +15,6 @@ import("//brave/browser/brave_vpn/sources.gni")
import("//brave/browser/brave_wallet/android/sources.gni")
import("//brave/browser/brave_wallet/notifications/sources.gni")
import("//brave/browser/browsing_data/sources.gni")
import("//brave/browser/component_updater/sources.gni")
import("//brave/browser/debounce/sources.gni")
import("//brave/browser/download/sources.gni")
import("//brave/browser/ephemeral_storage/sources.gni")
@@ -442,7 +441,6 @@ brave_chrome_browser_sources += brave_browser_brave_rewards_sources
brave_chrome_browser_sources += brave_browser_brave_shields_sources
brave_chrome_browser_sources += brave_browser_brave_stats_updater_sources
brave_chrome_browser_sources += brave_browser_browsing_data_sources
brave_chrome_browser_sources += brave_browser_component_updater_sources
brave_chrome_browser_sources += brave_browser_debounce_sources
brave_chrome_browser_sources += brave_browser_download_sources
brave_chrome_browser_sources += brave_browser_ephemeral_storage_sources
@@ -477,7 +475,6 @@ brave_chrome_browser_deps += brave_browser_brave_rewards_deps
brave_chrome_browser_deps += brave_browser_brave_shields_deps
brave_chrome_browser_deps += brave_browser_brave_stats_updater_deps
brave_chrome_browser_deps += brave_browser_browsing_data_deps
brave_chrome_browser_deps += brave_browser_component_updater_deps
brave_chrome_browser_deps += brave_browser_debounce_deps
brave_chrome_browser_deps += brave_browser_download_deps
brave_chrome_browser_deps += brave_browser_ephemeral_storage_deps
@@ -4,6 +4,8 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "brave/browser/component_updater/brave_component_updater_configurator.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/net/system_network_context_manager.h"
#define MakeChromeComponentUpdaterConfigurator \
MakeChromeComponentUpdaterConfigurator_ChromiumImpl
@@ -15,7 +17,10 @@ namespace component_updater {
scoped_refptr<update_client::Configurator>
MakeChromeComponentUpdaterConfigurator(const base::CommandLine* cmdline,
PrefService* pref_service) {
return base::MakeRefCounted<BraveConfigurator>(cmdline, pref_service);
return base::MakeRefCounted<BraveConfigurator>(
cmdline, pref_service,
g_browser_process->system_network_context_manager()
->GetSharedURLLoaderFactory());
}
} // namespace component_updater
@@ -9,6 +9,10 @@ static_library("browser") {
sources = [
"brave_component.cc",
"brave_component.h",
"brave_component_installer.cc",
"brave_component_installer.h",
"brave_component_updater_delegate.cc",
"brave_component_updater_delegate.h",
"brave_on_demand_updater.cc",
"brave_on_demand_updater.h",
"dat_file_util.cc",
@@ -25,5 +29,9 @@ static_library("browser") {
deps = [
"//base",
"//components/component_updater:component_updater",
"//components/crx_file",
"//components/prefs",
"//components/update_client",
"//crypto",
]
}
@@ -44,7 +44,7 @@ class BraveComponent {
virtual scoped_refptr<base::SequencedTaskRunner> GetTaskRunner() = 0;
// hacky temporary workaround for g_browser_process
virtual const std::string locale() const = 0;
virtual const std::string& locale() const = 0;
virtual PrefService* local_state() = 0;
};
@@ -1,17 +1,16 @@
/* Copyright (c) 2019 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/. */
* You can obtain one at https://mozilla.org/MPL/2.0/. */
#include "brave/browser/component_updater/brave_component_installer.h"
#include "brave/components/brave_component_updater/browser/brave_component_installer.h"
#include <memory>
#include <utility>
#include "base/base64.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/json/json_string_value_serializer.h"
#include "base/values.h"
#include "base/version.h"
@@ -19,7 +18,6 @@
#include "components/crx_file/id_util.h"
#include "components/update_client/update_client.h"
#include "components/update_client/update_client_errors.h"
#include "components/update_client/utils.h"
#include "crypto/sha2.h"
using brave_component_updater::BraveComponent;
@@ -48,10 +46,7 @@ bool RewriteManifestFile(const base::FilePath& extension_root,
base::FilePath manifest_path =
extension_root.Append(FILE_PATH_LITERAL("manifest.json"));
if (!base::WriteFile(manifest_path, manifest_json)) {
return false;
}
return true;
return base::WriteFile(manifest_path, manifest_json);
}
std::string GetManifestString(base::Value::Dict* manifest,
@@ -1,20 +1,17 @@
/* Copyright (c) 2019 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/. */
* You can obtain one at https://mozilla.org/MPL/2.0/. */
#ifndef BRAVE_BROWSER_COMPONENT_UPDATER_BRAVE_COMPONENT_INSTALLER_H_
#define BRAVE_BROWSER_COMPONENT_UPDATER_BRAVE_COMPONENT_INSTALLER_H_
#ifndef BRAVE_COMPONENTS_BRAVE_COMPONENT_UPDATER_BROWSER_BRAVE_COMPONENT_INSTALLER_H_
#define BRAVE_COMPONENTS_BRAVE_COMPONENT_UPDATER_BROWSER_BRAVE_COMPONENT_INSTALLER_H_
#include <stdint.h>
#include <memory>
#include <string>
#include <vector>
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/values.h"
#include "brave/components/brave_component_updater/browser/brave_component.h"
#include "components/component_updater/component_installer.h"
#include "components/update_client/update_client.h"
@@ -69,4 +66,4 @@ void RegisterComponent(component_updater::ComponentUpdateService* cus,
} // namespace brave
#endif // BRAVE_BROWSER_COMPONENT_UPDATER_BRAVE_COMPONENT_INSTALLER_H_
#endif // BRAVE_COMPONENTS_BRAVE_COMPONENT_UPDATER_BROWSER_BRAVE_COMPONENT_INSTALLER_H_
@@ -1,26 +1,34 @@
/* Copyright (c) 2019 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/. */
* You can obtain one at https://mozilla.org/MPL/2.0/. */
#include "brave/browser/component_updater/brave_component_updater_delegate.h"
#include "brave/components/brave_component_updater/browser/brave_component_updater_delegate.h"
#include <utility>
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "brave/browser/component_updater/brave_component_installer.h"
#include "brave/components/brave_component_updater/browser/brave_component_installer.h"
#include "brave/components/brave_component_updater/browser/brave_on_demand_updater.h"
#include "chrome/browser/browser_process.h"
#include "components/component_updater/component_updater_service.h"
#include "components/prefs/pref_service.h"
using brave_component_updater::BraveComponent;
using brave_component_updater::BraveOnDemandUpdater;
using component_updater::ComponentUpdateService;
namespace brave {
BraveComponentUpdaterDelegate::BraveComponentUpdaterDelegate()
: task_runner_(base::ThreadPool::CreateSequencedTaskRunner(
BraveComponentUpdaterDelegate::BraveComponentUpdaterDelegate(
ComponentUpdateService* component_updater,
PrefService* local_state,
const std::string& locale)
: component_updater_(
raw_ref<ComponentUpdateService>::from_ptr(component_updater)),
local_state_(raw_ref<PrefService>::from_ptr(local_state)),
locale_(locale),
task_runner_(base::ThreadPool::CreateSequencedTaskRunner(
{base::MayBlock(), base::TaskPriority::USER_BLOCKING,
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN})) {}
@@ -31,8 +39,7 @@ void BraveComponentUpdaterDelegate::Register(
const std::string& component_base64_public_key,
base::OnceClosure registered_callback,
BraveComponent::ReadyCallback ready_callback) {
brave::RegisterComponent(g_browser_process->component_updater(),
component_name,
brave::RegisterComponent(base::to_address(component_updater_), component_name,
component_base64_public_key,
std::move(registered_callback),
std::move(ready_callback));
@@ -40,8 +47,7 @@ void BraveComponentUpdaterDelegate::Register(
bool BraveComponentUpdaterDelegate::Unregister(
const std::string& component_id) {
return g_browser_process->component_updater()->UnregisterComponent(
component_id);
return component_updater_->UnregisterComponent(component_id);
}
void BraveComponentUpdaterDelegate::OnDemandUpdate(
@@ -50,12 +56,12 @@ void BraveComponentUpdaterDelegate::OnDemandUpdate(
}
void BraveComponentUpdaterDelegate::AddObserver(ComponentObserver* observer) {
g_browser_process->component_updater()->AddObserver(observer);
component_updater_->AddObserver(observer);
}
void BraveComponentUpdaterDelegate::RemoveObserver(
ComponentObserver* observer) {
g_browser_process->component_updater()->RemoveObserver(observer);
component_updater_->RemoveObserver(observer);
}
scoped_refptr<base::SequencedTaskRunner>
@@ -63,12 +69,12 @@ BraveComponentUpdaterDelegate::GetTaskRunner() {
return task_runner_;
}
const std::string BraveComponentUpdaterDelegate::locale() const {
return g_browser_process->GetApplicationLocale();
const std::string& BraveComponentUpdaterDelegate::locale() const {
return locale_;
}
PrefService* BraveComponentUpdaterDelegate::local_state() {
return g_browser_process->local_state();
return base::to_address(local_state_);
}
} // namespace brave
@@ -1,15 +1,16 @@
/* Copyright (c) 2019 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/. */
* You can obtain one at https://mozilla.org/MPL/2.0/. */
#ifndef BRAVE_BROWSER_COMPONENT_UPDATER_BRAVE_COMPONENT_UPDATER_DELEGATE_H_
#define BRAVE_BROWSER_COMPONENT_UPDATER_BRAVE_COMPONENT_UPDATER_DELEGATE_H_
#ifndef BRAVE_COMPONENTS_BRAVE_COMPONENT_UPDATER_BROWSER_BRAVE_COMPONENT_UPDATER_DELEGATE_H_
#define BRAVE_COMPONENTS_BRAVE_COMPONENT_UPDATER_BROWSER_BRAVE_COMPONENT_UPDATER_DELEGATE_H_
#include <string>
#include "base/functional/callback.h"
#include "base/memory/raw_ref.h"
#include "brave/components/brave_component_updater/browser/brave_component.h"
#include "components/component_updater/component_updater_service.h"
using brave_component_updater::BraveComponent;
@@ -17,13 +18,20 @@ namespace base {
class SequencedTaskRunner;
}
namespace component_updater {
class ComponentUpdateService;
}
class PrefService;
namespace brave {
class BraveComponentUpdaterDelegate : public BraveComponent::Delegate {
public:
BraveComponentUpdaterDelegate();
BraveComponentUpdaterDelegate(
component_updater::ComponentUpdateService* updater,
PrefService* local_state,
const std::string& locale);
BraveComponentUpdaterDelegate(const BraveComponentUpdaterDelegate&) = delete;
BraveComponentUpdaterDelegate& operator=(
const BraveComponentUpdaterDelegate&) = delete;
@@ -43,13 +51,16 @@ class BraveComponentUpdaterDelegate : public BraveComponent::Delegate {
scoped_refptr<base::SequencedTaskRunner> GetTaskRunner() override;
const std::string locale() const override;
const std::string& locale() const override;
PrefService* local_state() override;
private:
const raw_ref<component_updater::ComponentUpdateService> component_updater_;
const raw_ref<PrefService> local_state_;
std::string locale_;
scoped_refptr<base::SequencedTaskRunner> task_runner_;
};
} // namespace brave
#endif // BRAVE_BROWSER_COMPONENT_UPDATER_BRAVE_COMPONENT_UPDATER_DELEGATE_H_
#endif // BRAVE_COMPONENTS_BRAVE_COMPONENT_UPDATER_BROWSER_BRAVE_COMPONENT_UPDATER_DELEGATE_H_