| 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(roots[i], key_name_.c_str(), KEY_QUERY_VALUE); |
| 194 if (config_key.Open(roots[i], key_name_.c_str(), KEY_QUERY_VALUE)) { | 196 if (result == ERROR_SUCCESS) { |
| 195 if (config_key.ValueExists(installer::kChromeFrameReadyModeField)) { | 197 result = config_key.ReadInt64(installer::kChromeFrameReadyModeField, |
| 196 int64 temp; | 198 value); |
| 197 DWORD value_size = sizeof(temp); | 199 if (result == ERROR_SUCCESS) { |
| 198 DWORD type = 0; | |
| 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; | 200 *exists = true; |
| 215 return true; | 201 return true; |
| 216 } | 202 } |
| 203 if (result != ERROR_FILE_NOT_FOUND) { |
| 204 DLOG(ERROR) << "Failed to read from registry key " << key_name_ |
| 205 << " and value " << installer::kChromeFrameReadyModeField |
| 206 << " error: " << result; |
| 207 return false; |
| 208 } |
| 217 } | 209 } |
| 218 } | 210 } |
| 219 | 211 |
| 220 return true; | 212 return true; |
| 221 } | 213 } |
| 222 | 214 |
| 223 void RegistryReadyModeState::RefreshStateAndNotify() { | 215 void RegistryReadyModeState::RefreshStateAndNotify() { |
| 224 HRESULT hr = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT_REFRESH, | 216 HRESULT hr = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT_REFRESH, |
| 225 NULL, 0, 0); | 217 NULL, 0, 0); |
| 226 if (FAILED(hr)) { | 218 if (FAILED(hr)) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 244 | 236 |
| 245 void RegistryReadyModeState::PermanentlyDeclineChromeFrame() { | 237 void RegistryReadyModeState::PermanentlyDeclineChromeFrame() { |
| 246 if (LaunchAndCheckCommand(google_update::kRegCFOptOutCmdField)) | 238 if (LaunchAndCheckCommand(google_update::kRegCFOptOutCmdField)) |
| 247 RefreshStateAndNotify(); | 239 RefreshStateAndNotify(); |
| 248 } | 240 } |
| 249 | 241 |
| 250 void RegistryReadyModeState::AcceptChromeFrame() { | 242 void RegistryReadyModeState::AcceptChromeFrame() { |
| 251 if (LaunchAndCheckCommand(google_update::kRegCFOptInCmdField)) | 243 if (LaunchAndCheckCommand(google_update::kRegCFOptInCmdField)) |
| 252 NotifyObserver(); | 244 NotifyObserver(); |
| 253 } | 245 } |
| OLD | NEW |