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

Updater: Fix XPC. Correctly dial XPC service. Repeating callbacks fixed.

With this CL we are properly dialing the XPC connection and sending messages.
This also fixes the issues with the StateChangeCallback being sent over XPC.

Bug: 1055876
Change-Id: I81077476e49be486620ae4e2eb8cba022c3ae4de
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2124933
Commit-Queue: Mila Green <milagreen@chromium.org>
Reviewed-by: default avatarJoshua Pawlicki <waffles@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarSorin Jianu <sorin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#754971}
parent 9511185c
...@@ -97,6 +97,7 @@ if (is_win || is_mac) { ...@@ -97,6 +97,7 @@ if (is_win || is_mac) {
"server/mac/server.mm", "server/mac/server.mm",
"server/mac/service_delegate.h", "server/mac/service_delegate.h",
"server/mac/service_delegate.mm", "server/mac/service_delegate.mm",
"server/mac/service_protocol.mm",
"server/mac/update_service_wrappers.h", "server/mac/update_service_wrappers.h",
"server/mac/update_service_wrappers.mm", "server/mac/update_service_wrappers.mm",
"update_apps_mac.mm", "update_apps_mac.mm",
......
...@@ -34,9 +34,10 @@ using base::SysUTF8ToNSString; ...@@ -34,9 +34,10 @@ using base::SysUTF8ToNSString;
- (instancetype)init { - (instancetype)init {
if ((self = [super init])) { if ((self = [super init])) {
_xpcConnection.reset([[NSXPCConnection alloc] _xpcConnection.reset([[NSXPCConnection alloc]
initWithServiceName:updater::GetGoogleUpdateServiceMachName().get()]); initWithMachServiceName:updater::GetGoogleUpdateServiceMachName().get()
_xpcConnection.get().remoteObjectInterface = options:0]);
[NSXPCInterface interfaceWithProtocol:@protocol(CRUUpdateChecking)];
_xpcConnection.get().remoteObjectInterface = updater::GetXpcInterface();
_xpcConnection.get().interruptionHandler = ^{ _xpcConnection.get().interruptionHandler = ^{
LOG(WARNING) << "CRUUpdateCheckingService: XPC connection interrupted."; LOG(WARNING) << "CRUUpdateCheckingService: XPC connection interrupted.";
...@@ -73,7 +74,9 @@ using base::SysUTF8ToNSString; ...@@ -73,7 +74,9 @@ using base::SysUTF8ToNSString;
reply:reply]; reply:reply];
} }
- (void)checkForUpdatesWithReply:(void (^_Nullable)(int rc))reply { - (void)checkForUpdatesWithUpdateState:
(id<CRUUpdateStateObserving> _Nonnull)updateState
reply:(void (^_Nullable)(int rc))reply {
auto errorHandler = ^(NSError* xpcError) { auto errorHandler = ^(NSError* xpcError) {
LOG(ERROR) << "XPC connection failed: " LOG(ERROR) << "XPC connection failed: "
<< base::SysNSStringToUTF8([xpcError description]); << base::SysNSStringToUTF8([xpcError description]);
...@@ -81,12 +84,14 @@ using base::SysUTF8ToNSString; ...@@ -81,12 +84,14 @@ using base::SysUTF8ToNSString;
}; };
[[_xpcConnection remoteObjectProxyWithErrorHandler:errorHandler] [[_xpcConnection remoteObjectProxyWithErrorHandler:errorHandler]
checkForUpdatesWithReply:reply]; checkForUpdatesWithUpdateState:updateState
reply:reply];
} }
- (void)checkForUpdateWithAppID:(NSString* _Nonnull)appID - (void)checkForUpdateWithAppID:(NSString* _Nonnull)appID
priority:(CRUPriorityWrapper* _Nonnull)priority priority:(CRUPriorityWrapper* _Nonnull)priority
updateState:(CRUUpdateStateObserver* _Nonnull)updateState updateState:
(id<CRUUpdateStateObserving> _Nonnull)updateState
reply:(void (^_Nullable)(int rc))reply { reply:(void (^_Nullable)(int rc))reply {
auto errorHandler = ^(NSError* xpcError) { auto errorHandler = ^(NSError* xpcError) {
LOG(ERROR) << "XPC connection failed: " LOG(ERROR) << "XPC connection failed: "
...@@ -147,7 +152,11 @@ void UpdateServiceOutOfProcess::UpdateAll(StateChangeCallback state_update, ...@@ -147,7 +152,11 @@ void UpdateServiceOutOfProcess::UpdateAll(StateChangeCallback state_update,
static_cast<update_client::Error>(error))); static_cast<update_client::Error>(error)));
}; };
[client_ checkForUpdatesWithReply:reply]; base::scoped_nsprotocol<id<CRUUpdateStateObserving>> stateObserver(
[[CRUUpdateStateObserver alloc]
initWithRepeatingCallback:state_update
callbackRunner:callback_runner_]);
[client_ checkForUpdatesWithUpdateState:stateObserver.get() reply:reply];
} }
void UpdateServiceOutOfProcess::Update(const std::string& app_id, void UpdateServiceOutOfProcess::Update(const std::string& app_id,
...@@ -166,7 +175,7 @@ void UpdateServiceOutOfProcess::Update(const std::string& app_id, ...@@ -166,7 +175,7 @@ void UpdateServiceOutOfProcess::Update(const std::string& app_id,
base::scoped_nsobject<CRUPriorityWrapper> priorityWrapper( base::scoped_nsobject<CRUPriorityWrapper> priorityWrapper(
[[CRUPriorityWrapper alloc] initWithPriority:priority]); [[CRUPriorityWrapper alloc] initWithPriority:priority]);
base::scoped_nsobject<CRUUpdateStateObserver> stateObserver( base::scoped_nsprotocol<id<CRUUpdateStateObserving>> stateObserver(
[[CRUUpdateStateObserver alloc] [[CRUUpdateStateObserver alloc]
initWithRepeatingCallback:state_update initWithRepeatingCallback:state_update
callbackRunner:callback_runner_]); callbackRunner:callback_runner_]);
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
namespace updater { namespace updater {
RegistrationRequest::RegistrationRequest() = default; RegistrationRequest::RegistrationRequest() = default;
RegistrationRequest::RegistrationRequest(const RegistrationRequest&) = default;
RegistrationRequest::~RegistrationRequest() = default; RegistrationRequest::~RegistrationRequest() = default;
} // namespace updater } // namespace updater
...@@ -15,10 +15,9 @@ namespace updater { ...@@ -15,10 +15,9 @@ namespace updater {
struct RegistrationRequest { struct RegistrationRequest {
RegistrationRequest(); RegistrationRequest();
RegistrationRequest(const RegistrationRequest&);
RegistrationRequest& operator=(const RegistrationRequest& other) = default;
~RegistrationRequest(); ~RegistrationRequest();
RegistrationRequest(const RegistrationRequest&) = delete;
RegistrationRequest& operator=(const RegistrationRequest&) = delete;
// Application ID of the app. // Application ID of the app.
std::string app_id; std::string app_id;
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/mac/scoped_block.h" #include "base/mac/scoped_block.h"
#include "base/mac/scoped_nsobject.h" #include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "base/threading/sequenced_task_runner_handle.h"
#import "chrome/updater/server/mac/service_protocol.h" #import "chrome/updater/server/mac/service_protocol.h"
#import "chrome/updater/server/mac/update_service_wrappers.h" #import "chrome/updater/server/mac/update_service_wrappers.h"
#include "chrome/updater/update_service.h" #include "chrome/updater/update_service.h"
...@@ -19,17 +20,23 @@ ...@@ -19,17 +20,23 @@
// Designated initializer. // Designated initializer.
- (instancetype)initWithUpdateService:(updater::UpdateService*)service - (instancetype)initWithUpdateService:(updater::UpdateService*)service
callbackRunner:(scoped_refptr<base::SequencedTaskRunner>)
callbackRunner
NS_DESIGNATED_INITIALIZER; NS_DESIGNATED_INITIALIZER;
@end @end
@implementation CRUUpdateCheckXPCServiceImpl { @implementation CRUUpdateCheckXPCServiceImpl {
updater::UpdateService* _service; updater::UpdateService* _service;
scoped_refptr<base::SequencedTaskRunner> _callbackRunner;
} }
- (instancetype)initWithUpdateService:(updater::UpdateService*)service { - (instancetype)initWithUpdateService:(updater::UpdateService*)service
callbackRunner:(scoped_refptr<base::SequencedTaskRunner>)
callbackRunner {
if (self = [super init]) { if (self = [super init]) {
_service = service; _service = service;
_callbackRunner = callbackRunner;
} }
return self; return self;
} }
...@@ -38,31 +45,51 @@ ...@@ -38,31 +45,51 @@
// Unsupported, but we must override NSObject's designated initializer. // Unsupported, but we must override NSObject's designated initializer.
DLOG(ERROR) DLOG(ERROR)
<< "Plain init method not supported for CRUUpdateCheckXPCServiceImpl."; << "Plain init method not supported for CRUUpdateCheckXPCServiceImpl.";
return [self initWithUpdateService:nullptr]; return [self initWithUpdateService:nullptr callbackRunner:nullptr];
} }
- (void)checkForUpdatesWithReply:(void (^_Nullable)(int rc))reply { - (void)checkForUpdatesWithUpdateState:(id<CRUUpdateStateObserving>)updateState
base::OnceCallback<void(updater::UpdateService::Result)> cb = reply:(void (^_Nullable)(int rc))reply {
auto cb =
base::BindOnce(base::RetainBlock(^(updater::UpdateService::Result error) { base::BindOnce(base::RetainBlock(^(updater::UpdateService::Result error) {
VLOG(0) << "UpdateAll complete: error = " << static_cast<int>(error); VLOG(0) << "UpdateAll complete: error = " << static_cast<int>(error);
reply(static_cast<int>(error)); reply(static_cast<int>(error));
})); }));
_service->UpdateAll({}, base::BindOnce(std::move(cb))); auto sccb = base::BindRepeating(
base::RetainBlock(^(updater::UpdateService::UpdateState state) {
base::scoped_nsobject<CRUUpdateStateWrapper> updateStateWrapper(
[[CRUUpdateStateWrapper alloc] initWithUpdateState:state]);
[updateState observeUpdateState:updateStateWrapper.get()];
}));
_callbackRunner->PostTask(
FROM_HERE, base::BindOnce(&updater::UpdateService::UpdateAll, _service,
std::move(sccb), std::move(cb)));
} }
- (void)checkForUpdateWithAppID:(NSString* _Nonnull)appID - (void)checkForUpdateWithAppID:(NSString* _Nonnull)appID
priority:(CRUPriorityWrapper* _Nonnull)priority priority:(CRUPriorityWrapper* _Nonnull)priority
updateState:(CRUUpdateStateObserver* _Nonnull)updateState updateState:(id<CRUUpdateStateObserving>)updateState
reply:(void (^_Nullable)(int rc))reply { reply:(void (^_Nullable)(int rc))reply {
base::OnceCallback<void(updater::UpdateService::Result)> cb = auto cb =
base::BindOnce(base::RetainBlock(^(updater::UpdateService::Result error) { base::BindOnce(base::RetainBlock(^(updater::UpdateService::Result error) {
VLOG(0) << "Update complete: error = " << static_cast<int>(error); VLOG(0) << "Update complete: error = " << static_cast<int>(error);
reply(static_cast<int>(error)); reply(static_cast<int>(error));
})); }));
_service->Update(base::SysNSStringToUTF8(appID), [priority priority], auto sccb = base::BindRepeating(
[updateState callback], base::BindOnce(std::move(cb))); base::RetainBlock(^(updater::UpdateService::UpdateState state) {
base::scoped_nsobject<CRUUpdateStateWrapper> updateStateWrapper(
[[CRUUpdateStateWrapper alloc] initWithUpdateState:state]);
[updateState observeUpdateState:updateStateWrapper.get()];
}));
_callbackRunner->PostTask(
FROM_HERE,
base::BindOnce(&updater::UpdateService::Update, _service,
base::SysNSStringToUTF8(appID), [priority priority],
std::move(sccb), std::move(cb)));
} }
- (void)registerForUpdatesWithAppId:(NSString* _Nullable)appId - (void)registerForUpdatesWithAppId:(NSString* _Nullable)appId
...@@ -79,27 +106,30 @@ ...@@ -79,27 +106,30 @@
request.existence_checker_path = request.existence_checker_path =
base::FilePath(base::SysNSStringToUTF8(existenceCheckerPath)); base::FilePath(base::SysNSStringToUTF8(existenceCheckerPath));
base::OnceCallback<void(const updater::RegistrationResponse&)> cb = auto cb = base::BindOnce(
base::BindOnce(
base::RetainBlock(^(const updater::RegistrationResponse& response) { base::RetainBlock(^(const updater::RegistrationResponse& response) {
VLOG(0) << "Registration complete: status code = " VLOG(0) << "Registration complete: status code = "
<< response.status_code; << response.status_code;
reply(response.status_code); reply(response.status_code);
})); }));
_service->RegisterApp(request, base::BindOnce(std::move(cb))); _callbackRunner->PostTask(
FROM_HERE, base::BindOnce(&updater::UpdateService::RegisterApp, _service,
request, std::move(cb)));
} }
@end @end
@implementation CRUUpdateCheckXPCServiceDelegate { @implementation CRUUpdateCheckXPCServiceDelegate {
scoped_refptr<updater::UpdateService> _service; scoped_refptr<updater::UpdateService> _service;
scoped_refptr<base::SequencedTaskRunner> _callbackRunner;
} }
- (instancetype)initWithUpdateService: - (instancetype)initWithUpdateService:
(scoped_refptr<updater::UpdateService>)service { (scoped_refptr<updater::UpdateService>)service {
if (self = [super init]) { if (self = [super init]) {
_service = service; _service = service;
_callbackRunner = base::SequencedTaskRunnerHandle::Get();
} }
return self; return self;
} }
...@@ -115,22 +145,13 @@ ...@@ -115,22 +145,13 @@
shouldAcceptNewConnection:(NSXPCConnection*)newConnection { shouldAcceptNewConnection:(NSXPCConnection*)newConnection {
// Check to see if the other side of the connection is "okay"; // Check to see if the other side of the connection is "okay";
// if not, invalidate newConnection and return NO. // if not, invalidate newConnection and return NO.
NSXPCInterface* updateCheckingInterface =
[NSXPCInterface interfaceWithProtocol:@protocol(CRUUpdateChecking)]; newConnection.exportedInterface = updater::GetXpcInterface();
NSXPCInterface* updateStateObservingInterface =
[NSXPCInterface interfaceWithProtocol:@protocol(CRUUpdateStateObserving)];
[updateCheckingInterface
setInterface:updateStateObservingInterface
forSelector:@selector(checkForUpdateWithAppID:
priority:updateState:reply:)
argumentIndex:2
ofReply:NO];
newConnection.exportedInterface = updateCheckingInterface;
base::scoped_nsobject<CRUUpdateCheckXPCServiceImpl> object( base::scoped_nsobject<CRUUpdateCheckXPCServiceImpl> object(
[[CRUUpdateCheckXPCServiceImpl alloc] [[CRUUpdateCheckXPCServiceImpl alloc]
initWithUpdateService:_service.get()]); initWithUpdateService:_service.get()
callbackRunner:_callbackRunner.get()]);
newConnection.exportedObject = object.get(); newConnection.exportedObject = object.get();
[newConnection resume]; [newConnection resume];
return YES; return YES;
......
...@@ -26,7 +26,9 @@ ...@@ -26,7 +26,9 @@
@protocol CRUUpdateChecking <NSObject> @protocol CRUUpdateChecking <NSObject>
// Checks for updates and returns the result in the reply block. // Checks for updates and returns the result in the reply block.
- (void)checkForUpdatesWithReply:(void (^_Nullable)(int rc))reply; - (void)checkForUpdatesWithUpdateState:
(CRUUpdateStateObserver* _Nonnull)updateState
reply:(void (^_Nullable)(int rc))reply;
// Checks for update of a given app, with specified priority. Sends repeated // Checks for update of a given app, with specified priority. Sends repeated
// updates of progress and returns the result in the reply block. // updates of progress and returns the result in the reply block.
...@@ -45,4 +47,12 @@ ...@@ -45,4 +47,12 @@
@end @end
namespace updater {
// Constructs an NSXPCInterface for a connection using CRUUpdateChecking and
// CRUUpdateStateObserving protocols.
NSXPCInterface* _Nonnull GetXpcInterface();
} // namespace updater
#endif // CHROME_UPDATER_SERVER_MAC_SERVICE_PROTOCOL_H_ #endif // CHROME_UPDATER_SERVER_MAC_SERVICE_PROTOCOL_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.
#import <Foundation/Foundation.h>
#import "chrome/updater/server/mac/service_protocol.h"
namespace updater {
NSXPCInterface* GetXpcInterface() {
NSXPCInterface* updateCheckingInterface =
[NSXPCInterface interfaceWithProtocol:@protocol(CRUUpdateChecking)];
NSXPCInterface* updateStateObservingInterface =
[NSXPCInterface interfaceWithProtocol:@protocol(CRUUpdateStateObserving)];
[updateCheckingInterface
setInterface:updateStateObservingInterface
forSelector:@selector(checkForUpdatesWithUpdateState:reply:)
argumentIndex:0
ofReply:NO];
[updateCheckingInterface
setInterface:updateStateObservingInterface
forSelector:@selector(checkForUpdateWithAppID:
priority:updateState:reply:)
argumentIndex:2
ofReply:NO];
return updateCheckingInterface;
}
} // 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