OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "win8/viewer/metro_viewer_process_host.h" | 5 #include "win8/viewer/metro_viewer_process_host.h" |
6 | 6 |
7 #include <shlobj.h> | 7 #include <shlobj.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/path_service.h" |
13 #include "base/process/process.h" | 14 #include "base/process/process.h" |
14 #include "base/process/process_handle.h" | 15 #include "base/process/process_handle.h" |
15 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
16 #include "base/synchronization/waitable_event.h" | 17 #include "base/synchronization/waitable_event.h" |
17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
18 #include "base/win/scoped_comptr.h" | 19 #include "base/win/scoped_comptr.h" |
| 20 #include "base/win/windows_version.h" |
19 #include "ipc/ipc_message.h" | 21 #include "ipc/ipc_message.h" |
20 #include "ipc/ipc_message_macros.h" | 22 #include "ipc/ipc_message_macros.h" |
21 #include "ui/aura/remote_window_tree_host_win.h" | 23 #include "ui/aura/remote_window_tree_host_win.h" |
22 #include "ui/metro_viewer/metro_viewer_messages.h" | 24 #include "ui/metro_viewer/metro_viewer_messages.h" |
23 #include "win8/viewer/metro_viewer_constants.h" | 25 #include "win8/viewer/metro_viewer_constants.h" |
24 | 26 |
25 namespace { | 27 namespace { |
26 | 28 |
27 const int kViewerProcessConnectionTimeoutSecs = 60; | 29 const int kViewerProcessConnectionTimeoutSecs = 60; |
28 | 30 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 82 |
81 bool MetroViewerProcessHost::LaunchViewerAndWaitForConnection( | 83 bool MetroViewerProcessHost::LaunchViewerAndWaitForConnection( |
82 const base::string16& app_user_model_id) { | 84 const base::string16& app_user_model_id) { |
83 DCHECK_EQ(base::kNullProcessId, channel_->peer_pid()); | 85 DCHECK_EQ(base::kNullProcessId, channel_->peer_pid()); |
84 | 86 |
85 channel_connected_event_.reset(new base::WaitableEvent(false, false)); | 87 channel_connected_event_.reset(new base::WaitableEvent(false, false)); |
86 | 88 |
87 message_filter_ = new InternalMessageFilter(this); | 89 message_filter_ = new InternalMessageFilter(this); |
88 channel_->AddFilter(message_filter_); | 90 channel_->AddFilter(message_filter_); |
89 | 91 |
90 base::win::ScopedComPtr<IApplicationActivationManager> activator; | 92 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { |
91 HRESULT hr = activator.CreateInstance(CLSID_ApplicationActivationManager); | 93 base::win::ScopedComPtr<IApplicationActivationManager> activator; |
92 if (SUCCEEDED(hr)) { | 94 HRESULT hr = activator.CreateInstance(CLSID_ApplicationActivationManager); |
93 DWORD pid = 0; | 95 if (SUCCEEDED(hr)) { |
94 // Use the "connect" verb to | 96 DWORD pid = 0; |
95 hr = activator->ActivateApplication( | 97 // Use the "connect" verb to |
96 app_user_model_id.c_str(), kMetroViewerConnectVerb, AO_NONE, &pid); | 98 hr = activator->ActivateApplication( |
| 99 app_user_model_id.c_str(), kMetroViewerConnectVerb, AO_NONE, &pid); |
| 100 } |
| 101 |
| 102 LOG_IF(ERROR, FAILED(hr)) << "Tried and failed to launch Metro Chrome. " |
| 103 << "hr=" << std::hex << hr; |
| 104 } else { |
| 105 // For Windows 7 we need to launch the viewer ourselves. |
| 106 base::FilePath chrome_path; |
| 107 if (!PathService::Get(base::DIR_EXE, &chrome_path)) |
| 108 return false; |
| 109 // TODO(cpu): launch with "-ServerName:DefaultBrowserServer" |
| 110 // note that the viewer might try to launch chrome again. |
| 111 CHECK(false); |
97 } | 112 } |
98 | 113 |
99 LOG_IF(ERROR, FAILED(hr)) << "Tried and failed to launch Metro Chrome. " | |
100 << "hr=" << std::hex << hr; | |
101 | |
102 // Having launched the viewer process, now we wait for it to connect. | 114 // Having launched the viewer process, now we wait for it to connect. |
103 bool success = | 115 bool success = |
104 channel_connected_event_->TimedWait(base::TimeDelta::FromSeconds( | 116 channel_connected_event_->TimedWait(base::TimeDelta::FromSeconds( |
105 kViewerProcessConnectionTimeoutSecs)); | 117 kViewerProcessConnectionTimeoutSecs)); |
106 channel_connected_event_.reset(); | 118 channel_connected_event_.reset(); |
107 return success; | 119 return success; |
108 } | 120 } |
109 | 121 |
110 bool MetroViewerProcessHost::Send(IPC::Message* msg) { | 122 bool MetroViewerProcessHost::Send(IPC::Message* msg) { |
111 return channel_->Send(msg); | 123 return channel_->Send(msg); |
(...skipping 14 matching lines...) Expand all Loading... |
126 return handled ? true : | 138 return handled ? true : |
127 aura::RemoteWindowTreeHostWin::Instance()->OnMessageReceived(message); | 139 aura::RemoteWindowTreeHostWin::Instance()->OnMessageReceived(message); |
128 } | 140 } |
129 | 141 |
130 void MetroViewerProcessHost::NotifyChannelConnected() { | 142 void MetroViewerProcessHost::NotifyChannelConnected() { |
131 if (channel_connected_event_) | 143 if (channel_connected_event_) |
132 channel_connected_event_->Signal(); | 144 channel_connected_event_->Signal(); |
133 } | 145 } |
134 | 146 |
135 } // namespace win8 | 147 } // namespace win8 |
OLD | NEW |