| 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 // Base class for managing an action of a sequence of actions to be carried | 5 // Base class for managing an action of a sequence of actions to be carried |
| 6 // out during install/update/uninstall. Supports rollback of actions if this | 6 // out during install/update/uninstall. Supports rollback of actions if this |
| 7 // process fails. | 7 // process fails. |
| 8 | 8 |
| 9 #ifndef CHROME_INSTALLER_UTIL_WORK_ITEM_H_ | 9 #ifndef CHROME_INSTALLER_UTIL_WORK_ITEM_H_ |
| 10 #define CHROME_INSTALLER_UTIL_WORK_ITEM_H_ | 10 #define CHROME_INSTALLER_UTIL_WORK_ITEM_H_ |
| 11 | 11 |
| 12 #include <windows.h> | 12 #include <windows.h> |
| 13 | 13 |
| 14 #include <string> | 14 #include <string> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
| 18 #include "base/callback_forward.h" | 18 #include "base/callback_forward.h" |
| 19 | 19 |
| 20 class CallbackWorkItem; | 20 class CallbackWorkItem; |
| 21 class CopyRegKeyWorkItem; | |
| 22 class CopyTreeWorkItem; | 21 class CopyTreeWorkItem; |
| 23 class CreateDirWorkItem; | 22 class CreateDirWorkItem; |
| 24 class CreateRegKeyWorkItem; | 23 class CreateRegKeyWorkItem; |
| 25 class DeleteTreeWorkItem; | 24 class DeleteTreeWorkItem; |
| 26 class DeleteRegKeyWorkItem; | 25 class DeleteRegKeyWorkItem; |
| 27 class DeleteRegValueWorkItem; | 26 class DeleteRegValueWorkItem; |
| 28 class MoveTreeWorkItem; | 27 class MoveTreeWorkItem; |
| 29 class SelfRegWorkItem; | 28 class SelfRegWorkItem; |
| 30 class SetRegValueWorkItem; | 29 class SetRegValueWorkItem; |
| 31 class WorkItemList; | 30 class WorkItemList; |
| 32 | 31 |
| 33 namespace base { | 32 namespace base { |
| 34 class FilePath; | 33 class FilePath; |
| 35 } | 34 } |
| 36 | 35 |
| 37 // A base class that defines APIs to perform/rollback an action or a | 36 // A base class that defines APIs to perform/rollback an action or a |
| 38 // sequence of actions during install/update/uninstall. | 37 // sequence of actions during install/update/uninstall. |
| 39 class WorkItem { | 38 class WorkItem { |
| 40 public: | 39 public: |
| 40 // All registry operations can be instructed to operate on a specific view |
| 41 // of the registry by specifying a REGSAM value to the wow64_access parameter. |
| 42 // The wow64_access parameter can be one of: |
| 43 // KEY_WOW64_32KEY - Operate on the 32-bit view. |
| 44 // KEY_WOW64_64KEY - Operate on the 64-bit view. |
| 45 // kWow64Default - Operate on the default view (e.g. 32-bit on 32-bit |
| 46 // systems, and 64-bit on 64-bit systems). |
| 47 // See http://msdn.microsoft.com/en-us/library/windows/desktop/aa384129.aspx |
| 48 static const REGSAM kWow64Default = 0; |
| 41 // Possible states | 49 // Possible states |
| 42 enum CopyOverWriteOption { | 50 enum CopyOverWriteOption { |
| 43 ALWAYS, // Always overwrite regardless of what existed before. | 51 ALWAYS, // Always overwrite regardless of what existed before. |
| 44 NEVER, // Not used currently. | 52 NEVER, // Not used currently. |
| 45 IF_DIFFERENT, // Overwrite if different. Currently only applies to file. | 53 IF_DIFFERENT, // Overwrite if different. Currently only applies to file. |
| 46 IF_NOT_PRESENT, // Copy only if file/directory do not exist already. | 54 IF_NOT_PRESENT, // Copy only if file/directory do not exist already. |
| 47 NEW_NAME_IF_IN_USE // Copy to a new path if dest is in use(only files). | 55 NEW_NAME_IF_IN_USE // Copy to a new path if dest is in use(only files). |
| 48 }; | 56 }; |
| 49 | 57 |
| 50 // Options for the MoveTree work item. | 58 // Options for the MoveTree work item. |
| 51 enum MoveTreeOption { | 59 enum MoveTreeOption { |
| 52 ALWAYS_MOVE, // Always attempt to do a move operation. | 60 ALWAYS_MOVE, // Always attempt to do a move operation. |
| 53 CHECK_DUPLICATES // Only move if the move target is different. | 61 CHECK_DUPLICATES // Only move if the move target is different. |
| 54 }; | 62 }; |
| 55 | 63 |
| 56 // Abstract base class for the conditions used by ConditionWorkItemList. | 64 // Abstract base class for the conditions used by ConditionWorkItemList. |
| 57 // TODO(robertshield): Move this out of WorkItem. | 65 // TODO(robertshield): Move this out of WorkItem. |
| 58 class Condition { | 66 class Condition { |
| 59 public: | 67 public: |
| 60 virtual ~Condition() {} | 68 virtual ~Condition() {} |
| 61 virtual bool ShouldRun() const = 0; | 69 virtual bool ShouldRun() const = 0; |
| 62 }; | 70 }; |
| 63 | 71 |
| 64 virtual ~WorkItem(); | 72 virtual ~WorkItem(); |
| 65 | 73 |
| 66 // Create a CallbackWorkItem that invokes a callback. | 74 // Create a CallbackWorkItem that invokes a callback. |
| 67 static CallbackWorkItem* CreateCallbackWorkItem( | 75 static CallbackWorkItem* CreateCallbackWorkItem( |
| 68 base::Callback<bool(const CallbackWorkItem&)> callback); | 76 base::Callback<bool(const CallbackWorkItem&)> callback); |
| 69 | 77 |
| 70 // Create a CopyRegKeyWorkItem that recursively copies a given registry key. | |
| 71 static CopyRegKeyWorkItem* CreateCopyRegKeyWorkItem( | |
| 72 HKEY predefined_root, | |
| 73 const std::wstring& source_key_path, | |
| 74 const std::wstring& dest_key_path, | |
| 75 CopyOverWriteOption overwrite_option); | |
| 76 | |
| 77 // Create a CopyTreeWorkItem that recursively copies a file system hierarchy | 78 // Create a CopyTreeWorkItem that recursively copies a file system hierarchy |
| 78 // from source path to destination path. | 79 // from source path to destination path. |
| 79 // * If overwrite_option is ALWAYS, the created CopyTreeWorkItem always | 80 // * If overwrite_option is ALWAYS, the created CopyTreeWorkItem always |
| 80 // overwrites files. | 81 // overwrites files. |
| 81 // * If overwrite_option is NEW_NAME_IF_IN_USE, file is copied with an | 82 // * If overwrite_option is NEW_NAME_IF_IN_USE, file is copied with an |
| 82 // alternate name specified by alternative_path. | 83 // alternate name specified by alternative_path. |
| 83 static CopyTreeWorkItem* CreateCopyTreeWorkItem( | 84 static CopyTreeWorkItem* CreateCopyTreeWorkItem( |
| 84 const base::FilePath& source_path, | 85 const base::FilePath& source_path, |
| 85 const base::FilePath& dest_path, | 86 const base::FilePath& dest_path, |
| 86 const base::FilePath& temp_dir, | 87 const base::FilePath& temp_dir, |
| 87 CopyOverWriteOption overwrite_option, | 88 CopyOverWriteOption overwrite_option, |
| 88 const base::FilePath& alternative_path); | 89 const base::FilePath& alternative_path); |
| 89 | 90 |
| 90 // Create a CreateDirWorkItem that creates a directory at the given path. | 91 // Create a CreateDirWorkItem that creates a directory at the given path. |
| 91 static CreateDirWorkItem* CreateCreateDirWorkItem(const base::FilePath& path); | 92 static CreateDirWorkItem* CreateCreateDirWorkItem(const base::FilePath& path); |
| 92 | 93 |
| 93 // Create a CreateRegKeyWorkItem that creates a registry key at the given | 94 // Create a CreateRegKeyWorkItem that creates a registry key at the given |
| 94 // path. | 95 // path. |
| 95 static CreateRegKeyWorkItem* CreateCreateRegKeyWorkItem( | 96 static CreateRegKeyWorkItem* CreateCreateRegKeyWorkItem( |
| 96 HKEY predefined_root, const std::wstring& path); | 97 HKEY predefined_root, |
| 98 const std::wstring& path, |
| 99 REGSAM wow64_access); |
| 97 | 100 |
| 98 // Create a DeleteRegKeyWorkItem that deletes a registry key at the given | 101 // Create a DeleteRegKeyWorkItem that deletes a registry key at the given |
| 99 // path. | 102 // path. |
| 100 static DeleteRegKeyWorkItem* CreateDeleteRegKeyWorkItem( | 103 static DeleteRegKeyWorkItem* CreateDeleteRegKeyWorkItem( |
| 101 HKEY predefined_root, const std::wstring& path); | 104 HKEY predefined_root, |
| 105 const std::wstring& path, |
| 106 REGSAM wow64_access); |
| 102 | 107 |
| 103 // Create a DeleteRegValueWorkItem that deletes a registry value | 108 // Create a DeleteRegValueWorkItem that deletes a registry value |
| 104 static DeleteRegValueWorkItem* CreateDeleteRegValueWorkItem( | 109 static DeleteRegValueWorkItem* CreateDeleteRegValueWorkItem( |
| 105 HKEY predefined_root, | 110 HKEY predefined_root, |
| 106 const std::wstring& key_path, | 111 const std::wstring& key_path, |
| 112 REGSAM wow64_access, |
| 107 const std::wstring& value_name); | 113 const std::wstring& value_name); |
| 108 | 114 |
| 109 // Create a DeleteTreeWorkItem that recursively deletes a file system | 115 // Create a DeleteTreeWorkItem that recursively deletes a file system |
| 110 // hierarchy at the given root path. A key file can be optionally specified | 116 // hierarchy at the given root path. A key file can be optionally specified |
| 111 // by key_path. | 117 // by key_path. |
| 112 static DeleteTreeWorkItem* CreateDeleteTreeWorkItem( | 118 static DeleteTreeWorkItem* CreateDeleteTreeWorkItem( |
| 113 const base::FilePath& root_path, | 119 const base::FilePath& root_path, |
| 114 const base::FilePath& temp_path, | 120 const base::FilePath& temp_path, |
| 115 const std::vector<base::FilePath>& key_paths); | 121 const std::vector<base::FilePath>& key_paths); |
| 116 | 122 |
| 117 // Create a MoveTreeWorkItem that recursively moves a file system hierarchy | 123 // Create a MoveTreeWorkItem that recursively moves a file system hierarchy |
| 118 // from source path to destination path. | 124 // from source path to destination path. |
| 119 static MoveTreeWorkItem* CreateMoveTreeWorkItem( | 125 static MoveTreeWorkItem* CreateMoveTreeWorkItem( |
| 120 const base::FilePath& source_path, | 126 const base::FilePath& source_path, |
| 121 const base::FilePath& dest_path, | 127 const base::FilePath& dest_path, |
| 122 const base::FilePath& temp_dir, | 128 const base::FilePath& temp_dir, |
| 123 MoveTreeOption duplicate_option); | 129 MoveTreeOption duplicate_option); |
| 124 | 130 |
| 125 // Create a SetRegValueWorkItem that sets a registry value with REG_SZ type | 131 // Create a SetRegValueWorkItem that sets a registry value with REG_SZ type |
| 126 // at the key with specified path. | 132 // at the key with specified path. |
| 127 static SetRegValueWorkItem* CreateSetRegValueWorkItem( | 133 static SetRegValueWorkItem* CreateSetRegValueWorkItem( |
| 128 HKEY predefined_root, | 134 HKEY predefined_root, |
| 129 const std::wstring& key_path, | 135 const std::wstring& key_path, |
| 136 REGSAM wow64_access, |
| 130 const std::wstring& value_name, | 137 const std::wstring& value_name, |
| 131 const std::wstring& value_data, | 138 const std::wstring& value_data, |
| 132 bool overwrite); | 139 bool overwrite); |
| 133 | 140 |
| 134 // Create a SetRegValueWorkItem that sets a registry value with REG_DWORD type | 141 // Create a SetRegValueWorkItem that sets a registry value with REG_DWORD type |
| 135 // at the key with specified path. | 142 // at the key with specified path. |
| 136 static SetRegValueWorkItem* CreateSetRegValueWorkItem( | 143 static SetRegValueWorkItem* CreateSetRegValueWorkItem( |
| 137 HKEY predefined_root, | 144 HKEY predefined_root, |
| 138 const std::wstring& key_path, | 145 const std::wstring& key_path, |
| 146 REGSAM wow64_access, |
| 139 const std::wstring& value_name, | 147 const std::wstring& value_name, |
| 140 DWORD value_data, bool overwrite); | 148 DWORD value_data, |
| 149 bool overwrite); |
| 141 | 150 |
| 142 // Create a SetRegValueWorkItem that sets a registry value with REG_QWORD type | 151 // Create a SetRegValueWorkItem that sets a registry value with REG_QWORD type |
| 143 // at the key with specified path. | 152 // at the key with specified path. |
| 144 static SetRegValueWorkItem* CreateSetRegValueWorkItem( | 153 static SetRegValueWorkItem* CreateSetRegValueWorkItem( |
| 145 HKEY predefined_root, | 154 HKEY predefined_root, |
| 146 const std::wstring& key_path, | 155 const std::wstring& key_path, |
| 156 REGSAM wow64_access, |
| 147 const std::wstring& value_name, | 157 const std::wstring& value_name, |
| 148 int64 value_data, bool overwrite); | 158 int64 value_data, |
| 159 bool overwrite); |
| 149 | 160 |
| 150 // Add a SelfRegWorkItem that registers or unregisters a DLL at the | 161 // Add a SelfRegWorkItem that registers or unregisters a DLL at the |
| 151 // specified path. | 162 // specified path. |
| 152 static SelfRegWorkItem* CreateSelfRegWorkItem(const std::wstring& dll_path, | 163 static SelfRegWorkItem* CreateSelfRegWorkItem(const std::wstring& dll_path, |
| 153 bool do_register, | 164 bool do_register, |
| 154 bool user_level_registration); | 165 bool user_level_registration); |
| 155 | 166 |
| 156 // Create an empty WorkItemList. A WorkItemList can recursively contains | 167 // Create an empty WorkItemList. A WorkItemList can recursively contains |
| 157 // a list of WorkItems. | 168 // a list of WorkItems. |
| 158 static WorkItemList* CreateWorkItemList(); | 169 static WorkItemList* CreateWorkItemList(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 WorkItem(); | 214 WorkItem(); |
| 204 | 215 |
| 205 // Specifies whether this work item my fail to complete and yet still | 216 // Specifies whether this work item my fail to complete and yet still |
| 206 // return true from Do(). | 217 // return true from Do(). |
| 207 bool ignore_failure_; | 218 bool ignore_failure_; |
| 208 | 219 |
| 209 std::string log_message_; | 220 std::string log_message_; |
| 210 }; | 221 }; |
| 211 | 222 |
| 212 #endif // CHROME_INSTALLER_UTIL_WORK_ITEM_H_ | 223 #endif // CHROME_INSTALLER_UTIL_WORK_ITEM_H_ |
| OLD | NEW |