Revert of ui: Clean up damaged rects and clear them after painting. (patchset #2...
[chromium-blink-merge.git] / components / update_client / action.h
blobd85e868b2d0c975a4324e394976e94170512612a
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_UPDATE_CLIENT_ACTION_H_
6 #define COMPONENTS_UPDATE_CLIENT_ACTION_H_
8 #include <string>
10 #include "base/callback.h"
11 #include "base/macros.h"
12 #include "base/threading/thread_checker.h"
13 #include "components/update_client/crx_update_item.h"
14 #include "components/update_client/update_client.h"
16 namespace update_client {
18 class Configurator;
19 struct CrxUpdateItem;
20 struct UpdateContext;
22 // Any update can be broken down as a sequence of discrete steps, such as
23 // checking for updates, downloading patches, updating, and waiting between
24 // successive updates. An action is the smallest unit of work executed by
25 // the update engine.
27 // Defines an abstract interface for a unit of work, executed by the
28 // update engine as part of an update.
29 class Action {
30 public:
31 enum class ErrorCategory {
32 kErrorNone = 0,
33 kNetworkError,
34 kUnpackError,
35 kInstallError,
36 kServiceError, // Runtime errors which occur in the service itself.
39 enum class ServiceError {
40 ERROR_WAIT = 1,
43 using Callback = base::Callback<void(int error)>;
44 virtual ~Action() {}
46 // Runs the code encapsulated by the action. When an action completes, it can
47 // chain up and transfer the execution flow to another action or it can
48 // invoke the |callback| when this function has completed and there is nothing
49 // else to do.
50 virtual void Run(UpdateContext* update_context, Callback callback) = 0;
53 // Provides a reusable implementation of common functions needed by actions.
54 class ActionImpl {
55 protected:
56 ActionImpl();
57 ~ActionImpl();
59 void Run(UpdateContext* update_context, Action::Callback callback);
61 // Changes the current state of the |item| to the new state |to|.
62 void ChangeItemState(CrxUpdateItem* item, CrxUpdateItem::State to);
64 // Changes the state of all items in |update_context_|. Returns the count
65 // of items affected by the call.
66 size_t ChangeAllItemsState(CrxUpdateItem::State from,
67 CrxUpdateItem::State to);
69 // Returns the item associated with the component |id| or nullptr in case
70 // of errors.
71 CrxUpdateItem* FindUpdateItemById(const std::string& id) const;
73 void NotifyObservers(UpdateClient::Observer::Events event,
74 const std::string& id);
76 // Updates the CRX at the front of the CRX queue in this update context.
77 void UpdateCrx();
79 // Completes updating the CRX at the front of the queue, and initiates
80 // the update for the next CRX in the queue, if the queue is not empty.
81 void UpdateCrxComplete(CrxUpdateItem* item);
83 // Called when the updates for all CRXs have finished and the execution
84 // flow must return back to the update engine.
85 void UpdateComplete(int error);
87 base::ThreadChecker thread_checker_;
89 UpdateContext* update_context_; // Not owned by this class.
90 Action::Callback callback_;
92 private:
93 DISALLOW_COPY_AND_ASSIGN(ActionImpl);
96 } // namespace update_client
98 #endif // COMPONENTS_UPDATE_CLIENT_ACTION_H_