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
3 // found in the LICENSE file.
5 #include "chrome/installer/util/work_item_list.h"
7 #include "base/files/file_path.h"
8 #include "base/logging.h"
9 #include "chrome/installer/util/callback_work_item.h"
10 #include "chrome/installer/util/copy_tree_work_item.h"
11 #include "chrome/installer/util/create_dir_work_item.h"
12 #include "chrome/installer/util/create_reg_key_work_item.h"
13 #include "chrome/installer/util/delete_reg_key_work_item.h"
14 #include "chrome/installer/util/delete_reg_value_work_item.h"
15 #include "chrome/installer/util/delete_tree_work_item.h"
16 #include "chrome/installer/util/logging_installer.h"
17 #include "chrome/installer/util/move_tree_work_item.h"
18 #include "chrome/installer/util/self_reg_work_item.h"
19 #include "chrome/installer/util/set_reg_value_work_item.h"
21 WorkItemList::~WorkItemList() {
22 for (WorkItemIterator itr
= list_
.begin(); itr
!= list_
.end(); ++itr
) {
25 for (WorkItemIterator itr
= executed_list_
.begin();
26 itr
!= executed_list_
.end(); ++itr
) {
31 WorkItemList::WorkItemList()
35 bool WorkItemList::Do() {
36 if (status_
!= ADD_ITEM
)
40 while (!list_
.empty()) {
41 WorkItem
* work_item
= list_
.front();
43 executed_list_
.push_front(work_item
);
44 if (!work_item
->Do()) {
45 LOG(ERROR
) << "item execution failed " << work_item
->log_message();
52 VLOG(1) << "list execution succeeded";
54 status_
= LIST_EXECUTED
;
58 void WorkItemList::Rollback() {
59 if (status_
!= LIST_EXECUTED
)
62 for (WorkItemIterator itr
= executed_list_
.begin();
63 itr
!= executed_list_
.end(); ++itr
) {
67 status_
= LIST_ROLLED_BACK
;
71 void WorkItemList::AddWorkItem(WorkItem
* work_item
) {
72 DCHECK(status_
== ADD_ITEM
);
73 list_
.push_back(work_item
);
76 WorkItem
* WorkItemList::AddCallbackWorkItem(
77 base::Callback
<bool(const CallbackWorkItem
&)> callback
) {
78 WorkItem
* item
= WorkItem::CreateCallbackWorkItem(callback
);
83 WorkItem
* WorkItemList::AddCopyTreeWorkItem(
84 const std::wstring
& source_path
,
85 const std::wstring
& dest_path
,
86 const std::wstring
& temp_dir
,
87 CopyOverWriteOption overwrite_option
,
88 const std::wstring
& alternative_path
) {
89 WorkItem
* item
= WorkItem::CreateCopyTreeWorkItem(
90 base::FilePath(source_path
),
91 base::FilePath(dest_path
),
92 base::FilePath(temp_dir
),
94 base::FilePath(alternative_path
));
99 WorkItem
* WorkItemList::AddCreateDirWorkItem(const base::FilePath
& path
) {
100 WorkItem
* item
= WorkItem::CreateCreateDirWorkItem(path
);
105 WorkItem
* WorkItemList::AddCreateRegKeyWorkItem(HKEY predefined_root
,
106 const std::wstring
& path
,
107 REGSAM wow64_access
) {
109 WorkItem::CreateCreateRegKeyWorkItem(predefined_root
, path
, wow64_access
);
114 WorkItem
* WorkItemList::AddDeleteRegKeyWorkItem(HKEY predefined_root
,
115 const std::wstring
& path
,
116 REGSAM wow64_access
) {
118 WorkItem::CreateDeleteRegKeyWorkItem(predefined_root
, path
, wow64_access
);
123 WorkItem
* WorkItemList::AddDeleteRegValueWorkItem(
124 HKEY predefined_root
,
125 const std::wstring
& key_path
,
127 const std::wstring
& value_name
) {
128 WorkItem
* item
= WorkItem::CreateDeleteRegValueWorkItem(
129 predefined_root
, key_path
, wow64_access
, value_name
);
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
,
144 WorkItem
* WorkItemList::AddDeleteTreeWorkItem(const base::FilePath
& root_path
,
145 const base::FilePath
& temp_path
) {
146 std::vector
<base::FilePath
> no_key_files
;
147 return AddDeleteTreeWorkItem(root_path
, temp_path
, no_key_files
);
150 WorkItem
* WorkItemList::AddMoveTreeWorkItem(const std::wstring
& source_path
,
151 const std::wstring
& dest_path
,
152 const std::wstring
& temp_dir
,
153 MoveTreeOption duplicate_option
) {
154 WorkItem
* item
= WorkItem::CreateMoveTreeWorkItem(base::FilePath(source_path
),
155 base::FilePath(dest_path
),
156 base::FilePath(temp_dir
),
162 WorkItem
* WorkItemList::AddSetRegValueWorkItem(HKEY predefined_root
,
163 const std::wstring
& key_path
,
165 const std::wstring
& value_name
,
166 const std::wstring
& value_data
,
168 WorkItem
* item
= WorkItem::CreateSetRegValueWorkItem(predefined_root
,
178 WorkItem
* WorkItemList::AddSetRegValueWorkItem(HKEY predefined_root
,
179 const std::wstring
& key_path
,
181 const std::wstring
& value_name
,
184 WorkItem
* item
= WorkItem::CreateSetRegValueWorkItem(predefined_root
,
194 WorkItem
* WorkItemList::AddSetRegValueWorkItem(HKEY predefined_root
,
195 const std::wstring
& key_path
,
197 const std::wstring
& value_name
,
200 WorkItem
* item
= reinterpret_cast<WorkItem
*>(
201 WorkItem::CreateSetRegValueWorkItem(predefined_root
,
211 WorkItem
* WorkItemList::AddSelfRegWorkItem(const std::wstring
& dll_path
,
213 bool user_level_registration
) {
214 WorkItem
* item
= WorkItem::CreateSelfRegWorkItem(dll_path
, do_register
,
215 user_level_registration
);
220 ////////////////////////////////////////////////////////////////////////////////
221 NoRollbackWorkItemList::~NoRollbackWorkItemList() {
224 bool NoRollbackWorkItemList::Do() {
225 if (status_
!= ADD_ITEM
)
229 while (!list_
.empty()) {
230 WorkItem
* work_item
= list_
.front();
232 executed_list_
.push_front(work_item
);
233 work_item
->set_ignore_failure(true);
234 if (!work_item
->Do()) {
235 LOG(ERROR
) << "NoRollbackWorkItemList: item execution failed "
236 << work_item
->log_message();
242 VLOG(1) << "NoRollbackWorkItemList: list execution succeeded";
244 status_
= LIST_EXECUTED
;
248 void NoRollbackWorkItemList::Rollback() {