Commit ebd57966 authored by Mila Green's avatar Mila Green Committed by Chromium LUCI CQ

Updater: Introduce a queue of tasks in UpdateServiceInternalImpl.

Bug: 1148839
Change-Id: I79e98003e07ad15fbdf507e03aecd8699ee9d826
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2569103Reviewed-by: default avatarSorin Jianu <sorin@chromium.org>
Reviewed-by: default avatarJoshua Pawlicki <waffles@chromium.org>
Commit-Queue: Mila Green <milagreen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#834528}
parent 3a8e86f9
......@@ -10,21 +10,16 @@
#include "base/callback.h"
#include "base/callback_forward.h"
#include "base/containers/queue.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_refptr.h"
#include "base/sequence_checker.h"
#include "base/version.h"
#include "chrome/updater/update_service_internal.h"
namespace update_client {
enum class Error;
class UpdateClient;
} // namespace update_client
namespace updater {
class Configurator;
class PersistedData;
// All functions and callbacks must be called on the same sequence.
class UpdateServiceInternalImpl : public UpdateServiceInternal {
......@@ -38,68 +33,30 @@ class UpdateServiceInternalImpl : public UpdateServiceInternal {
void Uninitialize() override;
private:
~UpdateServiceInternalImpl() override;
SEQUENCE_CHECKER(sequence_checker_);
class Task : public base::RefCountedThreadSafe<Task> {
public:
virtual void Run() = 0;
struct AppInfo {
AppInfo(const std::string& app_id,
const base::Version& app_version,
const base::FilePath& ecp)
: app_id_(app_id), app_version_(app_version), ecp_(ecp) {}
std::string app_id_;
base::Version app_version_;
base::FilePath ecp_;
};
protected:
friend class base::RefCountedThreadSafe<Task>;
struct PingInfo {
PingInfo(const std::string& app_id,
const base::Version& app_version,
int ping_reason)
: app_id_(app_id),
app_version_(app_version),
ping_reason_(ping_reason) {}
std::string app_id_;
base::Version app_version_;
int ping_reason_;
virtual ~Task() = default;
};
// Checks for updates of all registered applications if it has been longer
// than the last check time by NextCheckDelay() amount defined in the config.
void MaybeCheckForUpdates();
// Returns a list of apps registered with the updater.
std::vector<AppInfo> GetRegisteredApps();
void UnregisterMissingAppsDone();
// Callback to run after a `Task` has finished.
void TaskDone(base::OnceClosure callback);
// Provides a way to remove apps from the persisted data if the app is no
// longer installed on the machine.
void UnregisterMissingApps(const std::vector<AppInfo>& apps);
// After an uninstall ping has been processed, reduces the number of pings
// that we need to wait on before checking for updates.
void UninstallPingSent(update_client::Error error);
// Returns true if there are uninstall ping tasks which haven't finished.
// Returns false if |number_of_pings_remaining_| is 0.
bool WaitingOnUninstallPings() const;
// Returns a list of apps that need to be unregistered.
std::vector<UpdateServiceInternalImpl::PingInfo> GetAppIDsToRemove(
const std::vector<AppInfo>& apps);
private:
~UpdateServiceInternalImpl() override;
// Unregisters the apps in |app_ids_to_remove| and starts an update check
// if necessary.
void RemoveAppIDsAndSendUninstallPings(
const std::vector<PingInfo>& app_ids_to_remove);
void RunNextTask();
SEQUENCE_CHECKER(sequence_checker_);
scoped_refptr<updater::Configurator> config_;
scoped_refptr<updater::PersistedData> persisted_data_;
scoped_refptr<update_client::UpdateClient> update_client_;
base::OnceClosure callback_;
int number_of_pings_remaining_;
// The queue prevents multiple Task instances from running simultaneously and
// processes them sequentially.
base::queue<scoped_refptr<Task>> tasks_;
};
} // 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