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 #ifndef CHROME_INSTALLER_UTIL_SET_REG_VALUE_WORK_ITEM_H__ | 5 #ifndef CHROME_INSTALLER_UTIL_SET_REG_VALUE_WORK_ITEM_H__ |
6 #define CHROME_INSTALLER_UTIL_SET_REG_VALUE_WORK_ITEM_H__ | 6 #define CHROME_INSTALLER_UTIL_SET_REG_VALUE_WORK_ITEM_H__ |
7 | 7 |
8 #include <windows.h> | 8 #include <windows.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "chrome/installer/util/work_item.h" | 14 #include "chrome/installer/util/work_item.h" |
15 | 15 |
16 // A WorkItem subclass that sets a registry value with REG_SZ, REG_DWORD, or | 16 // A WorkItem subclass that sets a registry value with REG_SZ, REG_DWORD, or |
17 // REG_QWORD type at the specified path. The value is only set if the target key | 17 // REG_QWORD type at the specified path. The value is only set if the target key |
18 // exists. | 18 // exists. |
19 class SetRegValueWorkItem : public WorkItem { | 19 class SetRegValueWorkItem : public WorkItem { |
20 public: | 20 public: |
21 ~SetRegValueWorkItem() override; | 21 ~SetRegValueWorkItem() override; |
22 | 22 |
23 bool Do() override; | 23 bool Do() override; |
24 | 24 |
25 void Rollback() override; | 25 void Rollback() override; |
26 | 26 |
27 private: | 27 protected: |
28 friend class WorkItem; | |
29 | |
30 enum SettingStatus { | |
31 // The status before Do is called. | |
32 SET_VALUE, | |
33 // One possible outcome after Do(). A new value is created under the key. | |
34 NEW_VALUE_CREATED, | |
35 // One possible outcome after Do(). The previous value under the key has | |
36 // been overwritten. | |
37 VALUE_OVERWRITTEN, | |
38 // One possible outcome after Do(). No change is applied, either | |
39 // because we are not allowed to overwrite the previous value, or due to | |
40 // some errors like the key does not exist. | |
41 VALUE_UNCHANGED, | |
42 // The status after Do and Rollback is called. | |
43 VALUE_ROLL_BACK | |
44 }; | |
45 | |
46 SetRegValueWorkItem(HKEY predefined_root, | 28 SetRegValueWorkItem(HKEY predefined_root, |
47 const std::wstring& key_path, | 29 const std::wstring& key_path, |
48 REGSAM wow64_access, | 30 REGSAM wow64_access, |
49 const std::wstring& value_name, | 31 const std::wstring& value_name, |
50 const std::wstring& value_data, | 32 const std::wstring& value_data, |
51 bool overwrite); | 33 bool overwrite); |
52 | 34 |
53 SetRegValueWorkItem(HKEY predefined_root, | 35 SetRegValueWorkItem(HKEY predefined_root, |
54 const std::wstring& key_path, | 36 const std::wstring& key_path, |
55 REGSAM wow64_access, | 37 REGSAM wow64_access, |
56 const std::wstring& value_name, | 38 const std::wstring& value_name, |
57 DWORD value_data, | 39 DWORD value_data, |
58 bool overwrite); | 40 bool overwrite); |
59 | 41 |
60 SetRegValueWorkItem(HKEY predefined_root, | 42 SetRegValueWorkItem(HKEY predefined_root, |
61 const std::wstring& key_path, | 43 const std::wstring& key_path, |
62 REGSAM wow64_access, | 44 REGSAM wow64_access, |
63 const std::wstring& value_name, | 45 const std::wstring& value_name, |
64 int64 value_data, | 46 int64 value_data, |
65 bool overwrite); | 47 bool overwrite); |
66 | 48 |
67 // Implies |overwrite_| and TYPE_SZ for now. | 49 // Implies |overwrite_| and TYPE_SZ for now. |
68 SetRegValueWorkItem(HKEY predefined_root, | 50 SetRegValueWorkItem(HKEY predefined_root, |
69 const std::wstring& key_path, | 51 const std::wstring& key_path, |
70 REGSAM wow64_access, | 52 REGSAM wow64_access, |
71 const std::wstring& value_name, | 53 const std::wstring& value_name, |
72 const GetValueFromExistingCallback& get_value_callback); | 54 const GetValueFromExistingCallback& get_value_callback); |
73 | 55 |
| 56 private: |
| 57 friend class WorkItem; |
| 58 |
| 59 enum SettingStatus { |
| 60 // The status before Do is called. |
| 61 SET_VALUE, |
| 62 // One possible outcome after Do(). A new value is created under the key. |
| 63 NEW_VALUE_CREATED, |
| 64 // One possible outcome after Do(). The previous value under the key has |
| 65 // been overwritten. |
| 66 VALUE_OVERWRITTEN, |
| 67 // One possible outcome after Do(). No change is applied, either |
| 68 // because we are not allowed to overwrite the previous value, or due to |
| 69 // some errors like the key does not exist. |
| 70 VALUE_UNCHANGED, |
| 71 // The status after Do and Rollback is called. |
| 72 VALUE_ROLL_BACK |
| 73 }; |
| 74 |
74 // Root key of the target key under which the value is set. The root key can | 75 // Root key of the target key under which the value is set. The root key can |
75 // only be one of the predefined keys on Windows. | 76 // only be one of the predefined keys on Windows. |
76 HKEY predefined_root_; | 77 HKEY predefined_root_; |
77 | 78 |
78 // Path of the target key under which the value is set. | 79 // Path of the target key under which the value is set. |
79 std::wstring key_path_; | 80 std::wstring key_path_; |
80 | 81 |
81 // Name of the value to be set. | 82 // Name of the value to be set. |
82 std::wstring value_name_; | 83 std::wstring value_name_; |
83 | 84 |
(...skipping 10 matching lines...) Expand all Loading... |
94 // Type of data to store | 95 // Type of data to store |
95 DWORD type_; | 96 DWORD type_; |
96 std::vector<uint8> value_; | 97 std::vector<uint8> value_; |
97 DWORD previous_type_; | 98 DWORD previous_type_; |
98 std::vector<uint8> previous_value_; | 99 std::vector<uint8> previous_value_; |
99 | 100 |
100 SettingStatus status_; | 101 SettingStatus status_; |
101 }; | 102 }; |
102 | 103 |
103 #endif // CHROME_INSTALLER_UTIL_SET_REG_VALUE_WORK_ITEM_H__ | 104 #endif // CHROME_INSTALLER_UTIL_SET_REG_VALUE_WORK_ITEM_H__ |
OLD | NEW |