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

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: Created 4 years, 8 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
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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 // Create an empty WorkItemList that cannot be rolled back. 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 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. 189 // not abort execution if an item in the list fails.
190 static WorkItemList* CreateNoRollbackWorkItemList(); 190 static WorkItemList* CreateNoRollbackWorkItemList();
191 191
192 // Create a conditional work item list that will execute only if 192 // Create a conditional work item list that will execute only if
193 // condition->ShouldRun() returns true. The WorkItemList instance 193 // condition->ShouldRun() returns true. The WorkItemList instance
194 // assumes ownership of condition. 194 // assumes ownership of condition.
195 static WorkItemList* CreateConditionalWorkItemList(Condition* condition); 195 static WorkItemList* CreateConditionalWorkItemList(Condition* condition);
196 196
197 // Perform the actions of WorkItem. Returns true if success, returns false 197 // Perform the actions of WorkItem. Returns true if success or if this is a
198 // otherwise. 198 // best-effort WorkItem. Can only be called once per instance.
199 // If the WorkItem is transactional, then Do() is done as a transaction. 199 bool Do();
200 // If it returns false, there will be no change on the system.
201 virtual bool Do() = 0;
202 200
203 // Rollback any actions previously carried out by this WorkItem. If the 201 // Rollback any actions previously carried out by this WorkItem. Can only be
204 // WorkItem is transactional, then the previous actions can be fully 202 // called once per instance, after Do() has returned.
205 // rolled back. If the WorkItem is non-transactional, the rollback is a 203 void Rollback();
206 // best effort.
207 virtual void Rollback() = 0;
208 204
209 // If called with true, this WorkItem may return true from its Do() method 205 // If called with true, Do() will always returns true, even when it does
210 // even on failure and Rollback will have no effect. 206 // partial work or no work at all.
211 void set_ignore_failure(bool ignore_failure) { 207 void set_best_effort(bool best_effort) { best_effort_ = best_effort; }
212 ignore_failure_ = ignore_failure; 208
209 // Returns true if Do() always returns true.
210 bool best_effort() const { return best_effort_; }
211
212 // If called with false, Rollback() becomes a no-op.
213 void set_allow_rollback(bool allow_rollback) {
214 allow_rollback_ = allow_rollback;
213 } 215 }
214 216
215 // Returns true if this WorkItem should ignore failures. 217 // Returns false if Rollback() is a no-op.
216 bool ignore_failure() const { 218 bool allow_rollback() const { return allow_rollback_; }
grt (UTC plus 2) 2016/04/27 17:29:16 i'm not sure if "allow" is the right term here sin
fdoray 2016/05/02 20:10:00 "enable" seems to be the best word. All WIs "suppo
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 WorkItem(); 230 WorkItem();
231 231
232 // Specifies whether this work item my fail to complete and yet still 232 std::string log_message_;
233 // return true from Do().
234 bool ignore_failure_;
235 233
236 std::string log_message_; 234 private:
235 enum State {
grt (UTC plus 2) 2016/04/27 17:29:16 wdyt of making this and an accessor for it protect
fdoray 2016/05/02 20:10:00 Done.
236 BEFORE_DO,
237 AFTER_DO,
238 AFTER_ROLLBACK,
239 };
240
241 // Called by Do(). Performs the actions of the Workitem.
242 virtual bool DoImpl() = 0;
243
244 // Called by Rollback() if allow_rollback() is true. Rollbacks the actions
245 // performed by Do().
grt (UTC plus 2) 2016/04/27 17:29:17 please add to the comment that implementations mus
fdoray 2016/05/02 20:10:00 Done.
246 virtual void RollbackImpl() = 0;
247
248 State state_ = BEFORE_DO;
249 bool best_effort_ = false;
grt (UTC plus 2) 2016/04/27 17:29:16 suggestion: document the "best effort" and "allow
fdoray 2016/05/02 20:10:00 Done.
250 bool allow_rollback_ = true;
237 }; 251 };
238 252
239 #endif // CHROME_INSTALLER_UTIL_WORK_ITEM_H_ 253 #endif // CHROME_INSTALLER_UTIL_WORK_ITEM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698