Commit 4d6a5015 authored by Mila Green's avatar Mila Green Committed by Commit Bot

Implement an XPC client for the UpdateService.

Bug: 1055876
Change-Id: I5ffb6614730422b3ef98ea8d02cefd94581e1449
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2072661
Commit-Queue: Mila Green <milagreen@chromium.org>
Reviewed-by: default avatarSorin Jianu <sorin@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarJoshua Pawlicki <waffles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744776}
parent 25343c18
...@@ -28,6 +28,22 @@ source_set("network_fetcher_sources") { ...@@ -28,6 +28,22 @@ source_set("network_fetcher_sources") {
] ]
} }
source_set("update_service_client_sources") {
sources = [
"update_service_out_of_process.h",
"update_service_out_of_process.mm",
]
deps = [
"//base",
"//chrome/updater:base",
"//chrome/updater:lib",
"//chrome/updater:version_header",
"//chrome/updater/server",
"//components/update_client",
]
}
source_set("updater_tests") { source_set("updater_tests") {
testonly = true testonly = true
...@@ -50,6 +66,7 @@ mac_app_bundle("updater_bundle") { ...@@ -50,6 +66,7 @@ mac_app_bundle("updater_bundle") {
sources = [ "main.cc" ] sources = [ "main.cc" ]
deps = [ deps = [
":network_fetcher_sources", ":network_fetcher_sources",
":update_service_client_sources",
":updater_setup_sources", ":updater_setup_sources",
"//chrome/updater:lib", "//chrome/updater:lib",
] ]
......
// 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_UPDATE_SERVICE_OUT_OF_PROCESS_H_
#define CHROME_UPDATER_MAC_UPDATE_SERVICE_OUT_OF_PROCESS_H_
#include "base/callback_forward.h"
#include "base/mac/scoped_nsobject.h"
#include "base/memory/ref_counted.h"
#import "chrome/updater/server/mac/service_protocol.h"
#include "chrome/updater/update_service.h"
@class CRUUpdateServiceOutOfProcessImpl;
namespace update_client {
enum class Error;
} // namespace update_client
namespace updater {
// All functions and callbacks must be called on the same sequence.
class UpdateServiceOutOfProcess : public UpdateService {
public:
UpdateServiceOutOfProcess();
UpdateServiceOutOfProcess(const UpdateServiceOutOfProcess&) = delete;
UpdateServiceOutOfProcess& operator=(const UpdateServiceOutOfProcess&) =
delete;
~UpdateServiceOutOfProcess() override;
// Overrides for updater::UpdateService.
// Update-checks all registered applications. Calls |callback| once the
// operation is complete.
void RegisterApp(
const RegistrationRequest& request,
base::OnceCallback<void(const RegistrationResponse&)> callback) override;
void UpdateAll(
base::OnceCallback<void(update_client::Error)> callback) override;
private:
SEQUENCE_CHECKER(sequence_checker_);
base::scoped_nsobject<CRUUpdateServiceOutOfProcessImpl> _client;
};
} // namespace updater
#endif // CHROME_UPDATER_MAC_UPDATE_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/update_service_out_of_process.h"
#include <string>
#include "base/bind.h"
#include "base/callback.h"
#include "base/logging.h"
#include "base/mac/scoped_nsobject.h"
#include "base/memory/scoped_refptr.h"
#include "base/strings/sys_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
#import "chrome/updater/server/mac/service_protocol.h"
#include "chrome/updater/updater_version.h"
#include "components/update_client/update_client_errors.h"
// Interface to communicate with the XPC Updater Service.
@interface CRUUpdateServiceOutOfProcessImpl : NSObject <CRUUpdateChecking>
@end
@implementation CRUUpdateServiceOutOfProcessImpl {
base::scoped_nsobject<NSXPCConnection> _xpcConnection;
}
- (instancetype)init {
if ((self = [super init])) {
std::string serviceName = MAC_BUNDLE_IDENTIFIER_STRING;
serviceName.append(".UpdaterXPCService");
_xpcConnection.reset([[NSXPCConnection alloc]
initWithServiceName:base::SysUTF8ToNSString(serviceName)]);
_xpcConnection.get().remoteObjectInterface =
[NSXPCInterface interfaceWithProtocol:@protocol(CRUUpdateChecking)];
[_xpcConnection resume];
}
return self;
}
- (void)registerForUpdatesWithAppId:(NSString* _Nullable)appId
brandCode:(NSString* _Nullable)brandCode
tag:(NSString* _Nullable)tag
version:(NSString* _Nullable)version
existenceCheckerPath:(NSString* _Nullable)existenceCheckerPath
reply:(void (^_Nullable)(int rc))reply {
auto errorHandler = ^(NSError* xpcError) {
LOG(ERROR) << "XPC connection failed: " << [xpcError description];
reply(-1);
};
[[_xpcConnection.get() remoteObjectProxyWithErrorHandler:errorHandler]
registerForUpdatesWithAppId:appId
brandCode:brandCode
tag:tag
version:version
existenceCheckerPath:existenceCheckerPath
reply:reply];
}
- (void)checkForUpdatesWithReply:(void (^_Nullable)(int rc))reply {
auto errorHandler = ^(NSError* xpcError) {
LOG(ERROR) << "XPC connection failed: " << [xpcError description];
reply(-1);
};
[[_xpcConnection.get() remoteObjectProxyWithErrorHandler:errorHandler]
checkForUpdatesWithReply:reply];
}
@end
namespace updater {
UpdateServiceOutOfProcess::UpdateServiceOutOfProcess() {
_client.reset([[CRUUpdateServiceOutOfProcessImpl alloc] init]);
}
void UpdateServiceOutOfProcess::RegisterApp(
const RegistrationRequest& request,
base::OnceCallback<void(const RegistrationResponse&)> callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
NOTREACHED();
// TODO(crbug.com/1055942): Implement.
}
void UpdateServiceOutOfProcess::UpdateAll(
base::OnceCallback<void(update_client::Error)> callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
__block base::OnceCallback<void(update_client::Error)> block_callback =
std::move(callback);
auto reply = ^(int error) {
base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(std::move(block_callback),
static_cast<update_client::Error>(error)));
};
[_client.get() checkForUpdatesWithReply:reply];
}
UpdateServiceOutOfProcess::~UpdateServiceOutOfProcess() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
} // 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