Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/extensions/app_host/update.h" | |
| 6 | |
| 7 #include <windows.h> | |
| 8 #include "base/command_line.h" | |
| 9 #include "base/file_version_info.h" | |
| 10 #include "base/logging.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/process_util.h" | |
| 13 #include "base/string16.h" | |
| 14 #include "base/string_util.h" | |
| 15 #include "base/version.h" | |
| 16 #include "base/win/registry.h" | |
| 17 #include "chrome/installer/launcher_support/chrome_launcher_support.h" | |
| 18 | |
| 19 namespace app_host { | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 23 // http://crbug.com/148538 | |
| 24 // TODO(huangs) Refactor the constants: | |
| 25 const wchar_t kGoogleRegClientsKey[] = L"Software\\Google\\Update\\Clients\\"; | |
| 26 | |
| 27 // Copied from util_constants.cc. | |
| 28 const char kMultiInstall[] = "multi-install"; | |
| 29 const char kChromeAppHost[] = "app-host"; | |
| 30 const char kVerboseLogging[] = "verbose-logging"; | |
| 31 | |
| 32 // Copied from google_update_constants.cc. | |
| 33 const wchar_t kRegVersionField[] = L"pv"; | |
| 34 | |
| 35 // Copied from chrome_appid.cc and google_chrome_binaries_distribution.cc. | |
| 36 const wchar_t kChromeBinariesAppGuid[] = | |
| 37 L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"; | |
| 38 const wchar_t kChromeAppGuid[] = L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; | |
| 39 | |
| 40 // Fetches the version of the App Host, directly from the process. | |
| 41 Version GetAppHostVersion() { | |
| 42 scoped_ptr<FileVersionInfo> version_info( | |
| 43 FileVersionInfo::CreateFileVersionInfoForCurrentModule()); | |
| 44 return Version(WideToASCII(version_info->product_version())); | |
| 45 } | |
| 46 | |
| 47 // Fetches the app version ("pv" entry) of a Google product from the | |
| 48 // system-level registry, given the app GUID ("{###...###}"). | |
| 49 Version GetAppVersionFromRegistry(const wchar_t* app_guid) { | |
| 50 HKEY root_key = HKEY_LOCAL_MACHINE; | |
| 51 string16 client_key(kGoogleRegClientsKey); | |
| 52 client_key.append(app_guid); | |
| 53 base::win::RegKey reg_key; | |
| 54 string16 version_str; | |
| 55 if ((reg_key.Open(root_key, client_key.c_str(), | |
| 56 KEY_QUERY_VALUE) == ERROR_SUCCESS) && | |
| 57 (reg_key.ReadValue(kRegVersionField, &version_str) == ERROR_SUCCESS)) { | |
| 58 return Version(WideToASCII(version_str)); | |
| 59 } | |
| 60 return Version(); | |
| 61 } | |
| 62 | |
| 63 // Calls setup.exe to update App Host, using the system-level setup.exe. | |
| 64 bool UpdateAppHost() { | |
| 65 // Get the path to the setup.exe. | |
| 66 FilePath setup_exe( | |
| 67 chrome_launcher_support::GetSetupExeForInstallationLevel( | |
| 68 chrome_launcher_support::SYSTEM_LEVEL_INSTALLATION)); | |
| 69 if (setup_exe.empty()) { | |
| 70 LOG(ERROR) << "Failed to find setup.exe"; | |
| 71 return false; | |
| 72 } | |
| 73 CommandLine cmd_line(setup_exe); | |
| 74 cmd_line.AppendSwitch(kMultiInstall); | |
| 75 cmd_line.AppendSwitch(kChromeAppHost); | |
| 76 cmd_line.AppendSwitch(kVerboseLogging); | |
| 77 LOG(INFO) << "Launching: " << cmd_line.GetCommandLineString(); | |
| 78 return base::LaunchProcess(cmd_line, base::LaunchOptions(), NULL); | |
| 79 } | |
| 80 | |
| 81 } // namespace | |
| 82 | |
| 83 void EnsureAppHostUpToDate() { | |
| 84 // Check version from Chrome Binaries first, then Chrome (all system-level). | |
| 85 Version new_version; | |
|
erikwright (departed)
2012/09/14 01:21:36
combine declaration and assignment (lines 85,86)
huangs
2012/09/14 04:03:14
Done.
| |
| 86 new_version = GetAppVersionFromRegistry(kChromeBinariesAppGuid); | |
| 87 if (!new_version.IsValid()) | |
| 88 new_version = GetAppVersionFromRegistry(kChromeAppGuid); | |
| 89 if (!new_version.IsValid()) | |
| 90 return; // Not an error: System-level Chrome might not be installed. | |
| 91 Version app_host_version(GetAppHostVersion()); | |
| 92 DCHECK(app_host_version.IsValid()); | |
| 93 if (app_host_version.IsOlderThan(new_version.GetString())) { | |
| 94 LOG(INFO) << "Updating App Host from " << app_host_version.GetString() | |
| 95 << " to " << new_version.GetString(); | |
| 96 if (!UpdateAppHost()) | |
|
erikwright (departed)
2012/09/14 01:21:36
I think this should be renamed to LaunchAppHostUpd
huangs
2012/09/14 04:03:14
Done.
erikwright (departed)
2012/09/14 13:21:24
Sorry, misunderstanding:
EnsureAppHostUpToDate wa
huangs
2012/09/14 16:34:23
Done.
| |
| 97 LOG(ERROR) << "Failed to update App Host"; | |
|
erikwright (departed)
2012/09/14 01:21:36
"Failed to launch App Host update."
huangs
2012/09/14 04:03:14
Done.
| |
| 98 } | |
| 99 } | |
| 100 | |
| 101 } // namespace app_host | |
| OLD | NEW |