Chromium Code Reviews| 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 | |
|
grt (UTC plus 2)
2016/05/06 18:39:13
uber-nit: "i.e.,"
fdoray
2016/05/10 18:35:30
Done.
| |
| 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 false. | |
|
grt (UTC plus 2)
2016/05/06 18:39:13
false -> true
fdoray
2016/05/10 18:35:31
Done.
| |
| 52 // | |
| 53 // The value of the "best-effort" and "rollback enabled" flags can't be modified | |
|
grt (UTC plus 2)
2016/05/06 18:39:13
how about instead stating that they must be set be
fdoray
2016/05/10 18:35:31
Done.
| |
| 54 // once Do() has been called. | |
| 38 class WorkItem { | 55 class WorkItem { |
| 39 public: | 56 public: |
| 40 // A callback that returns the desired value based on the |existing_value|. | 57 // A callback that returns the desired value based on the |existing_value|. |
| 41 // |existing_value| will be empty if the value didn't previously exist or | 58 // |existing_value| will be empty if the value didn't previously exist or |
| 42 // existed under a non-string type. | 59 // existed under a non-string type. |
| 43 using GetValueFromExistingCallback = | 60 using GetValueFromExistingCallback = |
| 44 base::Callback<std::wstring(const std::wstring& existing_value)>; | 61 base::Callback<std::wstring(const std::wstring& existing_value)>; |
| 45 | 62 |
| 46 // All registry operations can be instructed to operate on a specific view | 63 // All registry operations can be instructed to operate on a specific view |
| 47 // of the registry by specifying a REGSAM value to the wow64_access parameter. | 64 // of the registry by specifying a REGSAM value to the wow64_access parameter. |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 // Create an empty WorkItemList that cannot be rolled back. | 204 // 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 | 205 // 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. | 206 // not abort execution if an item in the list fails. |
| 190 static WorkItemList* CreateNoRollbackWorkItemList(); | 207 static WorkItemList* CreateNoRollbackWorkItemList(); |
| 191 | 208 |
| 192 // Create a conditional work item list that will execute only if | 209 // Create a conditional work item list that will execute only if |
| 193 // condition->ShouldRun() returns true. The WorkItemList instance | 210 // condition->ShouldRun() returns true. The WorkItemList instance |
| 194 // assumes ownership of condition. | 211 // assumes ownership of condition. |
| 195 static WorkItemList* CreateConditionalWorkItemList(Condition* condition); | 212 static WorkItemList* CreateConditionalWorkItemList(Condition* condition); |
| 196 | 213 |
| 197 // Perform the actions of WorkItem. Returns true if success, returns false | 214 // Perform the actions of WorkItem. Returns true if success or if |
| 198 // otherwise. | 215 // best_effort(). Can only be called once per instance. |
| 199 // If the WorkItem is transactional, then Do() is done as a transaction. | 216 bool Do(); |
| 200 // If it returns false, there will be no change on the system. | |
| 201 virtual bool Do() = 0; | |
| 202 | 217 |
| 203 // Rollback any actions previously carried out by this WorkItem. If the | 218 // Rollback any actions previously carried out by this WorkItem if |
| 204 // WorkItem is transactional, then the previous actions can be fully | 219 // rollback_enabled(). Can only be called once per instance, after Do() has |
| 205 // rolled back. If the WorkItem is non-transactional, the rollback is a | 220 // returned. |
| 206 // best effort. | 221 void Rollback(); |
| 207 virtual void Rollback() = 0; | |
| 208 | 222 |
| 209 // If called with true, this WorkItem may return true from its Do() method | 223 void set_best_effort(bool best_effort); |
| 210 // even on failure and Rollback will have no effect. | 224 bool best_effort() const { return best_effort_; } |
| 211 void set_ignore_failure(bool ignore_failure) { | 225 void set_rollback_enabled(bool rollback_enabled); |
| 212 ignore_failure_ = ignore_failure; | 226 bool rollback_enabled() const { return rollback_enabled_; } |
| 213 } | |
| 214 | |
| 215 // Returns true if this WorkItem should ignore failures. | |
| 216 bool ignore_failure() const { | |
| 217 return ignore_failure_; | |
| 218 } | |
| 219 | 227 |
| 220 // Sets an optional log message that a work item may use to print additional | 228 // Sets an optional log message that a work item may use to print additional |
| 221 // instance-specific information. | 229 // instance-specific information. |
| 222 void set_log_message(const std::string& log_message) { | 230 void set_log_message(const std::string& log_message) { |
| 223 log_message_ = log_message; | 231 log_message_ = log_message; |
| 224 } | 232 } |
| 225 | 233 |
| 226 // Retrieves the optional log message. The retrieved string may be empty. | 234 // Retrieves the optional log message. The retrieved string may be empty. |
| 227 const std::string& log_message() const { return log_message_; } | 235 const std::string& log_message() const { return log_message_; } |
| 228 | 236 |
| 229 protected: | 237 protected: |
| 238 enum State { | |
| 239 BEFORE_DO, | |
| 240 AFTER_DO, | |
| 241 AFTER_ROLLBACK, | |
| 242 }; | |
| 243 | |
| 230 WorkItem(); | 244 WorkItem(); |
| 231 | 245 |
| 232 // Specifies whether this work item my fail to complete and yet still | 246 State state() const { return state_; } |
| 233 // return true from Do(). | |
| 234 bool ignore_failure_; | |
| 235 | 247 |
| 236 std::string log_message_; | 248 std::string log_message_; |
| 249 | |
| 250 private: | |
| 251 // Called by Do(). Performs the actions of the Workitem. | |
| 252 virtual bool DoImpl() = 0; | |
| 253 | |
| 254 // Called by Rollback() if rollback_enabled() is true. Rollbacks the actions | |
| 255 // performed by DoImpl(). Implementations must support invocation of this even | |
| 256 // when DoImpl() returned false. | |
| 257 virtual void RollbackImpl() = 0; | |
| 258 | |
| 259 State state_ = BEFORE_DO; | |
| 260 bool best_effort_ = false; | |
| 261 bool rollback_enabled_ = true; | |
| 237 }; | 262 }; |
| 238 | 263 |
| 239 #endif // CHROME_INSTALLER_UTIL_WORK_ITEM_H_ | 264 #endif // CHROME_INSTALLER_UTIL_WORK_ITEM_H_ |
| OLD | NEW |