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 #ifndef CHROME_INSTALLER_UTIL_WORK_ITEM_LIST_H_
6 #define CHROME_INSTALLER_UTIL_WORK_ITEM_LIST_H_
14 #include "base/callback_forward.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "chrome/installer/util/work_item.h"
22 // A WorkItem subclass that recursively contains a list of WorkItems. Thus it
23 // provides functionalities to carry out or roll back the sequence of actions
24 // defined by the list of WorkItems it contains.
25 // The WorkItems are executed in the same order as they are added to the list.
26 class WorkItemList
: public WorkItem
{
28 virtual ~WorkItemList();
30 // Execute the WorkItems in the same order as they are added to the list.
31 // It aborts as soon as one WorkItem fails.
34 // Rollback the WorkItems in the reverse order as they are executed.
35 virtual void Rollback();
37 // Add a WorkItem to the list.
38 // A WorkItem can only be added to the list before the list's DO() is called.
39 // Once a WorkItem is added to the list. The list owns the WorkItem.
40 virtual void AddWorkItem(WorkItem
* work_item
);
42 // Add a CallbackWorkItem that invokes a callback.
43 virtual WorkItem
* AddCallbackWorkItem(
44 base::Callback
<bool(const CallbackWorkItem
&)> callback
);
46 // Add a CopyRegKeyWorkItem that recursively copies a given registry key.
47 virtual WorkItem
* AddCopyRegKeyWorkItem(HKEY predefined_root
,
48 const std::wstring
& source_key_path
,
49 const std::wstring
& dest_key_path
,
50 CopyOverWriteOption overwrite_option
);
52 // Add a CopyTreeWorkItem to the list of work items.
53 // See the NOTE in the documentation for the CopyTreeWorkItem class for
54 // special considerations regarding |temp_dir|.
55 virtual WorkItem
* AddCopyTreeWorkItem(
56 const std::wstring
& source_path
,
57 const std::wstring
& dest_path
,
58 const std::wstring
& temp_dir
,
59 CopyOverWriteOption overwrite_option
,
60 const std::wstring
& alternative_path
= L
"");
62 // Add a CreateDirWorkItem that creates a directory at the given path.
63 virtual WorkItem
* AddCreateDirWorkItem(const base::FilePath
& path
);
65 // Add a CreateRegKeyWorkItem that creates a registry key at the given
67 virtual WorkItem
* AddCreateRegKeyWorkItem(HKEY predefined_root
,
68 const std::wstring
& path
);
70 // Add a DeleteRegKeyWorkItem that deletes a registry key from the given
72 virtual WorkItem
* AddDeleteRegKeyWorkItem(HKEY predefined_root
,
73 const std::wstring
& path
);
75 // Add a DeleteRegValueWorkItem that deletes registry value of type REG_SZ
77 virtual WorkItem
* AddDeleteRegValueWorkItem(HKEY predefined_root
,
78 const std::wstring
& key_path
,
79 const std::wstring
& value_name
);
81 // Add a DeleteTreeWorkItem that recursively deletes a file system
82 // hierarchy at the given root path. A key file can be optionally specified
84 virtual WorkItem
* AddDeleteTreeWorkItem(
85 const base::FilePath
& root_path
,
86 const base::FilePath
& temp_path
,
87 const std::vector
<base::FilePath
>& key_paths
);
89 // Same as above but without support for key files.
90 virtual WorkItem
* AddDeleteTreeWorkItem(const base::FilePath
& root_path
,
91 const base::FilePath
& temp_path
);
93 // Add a MoveTreeWorkItem to the list of work items.
94 virtual WorkItem
* AddMoveTreeWorkItem(const std::wstring
& source_path
,
95 const std::wstring
& dest_path
,
96 const std::wstring
& temp_dir
,
97 MoveTreeOption duplicate_option
);
99 // Add a SetRegValueWorkItem that sets a registry value with REG_SZ type
100 // at the key with specified path.
101 virtual WorkItem
* AddSetRegValueWorkItem(HKEY predefined_root
,
102 const std::wstring
& key_path
,
103 const std::wstring
& value_name
,
104 const std::wstring
& value_data
,
107 // Add a SetRegValueWorkItem that sets a registry value with REG_DWORD type
108 // at the key with specified path.
109 virtual WorkItem
* AddSetRegValueWorkItem(HKEY predefined_root
,
110 const std::wstring
& key_path
,
111 const std::wstring
& value_name
,
115 // Add a SetRegValueWorkItem that sets a registry value with REG_QWORD type
116 // at the key with specified path.
117 virtual WorkItem
* AddSetRegValueWorkItem(HKEY predefined_root
,
118 const std::wstring
& key_path
,
119 const std::wstring
& value_name
,
123 // Add a SelfRegWorkItem that registers or unregisters a DLL at the
124 // specified path. If user_level_registration is true, then alternate
125 // registration and unregistration entry point names will be used.
126 virtual WorkItem
* AddSelfRegWorkItem(const std::wstring
& dll_path
,
128 bool user_level_registration
);
131 friend class WorkItem
;
133 typedef std::list
<WorkItem
*> WorkItems
;
134 typedef WorkItems::iterator WorkItemIterator
;
137 // List has not been executed. Ok to add new WorkItem.
139 // List has been executed. Can not add new WorkItem.
141 // List has been executed and rolled back. No further action is acceptable.
149 // The list of WorkItems, in the order of them being added.
152 // The list of executed WorkItems, in the reverse order of them being
154 WorkItems executed_list_
;
157 // A specialization of WorkItemList that executes items in the list on a
158 // best-effort basis. Failure of individual items to execute does not prevent
159 // subsequent items from being executed.
160 // Also, as the class name suggests, Rollback is not possible.
161 class NoRollbackWorkItemList
: public WorkItemList
{
163 virtual ~NoRollbackWorkItemList();
165 // Execute the WorkItems in the same order as they are added to the list.
166 // If a WorkItem fails, the function will return failure but all other
167 // WorkItems will still be executed.
171 virtual void Rollback();
174 #endif // CHROME_INSTALLER_UTIL_WORK_ITEM_LIST_H_