Commit ebbdfcbb authored by Mila Green's avatar Mila Green Committed by Commit Bot

Updater: Refactor the Scope enum out of the UpdateService class.

Bug: 1106783

Change-Id: Ie9e9f5ed1898b012469516a3b96491b1bcb98d39
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2313120Reviewed-by: default avatarJoshua Pawlicki <waffles@chromium.org>
Commit-Queue: Mila Green <milagreen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790871}
parent b61bcf7b
...@@ -54,6 +54,7 @@ if (is_win || is_mac) { ...@@ -54,6 +54,7 @@ if (is_win || is_mac) {
"policy_manager.h", "policy_manager.h",
"registration_data.cc", "registration_data.cc",
"registration_data.h", "registration_data.h",
"service_scope.h",
"unzipper.cc", "unzipper.cc",
"unzipper.h", "unzipper.h",
"update_service.cc", "update_service.cc",
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "base/sequence_checker.h" #include "base/sequence_checker.h"
#include "chrome/updater/control_service.h" #include "chrome/updater/control_service.h"
#include "chrome/updater/update_service.h" #include "chrome/updater/service_scope.h"
@class CRUControlServiceOutOfProcessImpl; @class CRUControlServiceOutOfProcessImpl;
...@@ -25,7 +25,7 @@ namespace updater { ...@@ -25,7 +25,7 @@ namespace updater {
// All functions and callbacks must be called on the same sequence. // All functions and callbacks must be called on the same sequence.
class ControlServiceOutOfProcess : public ControlService { class ControlServiceOutOfProcess : public ControlService {
public: public:
explicit ControlServiceOutOfProcess(UpdateService::Scope scope); explicit ControlServiceOutOfProcess(ServiceScope scope);
// Overrides for ControlService. // Overrides for ControlService.
void Run(base::OnceClosure callback) override; void Run(base::OnceClosure callback) override;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include "base/threading/sequenced_task_runner_handle.h" #include "base/threading/sequenced_task_runner_handle.h"
#import "chrome/updater/app/server/mac/service_protocol.h" #import "chrome/updater/app/server/mac/service_protocol.h"
#import "chrome/updater/mac/xpc_service_names.h" #import "chrome/updater/mac/xpc_service_names.h"
#include "chrome/updater/update_service.h" #include "chrome/updater/service_scope.h"
// Interface to communicate with the XPC Control Service. // Interface to communicate with the XPC Control Service.
@interface CRUControlServiceOutOfProcessImpl : NSObject <CRUControlling> @interface CRUControlServiceOutOfProcessImpl : NSObject <CRUControlling>
...@@ -77,14 +77,13 @@ ...@@ -77,14 +77,13 @@
namespace updater { namespace updater {
ControlServiceOutOfProcess::ControlServiceOutOfProcess( ControlServiceOutOfProcess::ControlServiceOutOfProcess(ServiceScope scope)
UpdateService::Scope scope)
: callback_runner_(base::SequencedTaskRunnerHandle::Get()) { : callback_runner_(base::SequencedTaskRunnerHandle::Get()) {
switch (scope) { switch (scope) {
case UpdateService::Scope::kSystem: case ServiceScope::kSystem:
client_.reset([[CRUControlServiceOutOfProcessImpl alloc] initPrivileged]); client_.reset([[CRUControlServiceOutOfProcessImpl alloc] initPrivileged]);
break; break;
case UpdateService::Scope::kUser: case ServiceScope::kUser:
client_.reset([[CRUControlServiceOutOfProcessImpl alloc] init]); client_.reset([[CRUControlServiceOutOfProcessImpl alloc] init]);
break; break;
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "base/sequence_checker.h" #include "base/sequence_checker.h"
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
#include "chrome/updater/service_scope.h"
#include "chrome/updater/update_service.h" #include "chrome/updater/update_service.h"
@class CRUUpdateServiceOutOfProcessImpl; @class CRUUpdateServiceOutOfProcessImpl;
...@@ -31,7 +32,7 @@ namespace updater { ...@@ -31,7 +32,7 @@ namespace updater {
// All functions and callbacks must be called on the same sequence. // All functions and callbacks must be called on the same sequence.
class UpdateServiceOutOfProcess : public UpdateService { class UpdateServiceOutOfProcess : public UpdateService {
public: public:
explicit UpdateServiceOutOfProcess(UpdateService::Scope scope); explicit UpdateServiceOutOfProcess(ServiceScope scope);
// Overrides for UpdateService. // Overrides for UpdateService.
void RegisterApp( void RegisterApp(
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#import "chrome/updater/app/server/mac/service_protocol.h" #import "chrome/updater/app/server/mac/service_protocol.h"
#import "chrome/updater/app/server/mac/update_service_wrappers.h" #import "chrome/updater/app/server/mac/update_service_wrappers.h"
#import "chrome/updater/mac/xpc_service_names.h" #import "chrome/updater/mac/xpc_service_names.h"
#include "chrome/updater/service_scope.h"
#include "chrome/updater/update_service.h" #include "chrome/updater/update_service.h"
#include "chrome/updater/updater_version.h" #include "chrome/updater/updater_version.h"
#include "components/update_client/update_client_errors.h" #include "components/update_client/update_client_errors.h"
...@@ -130,13 +131,12 @@ using base::SysUTF8ToNSString; ...@@ -130,13 +131,12 @@ using base::SysUTF8ToNSString;
namespace updater { namespace updater {
UpdateServiceOutOfProcess::UpdateServiceOutOfProcess( UpdateServiceOutOfProcess::UpdateServiceOutOfProcess(ServiceScope scope) {
UpdateService::Scope scope) {
switch (scope) { switch (scope) {
case UpdateService::Scope::kSystem: case ServiceScope::kSystem:
client_.reset([[CRUUpdateServiceOutOfProcessImpl alloc] initPrivileged]); client_.reset([[CRUUpdateServiceOutOfProcessImpl alloc] initPrivileged]);
break; break;
case UpdateService::Scope::kUser: case ServiceScope::kUser:
client_.reset([[CRUUpdateServiceOutOfProcessImpl alloc] init]); client_.reset([[CRUUpdateServiceOutOfProcessImpl alloc] init]);
break; break;
} }
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#import "chrome/updater/app/server/mac/update_service_wrappers.h" #import "chrome/updater/app/server/mac/update_service_wrappers.h"
#include "chrome/updater/mac/scoped_xpc_service_mock.h" #include "chrome/updater/mac/scoped_xpc_service_mock.h"
#import "chrome/updater/mac/xpc_service_names.h" #import "chrome/updater/mac/xpc_service_names.h"
#include "chrome/updater/service_scope.h"
#include "chrome/updater/unittest_util.h" #include "chrome/updater/unittest_util.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "testing/gtest_mac.h" #include "testing/gtest_mac.h"
...@@ -293,7 +294,7 @@ void MacUpdateServiceOutOfProcessTest::SetUp() { ...@@ -293,7 +294,7 @@ void MacUpdateServiceOutOfProcessTest::SetUp() {
base::SequencedTaskRunnerHandle::Get()->PostTask( base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindLambdaForTesting([this]() { FROM_HERE, base::BindLambdaForTesting([this]() {
service_ = base::MakeRefCounted<UpdateServiceOutOfProcess>( service_ = base::MakeRefCounted<UpdateServiceOutOfProcess>(
UpdateService::Scope::kUser); ServiceScope::kUser);
})); }));
} }
......
// 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_SERVICE_SCOPE_H_
#define CHROME_UPDATER_SERVICE_SCOPE_H_
namespace updater {
// Scope of the update/control service invocation.
enum class ServiceScope {
// The updater is running in the logged in user's scope.
kUser = 1,
// The updater is running in the system's scope.
kSystem = 2,
};
} // namespace updater
#endif // CHROME_UPDATER_SERVICE_SCOPE_H_
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "chrome/updater/constants.h" #include "chrome/updater/constants.h"
#include "chrome/updater/mac/control_service_out_of_process.h" #include "chrome/updater/mac/control_service_out_of_process.h"
#include "chrome/updater/mac/update_service_out_of_process.h" #include "chrome/updater/mac/update_service_out_of_process.h"
#include "chrome/updater/service_scope.h"
#include "chrome/updater/update_service_in_process.h" #include "chrome/updater/update_service_in_process.h"
namespace updater { namespace updater {
...@@ -20,18 +21,18 @@ scoped_refptr<UpdateService> CreateUpdateService( ...@@ -20,18 +21,18 @@ scoped_refptr<UpdateService> CreateUpdateService(
return cmdline->HasSwitch(kSystemSwitch) return cmdline->HasSwitch(kSystemSwitch)
? base::MakeRefCounted<UpdateServiceOutOfProcess>( ? base::MakeRefCounted<UpdateServiceOutOfProcess>(
UpdateService::Scope::kSystem) ServiceScope::kSystem)
: base::MakeRefCounted<UpdateServiceOutOfProcess>( : base::MakeRefCounted<UpdateServiceOutOfProcess>(
UpdateService::Scope::kUser); ServiceScope::kUser);
} }
scoped_refptr<ControlService> CreateControlService() { scoped_refptr<ControlService> CreateControlService() {
base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
return cmdline->HasSwitch(kSystemSwitch) return cmdline->HasSwitch(kSystemSwitch)
? base::MakeRefCounted<ControlServiceOutOfProcess>( ? base::MakeRefCounted<ControlServiceOutOfProcess>(
UpdateService::Scope::kSystem) ServiceScope::kSystem)
: base::MakeRefCounted<ControlServiceOutOfProcess>( : base::MakeRefCounted<ControlServiceOutOfProcess>(
UpdateService::Scope::kUser); ServiceScope::kUser);
} }
} // namespace updater } // namespace updater
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