Commit 7414a0ed authored by Mila Green's avatar Mila Green Committed by Commit Bot

Reland "AppWake starts the server instead of doing an update check."

Updater: Fix ASAN test failure. Reland "Updater: AppWake starts the server instead of doing an update check."

This is a reland of 4d324410

Original change's description:
> Updater: AppWake starts the server instead of doing an update check.
>
> Bug: 1105589
>
> Change-Id: I6d7e8b0b7858a4f1a538684758644f134318c0a4
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2298045
> Commit-Queue: Mila Green <milagreen@chromium.org>
> Reviewed-by: Joshua Pawlicki <waffles@chromium.org>
> Reviewed-by: Sorin Jianu <sorin@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#790139}

Bug: 1105589
Change-Id: I7946629e862fbd9d3d42113de16f194be7a56df7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2309225Reviewed-by: default avatarJoshua Pawlicki <waffles@chromium.org>
Commit-Queue: Mila Green <milagreen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790561}
parent ff3c173b
......@@ -41,6 +41,7 @@ if (is_win || is_mac) {
"action_handler.h",
"constants.cc",
"constants.h",
"control_service.h",
"crash_client.cc",
"crash_client.h",
"crash_reporter.cc",
......@@ -89,6 +90,8 @@ if (is_win || is_mac) {
"app/app_wake.h",
"configurator.cc",
"configurator.h",
"control_service_in_process.cc",
"control_service_in_process.h",
"dm_cached_policy_info.cc",
"dm_cached_policy_info.h",
"dm_message.cc",
......@@ -108,7 +111,6 @@ if (is_win || is_mac) {
"prefs_impl.h",
"tag.cc",
"tag.h",
"update_apps.h",
"update_service_in_process.cc",
"update_service_in_process.h",
"updater.cc",
......@@ -129,6 +131,8 @@ if (is_win || is_mac) {
"external_constants_mac.mm",
"installer_mac.cc",
"lib_util_mac.mm",
"mac/control_service_out_of_process.h",
"mac/control_service_out_of_process.mm",
"mac/update_service_out_of_process.h",
"mac/update_service_out_of_process.mm",
"prefs_mac.mm",
......@@ -138,6 +142,7 @@ if (is_win || is_mac) {
if (is_win) {
sources += [
"app/app_wake_win.cc",
"app/server/win/com_classes.cc",
"app/server/win/com_classes.h",
"app/server/win/com_classes_legacy.cc",
......
......@@ -4,18 +4,20 @@
#include "chrome/updater/app/app_wake.h"
#include <utility>
#include "base/bind.h"
#include "base/logging.h"
#include "build/build_config.h"
#include "chrome/updater/app/app.h"
#include "chrome/updater/configurator.h"
#include "chrome/updater/prefs.h"
#include "chrome/updater/update_apps.h"
#include "chrome/updater/update_service.h"
#include "chrome/updater/control_service.h"
namespace updater {
// TODO(sorin): Implement the control service for Windows. crbug.com/1105589.
#if !defined(OS_WIN)
// AppWake is a simple client which dials the same-versioned server via RPC and
// tells that server to run its control tasks. This is done via the
// ControlService interface.
class AppWake : public App {
public:
AppWake() = default;
......@@ -25,37 +27,16 @@ class AppWake : public App {
// Overrides for App.
void FirstTaskRun() override;
void Initialize() override;
void Uninitialize() override;
scoped_refptr<Configurator> config_;
scoped_refptr<UpdateService> update_service_;
};
void AppWake::Initialize() {
config_ = base::MakeRefCounted<Configurator>(CreateGlobalPrefs());
}
void AppWake::Uninitialize() {
update_service_->Uninitialize();
}
// AppWake triggers an update of all registered applications.
void AppWake::FirstTaskRun() {
update_service_ = CreateUpdateService(config_);
update_service_->UpdateAll(
base::BindRepeating([](UpdateService::UpdateState) {}),
base::BindOnce(
[](base::OnceCallback<void(int)> quit, UpdateService::Result result) {
const int exit_code = static_cast<int>(result);
VLOG(0) << "UpdateAll complete: exit_code = " << exit_code;
std::move(quit).Run(exit_code);
},
base::BindOnce(&AppWake::Shutdown, this)));
CreateControlService()->Run(base::BindOnce(&AppWake::Shutdown, this, 0));
}
scoped_refptr<App> MakeAppWake() {
return base::MakeRefCounted<AppWake>();
}
#endif
} // namespace updater
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/updater/app/app_wake.h"
#include <utility>
#include "base/bind.h"
#include "base/logging.h"
#include "chrome/updater/app/app.h"
#include "chrome/updater/configurator.h"
#include "chrome/updater/prefs.h"
#include "chrome/updater/update_service.h"
namespace updater {
class AppWake : public App {
public:
AppWake() = default;
private:
~AppWake() override = default;
// Overrides for App.
void FirstTaskRun() override;
void Initialize() override;
void Uninitialize() override;
scoped_refptr<Configurator> config_;
scoped_refptr<UpdateService> update_service_;
};
void AppWake::Initialize() {
config_ = base::MakeRefCounted<Configurator>(CreateGlobalPrefs());
}
void AppWake::Uninitialize() {
update_service_->Uninitialize();
}
// AppWake triggers an update of all registered applications.
// TODO(sorin): Implement the control service for Windows. crbug.com/1105589.
// This means that this code goes away, use the platform neutral implementation
// of AppWake, which delegates to the control service.
void AppWake::FirstTaskRun() {
update_service_ = CreateUpdateService(config_);
update_service_->UpdateAll(
base::BindRepeating([](UpdateService::UpdateState) {}),
base::BindOnce(
[](base::OnceCallback<void(int)> quit, UpdateService::Result result) {
const int exit_code = static_cast<int>(result);
VLOG(0) << "UpdateAll complete: exit_code = " << exit_code;
std::move(quit).Run(exit_code);
},
base::BindOnce(&AppWake::Shutdown, this)));
}
scoped_refptr<App> MakeAppWake() {
return base::MakeRefCounted<AppWake>();
}
} // namespace updater
......@@ -49,12 +49,11 @@ class AppServerMac : public AppServer {
SEQUENCE_CHECKER(sequence_checker_);
base::scoped_nsobject<CRUUpdateCheckXPCServiceDelegate>
base::scoped_nsobject<CRUUpdateCheckServiceXPCDelegate>
update_check_delegate_;
base::scoped_nsobject<NSXPCListener> update_check_listener_;
base::scoped_nsobject<CRUAdministrationXPCServiceDelegate>
administration_delegate_;
base::scoped_nsobject<NSXPCListener> administration_listener_;
base::scoped_nsobject<CRUControlServiceXPCDelegate> control_service_delegate_;
base::scoped_nsobject<NSXPCListener> control_service_listener_;
// Task runner bound to the main sequence and the update service instance.
scoped_refptr<base::SequencedTaskRunner> main_task_runner_;
......
......@@ -19,6 +19,7 @@
#import "chrome/updater/app/server/mac/app_server.h"
#include "chrome/updater/app/server/mac/service_delegate.h"
#include "chrome/updater/configurator.h"
#include "chrome/updater/control_service_in_process.h"
#include "chrome/updater/mac/setup/setup.h"
#import "chrome/updater/mac/xpc_service_names.h"
#include "chrome/updater/prefs.h"
......@@ -34,7 +35,7 @@ void AppServerMac::Uninitialize() {
// These delegates need to have a reference to the AppServer. To break the
// circular reference, we need to reset them.
update_check_delegate_.reset();
administration_delegate_.reset();
control_service_delegate_.reset();
AppServer::Uninitialize();
}
......@@ -49,7 +50,7 @@ void AppServerMac::ActiveDuty() {
@autoreleasepool {
// Sets up a listener and delegate for the CRUUpdateChecking XPC
// connection
update_check_delegate_.reset([[CRUUpdateCheckXPCServiceDelegate alloc]
update_check_delegate_.reset([[CRUUpdateCheckServiceXPCDelegate alloc]
initWithUpdateService:base::MakeRefCounted<UpdateServiceInProcess>(
config_)
appServer:scoped_refptr<AppServerMac>(this)]);
......@@ -60,18 +61,17 @@ void AppServerMac::ActiveDuty() {
[update_check_listener_ resume];
// Sets up a listener and delegate for the CRUAdministering XPC connection
administration_delegate_.reset([[CRUAdministrationXPCServiceDelegate alloc]
initWithUpdateService:base::MakeRefCounted<UpdateServiceInProcess>(
config_)
appServer:scoped_refptr<AppServerMac>(this)]);
// Sets up a listener and delegate for the CRUControlling XPC connection
control_service_delegate_.reset([[CRUControlServiceXPCDelegate alloc]
initWithControlService:base::MakeRefCounted<ControlServiceInProcess>()
appServer:scoped_refptr<AppServerMac>(this)]);
administration_listener_.reset([[NSXPCListener alloc]
control_service_listener_.reset([[NSXPCListener alloc]
initWithMachServiceName:base::mac::CFToNSCast(
CopyAdministrationLaunchDName().get())]);
administration_listener_.get().delegate = administration_delegate_.get();
CopyControlLaunchdName().get())]);
control_service_listener_.get().delegate = control_service_delegate_.get();
[administration_listener_ resume];
[control_service_listener_ resume];
}
}
......
......@@ -10,11 +10,12 @@
#include "base/memory/scoped_refptr.h"
namespace updater {
class ControlService;
class UpdateService;
class AppServerMac;
}
@interface CRUUpdateCheckXPCServiceDelegate : NSObject <NSXPCListenerDelegate>
@interface CRUUpdateCheckServiceXPCDelegate : NSObject <NSXPCListenerDelegate>
- (instancetype)init NS_UNAVAILABLE;
......@@ -26,15 +27,14 @@ class AppServerMac;
@end
@interface CRUAdministrationXPCServiceDelegate
: NSObject <NSXPCListenerDelegate>
@interface CRUControlServiceXPCDelegate : NSObject <NSXPCListenerDelegate>
- (instancetype)init NS_UNAVAILABLE;
// Designated initializer.
- (instancetype)
initWithUpdateService:(scoped_refptr<updater::UpdateService>)service
appServer:(scoped_refptr<updater::AppServerMac>)appServer
initWithControlService:(scoped_refptr<updater::ControlService>)service
appServer:(scoped_refptr<updater::AppServerMac>)appServer
NS_DESIGNATED_INITIALIZER;
@end
......
......@@ -21,13 +21,13 @@
#import "chrome/updater/app/server/mac/server.h"
#import "chrome/updater/app/server/mac/service_protocol.h"
#import "chrome/updater/app/server/mac/update_service_wrappers.h"
#include "chrome/updater/control_service.h"
#include "chrome/updater/mac/setup/setup.h"
#import "chrome/updater/mac/xpc_service_names.h"
#include "chrome/updater/update_service.h"
#include "chrome/updater/updater_version.h"
@interface CRUUpdateCheckXPCServiceImpl
: NSObject <CRUUpdateChecking, CRUAdministering>
@interface CRUUpdateCheckServiceXPCImpl : NSObject <CRUUpdateChecking>
- (instancetype)init NS_UNAVAILABLE;
......@@ -39,22 +39,12 @@
(scoped_refptr<base::SequencedTaskRunner>)callbackRunner
NS_DESIGNATED_INITIALIZER;
- (instancetype)
initWithUpdateService:(updater::UpdateService*)service
appServer:(scoped_refptr<updater::AppServerMac>)appServer
updaterConnectionOptions:(NSXPCConnectionOptions)options
callbackRunner:
(scoped_refptr<base::SequencedTaskRunner>)callbackRunner;
@end
@implementation CRUUpdateCheckXPCServiceImpl {
@implementation CRUUpdateCheckServiceXPCImpl {
updater::UpdateService* _service;
scoped_refptr<updater::AppServerMac> _appServer;
scoped_refptr<base::SequencedTaskRunner> _callbackRunner;
NSXPCConnectionOptions _updateCheckXPCConnectionOptions;
base::scoped_nsobject<NSXPCConnection> _updateCheckXPCConnection;
NSInteger _redialAttempts;
}
- (instancetype)
......@@ -70,38 +60,6 @@
return self;
}
- (instancetype)
initWithUpdateService:(updater::UpdateService*)service
appServer:(scoped_refptr<updater::AppServerMac>)appServer
updaterConnectionOptions:(NSXPCConnectionOptions)options
callbackRunner:
(scoped_refptr<base::SequencedTaskRunner>)callbackRunner {
[self initWithUpdateService:service
appServer:appServer
callbackRunner:callbackRunner];
_updateCheckXPCConnectionOptions = options;
[self dialUpdateCheckXPCConnection];
return self;
}
- (void)dialUpdateCheckXPCConnection {
_updateCheckXPCConnection.reset([[NSXPCConnection alloc]
initWithMachServiceName:updater::GetServiceMachName().get()
options:_updateCheckXPCConnectionOptions]);
_updateCheckXPCConnection.get().remoteObjectInterface =
updater::GetXPCUpdateCheckingInterface();
_updateCheckXPCConnection.get().interruptionHandler = ^{
LOG(WARNING) << "CRUUpdateCheckingService: XPC connection interrupted.";
};
_updateCheckXPCConnection.get().invalidationHandler = ^{
LOG(WARNING) << "CRUUpdateCheckingService: XPC connection invalidated.";
};
[_updateCheckXPCConnection resume];
}
#pragma mark CRUUpdateChecking
- (void)checkForUpdatesWithUpdateState:(id<CRUUpdateStateObserving>)updateState
reply:(void (^_Nonnull)(int rc))reply {
......@@ -227,14 +185,57 @@
request, std::move(cb)));
}
#pragma mark CRUAdministering
@end
@interface CRUControlServiceXPCImpl : NSObject <CRUControlling>
- (instancetype)init NS_UNAVAILABLE;
// Designated initializers.
- (instancetype)
initWithControlService:(updater::ControlService*)service
appServer:(scoped_refptr<updater::AppServerMac>)appServer
callbackRunner:
(scoped_refptr<base::SequencedTaskRunner>)callbackRunner
NS_DESIGNATED_INITIALIZER;
@end
@implementation CRUControlServiceXPCImpl {
updater::ControlService* _service;
scoped_refptr<updater::AppServerMac> _appServer;
scoped_refptr<base::SequencedTaskRunner> _callbackRunner;
}
- (instancetype)
initWithControlService:(updater::ControlService*)service
appServer:(scoped_refptr<updater::AppServerMac>)appServer
callbackRunner:
(scoped_refptr<base::SequencedTaskRunner>)callbackRunner {
if (self = [super init]) {
_service = service;
_appServer = appServer;
_callbackRunner = callbackRunner;
}
return self;
}
- (void)performAdminTasks {
#pragma mark CRUControlling
- (void)performControlTasksWithReply:(void (^)(void))reply {
auto cb = base::BindOnce(base::RetainBlock(^(void) {
VLOG(0) << "performControlTasks complete.";
if (reply)
reply();
}));
_callbackRunner->PostTask(
FROM_HERE,
base::BindOnce(&updater::ControlService::Run, _service, std::move(cb)));
}
@end
@implementation CRUUpdateCheckXPCServiceDelegate {
@implementation CRUUpdateCheckServiceXPCDelegate {
scoped_refptr<updater::UpdateService> _service;
scoped_refptr<updater::AppServerMac> _appServer;
scoped_refptr<base::SequencedTaskRunner> _callbackRunner;
......@@ -258,8 +259,8 @@
newConnection.exportedInterface = updater::GetXPCUpdateCheckingInterface();
base::scoped_nsobject<CRUUpdateCheckXPCServiceImpl> object(
[[CRUUpdateCheckXPCServiceImpl alloc]
base::scoped_nsobject<CRUUpdateCheckServiceXPCImpl> object(
[[CRUUpdateCheckServiceXPCImpl alloc]
initWithUpdateService:_service.get()
appServer:_appServer
callbackRunner:_callbackRunner.get()]);
......@@ -270,15 +271,15 @@
@end
@implementation CRUAdministrationXPCServiceDelegate {
scoped_refptr<updater::UpdateService> _service;
@implementation CRUControlServiceXPCDelegate {
scoped_refptr<updater::ControlService> _service;
scoped_refptr<updater::AppServerMac> _appServer;
scoped_refptr<base::SequencedTaskRunner> _callbackRunner;
}
- (instancetype)
initWithUpdateService:(scoped_refptr<updater::UpdateService>)service
appServer:(scoped_refptr<updater::AppServerMac>)appServer {
initWithControlService:(scoped_refptr<updater::ControlService>)service
appServer:(scoped_refptr<updater::AppServerMac>)appServer {
if (self = [super init]) {
_service = service;
_callbackRunner = base::SequencedTaskRunnerHandle::Get();
......@@ -291,19 +292,13 @@
// Check to see if the other side of the connection is "okay";
// if not, invalidate newConnection and return NO.
base::CommandLine* cmdLine = base::CommandLine::ForCurrentProcess();
NSXPCConnectionOptions options = cmdLine->HasSwitch(updater::kSystemSwitch)
? NSXPCConnectionPrivileged
: 0;
newConnection.exportedInterface = updater::GetXPCAdministeringInterface();
newConnection.exportedInterface = updater::GetXPCControllingInterface();
base::scoped_nsobject<CRUUpdateCheckXPCServiceImpl> object(
[[CRUUpdateCheckXPCServiceImpl alloc]
initWithUpdateService:_service.get()
appServer:_appServer
updaterConnectionOptions:options
callbackRunner:_callbackRunner.get()]);
base::scoped_nsobject<CRUControlServiceXPCImpl> object(
[[CRUControlServiceXPCImpl alloc]
initWithControlService:_service.get()
appServer:_appServer
callbackRunner:_callbackRunner.get()]);
newConnection.exportedObject = object.get();
[newConnection resume];
return YES;
......
......@@ -47,12 +47,12 @@
@end
// Protocol for the XPC administration tasks of the Updater.
@protocol CRUAdministering <NSObject>
// Protocol for the XPC control tasks of the Updater.
@protocol CRUControlling <NSObject>
// Performs the admin task (activate service, uninstall service, or no opp) that
// is relevant to the state of the Updater.
- (void)performAdminTasks;
// Performs the control task (activate service, uninstall service, or no-op)
// that is relevant to the state of the Updater.
- (void)performControlTasksWithReply:(void (^_Nullable)(void))reply;
@end
......@@ -62,9 +62,9 @@ namespace updater {
// CRUUpdateStateObserving protocols.
NSXPCInterface* _Nonnull GetXPCUpdateCheckingInterface();
// Constructs an NSXPCInterface for a connection using CRUAdministering
// Constructs an NSXPCInterface for a connection using CRUControlling
// protocol.
NSXPCInterface* _Nonnull GetXPCAdministeringInterface();
NSXPCInterface* _Nonnull GetXPCControllingInterface();
} // namespace updater
......
......@@ -30,8 +30,8 @@ NSXPCInterface* GetXPCUpdateCheckingInterface() {
return updateCheckingInterface;
}
NSXPCInterface* GetXPCAdministeringInterface() {
return [NSXPCInterface interfaceWithProtocol:@protocol(CRUAdministering)];
NSXPCInterface* GetXPCControllingInterface() {
return [NSXPCInterface interfaceWithProtocol:@protocol(CRUControlling)];
}
} // namespace updater
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_UPDATER_CONTROL_SERVICE_H_
#define CHROME_UPDATER_CONTROL_SERVICE_H_
#include "base/callback_forward.h"
#include "base/memory/ref_counted.h"
namespace updater {
// The ControlService is the cross-platform abstraction for performing admin
// tasks on the updater.
class ControlService : public base::RefCountedThreadSafe<ControlService> {
public:
virtual void Run(base::OnceClosure callback) = 0;
// Provides a way to commit data or clean up resources before the task
// scheduler is shutting down.
virtual void Uninitialize() = 0;
protected:
friend class base::RefCountedThreadSafe<ControlService>;
virtual ~ControlService() = default;
};
// A factory method to create a ControlService class instance.
scoped_refptr<ControlService> CreateControlService();
} // namespace updater
#endif // CHROME_UPDATER_CONTROL_SERVICE_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/updater/control_service_in_process.h"
#include "base/callback.h"
#include "base/threading/sequenced_task_runner_handle.h"
namespace updater {
ControlServiceInProcess::ControlServiceInProcess()
: main_task_runner_(base::SequencedTaskRunnerHandle::Get()) {}
void ControlServiceInProcess::Run(base::OnceClosure callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// TODO(crbug.com/1107586): Implement.
}
void ControlServiceInProcess::Uninitialize() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
ControlServiceInProcess::~ControlServiceInProcess() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
} // namespace updater
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_UPDATER_CONTROL_SERVICE_IN_PROCESS_H_
#define CHROME_UPDATER_CONTROL_SERVICE_IN_PROCESS_H_
#include "base/callback_forward.h"
#include "base/memory/scoped_refptr.h"
#include "base/sequence_checker.h"
#include "chrome/updater/control_service.h"
namespace base {
class SequencedTaskRunner;
}
namespace updater {
// All functions and callbacks must be called on the same sequence.
class ControlServiceInProcess : public ControlService {
public:
ControlServiceInProcess();
// Overrides for updater::ControlService.
void Run(base::OnceClosure callback) override;
void Uninitialize() override;
private:
~ControlServiceInProcess() override;
SEQUENCE_CHECKER(sequence_checker_);
scoped_refptr<base::SequencedTaskRunner> main_task_runner_;
};
} // namespace updater
#endif // CHROME_UPDATER_CONTROL_SERVICE_IN_PROCESS_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_UPDATER_MAC_CONTROL_SERVICE_OUT_OF_PROCESS_H_
#define CHROME_UPDATER_MAC_CONTROL_SERVICE_OUT_OF_PROCESS_H_
#import <Foundation/Foundation.h>
#include "base/callback_forward.h"
#include "base/mac/scoped_nsobject.h"
#include "base/memory/scoped_refptr.h"
#include "base/sequence_checker.h"
#include "chrome/updater/control_service.h"
#include "chrome/updater/update_service.h"
@class CRUControlServiceOutOfProcessImpl;
namespace base {
class SequencedTaskRunner;
} // namespace base
namespace updater {
// All functions and callbacks must be called on the same sequence.
class ControlServiceOutOfProcess : public ControlService {
public:
explicit ControlServiceOutOfProcess(UpdateService::Scope scope);
// Overrides for ControlService.
void Run(base::OnceClosure callback) override;
void Uninitialize() override;
private:
~ControlServiceOutOfProcess() override;
SEQUENCE_CHECKER(sequence_checker_);
base::scoped_nsobject<CRUControlServiceOutOfProcessImpl> client_;
scoped_refptr<base::SequencedTaskRunner> callback_runner_;
};
} // namespace updater
#endif // CHROME_UPDATER_MAC_CONTROL_SERVICE_OUT_OF_PROCESS_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/updater/mac/control_service_out_of_process.h"
#import <Foundation/Foundation.h>
#include "base/callback.h"
#include "base/logging.h"
#include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h"
#include "base/threading/sequenced_task_runner_handle.h"
#import "chrome/updater/app/server/mac/service_protocol.h"
#import "chrome/updater/mac/xpc_service_names.h"
#include "chrome/updater/update_service.h"
// Interface to communicate with the XPC Control Service.
@interface CRUControlServiceOutOfProcessImpl : NSObject <CRUControlling>
- (instancetype)initPrivileged;
@end
@implementation CRUControlServiceOutOfProcessImpl {
base::scoped_nsobject<NSXPCConnection> _controlXPCConnection;
}
- (instancetype)init {
return [self initWithConnectionOptions:0];
}
- (instancetype)initPrivileged {
return [self initWithConnectionOptions:NSXPCConnectionPrivileged];
}
- (instancetype)initWithConnectionOptions:(NSXPCConnectionOptions)options {
if ((self = [super init])) {
_controlXPCConnection.reset([[NSXPCConnection alloc]
initWithMachServiceName:updater::GetVersionedServiceMachName().get()
options:options]);
_controlXPCConnection.get().remoteObjectInterface =
updater::GetXPCControllingInterface();
_controlXPCConnection.get().interruptionHandler = ^{
LOG(WARNING) << "CRUControlling: XPC connection interrupted.";
};
_controlXPCConnection.get().invalidationHandler = ^{
LOG(WARNING) << "CRUControlling: XPC connection invalidated.";
};
[_controlXPCConnection resume];
}
return self;
}
- (void)dealloc {
[_controlXPCConnection invalidate];
[super dealloc];
}
- (void)performControlTasksWithReply:(void (^)(void))reply {
auto errorHandler = ^(NSError* xpcError) {
LOG(ERROR) << "XPC connection failed: "
<< base::SysNSStringToUTF8([xpcError description]);
reply();
};
[[_controlXPCConnection remoteObjectProxyWithErrorHandler:errorHandler]
performControlTasksWithReply:reply];
}
@end
namespace updater {
ControlServiceOutOfProcess::ControlServiceOutOfProcess(
UpdateService::Scope scope)
: callback_runner_(base::SequencedTaskRunnerHandle::Get()) {
switch (scope) {
case UpdateService::Scope::kSystem:
client_.reset([[CRUControlServiceOutOfProcessImpl alloc] initPrivileged]);
break;
case UpdateService::Scope::kUser:
client_.reset([[CRUControlServiceOutOfProcessImpl alloc] init]);
break;
}
}
void ControlServiceOutOfProcess::Run(base::OnceClosure callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
__block base::OnceClosure block_callback = std::move(callback);
auto reply = ^() {
callback_runner_->PostTask(FROM_HERE,
base::BindOnce(std::move(block_callback)));
};
[client_ performControlTasksWithReply:reply];
}
void ControlServiceOutOfProcess::Uninitialize() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
ControlServiceOutOfProcess::~ControlServiceOutOfProcess() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
} // namespace updater
......@@ -24,8 +24,11 @@ constexpr int kFailedToRemoveActiveUpdateServiceJobFromLaunchd = 20;
// Failed to remove versioned update service job from Launchd.
constexpr int kFailedToRemoveCandidateUpdateServiceJobFromLaunchd = 21;
// Failed to remove versioned administration job from Launchd.
constexpr int kFailedToRemoveAdministrationJobFromLaunchd = 22;
// Failed to remove versioned control job from Launchd.
constexpr int kFailedToRemoveControlJobFromLaunchd = 22;
// Failed to remove versioned wake job from Launchd.
constexpr int kFailedToRemoveWakeJobFromLaunchd = 23;
// Failed to create the active(unversioned) update service Launchd plist.
constexpr int kFailedToCreateUpdateServiceLaunchdJobPlist = 30;
......@@ -33,8 +36,11 @@ constexpr int kFailedToCreateUpdateServiceLaunchdJobPlist = 30;
// Failed to create the versioned update service Launchd plist.
constexpr int kFailedToCreateVersionedUpdateServiceLaunchdJobPlist = 31;
// Failed to create the versioned administration Launchd plist.
constexpr int kFailedToCreateAdministrationLaunchdJobPlist = 32;
// Failed to create the versioned control Launchd plist.
constexpr int kFailedToCreateControlLaunchdJobPlist = 32;
// Failed to create the versioned wake Launchd plist.
constexpr int kFailedToCreateWakeLaunchdJobPlist = 33;
// Failed to start the active(unversioned) update service job.
constexpr int kFailedToStartLaunchdActiveServiceJob = 40;
......@@ -42,8 +48,11 @@ constexpr int kFailedToStartLaunchdActiveServiceJob = 40;
// Failed to start the versioned update service job.
constexpr int kFailedToStartLaunchdVersionedServiceJob = 41;
// Failed to start the administration job.
constexpr int kFailedToStartLaunchdAdministrationJob = 42;
// Failed to start the control job.
constexpr int kFailedToStartLaunchdControlJob = 42;
// Failed to start the wake job.
constexpr int kFailedToStartLaunchdWakeJob = 43;
} // namespace setup_exit_codes
......
......@@ -114,17 +114,15 @@ NSString* MakeProgramArgument(const char* argument) {
}
base::ScopedCFTypeRef<CFDictionaryRef> CreateServiceLaunchdPlist(
const base::ScopedCFTypeRef<CFStringRef> label,
const base::FilePath& updater_path) {
// See the man page for launchd.plist.
NSDictionary<NSString*, id>* launchd_plist = @{
@LAUNCH_JOBKEY_LABEL : base::mac::CFToNSCast(label),
@LAUNCH_JOBKEY_LABEL : GetServiceLaunchdLabel(),
@LAUNCH_JOBKEY_PROGRAMARGUMENTS : @[
base::SysUTF8ToNSString(updater_path.value()),
MakeProgramArgument(kServerSwitch)
],
@LAUNCH_JOBKEY_MACHSERVICES :
@{GetServiceMachName(base::mac::CFToNSCast(label)) : @YES},
@LAUNCH_JOBKEY_MACHSERVICES : @{GetServiceMachName() : @YES},
@LAUNCH_JOBKEY_ABANDONPROCESSGROUP : @NO,
@LAUNCH_JOBKEY_LIMITLOADTOSESSIONTYPE : @"Aqua"
};
......@@ -134,7 +132,7 @@ base::ScopedCFTypeRef<CFDictionaryRef> CreateServiceLaunchdPlist(
base::scoped_policy::RETAIN);
}
base::ScopedCFTypeRef<CFDictionaryRef> CreateAdministrationLaunchdPlist(
base::ScopedCFTypeRef<CFDictionaryRef> CreateWakeLaunchdPlist(
const base::FilePath& updater_path) {
// See the man page for launchd.plist.
NSMutableArray<NSString*>* program_arguments =
......@@ -147,8 +145,7 @@ base::ScopedCFTypeRef<CFDictionaryRef> CreateAdministrationLaunchdPlist(
[program_arguments addObject:MakeProgramArgument(kSystemSwitch)];
NSDictionary<NSString*, id>* launchd_plist = @{
@LAUNCH_JOBKEY_LABEL :
base::mac::CFToNSCast(CopyAdministrationLaunchDName()),
@LAUNCH_JOBKEY_LABEL : GetWakeLaunchdLabel(),
@LAUNCH_JOBKEY_PROGRAMARGUMENTS : program_arguments,
@LAUNCH_JOBKEY_STARTINTERVAL : @3600,
@LAUNCH_JOBKEY_ABANDONPROCESSGROUP : @NO,
......@@ -160,29 +157,54 @@ base::ScopedCFTypeRef<CFDictionaryRef> CreateAdministrationLaunchdPlist(
base::scoped_policy::RETAIN);
}
bool CreateUpdateServiceLaunchdJobPlist(
const base::ScopedCFTypeRef<CFStringRef> name,
base::ScopedCFTypeRef<CFDictionaryRef> CreateControlLaunchdPlist(
const base::FilePath& updater_path) {
// See the man page for launchd.plist.
NSDictionary<NSString*, id>* launchd_plist = @{
@LAUNCH_JOBKEY_LABEL : GetControlLaunchdLabel(),
@LAUNCH_JOBKEY_PROGRAMARGUMENTS : @[
base::SysUTF8ToNSString(updater_path.value()),
MakeProgramArgument(kServerSwitch)
],
@LAUNCH_JOBKEY_MACHSERVICES : @{GetVersionedServiceMachName() : @YES},
@LAUNCH_JOBKEY_ABANDONPROCESSGROUP : @NO,
@LAUNCH_JOBKEY_LIMITLOADTOSESSIONTYPE : @"Aqua"
};
return base::ScopedCFTypeRef<CFDictionaryRef>(
base::mac::CFCast<CFDictionaryRef>(launchd_plist),
base::scoped_policy::RETAIN);
}
bool CreateUpdateServiceLaunchdJobPlist(const base::FilePath& updater_path) {
// We're creating directories and writing a file.
base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
base::BlockingType::MAY_BLOCK);
base::ScopedCFTypeRef<CFDictionaryRef> plist(
CreateServiceLaunchdPlist(name, updater_path));
CreateServiceLaunchdPlist(updater_path));
return Launchd::GetInstance()->WritePlistToFile(
LaunchdDomain(), ServiceLaunchdType(), name, plist);
LaunchdDomain(), ServiceLaunchdType(), CopyServiceLaunchdName(), plist);
}
bool CreateUpdateAdministrationLaunchdJobPlist(
const base::FilePath& updater_path) {
bool CreateWakeLaunchdJobPlist(const base::FilePath& updater_path) {
// We're creating directories and writing a file.
base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
base::BlockingType::MAY_BLOCK);
base::ScopedCFTypeRef<CFDictionaryRef> plist(
CreateAdministrationLaunchdPlist(updater_path));
CreateWakeLaunchdPlist(updater_path));
return Launchd::GetInstance()->WritePlistToFile(
LaunchdDomain(), ServiceLaunchdType(), CopyAdministrationLaunchDName(),
plist);
LaunchdDomain(), ServiceLaunchdType(), CopyWakeLaunchdName(), plist);
}
bool CreateControlLaunchdJobPlist(const base::FilePath& updater_path) {
// We're creating directories and writing a file.
base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
base::BlockingType::MAY_BLOCK);
base::ScopedCFTypeRef<CFDictionaryRef> plist(
CreateControlLaunchdPlist(updater_path));
return Launchd::GetInstance()->WritePlistToFile(
LaunchdDomain(), ServiceLaunchdType(), CopyControlLaunchdName(), plist);
}
bool StartUpdateServiceVersionedLaunchdJob(
......@@ -191,14 +213,20 @@ bool StartUpdateServiceVersionedLaunchdJob(
LaunchdDomain(), ServiceLaunchdType(), name, CFSTR("Aqua"));
}
bool StartUpdateAdministrationVersionedLaunchdJob() {
bool StartUpdateWakeVersionedLaunchdJob() {
return Launchd::GetInstance()->RestartJob(
LaunchdDomain(), ServiceLaunchdType(), CopyWakeLaunchdName(),
CFSTR("Aqua"));
}
bool StartUpdateControlVersionedLaunchdJob() {
return Launchd::GetInstance()->RestartJob(
LaunchdDomain(), ServiceLaunchdType(), CopyAdministrationLaunchDName(),
LaunchdDomain(), ServiceLaunchdType(), CopyControlLaunchdName(),
CFSTR("Aqua"));
}
bool StartLaunchdServiceJob() {
return StartUpdateServiceVersionedLaunchdJob(CopyServiceLaunchDName());
return StartUpdateServiceVersionedLaunchdJob(CopyServiceLaunchdName());
}
bool RemoveJobFromLaunchd(Launchd::Domain domain,
......@@ -225,11 +253,15 @@ bool RemoveUpdateServiceJobFromLaunchd(
}
bool RemoveUpdateServiceJobFromLaunchd() {
return RemoveUpdateServiceJobFromLaunchd(CopyServiceLaunchDName());
return RemoveUpdateServiceJobFromLaunchd(CopyServiceLaunchdName());
}
bool RemoveUpdateAdministrationJobFromLaunchd() {
return RemoveClientJobFromLaunchd(CopyAdministrationLaunchDName());
bool RemoveUpdateWakeJobFromLaunchd() {
return RemoveClientJobFromLaunchd(CopyWakeLaunchdName());
}
bool RemoveUpdateControlJobFromLaunchd() {
return RemoveClientJobFromLaunchd(CopyControlLaunchdName());
}
bool DeleteInstallFolder(const base::FilePath& installed_path) {
......@@ -256,20 +288,24 @@ int InstallCandidate() {
dest_path.Append(GetUpdaterAppName())
.Append(GetUpdaterAppExecutablePath());
if (!CreateUpdateAdministrationLaunchdJobPlist(
updater_executable_path)) {
return setup_exit_codes::kFailedToCreateAdministrationLaunchdJobPlist;
}
if (!CreateWakeLaunchdJobPlist(updater_executable_path))
return setup_exit_codes::kFailedToCreateWakeLaunchdJobPlist;
if (!StartUpdateAdministrationVersionedLaunchdJob()) {
return setup_exit_codes::kFailedToStartLaunchdAdministrationJob;
}
if (!CreateControlLaunchdJobPlist(updater_executable_path))
return setup_exit_codes::kFailedToCreateControlLaunchdJobPlist;
if (!StartUpdateControlVersionedLaunchdJob())
return setup_exit_codes::kFailedToStartLaunchdControlJob;
if (!StartUpdateWakeVersionedLaunchdJob())
return setup_exit_codes::kFailedToStartLaunchdWakeJob;
return setup_exit_codes::kSuccess;
}
int UninstallCandidate() {
RemoveUpdateAdministrationJobFromLaunchd();
RemoveUpdateControlJobFromLaunchd();
RemoveUpdateWakeJobFromLaunchd();
DeleteInstallFolder(GetVersionedUpdaterFolderPath());
return setup_exit_codes::kSuccess;
}
......@@ -280,14 +316,11 @@ int PromoteCandidate() {
dest_path.Append(GetUpdaterAppName())
.Append(GetUpdaterAppExecutablePath());
if (!CreateUpdateServiceLaunchdJobPlist(CopyServiceLaunchDName(),
updater_executable_path)) {
if (!CreateUpdateServiceLaunchdJobPlist(updater_executable_path))
return setup_exit_codes::kFailedToCreateUpdateServiceLaunchdJobPlist;
}
if (!StartLaunchdServiceJob()) {
if (!StartLaunchdServiceJob())
return setup_exit_codes::kFailedToStartLaunchdActiveServiceJob;
}
return setup_exit_codes::kSuccess;
}
......
......@@ -128,68 +128,6 @@ using base::SysUTF8ToNSString;
@end
// Interface to communicate with the XPC Updater Service.
@interface CRUAdministrationServiceOutOfProcessImpl
: NSObject <CRUAdministering>
- (instancetype)initPrivileged;
@end
@implementation CRUAdministrationServiceOutOfProcessImpl {
base::scoped_nsobject<NSXPCConnection> _administrationXPCConnection;
}
- (instancetype)init {
return [self initWithConnectionOptions:0];
}
- (instancetype)initPrivileged {
return [self initWithConnectionOptions:NSXPCConnectionPrivileged];
}
- (instancetype)initWithConnectionOptions:(NSXPCConnectionOptions)options {
if ((self = [super init])) {
_administrationXPCConnection.reset([[NSXPCConnection alloc]
initWithMachServiceName:base::mac::CFToNSCast(
updater::CopyAdministrationLaunchDName()
.get())
options:options]);
_administrationXPCConnection.get().remoteObjectInterface =
updater::GetXPCAdministeringInterface();
_administrationXPCConnection.get().interruptionHandler = ^{
LOG(WARNING) << "CRUAdministering: XPC connection interrupted.";
};
_administrationXPCConnection.get().invalidationHandler = ^{
LOG(WARNING) << "CRUAdministering: XPC connection invalidated.";
};
[_administrationXPCConnection resume];
}
return self;
}
- (void)dealloc {
[_administrationXPCConnection invalidate];
[super dealloc];
}
- (void)performAdminTasks {
auto errorHandler = ^(NSError* xpcError) {
LOG(ERROR) << "XPC connection failed: "
<< base::SysNSStringToUTF8([xpcError description]);
};
[[_administrationXPCConnection remoteObjectProxyWithErrorHandler:errorHandler]
performAdminTasks];
}
@end
namespace updater {
UpdateServiceOutOfProcess::UpdateServiceOutOfProcess(
......@@ -201,8 +139,6 @@ UpdateServiceOutOfProcess::UpdateServiceOutOfProcess(
case UpdateService::Scope::kUser:
client_.reset([[CRUUpdateServiceOutOfProcessImpl alloc] init]);
break;
default:
CHECK(false) << "Unexpected value for UpdateService::Scope";
}
callback_runner_ = base::SequencedTaskRunnerHandle::Get();
}
......
......@@ -10,12 +10,14 @@
namespace updater {
base::ScopedCFTypeRef<CFStringRef> CopyServiceLaunchDName();
base::ScopedCFTypeRef<CFStringRef> CopyAdministrationLaunchDName();
base::scoped_nsobject<NSString> GetServiceLaunchDLabel();
base::scoped_nsobject<NSString> GetAdministrationLaunchDLabel();
base::scoped_nsobject<NSString> GetServiceMachName(NSString* name);
base::ScopedCFTypeRef<CFStringRef> CopyServiceLaunchdName();
base::ScopedCFTypeRef<CFStringRef> CopyWakeLaunchdName();
base::ScopedCFTypeRef<CFStringRef> CopyControlLaunchdName();
base::scoped_nsobject<NSString> GetServiceLaunchdLabel();
base::scoped_nsobject<NSString> GetWakeLaunchdLabel();
base::scoped_nsobject<NSString> GetControlLaunchdLabel();
base::scoped_nsobject<NSString> GetServiceMachName();
base::scoped_nsobject<NSString> GetVersionedServiceMachName();
} // namespace updater
......
......@@ -12,37 +12,58 @@
namespace updater {
base::ScopedCFTypeRef<CFStringRef> CopyServiceLaunchDName() {
base::ScopedCFTypeRef<CFStringRef> CopyServiceLaunchdName() {
return base::SysUTF8ToCFStringRef(MAC_BUNDLE_IDENTIFIER_STRING ".service");
}
base::ScopedCFTypeRef<CFStringRef> CopyAdministrationLaunchDName() {
base::ScopedCFTypeRef<CFStringRef> CopyWakeLaunchdName() {
return base::SysUTF8ToCFStringRef(MAC_BUNDLE_IDENTIFIER_STRING
".admin." UPDATER_VERSION_STRING);
".wake." UPDATER_VERSION_STRING);
}
base::scoped_nsobject<NSString> GetServiceLaunchDLabel() {
base::ScopedCFTypeRef<CFStringRef> CopyControlLaunchdName() {
return base::SysUTF8ToCFStringRef(MAC_BUNDLE_IDENTIFIER_STRING
".control." UPDATER_VERSION_STRING);
}
base::scoped_nsobject<NSString> GetServiceLaunchdLabel() {
return base::scoped_nsobject<NSString>(
base::mac::CFToNSCast(CopyServiceLaunchdName().release()));
}
base::scoped_nsobject<NSString> GetWakeLaunchdLabel() {
return base::scoped_nsobject<NSString>(
base::mac::CFToNSCast(CopyServiceLaunchDName().release()));
base::mac::CFToNSCast(CopyWakeLaunchdName().release()));
}
base::scoped_nsobject<NSString> GetAdministrationLaunchDLabel() {
base::scoped_nsobject<NSString> GetControlLaunchdLabel() {
return base::scoped_nsobject<NSString>(
base::mac::CFToNSCast(CopyAdministrationLaunchDName().release()));
base::mac::CFToNSCast(CopyControlLaunchdName().release()));
}
base::scoped_nsobject<NSString> GetServiceMachName(NSString* name) {
base::scoped_nsobject<NSString> GetServiceMachName(
base::scoped_nsobject<NSString> name) {
return base::scoped_nsobject<NSString>(
[name stringByAppendingFormat:@".%lu", [name hash]],
base::scoped_policy::RETAIN);
}
base::scoped_nsobject<NSString> GetServiceMachName() {
return GetServiceMachName(GetServiceLaunchdLabel());
}
base::scoped_nsobject<NSString> GetVersionedServiceMachName() {
base::scoped_nsobject<NSString> serviceLaunchdLabel(
GetServiceLaunchdLabel(), base::scoped_policy::RETAIN);
base::scoped_nsobject<NSString> updaterVersionString(
base::SysUTF8ToNSString(UPDATER_VERSION_STRING),
base::scoped_policy::RETAIN);
base::scoped_nsobject<NSString> name(
base::mac::CFToNSCast(CopyServiceLaunchDName().release()));
return base::scoped_nsobject<NSString>(
[name stringByAppendingFormat:@".%lu", [GetServiceLaunchDLabel() hash]],
[NSString stringWithFormat:@"%@.%@", serviceLaunchdLabel.get(),
updaterVersionString.get()],
base::scoped_policy::RETAIN);
return GetServiceMachName(name);
}
} // namespace updater
......@@ -53,25 +53,31 @@ bool Run(base::CommandLine command_line, int* exit_code) {
void Clean() {
EXPECT_TRUE(base::DeletePathRecursively(GetProductPath()));
EXPECT_TRUE(Launchd::GetInstance()->DeletePlist(
Launchd::User, Launchd::Agent, updater::CopyAdministrationLaunchDName()));
Launchd::User, Launchd::Agent, updater::CopyWakeLaunchdName()));
EXPECT_TRUE(Launchd::GetInstance()->DeletePlist(
Launchd::User, Launchd::Agent, updater::CopyServiceLaunchDName()));
Launchd::User, Launchd::Agent, updater::CopyControlLaunchdName()));
EXPECT_TRUE(Launchd::GetInstance()->DeletePlist(
Launchd::User, Launchd::Agent, updater::CopyServiceLaunchdName()));
}
void ExpectClean() {
// Files must not exist on the file system.
EXPECT_FALSE(base::PathExists(GetProductPath()));
EXPECT_FALSE(Launchd::GetInstance()->PlistExists(
Launchd::User, Launchd::Agent, updater::CopyAdministrationLaunchDName()));
Launchd::User, Launchd::Agent, updater::CopyWakeLaunchdName()));
EXPECT_FALSE(Launchd::GetInstance()->PlistExists(
Launchd::User, Launchd::Agent, updater::CopyControlLaunchdName()));
EXPECT_FALSE(Launchd::GetInstance()->PlistExists(
Launchd::User, Launchd::Agent, updater::CopyServiceLaunchDName()));
Launchd::User, Launchd::Agent, updater::CopyServiceLaunchdName()));
}
void ExpectInstalled() {
// Files must exist on the file system.
EXPECT_TRUE(base::PathExists(GetProductPath()));
EXPECT_TRUE(Launchd::GetInstance()->PlistExists(
Launchd::User, Launchd::Agent, CopyAdministrationLaunchDName()));
EXPECT_TRUE(Launchd::GetInstance()->PlistExists(Launchd::User, Launchd::Agent,
CopyWakeLaunchdName()));
EXPECT_TRUE(Launchd::GetInstance()->PlistExists(Launchd::User, Launchd::Agent,
CopyControlLaunchdName()));
}
void Install() {
......@@ -88,7 +94,7 @@ void ExpectActive() {
// Files must exist on the file system.
EXPECT_TRUE(base::PathExists(GetProductPath()));
EXPECT_TRUE(Launchd::GetInstance()->PlistExists(Launchd::User, Launchd::Agent,
CopyServiceLaunchDName()));
CopyServiceLaunchdName()));
}
void PromoteCandidate() {
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_UPDATER_UPDATE_APPS_H_
#define CHROME_UPDATER_UPDATE_APPS_H_
#include "base/memory/scoped_refptr.h"
namespace update_client {
class Configurator;
} // namespace update_client
namespace updater {
class UpdateService;
// A factory method to create an UpdateService class instance.
scoped_refptr<UpdateService> CreateUpdateService(
scoped_refptr<update_client::Configurator> config);
} // namespace updater
#endif // CHROME_UPDATER_UPDATE_APPS_H_
......@@ -2,12 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/updater/update_apps.h"
#include "base/command_line.h"
#include "base/memory/ref_counted.h"
#include "chrome/updater/configurator.h"
#include "chrome/updater/constants.h"
#include "chrome/updater/mac/control_service_out_of_process.h"
#include "chrome/updater/mac/update_service_out_of_process.h"
#include "chrome/updater/update_service_in_process.h"
......@@ -26,4 +25,13 @@ scoped_refptr<UpdateService> CreateUpdateService(
UpdateService::Scope::kUser);
}
scoped_refptr<ControlService> CreateControlService() {
base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
return cmdline->HasSwitch(kSystemSwitch)
? base::MakeRefCounted<ControlServiceOutOfProcess>(
UpdateService::Scope::kSystem)
: base::MakeRefCounted<ControlServiceOutOfProcess>(
UpdateService::Scope::kUser);
}
} // namespace updater
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/updater/update_apps.h"
#include "base/command_line.h"
#include "base/memory/ref_counted.h"
#include "chrome/updater/configurator.h"
......
......@@ -11,6 +11,10 @@
#include "base/memory/ref_counted.h"
#include "base/version.h"
namespace update_client {
class Configurator;
} // namespace update_client
namespace updater {
struct RegistrationRequest;
......@@ -196,6 +200,10 @@ class UpdateService : public base::RefCountedThreadSafe<UpdateService> {
virtual ~UpdateService() = default;
};
// A factory method to create an UpdateService class instance.
scoped_refptr<UpdateService> CreateUpdateService(
scoped_refptr<update_client::Configurator> config);
} // namespace updater
#endif // CHROME_UPDATER_UPDATE_SERVICE_H_
......@@ -62,14 +62,6 @@ constexpr base::char16 kAppNameChrome[] = L"Google Chrome";
class AppInstallController;
scoped_refptr<UpdateService> CreateUpdateService(
scoped_refptr<update_client::Configurator> config) {
if (base::CommandLine::ForCurrentProcess()->HasSwitch(kSingleProcessSwitch))
return base::MakeRefCounted<UpdateServiceInProcess>(config);
else
return base::MakeRefCounted<UpdateServiceOutOfProcess>();
}
// Implements a simple inter-thread communication protocol based on Windows
// messages exchanged between the application installer and its UI.
//
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment