Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "win8/viewer/metro_viewer_process_host.h" | |
| 6 | |
| 7 #include <shlobj.h> | |
| 8 | |
| 9 #include "base/command_line.h" | |
| 10 #include "base/file_util.h" | |
| 11 #include "base/files/file_path.h" | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/process.h" | |
| 14 #include "base/string16.h" | |
| 15 #include "base/synchronization/waitable_event.h" | |
| 16 #include "base/time.h" | |
| 17 #include "base/win/scoped_comptr.h" | |
| 18 #include "ipc/ipc_message.h" | |
| 19 #include "ipc/ipc_message_macros.h" | |
| 20 #include "ui/aura/remote_root_window_host_win.h" | |
| 21 #include "ui/metro_viewer/metro_viewer_messages.h" | |
| 22 | |
| 23 namespace win8 { | |
| 24 | |
| 25 MetroViewerProcessHost::InternalMessageFilter::InternalMessageFilter( | |
| 26 MetroViewerProcessHost* owner) | |
| 27 : owner_(owner) { | |
|
robertshield
2013/05/15 21:17:18
don't wrap this line
gab
2013/05/21 15:08:12
Done.
| |
| 28 } | |
| 29 | |
| 30 void MetroViewerProcessHost::InternalMessageFilter::OnChannelConnected( | |
| 31 int32 /* peer_pid */) { | |
| 32 owner_->NotifyChannelConnected(); | |
| 33 } | |
| 34 | |
| 35 MetroViewerProcessHost::MetroViewerProcessHost( | |
| 36 const std::string& ipc_channel_name, | |
| 37 base::SingleThreadTaskRunner* ipc_task_runner) { | |
| 38 | |
| 39 channel_.reset(new IPC::ChannelProxy( | |
| 40 ipc_channel_name.c_str(), | |
| 41 IPC::Channel::MODE_NAMED_SERVER, | |
| 42 this, | |
| 43 ipc_task_runner)); | |
| 44 } | |
| 45 | |
| 46 MetroViewerProcessHost::~MetroViewerProcessHost() { | |
| 47 } | |
| 48 | |
| 49 base::ProcessId MetroViewerProcessHost::GetViewerProcessId() { | |
| 50 if (channel_) | |
| 51 return channel_->peer_pid(); | |
| 52 return base::kNullProcessId; | |
| 53 } | |
| 54 | |
| 55 bool MetroViewerProcessHost::LaunchViewerAndWaitForConnection( | |
| 56 const base::string16& app_user_model_id) { | |
| 57 DCHECK_EQ(base::kNullProcessId, channel_->peer_pid()); | |
| 58 | |
| 59 // Activate the viewer process. NOTE: This assumes that the viewer process is | |
| 60 // registered as the default browser using the provided |app_user_model_id|. | |
|
robertshield
2013/05/15 21:17:18
Document this assumption in the header and reword
gab
2013/05/21 15:08:12
Done.
| |
| 61 | |
| 62 channel_connected_event_.reset(new base::WaitableEvent(false, false)); | |
| 63 | |
| 64 scoped_refptr<InternalMessageFilter> message_filter( | |
| 65 new InternalMessageFilter(this)); | |
| 66 channel_->AddFilter(message_filter); | |
| 67 | |
| 68 base::win::ScopedComPtr<IApplicationActivationManager> activator; | |
| 69 HRESULT hr = activator.CreateInstance(CLSID_ApplicationActivationManager); | |
| 70 if (SUCCEEDED(hr)) { | |
| 71 DWORD pid = 0; | |
| 72 hr = activator->ActivateApplication( | |
| 73 app_user_model_id.c_str(), L"open", AO_NONE, &pid); | |
| 74 } | |
| 75 | |
| 76 LOG_IF(ERROR, FAILED(hr)) << "Tried and failed to launch Metro Chrome. " | |
| 77 << "hr=" << std::hex << hr; | |
| 78 | |
| 79 // Having launched the viewer process, now we wait for it to connect. | |
| 80 bool success = | |
| 81 channel_connected_event_->TimedWait(base::TimeDelta::FromSeconds(60)); | |
| 82 channel_connected_event_.reset(); | |
| 83 | |
| 84 channel_->RemoveFilter(message_filter); | |
|
robertshield
2013/05/15 21:17:18
Why is the message filter being removed?
gab
2013/05/21 15:08:12
Because it's only there to listen to the connectio
robertshield
2013/05/21 15:15:16
Ok, please add a comment to that effect.
gab
2013/05/21 15:23:27
Done.
| |
| 85 return success; | |
| 86 } | |
| 87 | |
| 88 bool MetroViewerProcessHost::Send(IPC::Message* msg) { | |
| 89 return channel_->Send(msg); | |
| 90 } | |
| 91 | |
| 92 bool MetroViewerProcessHost::OnMessageReceived( | |
| 93 const IPC::Message& message) { | |
| 94 DCHECK(CalledOnValidThread()); | |
| 95 bool handled = true; | |
| 96 IPC_BEGIN_MESSAGE_MAP(MetroViewerProcessHost, message) | |
| 97 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SetTargetSurface, OnSetTargetSurface) | |
| 98 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 99 IPC_END_MESSAGE_MAP() | |
| 100 return handled ? true : | |
| 101 aura::RemoteRootWindowHostWin::Instance()->OnMessageReceived(message); | |
| 102 } | |
| 103 | |
| 104 void MetroViewerProcessHost::NotifyChannelConnected() { | |
| 105 if (channel_connected_event_) | |
| 106 channel_connected_event_->Signal(); | |
| 107 } | |
| 108 | |
| 109 } // namespace win8 | |
| OLD | NEW |