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 // TODO(huangs) Refactor the constants: http://crbug.com/148538 | |
24 const wchar_t kGoogleRegClientsKey[] = L"Software\\Google\\Update\\Clients\\"; | |
25 | |
26 // Copied from util_constants.cc. | |
27 const char kMultiInstall[] = "multi-install"; | |
28 const char kChromeAppHost[] = "app-host"; | |
29 const char kVerboseLogging[] = "verbose-logging"; | |
30 | |
31 // Copied from google_update_constants.cc. | |
32 const wchar_t kRegVersionField[] = L"pv"; | |
33 | |
34 // Copied from chrome_appid.cc. | |
35 const wchar_t kBinariesAppGuid[] = L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"; | |
36 | |
37 // Copied from google_chrome_distribution.cc. | |
38 const wchar_t kBrowserAppGuid[] = L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; | |
39 | |
40 // Fetches the version of the App Host, directly from the image's version | |
41 // resource. | |
42 Version GetAppHostVersion() { | |
43 scoped_ptr<FileVersionInfo> version_info( | |
44 FileVersionInfo::CreateFileVersionInfoForCurrentModule()); | |
45 Version app_host_version(WideToASCII(version_info->product_version())); | |
46 DCHECK(app_host_version.IsValid()); | |
47 return app_host_version; | |
48 } | |
49 | |
50 // Fetches the app version ("pv" entry) of a Google product from the | |
51 // system-level registry, given the app GUID ("{###...###}"). | |
52 Version GetAppVersionFromRegistry(const wchar_t* app_guid) { | |
53 HKEY root_key = HKEY_LOCAL_MACHINE; | |
54 string16 client_key(kGoogleRegClientsKey); | |
55 client_key.append(app_guid); | |
56 base::win::RegKey reg_key; | |
57 string16 version_str; | |
58 if ((reg_key.Open(root_key, client_key.c_str(), | |
59 KEY_QUERY_VALUE) == ERROR_SUCCESS) && | |
60 (reg_key.ReadValue(kRegVersionField, &version_str) == ERROR_SUCCESS)) { | |
61 return Version(WideToASCII(version_str)); | |
62 } | |
63 return Version(); | |
64 } | |
65 | |
66 // Calls setup.exe to update App Host, using the system-level setup.exe. | |
67 bool LaunchAppHostUpdate() { | |
68 // Get the path to the setup.exe. | |
69 base::FilePath setup_exe( | |
70 chrome_launcher_support::GetSetupExeForInstallationLevel( | |
71 chrome_launcher_support::SYSTEM_LEVEL_INSTALLATION)); | |
72 if (setup_exe.empty()) { | |
73 LOG(ERROR) << "Failed to find setup.exe"; | |
74 return false; | |
75 } | |
76 CommandLine cmd_line(setup_exe); | |
77 cmd_line.AppendSwitch(kMultiInstall); | |
78 cmd_line.AppendSwitch(kChromeAppHost); | |
79 cmd_line.AppendSwitch(kVerboseLogging); | |
80 LOG(INFO) << "Launching: " << cmd_line.GetCommandLineString(); | |
81 return base::LaunchProcess(cmd_line, base::LaunchOptions(), NULL); | |
82 } | |
83 | |
84 } // namespace | |
85 | |
86 void EnsureAppHostUpToDate() { | |
87 // Check version from Chrome Binaries first, then Chrome (all system-level). | |
88 Version new_version(GetAppVersionFromRegistry(kBinariesAppGuid)); | |
89 if (!new_version.IsValid()) | |
90 new_version = GetAppVersionFromRegistry(kBrowserAppGuid); | |
91 if (!new_version.IsValid()) | |
92 return; // Not an error: System-level Chrome might not be installed. | |
93 Version app_host_version(GetAppHostVersion()); | |
94 if (app_host_version.CompareTo(new_version) < 0) { | |
95 LOG(INFO) << "Updating App Launcher from " << app_host_version.GetString() | |
96 << " to " << new_version.GetString(); | |
97 if (!LaunchAppHostUpdate()) | |
98 LOG(ERROR) << "Failed to launch App Launcher update."; | |
99 } | |
100 } | |
101 | |
102 } // namespace app_host | |
OLD | NEW |