OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef COMPONENTS_UPDATE_CLIENT_ACTION_H_ | |
6 #define COMPONENTS_UPDATE_CLIENT_ACTION_H_ | |
7 | |
8 #include <stddef.h> | |
9 | |
10 #include <string> | |
11 | |
12 #include "base/callback.h" | |
13 #include "base/macros.h" | |
14 #include "base/threading/thread_checker.h" | |
15 #include "components/update_client/crx_update_item.h" | |
16 #include "components/update_client/update_client.h" | |
17 | |
18 namespace update_client { | |
19 | |
20 enum class Error; | |
21 struct CrxUpdateItem; | |
22 struct UpdateContext; | |
23 | |
24 // Any update can be broken down as a sequence of discrete steps, such as | |
25 // checking for updates, downloading patches, updating, and waiting between | |
26 // successive updates. An action is the smallest unit of work executed by | |
27 // the update engine. | |
28 // | |
29 // Defines an abstract interface for a unit of work, executed by the | |
30 // update engine as part of an update. | |
31 class Action { | |
32 public: | |
33 virtual ~Action() {} | |
34 | |
35 // Runs the code encapsulated by the action. When an action completes, it can | |
36 // chain up and transfer the execution flow to another action or it can | |
37 // invoke the |callback| when this function has completed and there is nothing | |
38 // else to do. | |
39 virtual void Run(UpdateContext* update_context, Callback callback) = 0; | |
40 }; | |
41 | |
42 // Provides a reusable implementation of common functions needed by actions. | |
43 class ActionImpl { | |
44 protected: | |
45 ActionImpl(); | |
46 ~ActionImpl(); | |
47 | |
48 void Run(UpdateContext* update_context, Callback callback); | |
49 | |
50 // Changes the current state of the |item| to the new state |to|. | |
51 void ChangeItemState(CrxUpdateItem* item, CrxUpdateItem::State to); | |
52 | |
53 // Changes the state of all items in |update_context_|. Returns the count | |
54 // of items affected by the call. | |
55 size_t ChangeAllItemsState(CrxUpdateItem::State from, | |
56 CrxUpdateItem::State to); | |
57 | |
58 // Returns the item associated with the component |id| or nullptr in case | |
59 // of errors. | |
60 CrxUpdateItem* FindUpdateItemById(const std::string& id) const; | |
61 | |
62 void NotifyObservers(UpdateClient::Observer::Events event, | |
63 const std::string& id); | |
64 | |
65 // Updates the CRX at the front of the CRX queue in this update context. | |
66 void UpdateCrx(); | |
67 | |
68 // Completes updating the CRX at the front of the queue, and initiates | |
69 // the update for the next CRX in the queue, if the queue is not empty. | |
70 void UpdateCrxComplete(CrxUpdateItem* item); | |
71 | |
72 // Called when the updates for all CRXs have finished and the execution | |
73 // flow must return back to the update engine. | |
74 void UpdateComplete(Error error); | |
75 | |
76 base::ThreadChecker thread_checker_; | |
77 | |
78 UpdateContext* update_context_; // Not owned by this class. | |
79 Callback callback_; | |
80 | |
81 private: | |
82 DISALLOW_COPY_AND_ASSIGN(ActionImpl); | |
83 }; | |
84 | |
85 } // namespace update_client | |
86 | |
87 #endif // COMPONENTS_UPDATE_CLIENT_ACTION_H_ | |
OLD | NEW |