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 #include "chrome_frame/ready_mode/internal/registry_ready_mode_state.h" | 5 #include "chrome_frame/ready_mode/internal/registry_ready_mode_state.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
(...skipping 16 matching lines...) Expand all Loading... | |
27 // Returns the new process handle, which the caller is responsible for closing, | 27 // Returns the new process handle, which the caller is responsible for closing, |
28 // or NULL upon failure. | 28 // or NULL upon failure. |
29 HANDLE LaunchCommandDirectly(const std::wstring& command_field) { | 29 HANDLE LaunchCommandDirectly(const std::wstring& command_field) { |
30 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 30 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
31 std::wstring version_key_name(dist->GetVersionKey()); | 31 std::wstring version_key_name(dist->GetVersionKey()); |
32 | 32 |
33 HKEY roots[] = {HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE}; | 33 HKEY roots[] = {HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE}; |
34 | 34 |
35 for (int i = 0; i < arraysize(roots); i++) { | 35 for (int i = 0; i < arraysize(roots); i++) { |
36 base::win::RegKey version_key; | 36 base::win::RegKey version_key; |
37 if (version_key.Open(roots[i], version_key_name.c_str(), KEY_QUERY_VALUE)) { | 37 if (version_key.Open(roots[i], version_key_name.c_str(), |
38 KEY_QUERY_VALUE) == ERROR_SUCCESS) { | |
38 std::wstring command_line; | 39 std::wstring command_line; |
39 if (version_key.ReadValue(command_field.c_str(), &command_line)) { | 40 if (version_key.ReadValue(command_field.c_str(), |
41 &command_line) == ERROR_SUCCESS) { | |
40 HANDLE launched_process = NULL; | 42 HANDLE launched_process = NULL; |
41 if (base::LaunchApp(command_line, false, true, &launched_process)) { | 43 if (base::LaunchApp(command_line, false, true, &launched_process)) { |
42 return launched_process; | 44 return launched_process; |
43 } | 45 } |
44 } | 46 } |
45 } | 47 } |
46 } | 48 } |
47 return NULL; | 49 return NULL; |
48 } | 50 } |
49 | 51 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 | 181 |
180 void RegistryReadyModeState::NotifyObserver() { | 182 void RegistryReadyModeState::NotifyObserver() { |
181 if (observer_ != NULL) | 183 if (observer_ != NULL) |
182 observer_->OnStateChange(GetStatus()); | 184 observer_->OnStateChange(GetStatus()); |
183 } | 185 } |
184 | 186 |
185 bool RegistryReadyModeState::GetValue(int64* value, bool* exists) { | 187 bool RegistryReadyModeState::GetValue(int64* value, bool* exists) { |
186 *exists = false; | 188 *exists = false; |
187 *value = 0; | 189 *value = 0; |
188 | 190 |
189 HKEY roots[] = {HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE}; | 191 HKEY roots[] = { HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE }; |
190 | 192 LONG result = ERROR_SUCCESS; |
191 for (int i = 0; i < arraysize(roots); i++) { | 193 for (int i = 0; i < arraysize(roots); i++) { |
192 base::win::RegKey config_key; | 194 base::win::RegKey config_key; |
193 | 195 result = config_key.Open(HKEY_CURRENT_USER, key_name_.c_str(), |
grt (UTC plus 2)
2011/01/14 15:53:43
HKEY_CURRENT_USER -> roots[i] as brettw pointed ou
amit
2011/01/15 01:28:11
Done.
| |
194 if (config_key.Open(roots[i], key_name_.c_str(), KEY_QUERY_VALUE)) { | 196 KEY_QUERY_VALUE); |
195 if (config_key.ValueExists(installer::kChromeFrameReadyModeField)) { | 197 if (result == ERROR_SUCCESS) { |
196 int64 temp; | 198 result = config_key.ReadInt64(installer::kChromeFrameReadyModeField, |
197 DWORD value_size = sizeof(temp); | 199 value); |
198 DWORD type = 0; | 200 if (result == ERROR_SUCCESS) { |
199 if (!config_key.ReadValue(installer::kChromeFrameReadyModeField, | |
200 &temp, &value_size, &type)) { | |
201 DLOG(ERROR) << "Failed to read from registry key " << key_name_ | |
202 << " and value " << installer::kChromeFrameReadyModeField; | |
203 return false; | |
204 } | |
205 | |
206 if (value_size != sizeof(temp) || type != REG_QWORD) { | |
207 DLOG(ERROR) << "Unexpected state found under registry key " | |
208 << key_name_ << " and value " | |
209 << installer::kChromeFrameReadyModeField; | |
210 return false; | |
211 } | |
212 | |
213 *value = temp; | |
214 *exists = true; | 201 *exists = true; |
215 return true; | 202 return true; |
216 } | 203 } |
204 if (result != ERROR_FILE_NOT_FOUND) { | |
205 DLOG(ERROR) << "Failed to read from registry key " << key_name_ | |
206 << " and value " << installer::kChromeFrameReadyModeField | |
207 << " error: " << result; | |
208 return false; | |
209 } | |
217 } | 210 } |
218 } | 211 } |
219 | 212 |
220 return true; | 213 return true; |
221 } | 214 } |
222 | 215 |
223 void RegistryReadyModeState::RefreshStateAndNotify() { | 216 void RegistryReadyModeState::RefreshStateAndNotify() { |
224 HRESULT hr = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT_REFRESH, | 217 HRESULT hr = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT_REFRESH, |
225 NULL, 0, 0); | 218 NULL, 0, 0); |
226 if (FAILED(hr)) { | 219 if (FAILED(hr)) { |
(...skipping 17 matching lines...) Expand all Loading... | |
244 | 237 |
245 void RegistryReadyModeState::PermanentlyDeclineChromeFrame() { | 238 void RegistryReadyModeState::PermanentlyDeclineChromeFrame() { |
246 if (LaunchAndCheckCommand(google_update::kRegCFOptOutCmdField)) | 239 if (LaunchAndCheckCommand(google_update::kRegCFOptOutCmdField)) |
247 RefreshStateAndNotify(); | 240 RefreshStateAndNotify(); |
248 } | 241 } |
249 | 242 |
250 void RegistryReadyModeState::AcceptChromeFrame() { | 243 void RegistryReadyModeState::AcceptChromeFrame() { |
251 if (LaunchAndCheckCommand(google_update::kRegCFOptInCmdField)) | 244 if (LaunchAndCheckCommand(google_update::kRegCFOptInCmdField)) |
252 NotifyObserver(); | 245 NotifyObserver(); |
253 } | 246 } |
OLD | NEW |