1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_UPDATER_APP_SERVER_POSIX_UPDATE_SERVICE_STUB_H_
#define CHROME_UPDATER_APP_SERVER_POSIX_UPDATE_SERVICE_STUB_H_
#include <memory>
#include "base/functional/callback_forward.h"
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_refptr.h"
#include "base/sequence_checker.h"
#include "chrome/updater/mojom/updater_service.mojom.h"
#include "chrome/updater/update_service.h"
#include "chrome/updater/update_service_internal.h"
#include "components/named_mojo_ipc_server/named_mojo_ipc_server.h"
namespace policy {
enum class PolicyFetchReason;
} // namespace policy
namespace updater {
// Receives RPC calls from the client and delegates them to an UpdateService.
// The stub creates and manages a `NamedMojoIpcServer` to listen for and broker
// new Mojo connections with clients.
class UpdateServiceStub : public mojom::UpdateService {
public:
// Creates an `UpdateServiceStub` which forwards calls to `impl`. Opens a
// `NamedMojoIpcServer` which listens on a socket whose name is decided by
// `scope`.
UpdateServiceStub(scoped_refptr<updater::UpdateService> impl,
UpdaterScope scope,
base::RepeatingClosure task_start_listener,
base::RepeatingClosure task_end_listener);
UpdateServiceStub(const UpdateServiceStub&) = delete;
UpdateServiceStub& operator=(const UpdateServiceStub&) = delete;
~UpdateServiceStub() override;
// updater::mojom::UpdateService
void GetVersion(GetVersionCallback callback) override;
void FetchPolicies(policy::PolicyFetchReason reason,
FetchPoliciesCallback callback) override;
void RegisterApp(mojom::RegistrationRequestPtr request,
RegisterAppCallback callback) override;
void GetAppStates(GetAppStatesCallback callback) override;
void RunPeriodicTasks(RunPeriodicTasksCallback callback) override;
void Update(const std::string& app_id,
const std::string& install_data_index,
UpdateService::Priority priority,
UpdateService::PolicySameVersionUpdate policy_same_version_update,
bool do_update_check_only,
const std::optional<std::string>& language,
UpdateCallback callback) override;
void UpdateAll(UpdateAllCallback callback) override;
void Install(mojom::RegistrationRequestPtr registration,
const std::string& client_install_data,
const std::string& install_data_index,
UpdateService::Priority priority,
const std::optional<std::string>& language,
InstallCallback callback) override;
void CancelInstalls(const std::string& app_id) override;
void RunInstaller(const std::string& app_id,
const ::base::FilePath& installer_path,
const std::string& install_args,
const std::string& install_data,
const std::string& install_settings,
const std::optional<std::string>& language,
RunInstallerCallback callback) override;
void CheckForUpdate(
const std::string& app_id,
UpdateService::Priority priority,
UpdateService::PolicySameVersionUpdate policy_same_version_update,
const std::optional<std::string>& language,
UpdateCallback callback) override;
private:
FRIEND_TEST_ALL_PREFIXES(UpdaterIPCTestCase, AllRpcsComplete);
FRIEND_TEST_ALL_PREFIXES(KSAdminTest, Register);
// Creates an `UpdateServiceStub` and invokes a callback when the server
// endpoint is created. This is useful for tests.
UpdateServiceStub(
scoped_refptr<updater::UpdateService> impl,
UpdaterScope scope,
base::RepeatingClosure task_start_listener,
base::RepeatingClosure task_end_listener,
base::RepeatingClosure endpoint_created_listener_for_testing);
std::unique_ptr<mojom::UpdateService> filter_;
named_mojo_ipc_server::NamedMojoIpcServer<mojom::UpdateService> server_;
scoped_refptr<updater::UpdateService> impl_;
base::RepeatingClosure task_start_listener_;
base::RepeatingClosure task_end_listener_;
SEQUENCE_CHECKER(sequence_checker_);
};
} // namespace updater
#endif // CHROME_UPDATER_APP_SERVER_POSIX_UPDATE_SERVICE_STUB_H_
|