Chromium Code Reviews| Index: win8/viewer/metro_viewer_process_host.cc |
| diff --git a/win8/viewer/metro_viewer_process_host.cc b/win8/viewer/metro_viewer_process_host.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4834edf25e7c557022b943b8d290725a38b6d48e |
| --- /dev/null |
| +++ b/win8/viewer/metro_viewer_process_host.cc |
| @@ -0,0 +1,109 @@ |
| +// Copyright (c) 2013 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 "win8/viewer/metro_viewer_process_host.h" |
| + |
| +#include <shlobj.h> |
| + |
| +#include "base/command_line.h" |
| +#include "base/file_util.h" |
| +#include "base/files/file_path.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/process.h" |
| +#include "base/string16.h" |
| +#include "base/synchronization/waitable_event.h" |
| +#include "base/time.h" |
| +#include "base/win/scoped_comptr.h" |
| +#include "ipc/ipc_message.h" |
| +#include "ipc/ipc_message_macros.h" |
| +#include "ui/aura/remote_root_window_host_win.h" |
| +#include "ui/metro_viewer/metro_viewer_messages.h" |
| + |
| +namespace win8 { |
| + |
| +MetroViewerProcessHost::InternalMessageFilter::InternalMessageFilter( |
| + MetroViewerProcessHost* owner) |
| + : owner_(owner) { |
|
robertshield
2013/05/15 21:17:18
don't wrap this line
gab
2013/05/21 15:08:12
Done.
|
| +} |
| + |
| +void MetroViewerProcessHost::InternalMessageFilter::OnChannelConnected( |
| + int32 /* peer_pid */) { |
| + owner_->NotifyChannelConnected(); |
| +} |
| + |
| +MetroViewerProcessHost::MetroViewerProcessHost( |
| + const std::string& ipc_channel_name, |
| + base::SingleThreadTaskRunner* ipc_task_runner) { |
| + |
| + channel_.reset(new IPC::ChannelProxy( |
| + ipc_channel_name.c_str(), |
| + IPC::Channel::MODE_NAMED_SERVER, |
| + this, |
| + ipc_task_runner)); |
| +} |
| + |
| +MetroViewerProcessHost::~MetroViewerProcessHost() { |
| +} |
| + |
| +base::ProcessId MetroViewerProcessHost::GetViewerProcessId() { |
| + if (channel_) |
| + return channel_->peer_pid(); |
| + return base::kNullProcessId; |
| +} |
| + |
| +bool MetroViewerProcessHost::LaunchViewerAndWaitForConnection( |
| + const base::string16& app_user_model_id) { |
| + DCHECK_EQ(base::kNullProcessId, channel_->peer_pid()); |
| + |
| + // Activate the viewer process. NOTE: This assumes that the viewer process is |
| + // 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.
|
| + |
| + channel_connected_event_.reset(new base::WaitableEvent(false, false)); |
| + |
| + scoped_refptr<InternalMessageFilter> message_filter( |
| + new InternalMessageFilter(this)); |
| + channel_->AddFilter(message_filter); |
| + |
| + base::win::ScopedComPtr<IApplicationActivationManager> activator; |
| + HRESULT hr = activator.CreateInstance(CLSID_ApplicationActivationManager); |
| + if (SUCCEEDED(hr)) { |
| + DWORD pid = 0; |
| + hr = activator->ActivateApplication( |
| + app_user_model_id.c_str(), L"open", AO_NONE, &pid); |
| + } |
| + |
| + LOG_IF(ERROR, FAILED(hr)) << "Tried and failed to launch Metro Chrome. " |
| + << "hr=" << std::hex << hr; |
| + |
| + // Having launched the viewer process, now we wait for it to connect. |
| + bool success = |
| + channel_connected_event_->TimedWait(base::TimeDelta::FromSeconds(60)); |
| + channel_connected_event_.reset(); |
| + |
| + 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.
|
| + return success; |
| +} |
| + |
| +bool MetroViewerProcessHost::Send(IPC::Message* msg) { |
| + return channel_->Send(msg); |
| +} |
| + |
| +bool MetroViewerProcessHost::OnMessageReceived( |
| + const IPC::Message& message) { |
| + DCHECK(CalledOnValidThread()); |
| + bool handled = true; |
| + IPC_BEGIN_MESSAGE_MAP(MetroViewerProcessHost, message) |
| + IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SetTargetSurface, OnSetTargetSurface) |
| + IPC_MESSAGE_UNHANDLED(handled = false) |
| + IPC_END_MESSAGE_MAP() |
| + return handled ? true : |
| + aura::RemoteRootWindowHostWin::Instance()->OnMessageReceived(message); |
| +} |
| + |
| +void MetroViewerProcessHost::NotifyChannelConnected() { |
| + if (channel_connected_event_) |
| + channel_connected_event_->Signal(); |
| +} |
| + |
| +} // namespace win8 |