Commit 67647079 authored by Adam Norberg's avatar Adam Norberg Committed by Commit Bot

On-demand updates in UpdateService.

This introduces types to represent update states and update priority.

Bug: 1048654
Change-Id: I9c09df32cad49a7e9901ed93e7cf3dd43ead6a83
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2073399
Commit-Queue: Adam Norberg <norberg@google.com>
Reviewed-by: default avatarSorin Jianu <sorin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#747768}
parent f36971b4
......@@ -37,8 +37,11 @@ class UpdateServiceOutOfProcess : public UpdateService {
void RegisterApp(
const RegistrationRequest& request,
base::OnceCallback<void(const RegistrationResponse&)> callback) override;
void UpdateAll(
base::OnceCallback<void(update_client::Error)> callback) override;
void UpdateAll(base::OnceCallback<void(Result)> callback) override;
void Update(const std::string& app_id,
Priority priority,
base::RepeatingCallback<void(UpdateState)> state_update,
base::OnceCallback<void(Result)> done) override;
private:
SEQUENCE_CHECKER(sequence_checker_);
......
......@@ -108,7 +108,7 @@ void UpdateServiceOutOfProcess::RegisterApp(
}
void UpdateServiceOutOfProcess::UpdateAll(
base::OnceCallback<void(update_client::Error)> callback) {
base::OnceCallback<void(Result)> callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
__block base::OnceCallback<void(update_client::Error)> block_callback =
......@@ -122,6 +122,15 @@ void UpdateServiceOutOfProcess::UpdateAll(
[_client.get() checkForUpdatesWithReply:reply];
}
void UpdateServiceOutOfProcess::Update(
const std::string& app_id,
UpdateService::Priority priority,
base::RepeatingCallback<void(UpdateState)> state_update,
base::OnceCallback<void(Result)> done) {
// TODO(crbug.com/1059024): Implement.
NOTREACHED();
}
UpdateServiceOutOfProcess::~UpdateServiceOutOfProcess() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
......
......@@ -5,6 +5,8 @@
#ifndef CHROME_UPDATER_UPDATE_SERVICE_H_
#define CHROME_UPDATER_UPDATE_SERVICE_H_
#include <string>
#include "base/callback_forward.h"
namespace update_client {
......@@ -19,6 +21,51 @@ struct RegistrationResponse;
// All functions and callbacks must be called on the same sequence.
class UpdateService {
public:
typedef update_client::Error Result;
// Possible states for updating an app.
enum class UpdateState {
// This value represents the absence of a state. No update request has
// yet been issued.
kUnknown = 0,
// This update has not been started, but has been requested.
kNotStarted = 1,
// The engine began issuing an update check request.
kCheckingForUpdates = 2,
// The engine began downloading an update.
kDownloading = 3,
// The engine began running installation scripts.
kInstalling = 4,
// The engine found and installed an update for this product. The update
// is complete and the state will not change.
kUpdated = 100,
// The engine checked for updates. This product is already up to date.
// No update has been installed for this product. The update is complete
// and the state will not change.
kNoUpdate = 101,
// The engine encountered an error updating this product. The update has
// halted and the state will not change.
kUpdateError = 102,
};
// Urgency of the update service invocation.
enum class Priority {
// The caller has not set a valid priority value.
kUnknown = 0,
// The user is not waiting for this update.
kBackground = 1,
// The user actively requested this update.
kForeground = 2,
};
UpdateService(const UpdateService&) = delete;
UpdateService& operator=(const UpdateService&) = delete;
......@@ -31,8 +78,29 @@ class UpdateService {
// Update-checks all registered applications. Calls |callback| once the
// operation is complete.
virtual void UpdateAll(
base::OnceCallback<void(update_client::Error)> callback) = 0;
virtual void UpdateAll(base::OnceCallback<void(Result)> callback) = 0;
// Updates specified product. This update may be on-demand.
//
// Args:
// |app_id|: ID of app to update.
// |priority|: Priority for processing this update.
// |state_updates|: Callback will be invoked every time the update
// changes state when the engine starts. It will be called on the
// sequence used by the update service, so this callback must not block.
// It will not be called again after the update has reached a terminal
// state. It will not be called after the "done" callback is posted.
// |done|: Posted after the update stops (successfully or otherwise).
//
// |state_updates| arg:
// UpdateState: the new state of this update request.
//
// |done| arg:
// Result: the final result from the update engine.
virtual void Update(const std::string& app_id,
Priority priority,
base::RepeatingCallback<void(UpdateState)> state_update,
base::OnceCallback<void(Result)> done) = 0;
protected:
UpdateService() = default;
......
......@@ -50,7 +50,7 @@ void UpdateServiceInProcess::RegisterApp(
}
void UpdateServiceInProcess::UpdateAll(
base::OnceCallback<void(update_client::Error)> callback) {
base::OnceCallback<void(Result)> callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
const auto app_ids = persisted_data_->GetAppIds();
......@@ -73,6 +73,15 @@ void UpdateServiceInProcess::UpdateAll(
false, std::move(callback));
}
void UpdateServiceInProcess::Update(
const std::string& app_id,
Priority priority,
base::RepeatingCallback<void(UpdateState)> state_update,
base::OnceCallback<void(Result)> done) {
// TODO(crbug.com/1059020): Implement.
NOTREACHED();
}
UpdateServiceInProcess::~UpdateServiceInProcess() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
......
......@@ -18,7 +18,6 @@ class SequencedTaskRunner;
}
namespace update_client {
enum class Error;
class Configurator;
class UpdateClient;
} // namespace update_client
......@@ -47,8 +46,14 @@ class UpdateServiceInProcess : public UpdateService {
// Update-checks all registered applications. Calls |callback| once the
// operation is complete.
void UpdateAll(
base::OnceCallback<void(update_client::Error)> callback) override;
void UpdateAll(base::OnceCallback<void(Result)> callback) override;
// Update-checks one registered application. Calls |state_updates| as the
// update is processed and |done| once the operation is complete.
void Update(const std::string& app_id,
Priority priority,
base::RepeatingCallback<void(UpdateState)> state_update,
base::OnceCallback<void(Result)> done) override;
private:
SEQUENCE_CHECKER(sequence_checker_);
......
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