Chromium Code Reviews| Index: chrome/browser/extensions/app_host/update.cc |
| diff --git a/chrome/browser/extensions/app_host/update.cc b/chrome/browser/extensions/app_host/update.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..595ccf86666fd606dbfd86d4849b6de0e63f3922 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/app_host/update.cc |
| @@ -0,0 +1,100 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/extensions/app_host/update.h" |
| + |
| +#include <windows.h> |
| +#include "base/command_line.h" |
| +#include "base/file_version_info.h" |
| +#include "base/logging.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/process_util.h" |
| +#include "base/string16.h" |
| +#include "base/string_util.h" |
| +#include "base/version.h" |
| +#include "base/win/registry.h" |
| +#include "chrome/installer/launcher_support/chrome_launcher_support.h" |
| + |
| +namespace app_host { |
| + |
| +namespace { |
| + |
| +// http://crbug.com/148538 |
| +// TODO(huangs) Refactor the constants. |
| +const wchar_t kGoogleRegClientsKey[] = L"Software\\Google\\Update\\Clients\\"; |
| + |
| +// Copied from util_constants.cc. |
| +const char kMultiInstall[] = "multi-install"; |
| +const char kChromeAppHost[] = "app-host"; |
| +const char kVerboseLogging[] = "verbose-logging"; |
| + |
| +// Copied from google_update_constants.cc. |
| +const wchar_t kRegVersionField[] = L"pv"; |
| + |
| +// Copied from chrome_appid.cc and google_chrome_binaries_distribution.cc. |
| +const wchar_t kChromeBinariesAppGuid[] = |
|
grt (UTC plus 2)
2012/09/14 14:26:52
please:
- remove these constants
- export the iden
erikwright (departed)
2012/09/14 14:30:18
Negotiated with grt that this can be ignored.
huangs
2012/09/14 16:34:23
So no-op.
|
| + L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"; |
| +const wchar_t kChromeAppGuid[] = L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; |
| + |
| +// Fetches the version of the App Host, directly from the process. |
|
grt (UTC plus 2)
2012/09/14 14:26:52
", directly from the process." -> " from the image
huangs
2012/09/14 16:34:24
Done.
|
| +Version GetAppHostVersion() { |
| + scoped_ptr<FileVersionInfo> version_info( |
| + FileVersionInfo::CreateFileVersionInfoForCurrentModule()); |
| + return Version(WideToASCII(version_info->product_version())); |
| +} |
| + |
| +// Fetches the app version ("pv" entry) of a Google product from the |
| +// system-level registry, given the app GUID ("{###...###}"). |
| +Version GetAppVersionFromRegistry(const wchar_t* app_guid) { |
| + HKEY root_key = HKEY_LOCAL_MACHINE; |
| + string16 client_key(kGoogleRegClientsKey); |
| + client_key.append(app_guid); |
| + base::win::RegKey reg_key; |
| + string16 version_str; |
| + if ((reg_key.Open(root_key, client_key.c_str(), |
| + KEY_QUERY_VALUE) == ERROR_SUCCESS) && |
| + (reg_key.ReadValue(kRegVersionField, &version_str) == ERROR_SUCCESS)) { |
| + return Version(WideToASCII(version_str)); |
| + } |
| + return Version(); |
| +} |
| + |
| +// Calls setup.exe to update App Host, using the system-level setup.exe. |
| +bool UpdateAppHost() { |
| + // Get the path to the setup.exe. |
| + FilePath setup_exe( |
| + chrome_launcher_support::GetSetupExeForInstallationLevel( |
| + chrome_launcher_support::SYSTEM_LEVEL_INSTALLATION)); |
| + if (setup_exe.empty()) { |
| + LOG(ERROR) << "Failed to find setup.exe"; |
| + return false; |
| + } |
| + CommandLine cmd_line(setup_exe); |
| + cmd_line.AppendSwitch(kMultiInstall); |
| + cmd_line.AppendSwitch(kChromeAppHost); |
| + cmd_line.AppendSwitch(kVerboseLogging); |
| + LOG(INFO) << "Launching: " << cmd_line.GetCommandLineString(); |
| + return base::LaunchProcess(cmd_line, base::LaunchOptions(), NULL); |
| +} |
| + |
| +} // namespace |
| + |
| +void LaunchAppHostUpdate() { |
| + // Check version from Chrome Binaries first, then Chrome (all system-level). |
| + Version new_version(GetAppVersionFromRegistry(kChromeBinariesAppGuid)); |
| + if (!new_version.IsValid()) |
| + new_version = GetAppVersionFromRegistry(kChromeAppGuid); |
| + if (!new_version.IsValid()) |
| + return; // Not an error: System-level Chrome might not be installed. |
| + Version app_host_version(GetAppHostVersion()); |
| + DCHECK(app_host_version.IsValid()); |
|
grt (UTC plus 2)
2012/09/14 14:26:52
Version::Compare DCHECKs its args, so remove this.
huangs
2012/09/14 16:34:24
Done.
|
| + if (app_host_version.IsOlderThan(new_version.GetString())) { |
|
grt (UTC plus 2)
2012/09/14 14:26:52
if (app_host_version.CompareTo(new_version) < 0) t
huangs
2012/09/14 16:34:24
Done.
|
| + LOG(INFO) << "Updating App Host from " << app_host_version.GetString() |
| + << " to " << new_version.GetString(); |
| + if (!UpdateAppHost()) |
| + LOG(ERROR) << "Failed to launch App Host update."; |
| + } |
| +} |
| + |
| +} // namespace app_host |