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

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

Issue 1976443005: Revert of 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, 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() = default; 31 WorkItemList::WorkItemList()
32 : status_(ADD_ITEM) {
33 }
32 34
33 bool WorkItemList::DoImpl() { 35 bool WorkItemList::Do() {
34 VLOG(1) << "Beginning execution of work item list " << log_message(); 36 if (status_ != ADD_ITEM)
37 return false;
35 38
36 bool result = true; 39 bool result = true;
37 while (!list_.empty()) { 40 while (!list_.empty()) {
38 WorkItem* work_item = list_.front(); 41 WorkItem* work_item = list_.front();
39 list_.pop_front(); 42 list_.pop_front();
40 executed_list_.push_front(work_item); 43 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
47 if (!work_item->Do()) { 44 if (!work_item->Do()) {
48 LOG(ERROR) << "item execution failed " << work_item->log_message(); 45 LOG(ERROR) << "item execution failed " << work_item->log_message();
49 result = false; 46 result = false;
50 break; 47 break;
51 } 48 }
52 } 49 }
53 50
54 if (result) 51 if (result)
55 VLOG(1) << "Successful execution of work item list " << log_message(); 52 VLOG(1) << "list execution succeeded";
56 else
57 LOG(ERROR) << "Failed execution of work item list " << log_message();
58 53
54 status_ = LIST_EXECUTED;
59 return result; 55 return result;
60 } 56 }
61 57
62 void WorkItemList::RollbackImpl() { 58 void WorkItemList::Rollback() {
59 if (status_ != LIST_EXECUTED)
60 return;
61
63 for (WorkItemIterator itr = executed_list_.begin(); 62 for (WorkItemIterator itr = executed_list_.begin();
64 itr != executed_list_.end(); ++itr) { 63 itr != executed_list_.end(); ++itr) {
65 (*itr)->Rollback(); 64 (*itr)->Rollback();
66 } 65 }
66
67 status_ = LIST_ROLLED_BACK;
68 return;
67 } 69 }
68 70
69 void WorkItemList::AddWorkItem(WorkItem* work_item) { 71 void WorkItemList::AddWorkItem(WorkItem* work_item) {
70 DCHECK_EQ(BEFORE_DO, state()); 72 DCHECK(status_ == ADD_ITEM);
71 list_.push_back(work_item); 73 list_.push_back(work_item);
72 } 74 }
73 75
74 WorkItem* WorkItemList::AddCallbackWorkItem( 76 WorkItem* WorkItemList::AddCallbackWorkItem(
75 base::Callback<bool(const CallbackWorkItem&)> callback) { 77 base::Callback<bool(const CallbackWorkItem&)> callback) {
76 WorkItem* item = WorkItem::CreateCallbackWorkItem(callback); 78 WorkItem* item = WorkItem::CreateCallbackWorkItem(callback);
77 AddWorkItem(item); 79 AddWorkItem(item);
78 return item; 80 return item;
79 } 81 }
80 82
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 HKEY predefined_root, 124 HKEY predefined_root,
123 const std::wstring& key_path, 125 const std::wstring& key_path,
124 REGSAM wow64_access, 126 REGSAM wow64_access,
125 const std::wstring& value_name) { 127 const std::wstring& value_name) {
126 WorkItem* item = WorkItem::CreateDeleteRegValueWorkItem( 128 WorkItem* item = WorkItem::CreateDeleteRegValueWorkItem(
127 predefined_root, key_path, wow64_access, value_name); 129 predefined_root, key_path, wow64_access, value_name);
128 AddWorkItem(item); 130 AddWorkItem(item);
129 return item; 131 return item;
130 } 132 }
131 133
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
132 WorkItem* WorkItemList::AddDeleteTreeWorkItem(const base::FilePath& root_path, 144 WorkItem* WorkItemList::AddDeleteTreeWorkItem(const base::FilePath& root_path,
133 const base::FilePath& temp_path) { 145 const base::FilePath& temp_path) {
134 WorkItem* item = WorkItem::CreateDeleteTreeWorkItem(root_path, temp_path); 146 std::vector<base::FilePath> no_key_files;
135 AddWorkItem(item); 147 return AddDeleteTreeWorkItem(root_path, temp_path, no_key_files);
136 return item;
137 } 148 }
138 149
139 WorkItem* WorkItemList::AddMoveTreeWorkItem(const std::wstring& source_path, 150 WorkItem* WorkItemList::AddMoveTreeWorkItem(const std::wstring& source_path,
140 const std::wstring& dest_path, 151 const std::wstring& dest_path,
141 const std::wstring& temp_dir, 152 const std::wstring& temp_dir,
142 MoveTreeOption duplicate_option) { 153 MoveTreeOption duplicate_option) {
143 WorkItem* item = WorkItem::CreateMoveTreeWorkItem(base::FilePath(source_path), 154 WorkItem* item = WorkItem::CreateMoveTreeWorkItem(base::FilePath(source_path),
144 base::FilePath(dest_path), 155 base::FilePath(dest_path),
145 base::FilePath(temp_dir), 156 base::FilePath(temp_dir),
146 duplicate_option); 157 duplicate_option);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 } 224 }
214 225
215 WorkItem* WorkItemList::AddSelfRegWorkItem(const std::wstring& dll_path, 226 WorkItem* WorkItemList::AddSelfRegWorkItem(const std::wstring& dll_path,
216 bool do_register, 227 bool do_register,
217 bool user_level_registration) { 228 bool user_level_registration) {
218 WorkItem* item = WorkItem::CreateSelfRegWorkItem(dll_path, do_register, 229 WorkItem* item = WorkItem::CreateSelfRegWorkItem(dll_path, do_register,
219 user_level_registration); 230 user_level_registration);
220 AddWorkItem(item); 231 AddWorkItem(item);
221 return item; 232 return item;
222 } 233 }
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
« no previous file with comments | « chrome/installer/util/work_item_list.h ('k') | chrome/installer/util/work_item_list_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698