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 100755 |
| index 0000000000000000000000000000000000000000..274df940ae8e05615aa633e31bdf38a43ccde0a0 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/app_host/update.cc |
| @@ -0,0 +1,101 @@ |
| +// 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[] = |
| + 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. |
| +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 EnsureAppHostUpToDate() { |
| + // Check version from Chrome Binaries first, then Chrome (all system-level). |
| + 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.
|
| + 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()); |
| + if (app_host_version.IsOlderThan(new_version.GetString())) { |
| + LOG(INFO) << "Updating App Host from " << app_host_version.GetString() |
| + << " to " << new_version.GetString(); |
| + 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.
|
| + 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.
|
| + } |
| +} |
| + |
| +} // namespace app_host |