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 CopyTreeWorkItem to the list of work items.
47 // See the NOTE in the documentation for the CopyTreeWorkItem class for
48 // special considerations regarding |temp_dir|.
49 virtual WorkItem
* AddCopyTreeWorkItem(
50 const std::wstring
& source_path
,
51 const std::wstring
& dest_path
,
52 const std::wstring
& temp_dir
,
53 CopyOverWriteOption overwrite_option
,
54 const std::wstring
& alternative_path
= L
"");
56 // Add a CreateDirWorkItem that creates a directory at the given path.
57 virtual WorkItem
* AddCreateDirWorkItem(const base::FilePath
& path
);
59 // Add a CreateRegKeyWorkItem that creates a registry key at the given
61 virtual WorkItem
* AddCreateRegKeyWorkItem(HKEY predefined_root
,
62 const std::wstring
& path
,
65 // Add a DeleteRegKeyWorkItem that deletes a registry key from the given
67 virtual WorkItem
* AddDeleteRegKeyWorkItem(HKEY predefined_root
,
68 const std::wstring
& path
,
71 // Add a DeleteRegValueWorkItem that deletes registry value of type REG_SZ
73 virtual WorkItem
* AddDeleteRegValueWorkItem(HKEY predefined_root
,
74 const std::wstring
& key_path
,
76 const std::wstring
& value_name
);
78 // Add a DeleteTreeWorkItem that recursively deletes a file system
79 // hierarchy at the given root path. A key file can be optionally specified
81 virtual WorkItem
* AddDeleteTreeWorkItem(
82 const base::FilePath
& root_path
,
83 const base::FilePath
& temp_path
,
84 const std::vector
<base::FilePath
>& key_paths
);
86 // Same as above but without support for key files.
87 virtual WorkItem
* AddDeleteTreeWorkItem(const base::FilePath
& root_path
,
88 const base::FilePath
& temp_path
);
90 // Add a MoveTreeWorkItem to the list of work items.
91 virtual WorkItem
* AddMoveTreeWorkItem(const std::wstring
& source_path
,
92 const std::wstring
& dest_path
,
93 const std::wstring
& temp_dir
,
94 MoveTreeOption duplicate_option
);
96 // Add a SetRegValueWorkItem that sets a registry value with REG_SZ type
97 // at the key with specified path.
98 virtual WorkItem
* AddSetRegValueWorkItem(HKEY predefined_root
,
99 const std::wstring
& key_path
,
101 const std::wstring
& value_name
,
102 const std::wstring
& value_data
,
105 // Add a SetRegValueWorkItem that sets a registry value with REG_DWORD type
106 // at the key with specified path.
107 virtual WorkItem
* AddSetRegValueWorkItem(HKEY predefined_root
,
108 const std::wstring
& key_path
,
110 const std::wstring
& value_name
,
114 // Add a SetRegValueWorkItem that sets a registry value with REG_QWORD type
115 // at the key with specified path.
116 virtual WorkItem
* AddSetRegValueWorkItem(HKEY predefined_root
,
117 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_