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 |
11 #include <list> | 11 #include <list> |
12 #include <memory> | 12 #include <memory> |
13 #include <string> | 13 #include <string> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/callback_forward.h" | 16 #include "base/callback_forward.h" |
17 #include "chrome/installer/util/work_item.h" | 17 #include "chrome/installer/util/work_item.h" |
18 | 18 |
19 namespace base { | 19 namespace base { |
20 class FilePath; | 20 class FilePath; |
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 // The "best-effort" flag of the WorkItemList is propagated to the WorkItems |
| 28 // when it's true. Likewise, the "rollback enabled" flag of the WorkItemList is |
| 29 // propagated to the WorkItems when it's false. |
27 class WorkItemList : public WorkItem { | 30 class WorkItemList : public WorkItem { |
28 public: | 31 public: |
29 ~WorkItemList() override; | 32 ~WorkItemList() override; |
30 | 33 |
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. | 34 // Add a WorkItem to the list. |
39 // A WorkItem can only be added to the list before the list's DO() is called. | 35 // 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. | 36 // Once a WorkItem is added to the list. The list owns the WorkItem. |
41 virtual void AddWorkItem(WorkItem* work_item); | 37 virtual void AddWorkItem(WorkItem* work_item); |
42 | 38 |
43 // Add a CallbackWorkItem that invokes a callback. | 39 // Add a CallbackWorkItem that invokes a callback. |
44 virtual WorkItem* AddCallbackWorkItem( | 40 virtual WorkItem* AddCallbackWorkItem( |
45 base::Callback<bool(const CallbackWorkItem&)> callback); | 41 base::Callback<bool(const CallbackWorkItem&)> callback); |
46 | 42 |
47 // Add a CopyTreeWorkItem to the list of work items. | 43 // Add a CopyTreeWorkItem to the list of work items. |
(...skipping 21 matching lines...) Expand all Loading... |
69 const std::wstring& path, | 65 const std::wstring& path, |
70 REGSAM wow64_access); | 66 REGSAM wow64_access); |
71 | 67 |
72 // Add a DeleteRegValueWorkItem that deletes registry value of type REG_SZ | 68 // Add a DeleteRegValueWorkItem that deletes registry value of type REG_SZ |
73 // or REG_DWORD. | 69 // or REG_DWORD. |
74 virtual WorkItem* AddDeleteRegValueWorkItem(HKEY predefined_root, | 70 virtual WorkItem* AddDeleteRegValueWorkItem(HKEY predefined_root, |
75 const std::wstring& key_path, | 71 const std::wstring& key_path, |
76 REGSAM wow64_access, | 72 REGSAM wow64_access, |
77 const std::wstring& value_name); | 73 const std::wstring& value_name); |
78 | 74 |
79 // Add a DeleteTreeWorkItem that recursively deletes a file system | 75 // Add a DeleteTreeWorkItem that recursively deletes a file system hierarchy |
80 // hierarchy at the given root path. A key file can be optionally specified | 76 // at the given root path. |
81 // by key_path. | |
82 virtual WorkItem* AddDeleteTreeWorkItem( | |
83 const base::FilePath& root_path, | |
84 const base::FilePath& temp_path, | |
85 const std::vector<base::FilePath>& key_paths); | |
86 | |
87 // Same as above but without support for key files. | |
88 virtual WorkItem* AddDeleteTreeWorkItem(const base::FilePath& root_path, | 77 virtual WorkItem* AddDeleteTreeWorkItem(const base::FilePath& root_path, |
89 const base::FilePath& temp_path); | 78 const base::FilePath& temp_path); |
90 | 79 |
91 // Add a MoveTreeWorkItem to the list of work items. | 80 // Add a MoveTreeWorkItem to the list of work items. |
92 virtual WorkItem* AddMoveTreeWorkItem(const std::wstring& source_path, | 81 virtual WorkItem* AddMoveTreeWorkItem(const std::wstring& source_path, |
93 const std::wstring& dest_path, | 82 const std::wstring& dest_path, |
94 const std::wstring& temp_dir, | 83 const std::wstring& temp_dir, |
95 MoveTreeOption duplicate_option); | 84 MoveTreeOption duplicate_option); |
96 | 85 |
97 // Add a SetRegValueWorkItem that sets a registry value with REG_SZ type | 86 // Add a SetRegValueWorkItem that sets a registry value with REG_SZ type |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 virtual WorkItem* AddSelfRegWorkItem(const std::wstring& dll_path, | 126 virtual WorkItem* AddSelfRegWorkItem(const std::wstring& dll_path, |
138 bool do_register, | 127 bool do_register, |
139 bool user_level_registration); | 128 bool user_level_registration); |
140 | 129 |
141 protected: | 130 protected: |
142 friend class WorkItem; | 131 friend class WorkItem; |
143 | 132 |
144 typedef std::list<WorkItem*> WorkItems; | 133 typedef std::list<WorkItem*> WorkItems; |
145 typedef WorkItems::iterator WorkItemIterator; | 134 typedef WorkItems::iterator WorkItemIterator; |
146 | 135 |
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(); | 136 WorkItemList(); |
157 | 137 |
158 ListStatus status_; | 138 // WorkItem: |
| 139 |
| 140 // Execute the WorkItems in the same order as they are added to the list. It |
| 141 // aborts as soon as one WorkItem fails, unless the best-effort flag is true. |
| 142 bool DoImpl() override; |
| 143 |
| 144 // Rollback the WorkItems in the reverse order as they are executed. |
| 145 void RollbackImpl() override; |
159 | 146 |
160 // The list of WorkItems, in the order of them being added. | 147 // The list of WorkItems, in the order of them being added. |
161 WorkItems list_; | 148 WorkItems list_; |
162 | 149 |
163 // The list of executed WorkItems, in the reverse order of them being | 150 // The list of executed WorkItems, in the reverse order of them being |
164 // executed. | 151 // executed. |
165 WorkItems executed_list_; | 152 WorkItems executed_list_; |
166 }; | 153 }; |
167 | 154 |
168 // 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 | |
170 // subsequent items from being executed. | |
171 // Also, as the class name suggests, Rollback is not possible. | |
172 class NoRollbackWorkItemList : public WorkItemList { | |
173 public: | |
174 ~NoRollbackWorkItemList() override; | |
175 | |
176 // 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 | |
178 // WorkItems will still be executed. | |
179 bool Do() override; | |
180 | |
181 // No-op. | |
182 void Rollback() override; | |
183 }; | |
184 | |
185 #endif // CHROME_INSTALLER_UTIL_WORK_ITEM_LIST_H_ | 155 #endif // CHROME_INSTALLER_UTIL_WORK_ITEM_LIST_H_ |
OLD | NEW |