Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(553)

Side by Side Diff: chrome/browser/extensions/app_host/update.cc

Issue 10905238: If Chrome Binaries version > App Host version, then update App Host. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Renaming main update routine to LaunchAppHostUpdate(); fixing parameters of helper routines. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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[] =
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.
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.
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.
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 LaunchAppHostUpdate() {
84 // Check version from Chrome Binaries first, then Chrome (all system-level).
85 Version new_version(GetAppVersionFromRegistry(kChromeBinariesAppGuid));
86 if (!new_version.IsValid())
87 new_version = GetAppVersionFromRegistry(kChromeAppGuid);
88 if (!new_version.IsValid())
89 return; // Not an error: System-level Chrome might not be installed.
90 Version app_host_version(GetAppHostVersion());
91 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.
92 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.
93 LOG(INFO) << "Updating App Host from " << app_host_version.GetString()
94 << " to " << new_version.GetString();
95 if (!UpdateAppHost())
96 LOG(ERROR) << "Failed to launch App Host update.";
97 }
98 }
99
100 } // namespace app_host
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698