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 |