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. | |
30 class WorkItemList : public WorkItem { | 27 class WorkItemList : public WorkItem { |
31 public: | 28 public: |
32 ~WorkItemList() override; | 29 ~WorkItemList() override; |
33 | 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 |
34 // Add a WorkItem to the list. | 38 // Add a WorkItem to the list. |
35 // A WorkItem can only be added to the list before the list's DO() is called. | 39 // A WorkItem can only be added to the list before the list's DO() is called. |
36 // Once a WorkItem is added to the list. The list owns the WorkItem. | 40 // Once a WorkItem is added to the list. The list owns the WorkItem. |
37 virtual void AddWorkItem(WorkItem* work_item); | 41 virtual void AddWorkItem(WorkItem* work_item); |
38 | 42 |
39 // Add a CallbackWorkItem that invokes a callback. | 43 // Add a CallbackWorkItem that invokes a callback. |
40 virtual WorkItem* AddCallbackWorkItem( | 44 virtual WorkItem* AddCallbackWorkItem( |
41 base::Callback<bool(const CallbackWorkItem&)> callback); | 45 base::Callback<bool(const CallbackWorkItem&)> callback); |
42 | 46 |
43 // Add a CopyTreeWorkItem to the list of work items. | 47 // Add a CopyTreeWorkItem to the list of work items. |
(...skipping 21 matching lines...) Expand all Loading... |
65 const std::wstring& path, | 69 const std::wstring& path, |
66 REGSAM wow64_access); | 70 REGSAM wow64_access); |
67 | 71 |
68 // Add a DeleteRegValueWorkItem that deletes registry value of type REG_SZ | 72 // Add a DeleteRegValueWorkItem that deletes registry value of type REG_SZ |
69 // or REG_DWORD. | 73 // or REG_DWORD. |
70 virtual WorkItem* AddDeleteRegValueWorkItem(HKEY predefined_root, | 74 virtual WorkItem* AddDeleteRegValueWorkItem(HKEY predefined_root, |
71 const std::wstring& key_path, | 75 const std::wstring& key_path, |
72 REGSAM wow64_access, | 76 REGSAM wow64_access, |
73 const std::wstring& value_name); | 77 const std::wstring& value_name); |
74 | 78 |
75 // Add a DeleteTreeWorkItem that recursively deletes a file system hierarchy | 79 // Add a DeleteTreeWorkItem that recursively deletes a file system |
76 // at the given root path. | 80 // hierarchy at the given root path. A key file can be optionally specified |
| 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. |
77 virtual WorkItem* AddDeleteTreeWorkItem(const base::FilePath& root_path, | 88 virtual WorkItem* AddDeleteTreeWorkItem(const base::FilePath& root_path, |
78 const base::FilePath& temp_path); | 89 const base::FilePath& temp_path); |
79 | 90 |
80 // Add a MoveTreeWorkItem to the list of work items. | 91 // Add a MoveTreeWorkItem to the list of work items. |
81 virtual WorkItem* AddMoveTreeWorkItem(const std::wstring& source_path, | 92 virtual WorkItem* AddMoveTreeWorkItem(const std::wstring& source_path, |
82 const std::wstring& dest_path, | 93 const std::wstring& dest_path, |
83 const std::wstring& temp_dir, | 94 const std::wstring& temp_dir, |
84 MoveTreeOption duplicate_option); | 95 MoveTreeOption duplicate_option); |
85 | 96 |
86 // Add a SetRegValueWorkItem that sets a registry value with REG_SZ type | 97 // 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... |
126 virtual WorkItem* AddSelfRegWorkItem(const std::wstring& dll_path, | 137 virtual WorkItem* AddSelfRegWorkItem(const std::wstring& dll_path, |
127 bool do_register, | 138 bool do_register, |
128 bool user_level_registration); | 139 bool user_level_registration); |
129 | 140 |
130 protected: | 141 protected: |
131 friend class WorkItem; | 142 friend class WorkItem; |
132 | 143 |
133 typedef std::list<WorkItem*> WorkItems; | 144 typedef std::list<WorkItem*> WorkItems; |
134 typedef WorkItems::iterator WorkItemIterator; | 145 typedef WorkItems::iterator WorkItemIterator; |
135 | 146 |
| 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 |
136 WorkItemList(); | 156 WorkItemList(); |
137 | 157 |
138 // WorkItem: | 158 ListStatus status_; |
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; | |
146 | 159 |
147 // The list of WorkItems, in the order of them being added. | 160 // The list of WorkItems, in the order of them being added. |
148 WorkItems list_; | 161 WorkItems list_; |
149 | 162 |
150 // The list of executed WorkItems, in the reverse order of them being | 163 // The list of executed WorkItems, in the reverse order of them being |
151 // executed. | 164 // executed. |
152 WorkItems executed_list_; | 165 WorkItems executed_list_; |
153 }; | 166 }; |
154 | 167 |
| 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 |
155 #endif // CHROME_INSTALLER_UTIL_WORK_ITEM_LIST_H_ | 185 #endif // CHROME_INSTALLER_UTIL_WORK_ITEM_LIST_H_ |
OLD | NEW |