Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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) | |
| 37 return false; | |
| 38 | |
| 39 bool result = true; | 34 bool result = true; |
| 40 while (!list_.empty()) { | 35 while (!list_.empty()) { |
| 41 WorkItem* work_item = list_.front(); | 36 WorkItem* work_item = list_.front(); |
| 42 list_.pop_front(); | 37 list_.pop_front(); |
| 43 executed_list_.push_front(work_item); | 38 executed_list_.push_front(work_item); |
| 39 work_item->set_best_effort(best_effort()); | |
|
grt (UTC plus 2)
2016/05/06 18:39:13
hmm. one flaw with this is that you can't add a be
fdoray
2016/05/10 18:35:32
Now I only make the work items best-effort if the
| |
| 40 work_item->set_rollback_enabled(rollback_enabled()); | |
| 44 if (!work_item->Do()) { | 41 if (!work_item->Do()) { |
| 45 LOG(ERROR) << "item execution failed " << work_item->log_message(); | 42 LOG(ERROR) << "item execution failed " << work_item->log_message(); |
| 46 result = false; | 43 result = false; |
| 47 break; | 44 break; |
| 48 } | 45 } |
| 49 } | 46 } |
| 50 | 47 |
| 51 if (result) | 48 if (result) |
| 52 VLOG(1) << "list execution succeeded"; | 49 VLOG(1) << "list execution succeeded"; |
| 53 | 50 |
| 54 status_ = LIST_EXECUTED; | |
| 55 return result; | 51 return result; |
| 56 } | 52 } |
| 57 | 53 |
| 58 void WorkItemList::Rollback() { | 54 void WorkItemList::RollbackImpl() { |
| 59 if (status_ != LIST_EXECUTED) | |
| 60 return; | |
| 61 | |
| 62 for (WorkItemIterator itr = executed_list_.begin(); | 55 for (WorkItemIterator itr = executed_list_.begin(); |
| 63 itr != executed_list_.end(); ++itr) { | 56 itr != executed_list_.end(); ++itr) { |
| 64 (*itr)->Rollback(); | 57 (*itr)->Rollback(); |
| 65 } | 58 } |
| 66 | |
| 67 status_ = LIST_ROLLED_BACK; | |
| 68 return; | |
| 69 } | 59 } |
| 70 | 60 |
| 71 void WorkItemList::AddWorkItem(WorkItem* work_item) { | 61 void WorkItemList::AddWorkItem(WorkItem* work_item) { |
| 72 DCHECK(status_ == ADD_ITEM); | 62 DCHECK_EQ(WorkItem::BEFORE_DO, state()); |
|
grt (UTC plus 2)
2016/05/06 18:39:13
nit: no need for WorkItem:: here
fdoray
2016/05/10 18:35:31
Done.
| |
| 73 list_.push_back(work_item); | 63 list_.push_back(work_item); |
| 74 } | 64 } |
| 75 | 65 |
| 76 WorkItem* WorkItemList::AddCallbackWorkItem( | 66 WorkItem* WorkItemList::AddCallbackWorkItem( |
| 77 base::Callback<bool(const CallbackWorkItem&)> callback) { | 67 base::Callback<bool(const CallbackWorkItem&)> callback) { |
| 78 WorkItem* item = WorkItem::CreateCallbackWorkItem(callback); | 68 WorkItem* item = WorkItem::CreateCallbackWorkItem(callback); |
| 79 AddWorkItem(item); | 69 AddWorkItem(item); |
| 80 return item; | 70 return item; |
| 81 } | 71 } |
| 82 | 72 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 WorkItem* item = WorkItem::CreateSelfRegWorkItem(dll_path, do_register, | 219 WorkItem* item = WorkItem::CreateSelfRegWorkItem(dll_path, do_register, |
| 230 user_level_registration); | 220 user_level_registration); |
| 231 AddWorkItem(item); | 221 AddWorkItem(item); |
| 232 return item; | 222 return item; |
| 233 } | 223 } |
| 234 | 224 |
| 235 //////////////////////////////////////////////////////////////////////////////// | 225 //////////////////////////////////////////////////////////////////////////////// |
| 236 NoRollbackWorkItemList::~NoRollbackWorkItemList() { | 226 NoRollbackWorkItemList::~NoRollbackWorkItemList() { |
| 237 } | 227 } |
| 238 | 228 |
| 239 bool NoRollbackWorkItemList::Do() { | 229 bool NoRollbackWorkItemList::DoImpl() { |
| 240 if (status_ != ADD_ITEM) | |
| 241 return false; | |
| 242 | |
| 243 bool result = true; | 230 bool result = true; |
| 244 while (!list_.empty()) { | 231 while (!list_.empty()) { |
| 245 WorkItem* work_item = list_.front(); | 232 WorkItem* work_item = list_.front(); |
| 246 list_.pop_front(); | 233 list_.pop_front(); |
| 247 executed_list_.push_front(work_item); | 234 executed_list_.push_front(work_item); |
| 248 work_item->set_ignore_failure(true); | 235 work_item->set_rollback_enabled(false); |
| 249 if (!work_item->Do()) { | 236 if (!work_item->Do()) { |
| 250 LOG(ERROR) << "NoRollbackWorkItemList: item execution failed " | 237 LOG(ERROR) << "NoRollbackWorkItemList: item execution failed " |
| 251 << work_item->log_message(); | 238 << work_item->log_message(); |
| 252 result = false; | 239 result = false; |
| 253 } | 240 } |
| 254 } | 241 } |
| 255 | 242 |
| 256 if (result) | 243 if (result) |
| 257 VLOG(1) << "NoRollbackWorkItemList: list execution succeeded"; | 244 VLOG(1) << "NoRollbackWorkItemList: list execution succeeded"; |
| 258 | 245 |
| 259 status_ = LIST_EXECUTED; | |
| 260 return result; | 246 return result; |
| 261 } | 247 } |
| 262 | 248 |
| 263 void NoRollbackWorkItemList::Rollback() { | 249 void NoRollbackWorkItemList::RollbackImpl() { |
| 264 // Ignore rollback. | 250 // Ignore rollback. |
| 265 } | 251 } |
| OLD | NEW |