OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_INSTALLER_UTIL_WORK_ITEM_LIST_H_ | 5 #ifndef CHROME_INSTALLER_UTIL_WORK_ITEM_LIST_H_ |
6 #define CHROME_INSTALLER_UTIL_WORK_ITEM_LIST_H_ | 6 #define CHROME_INSTALLER_UTIL_WORK_ITEM_LIST_H_ |
7 | 7 |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 } | 21 } |
22 | 22 |
23 // A WorkItem subclass that recursively contains a list of WorkItems. Thus it | 23 // A WorkItem subclass that recursively contains a list of WorkItems. Thus it |
24 // provides functionalities to carry out or roll back the sequence of actions | 24 // provides functionalities to carry out or roll back the sequence of actions |
25 // defined by the list of WorkItems it contains. | 25 // defined by the list of WorkItems it contains. |
26 // The WorkItems are executed in the same order as they are added to the list. | 26 // The WorkItems are executed in the same order as they are added to the list. |
27 class WorkItemList : public WorkItem { | 27 class WorkItemList : public WorkItem { |
28 public: | 28 public: |
29 ~WorkItemList() override; | 29 ~WorkItemList() override; |
30 | 30 |
31 // Execute the WorkItems in the same order as they are added to the list. | |
32 // It aborts as soon as one WorkItem fails. | |
33 bool Do() override; | |
34 | |
35 // Rollback the WorkItems in the reverse order as they are executed. | |
36 void Rollback() override; | |
37 | |
38 // Add a WorkItem to the list. | 31 // Add a WorkItem to the list. |
39 // A WorkItem can only be added to the list before the list's DO() is called. | 32 // A WorkItem can only be added to the list before the list's DO() is called. |
40 // Once a WorkItem is added to the list. The list owns the WorkItem. | 33 // Once a WorkItem is added to the list. The list owns the WorkItem. |
41 virtual void AddWorkItem(WorkItem* work_item); | 34 virtual void AddWorkItem(WorkItem* work_item); |
42 | 35 |
43 // Add a CallbackWorkItem that invokes a callback. | 36 // Add a CallbackWorkItem that invokes a callback. |
44 virtual WorkItem* AddCallbackWorkItem( | 37 virtual WorkItem* AddCallbackWorkItem( |
45 base::Callback<bool(const CallbackWorkItem&)> callback); | 38 base::Callback<bool(const CallbackWorkItem&)> callback); |
46 | 39 |
47 // Add a CopyTreeWorkItem to the list of work items. | 40 // Add a CopyTreeWorkItem to the list of work items. |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 virtual WorkItem* AddSelfRegWorkItem(const std::wstring& dll_path, | 130 virtual WorkItem* AddSelfRegWorkItem(const std::wstring& dll_path, |
138 bool do_register, | 131 bool do_register, |
139 bool user_level_registration); | 132 bool user_level_registration); |
140 | 133 |
141 protected: | 134 protected: |
142 friend class WorkItem; | 135 friend class WorkItem; |
143 | 136 |
144 typedef std::list<WorkItem*> WorkItems; | 137 typedef std::list<WorkItem*> WorkItems; |
145 typedef WorkItems::iterator WorkItemIterator; | 138 typedef WorkItems::iterator WorkItemIterator; |
146 | 139 |
147 enum ListStatus { | |
148 // List has not been executed. Ok to add new WorkItem. | |
149 ADD_ITEM, | |
150 // List has been executed. Can not add new WorkItem. | |
151 LIST_EXECUTED, | |
152 // List has been executed and rolled back. No further action is acceptable. | |
153 LIST_ROLLED_BACK | |
154 }; | |
155 | |
156 WorkItemList(); | 140 WorkItemList(); |
157 | 141 |
158 ListStatus status_; | 142 // WorkItem: |
| 143 |
| 144 // Execute the WorkItems in the same order as they are added to the list. It |
| 145 // aborts as soon as one WorkItem fails, unless the best-effort flag is true. |
| 146 bool DoImpl() override; |
| 147 |
| 148 // Rollback the WorkItems in the reverse order as they are executed. |
| 149 void RollbackImpl() override; |
159 | 150 |
160 // The list of WorkItems, in the order of them being added. | 151 // The list of WorkItems, in the order of them being added. |
161 WorkItems list_; | 152 WorkItems list_; |
162 | 153 |
163 // The list of executed WorkItems, in the reverse order of them being | 154 // The list of executed WorkItems, in the reverse order of them being |
164 // executed. | 155 // executed. |
165 WorkItems executed_list_; | 156 WorkItems executed_list_; |
166 }; | 157 }; |
167 | 158 |
168 // A specialization of WorkItemList that executes items in the list on a | 159 // A specialization of WorkItemList that executes items in the list on a |
169 // best-effort basis. Failure of individual items to execute does not prevent | 160 // best-effort basis. Failure of individual items to execute does not prevent |
170 // subsequent items from being executed. | 161 // subsequent items from being executed. |
171 // Also, as the class name suggests, Rollback is not possible. | 162 // Also, as the class name suggests, Rollback is not possible. |
172 class NoRollbackWorkItemList : public WorkItemList { | 163 class NoRollbackWorkItemList : public WorkItemList { |
173 public: | 164 public: |
174 ~NoRollbackWorkItemList() override; | 165 ~NoRollbackWorkItemList() override; |
175 | 166 |
| 167 private: |
| 168 // WorkItemList: |
| 169 |
176 // Execute the WorkItems in the same order as they are added to the list. | 170 // Execute the WorkItems in the same order as they are added to the list. |
177 // If a WorkItem fails, the function will return failure but all other | 171 // If a WorkItem fails, the function will return failure but all other |
178 // WorkItems will still be executed. | 172 // WorkItems will still be executed. |
179 bool Do() override; | 173 bool DoImpl() override; |
180 | 174 |
181 // No-op. | 175 // No-op. |
182 void Rollback() override; | 176 void RollbackImpl() override; |
183 }; | 177 }; |
184 | 178 |
185 #endif // CHROME_INSTALLER_UTIL_WORK_ITEM_LIST_H_ | 179 #endif // CHROME_INSTALLER_UTIL_WORK_ITEM_LIST_H_ |
OLD | NEW |