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_installer.h" | |
6 | |
7 #include <windows.h> | |
erikwright (departed)
2012/10/03 20:57:07
#ifdef OS_WIN
huangs
2012/10/04 00:53:14
Done.
| |
8 #include "base/bind.h" | |
9 #include "base/callback.h" | |
10 #include "base/logging.h" | |
11 #include "base/process_util.h" | |
12 #include "base/string16.h" | |
13 #include "chrome/common/extensions/extension.h" | |
14 #include "chrome/installer/launcher_support/chrome_launcher_support.h" | |
15 #include "content/public/browser/browser_thread.h" | |
16 | |
17 #if defined(OS_WIN) | |
18 #include "base/win/object_watcher.h" | |
19 #endif | |
20 | |
21 namespace { | |
22 | |
23 #if defined(OS_WIN) | |
24 | |
25 class QuickEnableWatcher : public base::win::ObjectWatcher::Delegate { | |
26 public: | |
27 QuickEnableWatcher(const base::Callback<void(bool)>& callback) | |
28 : callback_(callback) { | |
29 } | |
30 | |
31 // base::win::ObjectWatcher::Delegate implementation. | |
32 void OnObjectSignaled(HANDLE object) { | |
33 base::TerminationStatus status( | |
34 base::GetTerminationStatus(object, NULL)); | |
35 if (status == base::TERMINATION_STATUS_NORMAL_TERMINATION) { | |
36 callback_.Run(true); | |
37 } else { | |
38 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.
| |
39 callback_.Run(false); | |
40 } | |
41 callback_.Reset(); | |
42 } | |
43 | |
44 private: | |
45 base::Callback<void(bool)> callback_; | |
46 | |
47 DISALLOW_COPY_AND_ASSIGN(QuickEnableWatcher); | |
48 }; | |
49 | |
50 // Launches the Google Update command to quick-enable App Host. | |
51 // Returns true if the command is launched. | |
52 bool LaunchQuickEnableAppHost(base::win::ScopedHandle* process) { | |
53 using namespace chrome_launcher_support; | |
54 DCHECK(!process->IsValid()); | |
55 bool success = false; | |
56 string16 cmd_str(GetQuickEnableAppHostCommand(SYSTEM_LEVEL_INSTALLATION)); | |
57 if (cmd_str.empty()) { // Try user-level if absent from system-level. | |
58 cmd_str = GetQuickEnableAppHostCommand(USER_LEVEL_INSTALLATION); | |
59 } | |
60 if (!cmd_str.empty()) { | |
61 VLOG(1) << "Quick-enabling application host: " << cmd_str; | |
62 if (!base::LaunchProcess(cmd_str, base::LaunchOptions(), | |
63 process->Receive())) { | |
64 LOG(ERROR) << "Failed to quick-enable application host."; | |
65 } | |
66 success = process->IsValid(); | |
67 } | |
68 return success; | |
69 } | |
70 | |
71 #endif | |
72 | |
73 } // namespace | |
74 | |
75 namespace extensions { | |
76 | |
77 AppHostInstaller::AppHostInstaller() { | |
78 } | |
79 | |
80 // static | |
81 bool AppHostInstaller::IsAppHostInstallRequired(const Extension& extension) { | |
82 #if defined(OS_WIN) | |
83 return extension.is_platform_app() && | |
84 !chrome_launcher_support::IsAppHostPresent(); | |
85 #else | |
86 return false; | |
87 #endif | |
88 } | |
89 | |
90 void AppHostInstaller::InstallAppHost( | |
91 const base::Callback<void(bool)>& callback) { | |
92 #if defined(OS_WIN) | |
93 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::).
| |
94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
95 DCHECK(!process_.IsValid()); | |
96 if (FAILED(LaunchQuickEnableAppHost(&process_))) { | |
97 callback.Run(false); | |
98 } else { | |
99 DCHECK(process_.IsValid()); | |
100 DCHECK(!delegate_.get()); | |
101 delegate_.reset(new QuickEnableWatcher(callback)); | |
102 watcher_.StartWatching(process_, delegate_.get()); | |
103 } | |
104 #else | |
105 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.
| |
106 #endif | |
107 } | |
108 | |
109 } // namespace extensions | |
OLD | NEW |