Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1658)

Side by Side Diff: win8/viewer/metro_viewer_process_host.cc

Issue 14629025: Create MetroViewerProcessHost as a common base for TestMetroViewerProcessHost and ChromeMetroViewer… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge before dcommit Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « win8/viewer/metro_viewer_process_host.h ('k') | win8/win8.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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) : owner_(owner) {
27 }
28
29 void MetroViewerProcessHost::InternalMessageFilter::OnChannelConnected(
30 int32 /* peer_pid */) {
31 owner_->NotifyChannelConnected();
32 }
33
34 MetroViewerProcessHost::MetroViewerProcessHost(
35 const std::string& ipc_channel_name,
36 base::SingleThreadTaskRunner* ipc_task_runner) {
37
38 channel_.reset(new IPC::ChannelProxy(
39 ipc_channel_name.c_str(),
40 IPC::Channel::MODE_NAMED_SERVER,
41 this,
42 ipc_task_runner));
43 }
44
45 MetroViewerProcessHost::~MetroViewerProcessHost() {
46 }
47
48 base::ProcessId MetroViewerProcessHost::GetViewerProcessId() {
49 if (channel_)
50 return channel_->peer_pid();
51 return base::kNullProcessId;
52 }
53
54 bool MetroViewerProcessHost::LaunchViewerAndWaitForConnection(
55 const base::string16& app_user_model_id) {
56 DCHECK_EQ(base::kNullProcessId, channel_->peer_pid());
57
58 channel_connected_event_.reset(new base::WaitableEvent(false, false));
59
60 scoped_refptr<InternalMessageFilter> message_filter(
61 new InternalMessageFilter(this));
62 channel_->AddFilter(message_filter);
63
64 base::win::ScopedComPtr<IApplicationActivationManager> activator;
65 HRESULT hr = activator.CreateInstance(CLSID_ApplicationActivationManager);
66 if (SUCCEEDED(hr)) {
67 DWORD pid = 0;
68 hr = activator->ActivateApplication(
69 app_user_model_id.c_str(), L"open", AO_NONE, &pid);
70 }
71
72 LOG_IF(ERROR, FAILED(hr)) << "Tried and failed to launch Metro Chrome. "
73 << "hr=" << std::hex << hr;
74
75 // Having launched the viewer process, now we wait for it to connect.
76 bool success =
77 channel_connected_event_->TimedWait(base::TimeDelta::FromSeconds(60));
78 channel_connected_event_.reset();
79
80 // |message_filter| is only used to signal |channel_connected_event_| above
81 // and can thus be removed after |channel_connected_event_| is no longer
82 // waiting.
83 channel_->RemoveFilter(message_filter);
84 return success;
85 }
86
87 bool MetroViewerProcessHost::Send(IPC::Message* msg) {
88 return channel_->Send(msg);
89 }
90
91 bool MetroViewerProcessHost::OnMessageReceived(
92 const IPC::Message& message) {
93 DCHECK(CalledOnValidThread());
94 bool handled = true;
95 IPC_BEGIN_MESSAGE_MAP(MetroViewerProcessHost, message)
96 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SetTargetSurface, OnSetTargetSurface)
97 IPC_MESSAGE_UNHANDLED(handled = false)
98 IPC_END_MESSAGE_MAP()
99 return handled ? true :
100 aura::RemoteRootWindowHostWin::Instance()->OnMessageReceived(message);
101 }
102
103 void MetroViewerProcessHost::NotifyChannelConnected() {
104 if (channel_connected_event_)
105 channel_connected_event_->Signal();
106 }
107
108 } // namespace win8
OLDNEW
« no previous file with comments | « win8/viewer/metro_viewer_process_host.h ('k') | win8/win8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698