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