| 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/browser/google/google_update.h" | 5 #include "chrome/browser/google/google_update.h" |
| 6 | 6 |
| 7 #include <atlbase.h> | 7 #include <atlbase.h> |
| 8 #include <atlcom.h> | 8 #include <atlcom.h> |
| 9 | 9 |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/task.h" | 14 #include "base/task.h" |
| 15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
| 16 #include "base/win/registry.h" | |
| 17 #include "base/win/scoped_comptr.h" | 16 #include "base/win/scoped_comptr.h" |
| 18 #include "base/win/windows_version.h" | 17 #include "base/win/windows_version.h" |
| 19 #include "chrome/installer/util/browser_distribution.h" | 18 #include "chrome/installer/util/browser_distribution.h" |
| 20 #include "chrome/installer/util/google_update_constants.h" | 19 #include "chrome/installer/util/google_update_settings.h" |
| 21 #include "chrome/installer/util/helper.h" | 20 #include "chrome/installer/util/helper.h" |
| 22 #include "chrome/installer/util/install_util.h" | 21 #include "chrome/installer/util/install_util.h" |
| 23 #include "content/browser/browser_thread.h" | 22 #include "content/browser/browser_thread.h" |
| 24 #include "google_update_idl_i.c" | 23 #include "google_update_idl_i.c" |
| 25 #include "views/window/window.h" | 24 #include "views/window/window.h" |
| 26 | 25 |
| 27 using views::Window; | 26 using views::Window; |
| 28 | 27 |
| 29 namespace { | 28 namespace { |
| 30 | 29 |
| 31 // The registry location of the Google Update policies. | |
| 32 const wchar_t kGUPolicyRegistrySubKey[] = | |
| 33 L"SOFTWARE\\Policies\\Google\\Update"; | |
| 34 const wchar_t kGUPolicyGlobalValue[] = L"UpdateDefault"; | |
| 35 const wchar_t kGUPolicyAppValuePrefix[] = L"Update"; | |
| 36 const DWORD kGUPolicyUpdatesDisabled = 0; | |
| 37 | |
| 38 // Checks if the updates have been disabled by policy. | |
| 39 bool IsUpdateDisabledByPolicy(const std::wstring& guid) { | |
| 40 #if !defined(GOOGLE_CHROME_BUILD) | |
| 41 return true; | |
| 42 #else | |
| 43 std::wstring value_name(kGUPolicyAppValuePrefix); | |
| 44 value_name.append(guid); | |
| 45 DWORD value = 0; | |
| 46 base::win::RegKey policy(HKEY_LOCAL_MACHINE, | |
| 47 kGUPolicyRegistrySubKey, KEY_READ); | |
| 48 // Per application settings override global setting. | |
| 49 if ((policy.ReadValueDW(value_name.c_str(), &value) == ERROR_SUCCESS) || | |
| 50 (policy.ReadValueDW(kGUPolicyGlobalValue, &value) == ERROR_SUCCESS)) { | |
| 51 return value == kGUPolicyUpdatesDisabled; | |
| 52 } | |
| 53 return false; | |
| 54 #endif // defined(GOOGLE_CHROME_BUILD) | |
| 55 } | |
| 56 | |
| 57 // Check if the currently running instance can be updated by Google Update. | 30 // Check if the currently running instance can be updated by Google Update. |
| 58 // Returns true only if the instance running is a Google Chrome | 31 // Returns GOOGLE_UPDATE_NO_ERROR only if the instance running is a Google |
| 59 // distribution installed in a standard location. | 32 // Chrome distribution installed in a standard location. |
| 60 GoogleUpdateErrorCode CanUpdateCurrentChrome( | 33 GoogleUpdateErrorCode CanUpdateCurrentChrome( |
| 61 const std::wstring& chrome_exe_path) { | 34 const std::wstring& chrome_exe_path) { |
| 62 #if !defined(GOOGLE_CHROME_BUILD) | 35 #if !defined(GOOGLE_CHROME_BUILD) |
| 63 return CANNOT_UPGRADE_CHROME_IN_THIS_DIRECTORY; | 36 return CANNOT_UPGRADE_CHROME_IN_THIS_DIRECTORY; |
| 64 #else | 37 #else |
| 65 // TODO(tommi): Check if using the default distribution is always the right | 38 // TODO(tommi): Check if using the default distribution is always the right |
| 66 // thing to do. | 39 // thing to do. |
| 67 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 40 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 68 std::wstring user_exe_path = | 41 std::wstring user_exe_path = |
| 69 installer::GetChromeInstallPath(false, dist).value(); | 42 installer::GetChromeInstallPath(false, dist).value(); |
| 70 std::wstring machine_exe_path = | 43 std::wstring machine_exe_path = |
| 71 installer::GetChromeInstallPath(true, dist).value(); | 44 installer::GetChromeInstallPath(true, dist).value(); |
| 72 std::transform(user_exe_path.begin(), user_exe_path.end(), | 45 std::transform(user_exe_path.begin(), user_exe_path.end(), |
| 73 user_exe_path.begin(), tolower); | 46 user_exe_path.begin(), tolower); |
| 74 std::transform(machine_exe_path.begin(), machine_exe_path.end(), | 47 std::transform(machine_exe_path.begin(), machine_exe_path.end(), |
| 75 machine_exe_path.begin(), tolower); | 48 machine_exe_path.begin(), tolower); |
| 76 if (chrome_exe_path != user_exe_path && | 49 if (chrome_exe_path != user_exe_path && |
| 77 chrome_exe_path != machine_exe_path ) { | 50 chrome_exe_path != machine_exe_path ) { |
| 78 LOG(ERROR) << L"Google Update cannot update Chrome installed in a " | 51 LOG(ERROR) << L"Google Update cannot update Chrome installed in a " |
| 79 << L"non-standard location: " << chrome_exe_path.c_str() | 52 << L"non-standard location: " << chrome_exe_path.c_str() |
| 80 << L". The standard location is: " << user_exe_path.c_str() | 53 << L". The standard location is: " << user_exe_path.c_str() |
| 81 << L" or " << machine_exe_path.c_str() << L"."; | 54 << L" or " << machine_exe_path.c_str() << L"."; |
| 82 return CANNOT_UPGRADE_CHROME_IN_THIS_DIRECTORY; | 55 return CANNOT_UPGRADE_CHROME_IN_THIS_DIRECTORY; |
| 83 } | 56 } |
| 84 | 57 |
| 85 std::wstring app_guid = installer::GetAppGuidForUpdates( | 58 std::wstring app_guid = installer::GetAppGuidForUpdates( |
| 86 !InstallUtil::IsPerUserInstall(chrome_exe_path.c_str())); | 59 !InstallUtil::IsPerUserInstall(chrome_exe_path.c_str())); |
| 87 DCHECK(!app_guid.empty()); | 60 DCHECK(!app_guid.empty()); |
| 88 | 61 |
| 89 if (IsUpdateDisabledByPolicy(app_guid)) | 62 if (GoogleUpdateSettings::GetAppUpdatePolicy(app_guid, NULL) == |
| 63 GoogleUpdateSettings::UPDATES_DISABLED) |
| 90 return GOOGLE_UPDATE_DISABLED_BY_POLICY; | 64 return GOOGLE_UPDATE_DISABLED_BY_POLICY; |
| 91 | 65 |
| 92 return GOOGLE_UPDATE_NO_ERROR; | 66 return GOOGLE_UPDATE_NO_ERROR; |
| 93 #endif | 67 #endif |
| 94 } | 68 } |
| 95 | 69 |
| 96 // Creates an instance of a COM Local Server class using either plain vanilla | 70 // Creates an instance of a COM Local Server class using either plain vanilla |
| 97 // CoCreateInstance, or using the Elevation moniker if running on Vista. | 71 // CoCreateInstance, or using the Elevation moniker if running on Vista. |
| 98 // hwnd must refer to a foregound window in order to get the UAC prompt | 72 // hwnd must refer to a foregound window in order to get the UAC prompt |
| 99 // showing up in the foreground if running on Vista. It can also be NULL if | 73 // showing up in the foreground if running on Vista. It can also be NULL if |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 } | 343 } |
| 370 | 344 |
| 371 bool GoogleUpdate::ReportFailure(HRESULT hr, GoogleUpdateErrorCode error_code, | 345 bool GoogleUpdate::ReportFailure(HRESULT hr, GoogleUpdateErrorCode error_code, |
| 372 MessageLoop* main_loop) { | 346 MessageLoop* main_loop) { |
| 373 NOTREACHED() << "Communication with Google Update failed: " << hr | 347 NOTREACHED() << "Communication with Google Update failed: " << hr |
| 374 << " error: " << error_code; | 348 << " error: " << error_code; |
| 375 main_loop->PostTask(FROM_HERE, NewRunnableMethod(this, | 349 main_loop->PostTask(FROM_HERE, NewRunnableMethod(this, |
| 376 &GoogleUpdate::ReportResults, UPGRADE_ERROR, error_code)); | 350 &GoogleUpdate::ReportResults, UPGRADE_ERROR, error_code)); |
| 377 return false; | 351 return false; |
| 378 } | 352 } |
| OLD | NEW |