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

Side by Side Diff: chrome/installer/util/work_item_list.cc

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: CR grt #7 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
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 #include "chrome/installer/util/work_item_list.h" 5 #include "chrome/installer/util/work_item_list.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "chrome/installer/util/callback_work_item.h" 9 #include "chrome/installer/util/callback_work_item.h"
10 #include "chrome/installer/util/copy_tree_work_item.h" 10 #include "chrome/installer/util/copy_tree_work_item.h"
(...skipping 10 matching lines...) Expand all
21 WorkItemList::~WorkItemList() { 21 WorkItemList::~WorkItemList() {
22 for (WorkItemIterator itr = list_.begin(); itr != list_.end(); ++itr) { 22 for (WorkItemIterator itr = list_.begin(); itr != list_.end(); ++itr) {
23 delete (*itr); 23 delete (*itr);
24 } 24 }
25 for (WorkItemIterator itr = executed_list_.begin(); 25 for (WorkItemIterator itr = executed_list_.begin();
26 itr != executed_list_.end(); ++itr) { 26 itr != executed_list_.end(); ++itr) {
27 delete (*itr); 27 delete (*itr);
28 } 28 }
29 } 29 }
30 30
31 WorkItemList::WorkItemList() 31 WorkItemList::WorkItemList() = default;
32 : status_(ADD_ITEM) {
33 }
34 32
35 bool WorkItemList::Do() { 33 bool WorkItemList::DoImpl() {
36 if (status_ != ADD_ITEM) 34 VLOG(1) << "Beginning execution of work item list " << log_message();
37 return false;
38 35
39 bool result = true; 36 bool result = true;
40 while (!list_.empty()) { 37 while (!list_.empty()) {
41 WorkItem* work_item = list_.front(); 38 WorkItem* work_item = list_.front();
42 list_.pop_front(); 39 list_.pop_front();
43 executed_list_.push_front(work_item); 40 executed_list_.push_front(work_item);
41
42 if (best_effort())
43 work_item->set_best_effort(true);
44 if (!rollback_enabled())
45 work_item->set_rollback_enabled(false);
46
44 if (!work_item->Do()) { 47 if (!work_item->Do()) {
45 LOG(ERROR) << "item execution failed " << work_item->log_message(); 48 LOG(ERROR) << "item execution failed " << work_item->log_message();
46 result = false; 49 result = false;
47 break; 50 break;
48 } 51 }
49 } 52 }
50 53
51 if (result) 54 if (result)
grt (UTC plus 2) 2016/05/12 17:26:24 how about changing this to: if (result) VLOG
fdoray 2016/05/13 14:31:45 Done.
52 VLOG(1) << "list execution succeeded"; 55 VLOG(1) << "list execution succeeded";
53 56
54 status_ = LIST_EXECUTED;
55 return result; 57 return result;
56 } 58 }
57 59
58 void WorkItemList::Rollback() { 60 void WorkItemList::RollbackImpl() {
59 if (status_ != LIST_EXECUTED)
60 return;
61
62 for (WorkItemIterator itr = executed_list_.begin(); 61 for (WorkItemIterator itr = executed_list_.begin();
63 itr != executed_list_.end(); ++itr) { 62 itr != executed_list_.end(); ++itr) {
64 (*itr)->Rollback(); 63 (*itr)->Rollback();
65 } 64 }
66
67 status_ = LIST_ROLLED_BACK;
68 return;
69 } 65 }
70 66
71 void WorkItemList::AddWorkItem(WorkItem* work_item) { 67 void WorkItemList::AddWorkItem(WorkItem* work_item) {
72 DCHECK(status_ == ADD_ITEM); 68 DCHECK_EQ(BEFORE_DO, state());
73 list_.push_back(work_item); 69 list_.push_back(work_item);
74 } 70 }
75 71
76 WorkItem* WorkItemList::AddCallbackWorkItem( 72 WorkItem* WorkItemList::AddCallbackWorkItem(
77 base::Callback<bool(const CallbackWorkItem&)> callback) { 73 base::Callback<bool(const CallbackWorkItem&)> callback) {
78 WorkItem* item = WorkItem::CreateCallbackWorkItem(callback); 74 WorkItem* item = WorkItem::CreateCallbackWorkItem(callback);
79 AddWorkItem(item); 75 AddWorkItem(item);
80 return item; 76 return item;
81 } 77 }
82 78
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 HKEY predefined_root, 120 HKEY predefined_root,
125 const std::wstring& key_path, 121 const std::wstring& key_path,
126 REGSAM wow64_access, 122 REGSAM wow64_access,
127 const std::wstring& value_name) { 123 const std::wstring& value_name) {
128 WorkItem* item = WorkItem::CreateDeleteRegValueWorkItem( 124 WorkItem* item = WorkItem::CreateDeleteRegValueWorkItem(
129 predefined_root, key_path, wow64_access, value_name); 125 predefined_root, key_path, wow64_access, value_name);
130 AddWorkItem(item); 126 AddWorkItem(item);
131 return item; 127 return item;
132 } 128 }
133 129
134 WorkItem* WorkItemList::AddDeleteTreeWorkItem(
135 const base::FilePath& root_path,
136 const base::FilePath& temp_path,
137 const std::vector<base::FilePath>& key_paths) {
138 WorkItem* item = WorkItem::CreateDeleteTreeWorkItem(root_path, temp_path,
139 key_paths);
140 AddWorkItem(item);
141 return item;
142 }
143
144 WorkItem* WorkItemList::AddDeleteTreeWorkItem(const base::FilePath& root_path, 130 WorkItem* WorkItemList::AddDeleteTreeWorkItem(const base::FilePath& root_path,
145 const base::FilePath& temp_path) { 131 const base::FilePath& temp_path) {
146 std::vector<base::FilePath> no_key_files; 132 WorkItem* item = WorkItem::CreateDeleteTreeWorkItem(root_path, temp_path);
147 return AddDeleteTreeWorkItem(root_path, temp_path, no_key_files); 133 AddWorkItem(item);
134 return item;
148 } 135 }
149 136
150 WorkItem* WorkItemList::AddMoveTreeWorkItem(const std::wstring& source_path, 137 WorkItem* WorkItemList::AddMoveTreeWorkItem(const std::wstring& source_path,
151 const std::wstring& dest_path, 138 const std::wstring& dest_path,
152 const std::wstring& temp_dir, 139 const std::wstring& temp_dir,
153 MoveTreeOption duplicate_option) { 140 MoveTreeOption duplicate_option) {
154 WorkItem* item = WorkItem::CreateMoveTreeWorkItem(base::FilePath(source_path), 141 WorkItem* item = WorkItem::CreateMoveTreeWorkItem(base::FilePath(source_path),
155 base::FilePath(dest_path), 142 base::FilePath(dest_path),
156 base::FilePath(temp_dir), 143 base::FilePath(temp_dir),
157 duplicate_option); 144 duplicate_option);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 } 211 }
225 212
226 WorkItem* WorkItemList::AddSelfRegWorkItem(const std::wstring& dll_path, 213 WorkItem* WorkItemList::AddSelfRegWorkItem(const std::wstring& dll_path,
227 bool do_register, 214 bool do_register,
228 bool user_level_registration) { 215 bool user_level_registration) {
229 WorkItem* item = WorkItem::CreateSelfRegWorkItem(dll_path, do_register, 216 WorkItem* item = WorkItem::CreateSelfRegWorkItem(dll_path, do_register,
230 user_level_registration); 217 user_level_registration);
231 AddWorkItem(item); 218 AddWorkItem(item);
232 return item; 219 return item;
233 } 220 }
234
235 ////////////////////////////////////////////////////////////////////////////////
236 NoRollbackWorkItemList::~NoRollbackWorkItemList() {
237 }
238
239 bool NoRollbackWorkItemList::Do() {
240 if (status_ != ADD_ITEM)
241 return false;
242
243 bool result = true;
244 while (!list_.empty()) {
245 WorkItem* work_item = list_.front();
246 list_.pop_front();
247 executed_list_.push_front(work_item);
248 work_item->set_ignore_failure(true);
249 if (!work_item->Do()) {
250 LOG(ERROR) << "NoRollbackWorkItemList: item execution failed "
251 << work_item->log_message();
252 result = false;
253 }
254 }
255
256 if (result)
257 VLOG(1) << "NoRollbackWorkItemList: list execution succeeded";
258
259 status_ = LIST_EXECUTED;
260 return result;
261 }
262
263 void NoRollbackWorkItemList::Rollback() {
264 // Ignore rollback.
265 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698