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

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: 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
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)
52 VLOG(1) << "list execution succeeded"; 55 VLOG(1) << "Successful execution of work item list " << log_message();
56 else
57 LOG(ERROR) << "Failed execution of work item list " << log_message();
53 58
54 status_ = LIST_EXECUTED;
55 return result; 59 return result;
56 } 60 }
57 61
58 void WorkItemList::Rollback() { 62 void WorkItemList::RollbackImpl() {
59 if (status_ != LIST_EXECUTED)
60 return;
61
62 for (WorkItemIterator itr = executed_list_.begin(); 63 for (WorkItemIterator itr = executed_list_.begin();
63 itr != executed_list_.end(); ++itr) { 64 itr != executed_list_.end(); ++itr) {
64 (*itr)->Rollback(); 65 (*itr)->Rollback();
65 } 66 }
66
67 status_ = LIST_ROLLED_BACK;
68 return;
69 } 67 }
70 68
71 void WorkItemList::AddWorkItem(WorkItem* work_item) { 69 void WorkItemList::AddWorkItem(WorkItem* work_item) {
72 DCHECK(status_ == ADD_ITEM); 70 DCHECK_EQ(BEFORE_DO, state());
73 list_.push_back(work_item); 71 list_.push_back(work_item);
74 } 72 }
75 73
76 WorkItem* WorkItemList::AddCallbackWorkItem( 74 WorkItem* WorkItemList::AddCallbackWorkItem(
77 base::Callback<bool(const CallbackWorkItem&)> callback) { 75 base::Callback<bool(const CallbackWorkItem&)> callback) {
78 WorkItem* item = WorkItem::CreateCallbackWorkItem(callback); 76 WorkItem* item = WorkItem::CreateCallbackWorkItem(callback);
79 AddWorkItem(item); 77 AddWorkItem(item);
80 return item; 78 return item;
81 } 79 }
82 80
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 HKEY predefined_root, 122 HKEY predefined_root,
125 const std::wstring& key_path, 123 const std::wstring& key_path,
126 REGSAM wow64_access, 124 REGSAM wow64_access,
127 const std::wstring& value_name) { 125 const std::wstring& value_name) {
128 WorkItem* item = WorkItem::CreateDeleteRegValueWorkItem( 126 WorkItem* item = WorkItem::CreateDeleteRegValueWorkItem(
129 predefined_root, key_path, wow64_access, value_name); 127 predefined_root, key_path, wow64_access, value_name);
130 AddWorkItem(item); 128 AddWorkItem(item);
131 return item; 129 return item;
132 } 130 }
133 131
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, 132 WorkItem* WorkItemList::AddDeleteTreeWorkItem(const base::FilePath& root_path,
145 const base::FilePath& temp_path) { 133 const base::FilePath& temp_path) {
146 std::vector<base::FilePath> no_key_files; 134 WorkItem* item = WorkItem::CreateDeleteTreeWorkItem(root_path, temp_path);
147 return AddDeleteTreeWorkItem(root_path, temp_path, no_key_files); 135 AddWorkItem(item);
136 return item;
148 } 137 }
149 138
150 WorkItem* WorkItemList::AddMoveTreeWorkItem(const std::wstring& source_path, 139 WorkItem* WorkItemList::AddMoveTreeWorkItem(const std::wstring& source_path,
151 const std::wstring& dest_path, 140 const std::wstring& dest_path,
152 const std::wstring& temp_dir, 141 const std::wstring& temp_dir,
153 MoveTreeOption duplicate_option) { 142 MoveTreeOption duplicate_option) {
154 WorkItem* item = WorkItem::CreateMoveTreeWorkItem(base::FilePath(source_path), 143 WorkItem* item = WorkItem::CreateMoveTreeWorkItem(base::FilePath(source_path),
155 base::FilePath(dest_path), 144 base::FilePath(dest_path),
156 base::FilePath(temp_dir), 145 base::FilePath(temp_dir),
157 duplicate_option); 146 duplicate_option);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 } 213 }
225 214
226 WorkItem* WorkItemList::AddSelfRegWorkItem(const std::wstring& dll_path, 215 WorkItem* WorkItemList::AddSelfRegWorkItem(const std::wstring& dll_path,
227 bool do_register, 216 bool do_register,
228 bool user_level_registration) { 217 bool user_level_registration) {
229 WorkItem* item = WorkItem::CreateSelfRegWorkItem(dll_path, do_register, 218 WorkItem* item = WorkItem::CreateSelfRegWorkItem(dll_path, do_register,
230 user_level_registration); 219 user_level_registration);
231 AddWorkItem(item); 220 AddWorkItem(item);
232 return item; 221 return item;
233 } 222 }
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