OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/installer/util/installation_state.h" | 5 #include "chrome/installer/util/installation_state.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/version.h" | 10 #include "base/version.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 BrowserDistribution::Type type) { | 29 BrowserDistribution::Type type) { |
30 return Initialize(system_install, | 30 return Initialize(system_install, |
31 BrowserDistribution::GetSpecificDistribution(type)); | 31 BrowserDistribution::GetSpecificDistribution(type)); |
32 } | 32 } |
33 | 33 |
34 // Initializes |commands| from the "Commands" subkey of |version_key|. | 34 // Initializes |commands| from the "Commands" subkey of |version_key|. |
35 // Returns false if there is no "Commands" subkey or on error. | 35 // Returns false if there is no "Commands" subkey or on error. |
36 // static | 36 // static |
37 bool ProductState::InitializeCommands(const base::win::RegKey& version_key, | 37 bool ProductState::InitializeCommands(const base::win::RegKey& version_key, |
38 AppCommands* commands) { | 38 AppCommands* commands) { |
39 static const DWORD kAccess = | 39 static const DWORD kAccess = KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE; |
40 KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE | KEY_WOW64_32KEY; | |
41 base::win::RegKey commands_key; | 40 base::win::RegKey commands_key; |
42 | 41 |
43 if (commands_key.Open(version_key.Handle(), google_update::kRegCommandsKey, | 42 if (commands_key.Open(version_key.Handle(), google_update::kRegCommandsKey, |
44 kAccess) == ERROR_SUCCESS) | 43 kAccess) == ERROR_SUCCESS) |
45 return commands->Initialize(commands_key); | 44 return commands->Initialize(commands_key); |
46 return false; | 45 return false; |
47 } | 46 } |
48 | 47 |
49 bool ProductState::Initialize(bool system_install, | 48 bool ProductState::Initialize(bool system_install, |
50 BrowserDistribution* distribution) { | 49 BrowserDistribution* distribution) { |
51 static const DWORD kAccess = KEY_QUERY_VALUE | KEY_WOW64_32KEY; | |
52 const std::wstring version_key(distribution->GetVersionKey()); | 50 const std::wstring version_key(distribution->GetVersionKey()); |
53 const std::wstring state_key(distribution->GetStateKey()); | 51 const std::wstring state_key(distribution->GetStateKey()); |
54 const HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 52 const HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
55 base::win::RegKey key; | 53 base::win::RegKey key; |
56 | 54 |
57 // Clear the runway. | 55 // Clear the runway. |
58 Clear(); | 56 Clear(); |
59 | 57 |
60 // Read from the Clients key. | 58 // Read from the Clients key. |
61 if (key.Open(root_key, version_key.c_str(), kAccess) == ERROR_SUCCESS) { | 59 if (key.Open(root_key, version_key.c_str(), |
| 60 KEY_QUERY_VALUE) == ERROR_SUCCESS) { |
62 base::string16 version_str; | 61 base::string16 version_str; |
63 if (key.ReadValue(google_update::kRegVersionField, | 62 if (key.ReadValue(google_update::kRegVersionField, |
64 &version_str) == ERROR_SUCCESS) { | 63 &version_str) == ERROR_SUCCESS) { |
65 version_.reset(new Version(base::UTF16ToASCII(version_str))); | 64 version_.reset(new Version(base::UTF16ToASCII(version_str))); |
66 if (!version_->IsValid()) | 65 if (!version_->IsValid()) |
67 version_.reset(); | 66 version_.reset(); |
68 } | 67 } |
69 | 68 |
70 // Attempt to read the other values even if the "pv" version value was | 69 // Attempt to read the other values even if the "pv" version value was |
71 // absent. Note that ProductState instances containing these values will | 70 // absent. Note that ProductState instances containing these values will |
72 // only be accessible via InstallationState::GetNonVersionedProductState. | 71 // only be accessible via InstallationState::GetNonVersionedProductState. |
73 if (key.ReadValue(google_update::kRegOldVersionField, | 72 if (key.ReadValue(google_update::kRegOldVersionField, |
74 &version_str) == ERROR_SUCCESS) { | 73 &version_str) == ERROR_SUCCESS) { |
75 old_version_.reset(new Version(base::UTF16ToASCII(version_str))); | 74 old_version_.reset(new Version(base::UTF16ToASCII(version_str))); |
76 if (!old_version_->IsValid()) | 75 if (!old_version_->IsValid()) |
77 old_version_.reset(); | 76 old_version_.reset(); |
78 } | 77 } |
79 | 78 |
80 key.ReadValue(google_update::kRegRenameCmdField, &rename_cmd_); | 79 key.ReadValue(google_update::kRegRenameCmdField, &rename_cmd_); |
81 if (!InitializeCommands(key, &commands_)) | 80 if (!InitializeCommands(key, &commands_)) |
82 commands_.Clear(); | 81 commands_.Clear(); |
83 } | 82 } |
84 | 83 |
85 // Read from the ClientState key. | 84 // Read from the ClientState key. |
86 if (key.Open(root_key, state_key.c_str(), kAccess) == ERROR_SUCCESS) { | 85 if (key.Open(root_key, state_key.c_str(), |
| 86 KEY_QUERY_VALUE) == ERROR_SUCCESS) { |
87 std::wstring setup_path; | 87 std::wstring setup_path; |
88 std::wstring uninstall_arguments; | 88 std::wstring uninstall_arguments; |
89 // "ap" will be absent if not managed by Google Update. | 89 // "ap" will be absent if not managed by Google Update. |
90 channel_.Initialize(key); | 90 channel_.Initialize(key); |
91 | 91 |
92 // Read in the brand code, it may be absent | 92 // Read in the brand code, it may be absent |
93 key.ReadValue(google_update::kRegBrandField, &brand_); | 93 key.ReadValue(google_update::kRegBrandField, &brand_); |
94 | 94 |
95 // "UninstallString" will be absent for the multi-installer package. | 95 // "UninstallString" will be absent for the multi-installer package. |
96 key.ReadValue(kUninstallStringField, &setup_path); | 96 key.ReadValue(kUninstallStringField, &setup_path); |
(...skipping 20 matching lines...) Expand all Loading... |
117 // Multi-install is implied or is derived from the command-line. | 117 // Multi-install is implied or is derived from the command-line. |
118 if (distribution->GetType() == BrowserDistribution::CHROME_BINARIES) | 118 if (distribution->GetType() == BrowserDistribution::CHROME_BINARIES) |
119 multi_install_ = true; | 119 multi_install_ = true; |
120 else | 120 else |
121 multi_install_ = uninstall_command_.HasSwitch(switches::kMultiInstall); | 121 multi_install_ = uninstall_command_.HasSwitch(switches::kMultiInstall); |
122 } | 122 } |
123 | 123 |
124 // Read from the ClientStateMedium key. Values here override those in | 124 // Read from the ClientStateMedium key. Values here override those in |
125 // ClientState. | 125 // ClientState. |
126 if (system_install && | 126 if (system_install && |
127 key.Open(root_key, distribution->GetStateMediumKey().c_str(), kAccess) == | 127 key.Open(root_key, distribution->GetStateMediumKey().c_str(), |
128 ERROR_SUCCESS) { | 128 KEY_QUERY_VALUE) == ERROR_SUCCESS) { |
129 DWORD dword_value = 0; | 129 DWORD dword_value = 0; |
130 | 130 |
131 if (key.ReadValueDW(google_update::kRegUsageStatsField, | 131 if (key.ReadValueDW(google_update::kRegUsageStatsField, |
132 &dword_value) == ERROR_SUCCESS) { | 132 &dword_value) == ERROR_SUCCESS) { |
133 has_usagestats_ = true; | 133 has_usagestats_ = true; |
134 usagestats_ = dword_value; | 134 usagestats_ = dword_value; |
135 } | 135 } |
136 | 136 |
137 if (key.ReadValueDW(google_update::kRegEULAAceptedField, | 137 if (key.ReadValueDW(google_update::kRegEULAAceptedField, |
138 &dword_value) == ERROR_SUCCESS) { | 138 &dword_value) == ERROR_SUCCESS) { |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 } | 269 } |
270 | 270 |
271 const ProductState* InstallationState::GetProductState( | 271 const ProductState* InstallationState::GetProductState( |
272 bool system_install, | 272 bool system_install, |
273 BrowserDistribution::Type type) const { | 273 BrowserDistribution::Type type) const { |
274 const ProductState* product_state = | 274 const ProductState* product_state = |
275 GetNonVersionedProductState(system_install, type); | 275 GetNonVersionedProductState(system_install, type); |
276 return product_state->version_.get() == NULL ? NULL : product_state; | 276 return product_state->version_.get() == NULL ? NULL : product_state; |
277 } | 277 } |
278 } // namespace installer | 278 } // namespace installer |
OLD | NEW |