Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: chrome/installer/util/work_item.h

Issue 1882923003: Add best-effort/allow rollback flags on WorkItem. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@simple_list_tests
Patch Set: fix build error Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/installer/util/set_reg_value_work_item.cc ('k') | chrome/installer/util/work_item.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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.
38 class WorkItem { 54 class WorkItem {
39 public: 55 public:
40 // A callback that returns the desired value based on the |existing_value|. 56 // 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 57 // |existing_value| will be empty if the value didn't previously exist or
42 // existed under a non-string type. 58 // existed under a non-string type.
43 using GetValueFromExistingCallback = 59 using GetValueFromExistingCallback =
44 base::Callback<std::wstring(const std::wstring& existing_value)>; 60 base::Callback<std::wstring(const std::wstring& existing_value)>;
45 61
46 // All registry operations can be instructed to operate on a specific view 62 // 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. 63 // 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
112 REGSAM wow64_access); 128 REGSAM wow64_access);
113 129
114 // Create a DeleteRegValueWorkItem that deletes a registry value 130 // Create a DeleteRegValueWorkItem that deletes a registry value
115 static DeleteRegValueWorkItem* CreateDeleteRegValueWorkItem( 131 static DeleteRegValueWorkItem* CreateDeleteRegValueWorkItem(
116 HKEY predefined_root, 132 HKEY predefined_root,
117 const std::wstring& key_path, 133 const std::wstring& key_path,
118 REGSAM wow64_access, 134 REGSAM wow64_access,
119 const std::wstring& value_name); 135 const std::wstring& value_name);
120 136
121 // Create a DeleteTreeWorkItem that recursively deletes a file system 137 // Create a DeleteTreeWorkItem that recursively deletes a file system
122 // hierarchy at the given root path. A key file can be optionally specified 138 // hierarchy at the given root path.
123 // by key_path.
124 static DeleteTreeWorkItem* CreateDeleteTreeWorkItem( 139 static DeleteTreeWorkItem* CreateDeleteTreeWorkItem(
125 const base::FilePath& root_path, 140 const base::FilePath& root_path,
126 const base::FilePath& temp_path, 141 const base::FilePath& temp_path);
127 const std::vector<base::FilePath>& key_paths);
128 142
129 // Create a MoveTreeWorkItem that recursively moves a file system hierarchy 143 // Create a MoveTreeWorkItem that recursively moves a file system hierarchy
130 // from source path to destination path. 144 // from source path to destination path.
131 static MoveTreeWorkItem* CreateMoveTreeWorkItem( 145 static MoveTreeWorkItem* CreateMoveTreeWorkItem(
132 const base::FilePath& source_path, 146 const base::FilePath& source_path,
133 const base::FilePath& dest_path, 147 const base::FilePath& dest_path,
134 const base::FilePath& temp_dir, 148 const base::FilePath& temp_dir,
135 MoveTreeOption duplicate_option); 149 MoveTreeOption duplicate_option);
136 150
137 // Create a SetRegValueWorkItem that sets a registry value with REG_SZ type 151 // Create a SetRegValueWorkItem that sets a registry value with REG_SZ type
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 // Add a SelfRegWorkItem that registers or unregisters a DLL at the 191 // Add a SelfRegWorkItem that registers or unregisters a DLL at the
178 // specified path. 192 // specified path.
179 static SelfRegWorkItem* CreateSelfRegWorkItem(const std::wstring& dll_path, 193 static SelfRegWorkItem* CreateSelfRegWorkItem(const std::wstring& dll_path,
180 bool do_register, 194 bool do_register,
181 bool user_level_registration); 195 bool user_level_registration);
182 196
183 // Create an empty WorkItemList. A WorkItemList can recursively contains 197 // Create an empty WorkItemList. A WorkItemList can recursively contains
184 // a list of WorkItems. 198 // a list of WorkItems.
185 static WorkItemList* CreateWorkItemList(); 199 static WorkItemList* CreateWorkItemList();
186 200
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
192 // Create a conditional work item list that will execute only if 201 // Create a conditional work item list that will execute only if
193 // condition->ShouldRun() returns true. The WorkItemList instance 202 // condition->ShouldRun() returns true. The WorkItemList instance
194 // assumes ownership of condition. 203 // assumes ownership of condition.
195 static WorkItemList* CreateConditionalWorkItemList(Condition* condition); 204 static WorkItemList* CreateConditionalWorkItemList(Condition* condition);
196 205
197 // Perform the actions of WorkItem. Returns true if success, returns false 206 // Perform the actions of WorkItem. Returns true if success or if
198 // otherwise. 207 // best_effort(). Can only be called once per instance.
199 // If the WorkItem is transactional, then Do() is done as a transaction. 208 bool Do();
200 // If it returns false, there will be no change on the system.
201 virtual bool Do() = 0;
202 209
203 // Rollback any actions previously carried out by this WorkItem. If the 210 // Rollback any actions previously carried out by this WorkItem if
204 // WorkItem is transactional, then the previous actions can be fully 211 // 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 212 // returned.
206 // best effort. 213 void Rollback();
207 virtual void Rollback() = 0;
208 214
209 // If called with true, this WorkItem may return true from its Do() method 215 void set_best_effort(bool best_effort);
210 // even on failure and Rollback will have no effect. 216 bool best_effort() const { return best_effort_; }
211 void set_ignore_failure(bool ignore_failure) { 217 void set_rollback_enabled(bool rollback_enabled);
hans 2016/05/14 19:54:37 Removing this broke the build. From https://build.
212 ignore_failure_ = ignore_failure; 218 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 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
230 WorkItem(); 236 WorkItem();
231 237
232 // Specifies whether this work item my fail to complete and yet still 238 State state() const { return state_; }
233 // return true from Do().
234 bool ignore_failure_;
235 239
236 std::string log_message_; 240 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;
237 }; 254 };
238 255
239 #endif // CHROME_INSTALLER_UTIL_WORK_ITEM_H_ 256 #endif // CHROME_INSTALLER_UTIL_WORK_ITEM_H_
OLDNEW
« no previous file with comments | « chrome/installer/util/set_reg_value_work_item.cc ('k') | chrome/installer/util/work_item.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698