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 // Base class for managing an action of a sequence of actions to be carried | 5 // Base class for managing an action of a sequence of actions to be carried |
6 // out during install/update/uninstall. Supports rollback of actions if this | 6 // out during install/update/uninstall. Supports rollback of actions if this |
7 // process fails. | 7 // process fails. |
8 | 8 |
9 #ifndef CHROME_INSTALLER_UTIL_WORK_ITEM_H_ | 9 #ifndef CHROME_INSTALLER_UTIL_WORK_ITEM_H_ |
10 #define CHROME_INSTALLER_UTIL_WORK_ITEM_H_ | 10 #define CHROME_INSTALLER_UTIL_WORK_ITEM_H_ |
(...skipping 17 matching lines...) Expand all Loading... |
28 class SelfRegWorkItem; | 28 class SelfRegWorkItem; |
29 class SetRegValueWorkItem; | 29 class SetRegValueWorkItem; |
30 class WorkItemList; | 30 class WorkItemList; |
31 | 31 |
32 namespace base { | 32 namespace base { |
33 class FilePath; | 33 class FilePath; |
34 } | 34 } |
35 | 35 |
36 // A base class that defines APIs to perform/rollback an action or a | 36 // A base class that defines APIs to perform/rollback an action or a |
37 // sequence of actions during install/update/uninstall. | 37 // sequence of actions during install/update/uninstall. |
38 // | |
39 // Subclasses must implement DoImpl() and RollbackImpl(). | |
40 // | |
41 // Do() calls DoImpl(). When the "best-effort" flag is true, it always returns | |
42 // true. Otherwise, it returns the value returned by DoImpl(). Implementations | |
43 // of DoImpl() may use the "best-effort" flag as an indication that they should | |
44 // do as much work as possible (i.e., shouldn't abort as soon as one of the | |
45 // actions they have to perform fails). By default, the "best-effort" flag is | |
46 // false. | |
47 // | |
48 // Rollback() calls RollbackImpl() when the "rollback enabled" flag is true. | |
49 // Otherwise, it's a no-op. Implementations of DoImpl() may read the "rollback | |
50 // enabled" flag to determine whether they should save state to support | |
51 // rollback. By default, the "rollback enabled" flag is true. | |
52 // | |
53 // The "best-effort" and "rollback enabled" must be set before Do() is invoked. | |
54 class WorkItem { | 38 class WorkItem { |
55 public: | 39 public: |
56 // A callback that returns the desired value based on the |existing_value|. | 40 // A callback that returns the desired value based on the |existing_value|. |
57 // |existing_value| will be empty if the value didn't previously exist or | 41 // |existing_value| will be empty if the value didn't previously exist or |
58 // existed under a non-string type. | 42 // existed under a non-string type. |
59 using GetValueFromExistingCallback = | 43 using GetValueFromExistingCallback = |
60 base::Callback<std::wstring(const std::wstring& existing_value)>; | 44 base::Callback<std::wstring(const std::wstring& existing_value)>; |
61 | 45 |
62 // All registry operations can be instructed to operate on a specific view | 46 // All registry operations can be instructed to operate on a specific view |
63 // of the registry by specifying a REGSAM value to the wow64_access parameter. | 47 // of the registry by specifying a REGSAM value to the wow64_access parameter. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 REGSAM wow64_access); | 112 REGSAM wow64_access); |
129 | 113 |
130 // Create a DeleteRegValueWorkItem that deletes a registry value | 114 // Create a DeleteRegValueWorkItem that deletes a registry value |
131 static DeleteRegValueWorkItem* CreateDeleteRegValueWorkItem( | 115 static DeleteRegValueWorkItem* CreateDeleteRegValueWorkItem( |
132 HKEY predefined_root, | 116 HKEY predefined_root, |
133 const std::wstring& key_path, | 117 const std::wstring& key_path, |
134 REGSAM wow64_access, | 118 REGSAM wow64_access, |
135 const std::wstring& value_name); | 119 const std::wstring& value_name); |
136 | 120 |
137 // Create a DeleteTreeWorkItem that recursively deletes a file system | 121 // Create a DeleteTreeWorkItem that recursively deletes a file system |
138 // hierarchy at the given root path. | 122 // hierarchy at the given root path. A key file can be optionally specified |
| 123 // by key_path. |
139 static DeleteTreeWorkItem* CreateDeleteTreeWorkItem( | 124 static DeleteTreeWorkItem* CreateDeleteTreeWorkItem( |
140 const base::FilePath& root_path, | 125 const base::FilePath& root_path, |
141 const base::FilePath& temp_path); | 126 const base::FilePath& temp_path, |
| 127 const std::vector<base::FilePath>& key_paths); |
142 | 128 |
143 // Create a MoveTreeWorkItem that recursively moves a file system hierarchy | 129 // Create a MoveTreeWorkItem that recursively moves a file system hierarchy |
144 // from source path to destination path. | 130 // from source path to destination path. |
145 static MoveTreeWorkItem* CreateMoveTreeWorkItem( | 131 static MoveTreeWorkItem* CreateMoveTreeWorkItem( |
146 const base::FilePath& source_path, | 132 const base::FilePath& source_path, |
147 const base::FilePath& dest_path, | 133 const base::FilePath& dest_path, |
148 const base::FilePath& temp_dir, | 134 const base::FilePath& temp_dir, |
149 MoveTreeOption duplicate_option); | 135 MoveTreeOption duplicate_option); |
150 | 136 |
151 // Create a SetRegValueWorkItem that sets a registry value with REG_SZ type | 137 // Create a SetRegValueWorkItem that sets a registry value with REG_SZ type |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 // Add a SelfRegWorkItem that registers or unregisters a DLL at the | 177 // Add a SelfRegWorkItem that registers or unregisters a DLL at the |
192 // specified path. | 178 // specified path. |
193 static SelfRegWorkItem* CreateSelfRegWorkItem(const std::wstring& dll_path, | 179 static SelfRegWorkItem* CreateSelfRegWorkItem(const std::wstring& dll_path, |
194 bool do_register, | 180 bool do_register, |
195 bool user_level_registration); | 181 bool user_level_registration); |
196 | 182 |
197 // Create an empty WorkItemList. A WorkItemList can recursively contains | 183 // Create an empty WorkItemList. A WorkItemList can recursively contains |
198 // a list of WorkItems. | 184 // a list of WorkItems. |
199 static WorkItemList* CreateWorkItemList(); | 185 static WorkItemList* CreateWorkItemList(); |
200 | 186 |
| 187 // Create an empty WorkItemList that cannot be rolled back. |
| 188 // Such a work item list executes all items on a best effort basis and does |
| 189 // not abort execution if an item in the list fails. |
| 190 static WorkItemList* CreateNoRollbackWorkItemList(); |
| 191 |
201 // Create a conditional work item list that will execute only if | 192 // Create a conditional work item list that will execute only if |
202 // condition->ShouldRun() returns true. The WorkItemList instance | 193 // condition->ShouldRun() returns true. The WorkItemList instance |
203 // assumes ownership of condition. | 194 // assumes ownership of condition. |
204 static WorkItemList* CreateConditionalWorkItemList(Condition* condition); | 195 static WorkItemList* CreateConditionalWorkItemList(Condition* condition); |
205 | 196 |
206 // Perform the actions of WorkItem. Returns true if success or if | 197 // Perform the actions of WorkItem. Returns true if success, returns false |
207 // best_effort(). Can only be called once per instance. | 198 // otherwise. |
208 bool Do(); | 199 // If the WorkItem is transactional, then Do() is done as a transaction. |
| 200 // If it returns false, there will be no change on the system. |
| 201 virtual bool Do() = 0; |
209 | 202 |
210 // Rollback any actions previously carried out by this WorkItem if | 203 // Rollback any actions previously carried out by this WorkItem. If the |
211 // rollback_enabled(). Can only be called once per instance, after Do() has | 204 // WorkItem is transactional, then the previous actions can be fully |
212 // returned. | 205 // rolled back. If the WorkItem is non-transactional, the rollback is a |
213 void Rollback(); | 206 // best effort. |
| 207 virtual void Rollback() = 0; |
214 | 208 |
215 void set_best_effort(bool best_effort); | 209 // If called with true, this WorkItem may return true from its Do() method |
216 bool best_effort() const { return best_effort_; } | 210 // even on failure and Rollback will have no effect. |
217 void set_rollback_enabled(bool rollback_enabled); | 211 void set_ignore_failure(bool ignore_failure) { |
218 bool rollback_enabled() const { return rollback_enabled_; } | 212 ignore_failure_ = ignore_failure; |
| 213 } |
| 214 |
| 215 // Returns true if this WorkItem should ignore failures. |
| 216 bool ignore_failure() const { |
| 217 return ignore_failure_; |
| 218 } |
219 | 219 |
220 // Sets an optional log message that a work item may use to print additional | 220 // Sets an optional log message that a work item may use to print additional |
221 // instance-specific information. | 221 // instance-specific information. |
222 void set_log_message(const std::string& log_message) { | 222 void set_log_message(const std::string& log_message) { |
223 log_message_ = log_message; | 223 log_message_ = log_message; |
224 } | 224 } |
225 | 225 |
226 // Retrieves the optional log message. The retrieved string may be empty. | 226 // Retrieves the optional log message. The retrieved string may be empty. |
227 const std::string& log_message() const { return log_message_; } | 227 const std::string& log_message() const { return log_message_; } |
228 | 228 |
229 protected: | 229 protected: |
230 enum State { | |
231 BEFORE_DO, | |
232 AFTER_DO, | |
233 AFTER_ROLLBACK, | |
234 }; | |
235 | |
236 WorkItem(); | 230 WorkItem(); |
237 | 231 |
238 State state() const { return state_; } | 232 // Specifies whether this work item my fail to complete and yet still |
| 233 // return true from Do(). |
| 234 bool ignore_failure_; |
239 | 235 |
240 std::string log_message_; | 236 std::string log_message_; |
241 | |
242 private: | |
243 // Called by Do(). Performs the actions of the Workitem. | |
244 virtual bool DoImpl() = 0; | |
245 | |
246 // Called by Rollback() if rollback_enabled() is true. Rollbacks the actions | |
247 // performed by DoImpl(). Implementations must support invocation of this even | |
248 // when DoImpl() returned false. | |
249 virtual void RollbackImpl() = 0; | |
250 | |
251 State state_ = BEFORE_DO; | |
252 bool best_effort_ = false; | |
253 bool rollback_enabled_ = true; | |
254 }; | 237 }; |
255 | 238 |
256 #endif // CHROME_INSTALLER_UTIL_WORK_ITEM_H_ | 239 #endif // CHROME_INSTALLER_UTIL_WORK_ITEM_H_ |
OLD | NEW |