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 // TODO(huangs) Refactor the constants: | |
| 24 // http://code.google.com/p/chromium/issues/detail?id=148538 | |
|
grt (UTC plus 2)
2012/09/13 20:04:12
please use http://crbug.com/148538 and move to pre
huangs
2012/09/13 22:25:37
Done.
grt (UTC plus 2)
2012/09/14 14:26:52
I meant to put the bug number on the same line as
huangs
2012/09/14 16:34:23
Done. Just realized that comments can appear in o
| |
| 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. | |
| 36 const wchar_t kMultiInstallAppGuid[] = | |
| 37 L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"; | |
| 38 | |
| 39 // Fetches the version of the App Host, directly from the process. | |
| 40 // This is the preferred method to | |
|
erikwright (departed)
2012/09/13 19:27:49
no need for the "This is the preferred.." bit.
huangs
2012/09/13 22:25:37
Done.
| |
| 41 // GetAppVersion(L"{FDA71E6F-AC4C-4a00-8B70-9958A68906BF}", false, &version). | |
| 42 Version GetAppHostVersion() { | |
| 43 scoped_ptr<FileVersionInfo> version_info( | |
| 44 FileVersionInfo::CreateFileVersionInfoForCurrentModule()); | |
| 45 DCHECK(version_info.get() != NULL); | |
|
grt (UTC plus 2)
2012/09/13 20:04:12
remove DCHECK since scoped_ptr<> operator-> assert
huangs
2012/09/13 22:25:37
Done.
| |
| 46 Version version = Version(WideToASCII(version_info->product_version())); | |
|
erikwright (departed)
2012/09/13 19:27:49
just return directly. Don't assign to a local vari
huangs
2012/09/13 22:25:37
Done. Vestige of old "delete version_info;" code.
| |
| 47 return version; | |
| 48 } | |
| 49 | |
| 50 // Fetches the app version ("pv" entry) of a Google product from the registry, | |
| 51 // given the app GUID ("{###...###}") and the installation level. | |
| 52 Version GetAppVersion(const wchar_t* app_guid, bool system_level) { | |
|
erikwright (departed)
2012/09/13 19:27:49
remove the system_level parameter. It will always
huangs
2012/09/13 22:25:37
Done.
| |
| 53 HKEY root_key = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | |
| 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(), | |
|
grt (UTC plus 2)
2012/09/13 20:04:12
optional nit: it seems more natural to me to rever
huangs
2012/09/13 22:25:37
Done. de'Morgan's Law.
| |
| 59 KEY_QUERY_VALUE) != ERROR_SUCCESS) || | |
|
erikwright (departed)
2012/09/13 19:27:49
KEY_QUERY_VALUE should line up with root_key
huangs
2012/09/13 22:25:37
Done.
| |
| 60 (reg_key.ReadValue(kRegVersionField, &version_str) != ERROR_SUCCESS)) { | |
| 61 return Version(); | |
| 62 } | |
| 63 return Version(WideToASCII(version_str)); | |
| 64 } | |
| 65 | |
| 66 // Calls setup.exe to update App Host, using the system-level setup.exe. | |
| 67 bool UpdateAppHost() { | |
| 68 // Get the path to the setup.exe. | |
| 69 FilePath setup_exe(chrome_launcher_support::GetSetupExeForInstallationLevel( | |
| 70 chrome_launcher_support::SYSTEM_LEVEL_INSTALLATION)); | |
|
erikwright (departed)
2012/09/13 19:27:49
indent 4 from FilePath.
grt (UTC plus 2)
2012/09/13 20:04:12
hmm, my gut tells me:
FilePath setup_exe(
huangs
2012/09/13 22:25:37
Done. I prefer staircase.
| |
| 71 if (setup_exe.empty()) { | |
| 72 LOG(ERROR) << "Failed to find setup.exe"; | |
| 73 return false; | |
| 74 } | |
| 75 CommandLine cmd_line(setup_exe); | |
| 76 cmd_line.AppendSwitch(kMultiInstall); | |
| 77 cmd_line.AppendSwitch(kChromeAppHost); | |
| 78 cmd_line.AppendSwitch(kVerboseLogging); | |
| 79 LOG(INFO) << "Launching: " << cmd_line.GetCommandLineString(); | |
| 80 return base::LaunchProcess(cmd_line, base::LaunchOptions(), NULL); | |
| 81 } | |
| 82 | |
| 83 } | |
|
erikwright (departed)
2012/09/13 19:27:49
} // namespace
huangs
2012/09/13 22:25:37
Done.
| |
| 84 | |
| 85 void EnsureAppHostUpToDate() { | |
| 86 // Only checking system-level Chrome Binaries. | |
| 87 Version chrome_binaries_version(GetAppVersion(kMultiInstallAppGuid, true)); | |
| 88 if (chrome_binaries_version.IsValid()) { | |
|
erikwright (departed)
2012/09/13 19:27:49
if chrome_binaries_version is not valid, next try
huangs
2012/09/13 22:25:37
Done, but shuffled things around a lot.
| |
| 89 Version app_host_version(GetAppHostVersion()); | |
| 90 if (app_host_version.IsValid()) { | |
| 91 if (app_host_version.IsOlderThan(chrome_binaries_version.GetString())) { | |
| 92 LOG(INFO) << "Updating App Host from" | |
|
grt (UTC plus 2)
2012/09/13 20:04:12
space after "from", and condense as much as possib
huangs
2012/09/13 22:25:37
Done.
| |
| 93 << app_host_version.GetString() | |
| 94 << " to " | |
| 95 << chrome_binaries_version.GetString(); | |
| 96 if (!UpdateAppHost()) | |
| 97 LOG(ERROR) << "Failed to update App Host"; | |
| 98 } | |
| 99 } else { | |
| 100 LOG(ERROR) << "Failed to get App Host version"; | |
| 101 } | |
| 102 } // Else there is no system-level Chrome, so do nothing. | |
| 103 } | |
| 104 | |
| 105 } // namespace app_host | |
| OLD | NEW |