Add support for component updater on iOS

This commit is contained in:
Kyle Hickinson
2021-09-28 15:42:28 -04:00
parent 321eeee443
commit 1f20543eec
12 changed files with 154 additions and 22 deletions
@@ -21,6 +21,7 @@
#include "components/breadcrumbs/core/breadcrumb_manager.h"
#include "components/breadcrumbs/core/breadcrumb_persistent_storage_manager.h"
#include "components/component_updater/component_updater_service.h"
#include "components/component_updater/timer_update_scheduler.h"
#include "components/gcm_driver/gcm_driver.h"
#include "components/history/core/browser/history_service.h"
#include "components/keyed_service/core/service_access_type.h"
@@ -36,6 +37,7 @@
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state_manager_impl.h"
#include "ios/chrome/browser/chrome_paths.h"
#include "ios/chrome/browser/component_updater/ios_component_updater_configurator.h"
#import "ios/chrome/browser/crash_report/breadcrumbs/application_breadcrumbs_logger_ios.h"
#include "ios/chrome/browser/history/history_service_factory.h"
#include "ios/chrome/browser/ios_chrome_io_thread.h"
@@ -262,16 +264,15 @@ gcm::GCMDriver* ApplicationContextImpl::GetGCMDriver() {
component_updater::ComponentUpdateService*
ApplicationContextImpl::GetComponentUpdateService() {
DCHECK(thread_checker_.CalledOnValidThread());
// if (!component_updater_) {
// // Creating the component updater does not do anything, components need to
// // be registered and Start() needs to be called.
// component_updater_ = component_updater::ComponentUpdateServiceFactory(
// component_updater::MakeIOSComponentUpdaterConfigurator(
// base::CommandLine::ForCurrentProcess()),
// std::make_unique<component_updater::TimerUpdateScheduler>());
// }
// return component_updater_.get();
return nullptr;
if (!component_updater_) {
// Creating the component updater does not do anything, components need to
// be registered and Start() needs to be called.
component_updater_ = component_updater::ComponentUpdateServiceFactory(
component_updater::MakeIOSComponentUpdaterConfigurator(
base::CommandLine::ForCurrentProcess()),
std::make_unique<component_updater::TimerUpdateScheduler>());
}
return component_updater_.get();
}
SafeBrowsingService* ApplicationContextImpl::GetSafeBrowsingService() {
@@ -0,0 +1,3 @@
include_rules = [
"+../../../../../../ios/chrome/browser/component_updater",
]
@@ -0,0 +1,28 @@
/* 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/. */
#include "components/component_updater/configurator_impl.h"
namespace component_updater {
namespace {
class BraveConfiguratorImpl : public ConfiguratorImpl {
public:
using ConfiguratorImpl::ConfiguratorImpl;
bool EnabledCupSigning() const;
};
bool BraveConfiguratorImpl::EnabledCupSigning() const {
return false;
}
} // namespace
} // namespace component_updater
#define ConfiguratorImpl BraveConfiguratorImpl
#include "../../../../../../ios/chrome/browser/component_updater/ios_component_updater_configurator.cc" // NOLINT
#undef ConfiguratorImpl
+7 -1
View File
@@ -11,7 +11,13 @@ namespace brave_wallet {
namespace features {
const base::Feature kNativeBraveWalletFeature{
"NativeBraveWallet", base::FEATURE_DISABLED_BY_DEFAULT};
"NativeBraveWallet",
#if defined(OS_IOS)
base::FEATURE_ENABLED_BY_DEFAULT
#else
base::FEATURE_DISABLED_BY_DEFAULT
#endif
};
} // namespace features
} // namespace brave_wallet
+3
View File
@@ -23,6 +23,7 @@ source_set("app") {
deps = [
"//base",
"//brave/common:pref_names",
"//brave/components/brave_component_updater/browser",
"//brave/components/brave_sync:constants",
"//brave/components/brave_wallet/browser",
"//brave/ios/browser",
@@ -33,7 +34,9 @@ source_set("app") {
"//brave/ios/browser/api/ledger",
"//brave/ios/browser/api/sync/driver",
"//brave/ios/browser/brave_wallet",
"//brave/ios/browser/component_updater",
"//components/browser_sync",
"//components/component_updater",
"//components/history/core/browser",
"//components/keyed_service/core",
"//components/sync/base",
+1
View File
@@ -4,6 +4,7 @@ include_rules = [
"+ios/chrome/common",
"+brave/ios/app",
"+brave/ios/browser",
"+components/component_updater/component_updater_switches.h",
"+components/sync/driver",
"+components/sync/base",
"+components/browser_sync",
+5 -4
View File
@@ -35,14 +35,15 @@ OBJC_EXPORT
+ (void)setLogHandler:(nullable BraveCoreLogHandler)logHandler;
- (instancetype)init;
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithSyncServiceURL:(NSString*)syncServiceURL;
- (instancetype)initWithUserAgent:(NSString*)userAgent;
- (instancetype)initWithUserAgent:(NSString*)userAgent
syncServiceURL:(NSString*)syncServiceURL;
- (void)scheduleLowPriorityStartupTasks;
- (void)setUserAgent:(NSString*)userAgent;
@property(class, readonly) id<BraveWalletERCTokenRegistry> ercTokenRegistry;
@end
+22 -7
View File
@@ -11,7 +11,9 @@
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/strings/sys_string_conversions.h"
#include "brave/components/brave_component_updater/browser/brave_on_demand_updater.h"
#include "brave/components/brave_wallet/browser/erc_token_registry.h"
#include "brave/components/brave_wallet/browser/wallet_data_files_installer.h"
#include "brave/ios/app/brave_main_delegate.h"
#include "brave/ios/browser/api/bookmarks/brave_bookmarks_api+private.h"
#include "brave/ios/browser/api/brave_wallet/brave_wallet.mojom.objc+private.h"
@@ -19,6 +21,7 @@
#include "brave/ios/browser/api/sync/brave_sync_api+private.h"
#include "brave/ios/browser/api/sync/driver/brave_sync_profile_service+private.h"
#include "brave/ios/browser/brave_web_client.h"
#include "brave/ios/browser/component_updater/component_updater_utils.h"
#include "components/history/core/browser/history_service.h"
#include "components/keyed_service/core/service_access_type.h"
#include "ios/chrome/app/startup/provider_registration.h"
@@ -52,11 +55,12 @@ static BraveCoreLogHandler _Nullable _logHandler = nil;
@implementation BraveCoreMain
- (instancetype)init {
return [self initWithSyncServiceURL:@""];
- (instancetype)initWithUserAgent:(NSString*)userAgent {
return [self initWithUserAgent:userAgent syncServiceURL:@""];
}
- (instancetype)initWithSyncServiceURL:(NSString*)syncServiceURL {
- (instancetype)initWithUserAgent:(NSString*)userAgent
syncServiceURL:(NSString*)syncServiceURL {
if ((self = [super init])) {
[[NSNotificationCenter defaultCenter]
addObserver:self
@@ -78,6 +82,7 @@ static BraveCoreLogHandler _Nullable _logHandler = nil;
[ProviderRegistration registerProviders];
_webClient.reset(new BraveWebClient());
_webClient->SetUserAgent(base::SysNSStringToUTF8(userAgent));
web::SetWebClient(_webClient.get());
_delegate.reset(new BraveMainDelegate());
@@ -88,6 +93,8 @@ static BraveCoreLogHandler _Nullable _logHandler = nil;
ios::GetChromeBrowserProvider().Initialize();
[self registerComponentsForUpdate];
ios::ChromeBrowserStateManager* browserStateManager =
GetApplicationContext()->GetChromeBrowserStateManager();
ChromeBrowserState* chromeBrowserState =
@@ -117,6 +124,18 @@ static BraveCoreLogHandler _Nullable _logHandler = nil;
[StartupTasks scheduleDeferredBrowserStateInitialization:_mainBrowserState];
}
- (void)registerComponentsForUpdate {
brave_component_updater::BraveOnDemandUpdater::GetInstance()
->RegisterOnDemandUpdateCallback(
base::BindRepeating(&component_updater::BraveOnDemandUpdate));
component_updater::ComponentUpdateService* cus =
GetApplicationContext()->GetComponentUpdateService();
DCHECK(cus);
brave_wallet::RegisterWalletDataFilesComponent(cus);
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
_mainBrowserState = nullptr;
@@ -125,10 +144,6 @@ static BraveCoreLogHandler _Nullable _logHandler = nil;
_webClient.reset();
}
- (void)setUserAgent:(NSString*)userAgent {
_webClient->SetUserAgent(base::SysNSStringToUTF8(userAgent));
}
+ (void)setLogHandler:(BraveCoreLogHandler)logHandler {
_logHandler = logHandler;
logging::SetLogMessageHandler(&CustomLogHandler);
+19
View File
@@ -11,7 +11,11 @@
#include "base/files/file_path.h"
#include "base/mac/bundle_locations.h"
#include "base/path_service.h"
#include "brave/components/brave_component_updater/browser/brave_component.h"
#include "brave/components/brave_component_updater/browser/features.h"
#include "brave/components/brave_component_updater/browser/switches.h"
#include "components/browser_sync/browser_sync_switches.h"
#include "components/component_updater/component_updater_switches.h"
#include "components/sync/base/model_type.h"
#include "components/sync/base/sync_base_switches.h"
#include "components/sync/driver/sync_driver_switches.h"
@@ -23,6 +27,18 @@
namespace {
const char kBraveSyncServiceURL[] = BRAVE_SYNC_ENDPOINT;
std::string GetUpdateURLHost() {
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
if (!command_line.HasSwitch(brave_component_updater::kUseGoUpdateDev) &&
!base::FeatureList::IsEnabled(
brave_component_updater::kUseDevUpdaterUrl)) {
return UPDATER_PROD_ENDPOINT;
}
return UPDATER_DEV_ENDPOINT;
}
} // namespace
BraveMainDelegate::BraveMainDelegate() : brave_sync_service_url_(kBraveSyncServiceURL) {
@@ -51,6 +67,9 @@ void BraveMainDelegate::BasicStartupComplete() {
command_line->AppendSwitchASCII(switches::kDisableSyncTypes, syncer::ModelTypeSetToString(disabledTypes));
command_line->AppendSwitch(switches::kDisableEnterprisePolicy);
std::string source = "url-source=" + ::GetUpdateURLHost();
command_line->AppendSwitchASCII(switches::kComponentUpdater, source.c_str());
// Brave's sync protocol does not use the sync service url
command_line->AppendSwitchASCII(switches::kSyncServiceURL,
brave_sync_service_url_.c_str());
+16
View File
@@ -0,0 +1,16 @@
# 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/.
source_set("component_updater") {
sources = [
"component_updater_utils.cc",
"component_updater_utils.h",
]
deps = [
"//base",
"//components/component_updater",
"//ios/chrome/browser/",
]
}
@@ -0,0 +1,22 @@
/* 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/. */
#include "brave/ios/browser/component_updater/component_updater_utils.h"
#include "base/callback.h"
#include "components/component_updater/component_updater_service.h"
#include "ios/chrome/browser/application_context.h"
namespace component_updater {
void BraveOnDemandUpdate(const std::string& component_id) {
component_updater::ComponentUpdateService* cus =
GetApplicationContext()->GetComponentUpdateService();
cus->GetOnDemandUpdater().OnDemandUpdate(
component_id, component_updater::OnDemandUpdater::Priority::FOREGROUND,
component_updater::Callback());
}
} // namespace component_updater
@@ -0,0 +1,17 @@
/* 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/. */
#ifndef BRAVE_IOS_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_UTILS_H_
#define BRAVE_IOS_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_UTILS_H_
#include <string>
namespace component_updater {
void BraveOnDemandUpdate(const std::string& component_id);
} // namespace component_updater
#endif // BRAVE_IOS_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_UTILS_H_