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

Unified Diff: chrome/browser/extensions/app_host_installer.cc

Issue 11054006: Make application shortcuts point to app_host.exe, install App Host during app installation. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Moving quick-enable-app-host feature; adding App Host install code for unpacked extension installer. Created 8 years, 2 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_installer.cc
diff --git a/chrome/browser/extensions/app_host_installer.cc b/chrome/browser/extensions/app_host_installer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..07dec9e901dc8c1ee6549228c32520f5478efec6
--- /dev/null
+++ b/chrome/browser/extensions/app_host_installer.cc
@@ -0,0 +1,109 @@
+// 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_installer.h"
+
+#include <windows.h>
erikwright (departed) 2012/10/03 20:57:07 #ifdef OS_WIN
huangs 2012/10/04 00:53:14 Done.
+#include "base/bind.h"
+#include "base/callback.h"
+#include "base/logging.h"
+#include "base/process_util.h"
+#include "base/string16.h"
+#include "chrome/common/extensions/extension.h"
+#include "chrome/installer/launcher_support/chrome_launcher_support.h"
+#include "content/public/browser/browser_thread.h"
+
+#if defined(OS_WIN)
+#include "base/win/object_watcher.h"
+#endif
+
+namespace {
+
+#if defined(OS_WIN)
+
+class QuickEnableWatcher : public base::win::ObjectWatcher::Delegate {
+ public:
+ QuickEnableWatcher(const base::Callback<void(bool)>& callback)
+ : callback_(callback) {
+ }
+
+ // base::win::ObjectWatcher::Delegate implementation.
+ void OnObjectSignaled(HANDLE object) {
+ base::TerminationStatus status(
+ base::GetTerminationStatus(object, NULL));
+ if (status == base::TERMINATION_STATUS_NORMAL_TERMINATION) {
+ callback_.Run(true);
+ } else {
+ LOG(ERROR) << "App Host install failed, status = " << status;
erikwright (departed) 2012/10/03 20:57:07 log the exit code if appropriate
huangs 2012/10/04 00:53:14 Done.
+ callback_.Run(false);
+ }
+ callback_.Reset();
+ }
+
+ private:
+ base::Callback<void(bool)> callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(QuickEnableWatcher);
+};
+
+// Launches the Google Update command to quick-enable App Host.
+// Returns true if the command is launched.
+bool LaunchQuickEnableAppHost(base::win::ScopedHandle* process) {
+ using namespace chrome_launcher_support;
+ DCHECK(!process->IsValid());
+ bool success = false;
+ string16 cmd_str(GetQuickEnableAppHostCommand(SYSTEM_LEVEL_INSTALLATION));
+ if (cmd_str.empty()) { // Try user-level if absent from system-level.
+ cmd_str = GetQuickEnableAppHostCommand(USER_LEVEL_INSTALLATION);
+ }
+ if (!cmd_str.empty()) {
+ VLOG(1) << "Quick-enabling application host: " << cmd_str;
+ if (!base::LaunchProcess(cmd_str, base::LaunchOptions(),
+ process->Receive())) {
+ LOG(ERROR) << "Failed to quick-enable application host.";
+ }
+ success = process->IsValid();
+ }
+ return success;
+}
+
+#endif
+
+} // namespace
+
+namespace extensions {
+
+AppHostInstaller::AppHostInstaller() {
+}
+
+// static
+bool AppHostInstaller::IsAppHostInstallRequired(const Extension& extension) {
+#if defined(OS_WIN)
+ return extension.is_platform_app() &&
+ !chrome_launcher_support::IsAppHostPresent();
+#else
+ return false;
+#endif
+}
+
+void AppHostInstaller::InstallAppHost(
+ const base::Callback<void(bool)>& callback) {
+#if defined(OS_WIN)
+ using content::BrowserThread;
erikwright (departed) 2012/10/03 20:57:07 is the using necessary?
huangs 2012/10/04 00:53:14 Done (removed, added content::).
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+ DCHECK(!process_.IsValid());
+ if (FAILED(LaunchQuickEnableAppHost(&process_))) {
+ callback.Run(false);
+ } else {
+ DCHECK(process_.IsValid());
+ DCHECK(!delegate_.get());
+ delegate_.reset(new QuickEnableWatcher(callback));
+ watcher_.StartWatching(process_, delegate_.get());
+ }
+#else
+ callback.Run(true);
erikwright (departed) 2012/10/03 20:57:07 NOTREACHED() << "Attempt to install the app host o
huangs 2012/10/04 00:53:14 Done.
+#endif
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698