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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 // List has not been executed. Ok to add new WorkItem. | 141 // List has not been executed. Ok to add new WorkItem. |
149 ADD_ITEM, | 142 ADD_ITEM, |
150 // List has been executed. Can not add new WorkItem. | 143 // List has been executed. Can not add new WorkItem. |
151 LIST_EXECUTED, | 144 LIST_EXECUTED, |
152 // List has been executed and rolled back. No further action is acceptable. | 145 // List has been executed and rolled back. No further action is acceptable. |
153 LIST_ROLLED_BACK | 146 LIST_ROLLED_BACK |
154 }; | 147 }; |
155 | 148 |
156 WorkItemList(); | 149 WorkItemList(); |
157 | 150 |
| 151 // WorkItem: |
| 152 |
| 153 // Execute the WorkItems in the same order as they are added to the list. |
| 154 // It aborts as soon as one WorkItem fails. |
| 155 bool DoImpl() override; |
| 156 |
| 157 // Rollback the WorkItems in the reverse order as they are executed. |
| 158 void RollbackImpl() override; |
| 159 |
158 ListStatus status_; | 160 ListStatus status_; |
159 | 161 |
160 // The list of WorkItems, in the order of them being added. | 162 // The list of WorkItems, in the order of them being added. |
161 WorkItems list_; | 163 WorkItems list_; |
162 | 164 |
163 // The list of executed WorkItems, in the reverse order of them being | 165 // The list of executed WorkItems, in the reverse order of them being |
164 // executed. | 166 // executed. |
165 WorkItems executed_list_; | 167 WorkItems executed_list_; |
166 }; | 168 }; |
167 | 169 |
168 // A specialization of WorkItemList that executes items in the list on a | 170 // 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 | 171 // best-effort basis. Failure of individual items to execute does not prevent |
170 // subsequent items from being executed. | 172 // subsequent items from being executed. |
171 // Also, as the class name suggests, Rollback is not possible. | 173 // Also, as the class name suggests, Rollback is not possible. |
172 class NoRollbackWorkItemList : public WorkItemList { | 174 class NoRollbackWorkItemList : public WorkItemList { |
173 public: | 175 public: |
174 ~NoRollbackWorkItemList() override; | 176 ~NoRollbackWorkItemList() override; |
175 | 177 |
| 178 private: |
| 179 // WorkItemList: |
| 180 |
176 // Execute the WorkItems in the same order as they are added to the list. | 181 // 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 | 182 // If a WorkItem fails, the function will return failure but all other |
178 // WorkItems will still be executed. | 183 // WorkItems will still be executed. |
179 bool Do() override; | 184 bool DoImpl() override; |
180 | 185 |
181 // No-op. | 186 // No-op. |
182 void Rollback() override; | 187 void RollbackImpl() override; |
183 }; | 188 }; |
184 | 189 |
185 #endif // CHROME_INSTALLER_UTIL_WORK_ITEM_LIST_H_ | 190 #endif // CHROME_INSTALLER_UTIL_WORK_ITEM_LIST_H_ |
OLD | NEW |