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 class WorkItemList : public WorkItem { | 27 class WorkItemList : public WorkItem { |
grt (UTC plus 2)
2016/05/12 17:26:24
please document the behavior with respect to best_
fdoray
2016/05/13 14:31:45
Done.
| |
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 21 matching lines...) Expand all Loading... | |
69 const std::wstring& path, | 62 const std::wstring& path, |
70 REGSAM wow64_access); | 63 REGSAM wow64_access); |
71 | 64 |
72 // Add a DeleteRegValueWorkItem that deletes registry value of type REG_SZ | 65 // Add a DeleteRegValueWorkItem that deletes registry value of type REG_SZ |
73 // or REG_DWORD. | 66 // or REG_DWORD. |
74 virtual WorkItem* AddDeleteRegValueWorkItem(HKEY predefined_root, | 67 virtual WorkItem* AddDeleteRegValueWorkItem(HKEY predefined_root, |
75 const std::wstring& key_path, | 68 const std::wstring& key_path, |
76 REGSAM wow64_access, | 69 REGSAM wow64_access, |
77 const std::wstring& value_name); | 70 const std::wstring& value_name); |
78 | 71 |
79 // Add a DeleteTreeWorkItem that recursively deletes a file system | 72 // Add a DeleteTreeWorkItem that recursively deletes a file system hierarchy |
80 // hierarchy at the given root path. A key file can be optionally specified | 73 // 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, | 74 virtual WorkItem* AddDeleteTreeWorkItem(const base::FilePath& root_path, |
89 const base::FilePath& temp_path); | 75 const base::FilePath& temp_path); |
90 | 76 |
91 // Add a MoveTreeWorkItem to the list of work items. | 77 // Add a MoveTreeWorkItem to the list of work items. |
92 virtual WorkItem* AddMoveTreeWorkItem(const std::wstring& source_path, | 78 virtual WorkItem* AddMoveTreeWorkItem(const std::wstring& source_path, |
93 const std::wstring& dest_path, | 79 const std::wstring& dest_path, |
94 const std::wstring& temp_dir, | 80 const std::wstring& temp_dir, |
95 MoveTreeOption duplicate_option); | 81 MoveTreeOption duplicate_option); |
96 | 82 |
97 // Add a SetRegValueWorkItem that sets a registry value with REG_SZ type | 83 // 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, | 123 virtual WorkItem* AddSelfRegWorkItem(const std::wstring& dll_path, |
138 bool do_register, | 124 bool do_register, |
139 bool user_level_registration); | 125 bool user_level_registration); |
140 | 126 |
141 protected: | 127 protected: |
142 friend class WorkItem; | 128 friend class WorkItem; |
143 | 129 |
144 typedef std::list<WorkItem*> WorkItems; | 130 typedef std::list<WorkItem*> WorkItems; |
145 typedef WorkItems::iterator WorkItemIterator; | 131 typedef WorkItems::iterator WorkItemIterator; |
146 | 132 |
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(); | 133 WorkItemList(); |
157 | 134 |
158 ListStatus status_; | 135 // WorkItem: |
136 | |
137 // Execute the WorkItems in the same order as they are added to the list. It | |
138 // aborts as soon as one WorkItem fails, unless the best-effort flag is true. | |
139 bool DoImpl() override; | |
140 | |
141 // Rollback the WorkItems in the reverse order as they are executed. | |
142 void RollbackImpl() override; | |
159 | 143 |
160 // The list of WorkItems, in the order of them being added. | 144 // The list of WorkItems, in the order of them being added. |
161 WorkItems list_; | 145 WorkItems list_; |
162 | 146 |
163 // The list of executed WorkItems, in the reverse order of them being | 147 // The list of executed WorkItems, in the reverse order of them being |
164 // executed. | 148 // executed. |
165 WorkItems executed_list_; | 149 WorkItems executed_list_; |
166 }; | 150 }; |
167 | 151 |
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_ | 152 #endif // CHROME_INSTALLER_UTIL_WORK_ITEM_LIST_H_ |
OLD | NEW |