Commit 584f21d8 authored by Sorin Jianu's avatar Sorin Jianu Committed by Commit Bot

Implement --ua client-server (work in progress).

This CL provides the COM client code to call when --ua runs.
The code is not working yet since the query interface for IUpdater
returns "type libraries not registered (0x8002801d).

It seems that the server also does not get activated by COM and
it needs to be manually started with --server for now.

Bug: 1053729
Change-Id: Iaafd96ad81617537ee693cf702274b68cf3b374a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2101938Reviewed-by: default avatarS. Ganesh <ganesh@chromium.org>
Commit-Queue: Sorin Jianu <sorin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#750203}
parent 8541e86b
...@@ -25,6 +25,7 @@ class AppUpdateAll : public App { ...@@ -25,6 +25,7 @@ class AppUpdateAll : public App {
void Initialize() override; void Initialize() override;
scoped_refptr<Configurator> config_; scoped_refptr<Configurator> config_;
std::unique_ptr<UpdateService> update_service_;
}; };
void AppUpdateAll::Initialize() { void AppUpdateAll::Initialize() {
...@@ -33,9 +34,12 @@ void AppUpdateAll::Initialize() { ...@@ -33,9 +34,12 @@ void AppUpdateAll::Initialize() {
// AppUpdateAll triggers an update of all registered applications. // AppUpdateAll triggers an update of all registered applications.
void AppUpdateAll::FirstTaskRun() { void AppUpdateAll::FirstTaskRun() {
CreateUpdateService(config_)->UpdateAll(base::BindOnce( update_service_ = CreateUpdateService(config_);
update_service_->UpdateAll(base::BindOnce(
[](base::OnceCallback<void(int)> quit, update_client::Error error) { [](base::OnceCallback<void(int)> quit, update_client::Error error) {
VLOG(0) << "UpdateAll complete: error = " << static_cast<int>(error); const int err = static_cast<int>(error);
VLOG(0) << "UpdateAll complete: error = " << err << "/0x" << std::hex
<< err;
std::move(quit).Run(static_cast<int>(error)); std::move(quit).Run(static_cast<int>(error));
}, },
base::BindOnce(&AppUpdateAll::Shutdown, this))); base::BindOnce(&AppUpdateAll::Shutdown, this)));
......
...@@ -17,7 +17,7 @@ std::unique_ptr<UpdateService> CreateUpdateService( ...@@ -17,7 +17,7 @@ std::unique_ptr<UpdateService> CreateUpdateService(
if (base::CommandLine::ForCurrentProcess()->HasSwitch(kSingleProcessSwitch)) if (base::CommandLine::ForCurrentProcess()->HasSwitch(kSingleProcessSwitch))
return std::make_unique<UpdateServiceInProcess>(config); return std::make_unique<UpdateServiceInProcess>(config);
else else
return std::make_unique<UpdateServiceOutOfProcess>(); return UpdateServiceOutOfProcess::CreateInstance();
} }
} // namespace updater } // namespace updater
...@@ -21,7 +21,8 @@ struct RegistrationResponse; ...@@ -21,7 +21,8 @@ struct RegistrationResponse;
// All functions and callbacks must be called on the same sequence. // All functions and callbacks must be called on the same sequence.
class UpdateService { class UpdateService {
public: public:
typedef update_client::Error Result; using Result = update_client::Error;
// Possible states for updating an app. // Possible states for updating an app.
enum class UpdateState { enum class UpdateState {
// This value represents the absence of a state. No update request has // This value represents the absence of a state. No update request has
......
...@@ -4,8 +4,26 @@ ...@@ -4,8 +4,26 @@
#include "chrome/updater/win/update_service_out_of_process.h" #include "chrome/updater/win/update_service_out_of_process.h"
#include <windows.h>
#include <wrl/client.h>
#include <memory>
#include <utility>
#include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "chrome/updater/server/win/updater_idl.h"
namespace {
static constexpr base::TaskTraits kComClientTraits = {
base::TaskPriority::BEST_EFFORT,
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN};
} // namespace
namespace updater { namespace updater {
...@@ -15,6 +33,17 @@ UpdateServiceOutOfProcess::~UpdateServiceOutOfProcess() { ...@@ -15,6 +33,17 @@ UpdateServiceOutOfProcess::~UpdateServiceOutOfProcess() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
} }
std::unique_ptr<UpdateServiceOutOfProcess>
UpdateServiceOutOfProcess::CreateInstance() {
struct Creator : public UpdateServiceOutOfProcess {};
auto instance = std::make_unique<Creator>();
instance->com_task_runner_ =
base::ThreadPool::CreateCOMSTATaskRunner(kComClientTraits);
if (!instance->com_task_runner_)
return nullptr;
return instance;
}
void UpdateServiceOutOfProcess::RegisterApp( void UpdateServiceOutOfProcess::RegisterApp(
const RegistrationRequest& request, const RegistrationRequest& request,
base::OnceCallback<void(const RegistrationResponse&)> callback) { base::OnceCallback<void(const RegistrationResponse&)> callback) {
...@@ -31,7 +60,9 @@ void UpdateServiceOutOfProcess::UpdateAll( ...@@ -31,7 +60,9 @@ void UpdateServiceOutOfProcess::UpdateAll(
// TODO(sorin) the updater must be run with "--single-process" until // TODO(sorin) the updater must be run with "--single-process" until
// crbug.com/1053729 is resolved. // crbug.com/1053729 is resolved.
NOTREACHED(); com_task_runner_->PostTask(
FROM_HERE, base::BindOnce(&UpdateServiceOutOfProcess::UpdateAllOnSTA,
base::Unretained(this), std::move(callback)));
} }
void UpdateServiceOutOfProcess::Update(const std::string& app_id, void UpdateServiceOutOfProcess::Update(const std::string& app_id,
...@@ -45,4 +76,33 @@ void UpdateServiceOutOfProcess::Update(const std::string& app_id, ...@@ -45,4 +76,33 @@ void UpdateServiceOutOfProcess::Update(const std::string& app_id,
NOTREACHED(); NOTREACHED();
} }
void UpdateServiceOutOfProcess::UpdateAllOnSTA(
base::OnceCallback<void(Result)> callback) {
DCHECK(com_task_runner_->BelongsToCurrentThread());
Microsoft::WRL::ComPtr<IUnknown> server;
HRESULT hr = ::CoCreateInstance(CLSID_UpdaterClass, nullptr,
CLSCTX_LOCAL_SERVER, IID_PPV_ARGS(&server));
if (FAILED(hr)) {
VLOG(2) << "Failed to instantiate the update server. " << std::hex << hr;
std::move(callback).Run(static_cast<Result>(hr));
return;
}
Microsoft::WRL::ComPtr<IUpdater> updater;
hr = server.As(&updater);
if (FAILED(hr)) {
VLOG(2) << "Failed to query the updater interface. " << std::hex << hr;
std::move(callback).Run(static_cast<Result>(hr));
return;
}
hr = updater->UpdateAll();
if (FAILED(hr)) {
VLOG(2) << "Failed to call IUpdater::UpdateAll" << std::hex << hr;
std::move(callback).Run(static_cast<Result>(hr));
return;
}
}
} // namespace updater } // namespace updater
...@@ -5,12 +5,18 @@ ...@@ -5,12 +5,18 @@
#ifndef CHROME_UPDATER_WIN_UPDATE_SERVICE_OUT_OF_PROCESS_H_ #ifndef CHROME_UPDATER_WIN_UPDATE_SERVICE_OUT_OF_PROCESS_H_
#define CHROME_UPDATER_WIN_UPDATE_SERVICE_OUT_OF_PROCESS_H_ #define CHROME_UPDATER_WIN_UPDATE_SERVICE_OUT_OF_PROCESS_H_
#include <memory>
#include <string> #include <string>
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/memory/scoped_refptr.h"
#include "base/sequence_checker.h" #include "base/sequence_checker.h"
#include "chrome/updater/update_service.h" #include "chrome/updater/update_service.h"
namespace base {
class SingleThreadTaskRunner;
} // namespace base
namespace update_client { namespace update_client {
enum class Error; enum class Error;
} // namespace update_client } // namespace update_client
...@@ -23,12 +29,13 @@ using StateChangeCallback = ...@@ -23,12 +29,13 @@ using StateChangeCallback =
// 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:
UpdateServiceOutOfProcess();
UpdateServiceOutOfProcess(const UpdateServiceOutOfProcess&) = delete; UpdateServiceOutOfProcess(const UpdateServiceOutOfProcess&) = delete;
UpdateServiceOutOfProcess& operator=(const UpdateServiceOutOfProcess&) = UpdateServiceOutOfProcess& operator=(const UpdateServiceOutOfProcess&) =
delete; delete;
~UpdateServiceOutOfProcess() override; ~UpdateServiceOutOfProcess() override;
static std::unique_ptr<UpdateServiceOutOfProcess> CreateInstance();
// Overrides for updater::UpdateService. // Overrides for updater::UpdateService.
// Update-checks all registered applications. Calls |callback| once the // Update-checks all registered applications. Calls |callback| once the
// operation is complete. // operation is complete.
...@@ -42,7 +49,12 @@ class UpdateServiceOutOfProcess : public UpdateService { ...@@ -42,7 +49,12 @@ class UpdateServiceOutOfProcess : public UpdateService {
base::OnceCallback<void(Result)> done) override; base::OnceCallback<void(Result)> done) override;
private: private:
UpdateServiceOutOfProcess();
void UpdateAllOnSTA(base::OnceCallback<void(Result)> callback);
SEQUENCE_CHECKER(sequence_checker_); SEQUENCE_CHECKER(sequence_checker_);
scoped_refptr<base::SingleThreadTaskRunner> com_task_runner_;
}; };
} // 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