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" |
| 14 #include "base/process/launch.h" |
13 #include "base/process/process.h" | 15 #include "base/process/process.h" |
14 #include "base/process/process_handle.h" | 16 #include "base/process/process_handle.h" |
15 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
| 18 #include "base/strings/utf_string_conversions.h" |
16 #include "base/synchronization/waitable_event.h" | 19 #include "base/synchronization/waitable_event.h" |
17 #include "base/time/time.h" | 20 #include "base/time/time.h" |
18 #include "base/win/scoped_comptr.h" | 21 #include "base/win/scoped_comptr.h" |
| 22 #include "base/win/windows_version.h" |
| 23 //#include "chrome/common/chrome_constants.h" |
19 #include "ipc/ipc_message.h" | 24 #include "ipc/ipc_message.h" |
20 #include "ipc/ipc_message_macros.h" | 25 #include "ipc/ipc_message_macros.h" |
21 #include "ui/aura/remote_window_tree_host_win.h" | 26 #include "ui/aura/remote_window_tree_host_win.h" |
22 #include "ui/metro_viewer/metro_viewer_messages.h" | 27 #include "ui/metro_viewer/metro_viewer_messages.h" |
23 #include "win8/viewer/metro_viewer_constants.h" | 28 #include "win8/viewer/metro_viewer_constants.h" |
24 | 29 |
25 namespace { | 30 namespace { |
26 | 31 |
27 const int kViewerProcessConnectionTimeoutSecs = 60; | 32 const int kViewerProcessConnectionTimeoutSecs = 60; |
28 | 33 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 85 |
81 bool MetroViewerProcessHost::LaunchViewerAndWaitForConnection( | 86 bool MetroViewerProcessHost::LaunchViewerAndWaitForConnection( |
82 const base::string16& app_user_model_id) { | 87 const base::string16& app_user_model_id) { |
83 DCHECK_EQ(base::kNullProcessId, channel_->peer_pid()); | 88 DCHECK_EQ(base::kNullProcessId, channel_->peer_pid()); |
84 | 89 |
85 channel_connected_event_.reset(new base::WaitableEvent(false, false)); | 90 channel_connected_event_.reset(new base::WaitableEvent(false, false)); |
86 | 91 |
87 message_filter_ = new InternalMessageFilter(this); | 92 message_filter_ = new InternalMessageFilter(this); |
88 channel_->AddFilter(message_filter_); | 93 channel_->AddFilter(message_filter_); |
89 | 94 |
90 base::win::ScopedComPtr<IApplicationActivationManager> activator; | 95 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { |
91 HRESULT hr = activator.CreateInstance(CLSID_ApplicationActivationManager); | 96 base::win::ScopedComPtr<IApplicationActivationManager> activator; |
92 if (SUCCEEDED(hr)) { | 97 HRESULT hr = activator.CreateInstance(CLSID_ApplicationActivationManager); |
93 DWORD pid = 0; | 98 if (SUCCEEDED(hr)) { |
94 // Use the "connect" verb to | 99 DWORD pid = 0; |
95 hr = activator->ActivateApplication( | 100 // Use the "connect" verb to |
96 app_user_model_id.c_str(), kMetroViewerConnectVerb, AO_NONE, &pid); | 101 hr = activator->ActivateApplication( |
| 102 app_user_model_id.c_str(), kMetroViewerConnectVerb, AO_NONE, &pid); |
| 103 |
| 104 if (FAILED(hr)) { |
| 105 LOG(ERROR) << "Tried and failed to launch Metro Chrome. " |
| 106 << "hr=" << std::hex << hr; |
| 107 return false; |
| 108 } |
| 109 } |
| 110 } else { |
| 111 // For Windows 7 we just launch the viewer ourselves here. |
| 112 base::FilePath chrome_path; |
| 113 if (!PathService::Get(base::DIR_EXE, &chrome_path)) |
| 114 return false; |
| 115 // First try and go up a level to find chrome.exe. |
| 116 chrome_path = chrome_path.Append(L"chrome.exe"); |
| 117 if (!base::PathExists(chrome_path)) |
| 118 chrome_path = chrome_path.DirName().DirName().Append(L"chrome.exe"); |
| 119 if (!base::PathExists(chrome_path)) |
| 120 return false; |
| 121 |
| 122 CommandLine cl(chrome_path); |
| 123 cl.AppendArg("-ServerName:DefaultBrowserServer"); |
| 124 cl.AppendSwitch(base::UTF16ToASCII(kMetroViewerConnectVerb)); |
| 125 base::LaunchOptions launch_options; |
| 126 if (!base::LaunchProcess(cl, launch_options, NULL)) |
| 127 return false; |
97 } | 128 } |
98 | 129 |
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. | 130 // Having launched the viewer process, now we wait for it to connect. |
103 bool success = | 131 bool success = |
104 channel_connected_event_->TimedWait(base::TimeDelta::FromSeconds( | 132 channel_connected_event_->TimedWait(base::TimeDelta::FromSeconds( |
105 kViewerProcessConnectionTimeoutSecs)); | 133 kViewerProcessConnectionTimeoutSecs)); |
106 channel_connected_event_.reset(); | 134 channel_connected_event_.reset(); |
107 return success; | 135 return success; |
108 } | 136 } |
109 | 137 |
110 bool MetroViewerProcessHost::Send(IPC::Message* msg) { | 138 bool MetroViewerProcessHost::Send(IPC::Message* msg) { |
111 return channel_->Send(msg); | 139 return channel_->Send(msg); |
(...skipping 14 matching lines...) Expand all Loading... |
126 return handled ? true : | 154 return handled ? true : |
127 aura::RemoteWindowTreeHostWin::Instance()->OnMessageReceived(message); | 155 aura::RemoteWindowTreeHostWin::Instance()->OnMessageReceived(message); |
128 } | 156 } |
129 | 157 |
130 void MetroViewerProcessHost::NotifyChannelConnected() { | 158 void MetroViewerProcessHost::NotifyChannelConnected() { |
131 if (channel_connected_event_) | 159 if (channel_connected_event_) |
132 channel_connected_event_->Signal(); | 160 channel_connected_event_->Signal(); |
133 } | 161 } |
134 | 162 |
135 } // namespace win8 | 163 } // namespace win8 |
OLD | NEW |