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

Unified Diff: chrome/browser/extensions/app_host/app_host_upgrade.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: Refactoring; adding app_host_upgrade.*; focusing on system-level setup.exe. 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/app_host/app_host_upgrade.cc
diff --git a/chrome/browser/extensions/app_host/app_host_upgrade.cc b/chrome/browser/extensions/app_host/app_host_upgrade.cc
new file mode 100755
index 0000000000000000000000000000000000000000..21c062108da015557aa089f3737f3d6b71c73d07
--- /dev/null
+++ b/chrome/browser/extensions/app_host/app_host_upgrade.cc
@@ -0,0 +1,78 @@
+// 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/app_host_upgrade.h"
+#include "chrome/installer/launcher_support/chrome_launcher_support.h"
erikwright (departed) 2012/09/13 01:13:44 chrome_launcher_support should be ordered with the
huangs 2012/09/13 04:40:47 Done.
+
+#include <windows.h>
+#include <tchar.h>
erikwright (departed) 2012/09/13 01:13:44 what is tchar used for?
huangs 2012/09/13 04:40:47 I mistakenly thought it was needed for wchar_t. D
+#include "base/command_line.h"
+#include "base/logging.h"
+#include "base/process_util.h"
+#include "base/string16.h"
+#include "base/string_util.h"
+#include "base/version.h"
+#include "base/win/registry.h"
+
+namespace app_host {
+
+const wchar_t kGoogleRegClientsKey[] =
erikwright (departed) 2012/09/13 01:13:44 anonymous namespace for this and other constants n
huangs 2012/09/13 04:40:47 Done.
+ L"Software\\Google\\Update\\Clients\\";
+
+// Copied from chrome_appid.cc
+const wchar_t kMultiInstallAppGuid[] =
+ L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}";
+const wchar_t kChromeAppHostAppGuid[] =
+ L"{FDA71E6F-AC4C-4a00-8B70-9958A68906BF}";
+
+// 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";
+
+// TODO(huangs): Refactor parameter |system_level|.
erikwright (departed) 2012/09/13 01:13:44 TODO unnecessary.
huangs 2012/09/13 04:40:47 Done.
+bool GetAppVersionForInstallationLevel(const wchar_t* app_guid,
+ bool system_level,
+ Version* version) {
+ using base::win::RegKey;
erikwright (departed) 2012/09/13 01:13:44 This is only used once, right? So 'using' is overk
huangs 2012/09/13 04:40:47 Done.
+ HKEY root_key = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
+ string16 client_key(kGoogleRegClientsKey);
+ client_key.append(app_guid);
+ LOG(INFO) << "Trying to get " << client_key;
erikwright (departed) 2012/09/13 01:13:44 remove log statement.
huangs 2012/09/13 04:40:47 Done.
+ RegKey reg_key;
+ string16 version_str;
+ if ((reg_key.Open(root_key, client_key.c_str(), KEY_QUERY_VALUE)
+ != ERROR_SUCCESS) ||
erikwright (departed) 2012/09/13 01:13:44 != should go on previous line (prefer wrap after o
huangs 2012/09/13 04:40:47 Done.
+ (reg_key.ReadValue(kRegVersionField, &version_str) != ERROR_SUCCESS)) {
+ return false;
+ }
+ *version = Version(WideToASCII(version_str));
+ return version->IsValid();
+}
+
+// TODO(huangs): Refactor parameter |system_level|.
erikwright (departed) 2012/09/13 01:13:44 remove TODO
huangs 2012/09/13 04:40:47 Done.
+bool UpgradeAppHost(bool system_level) {
+ using namespace chrome_launcher_support;
+ // Get the path to the setup.exe.
+ FilePath setup_exe(GetSetupExeForInstallationLevel(
+ system_level ? SYSTEM_LEVEL_INSTALLATION : USER_LEVEL_INSTALLATION));
+ if (setup_exe.empty()) {
+ LOG(INFO) << "Failed to find setup.exe";
+ return false;
+ }
+ CommandLine cmd_line(setup_exe);
+ cmd_line.AppendSwitch(kMultiInstall);
+ cmd_line.AppendSwitch(kChromeAppHost);
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
erikwright (departed) 2012/09/13 01:13:44 Don't check the command-line for the current proce
huangs 2012/09/13 04:40:47 Done.
+ kVerboseLogging)) {
+ cmd_line.AppendSwitch(kVerboseLogging);
+ }
+ LOG(INFO) << "Command line: " << cmd_line.GetCommandLineString();
erikwright (departed) 2012/09/13 01:13:44 "Upgrading app_host.exe using command-line: ..."
huangs 2012/09/13 04:40:47 Done.
+ return base::LaunchProcess(cmd_line, base::LaunchOptions(), NULL);
+}
+
+} // namespace app_host

Powered by Google App Engine
This is Rietveld 408576698