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 #ifndef METRO_VIEWER_PROCESS_HOST_H_ | |
|
robertshield
2013/05/15 21:17:18
WIN8_VIEWER_METRO_VIEWER_PROCESS_HOST_H_
gab
2013/05/21 15:08:12
Done.
| |
| 6 #define METRO_VIEWER_PROCESS_HOST_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/string16.h" | |
| 13 #include "base/threading/non_thread_safe.h" | |
| 14 #include "ipc/ipc_channel_proxy.h" | |
| 15 #include "ipc/ipc_listener.h" | |
| 16 #include "ipc/ipc_sender.h" | |
| 17 #include "ui/gfx/native_widget_types.h" | |
| 18 | |
| 19 namespace base { | |
| 20 class SingleThreadTaskRunner; | |
| 21 class WaitableEvent; | |
| 22 } | |
| 23 | |
| 24 namespace IPC { | |
| 25 class Message; | |
| 26 } | |
| 27 | |
| 28 namespace win8 { | |
| 29 | |
| 30 // Abstract base class for various Metro viewer process host implementations. | |
| 31 class MetroViewerProcessHost : public IPC::Listener, | |
| 32 public IPC::Sender, | |
| 33 public base::NonThreadSafe { | |
| 34 public: | |
| 35 // Initializes a viewer process host over |ipc_channel_name|. The given task | |
| 36 // runner correspond to a thread on which IPC::Channel is created and used | |
| 37 // (e.g. IO thread). Instantly connects to the viewer process if one is | |
| 38 // already connected to |ipc_channel_name|; a viewer can otherwise be | |
| 39 // launched synchronously via LaunchViewerAndWaitForConnection(). | |
| 40 MetroViewerProcessHost(const std::string& ipc_channel_name, | |
| 41 base::SingleThreadTaskRunner* ipc_task_runner); | |
| 42 virtual ~MetroViewerProcessHost(); | |
| 43 | |
| 44 // Returns the process id of the viewer process if one is connected to this | |
| 45 // host, returns base::kNullProcessId otherwise. | |
| 46 base::ProcessId GetViewerProcessId(); | |
| 47 | |
| 48 // Launches the viewer process associated with the given |app_user_model_id| | |
| 49 // and blocks until that viewer process connects or until a timeout is | |
| 50 // reached. Returns true if the viewer process connects before the timeout is | |
| 51 // reached. | |
| 52 bool LaunchViewerAndWaitForConnection( | |
| 53 const base::string16& app_user_model_id); | |
| 54 | |
| 55 private: | |
| 56 // IPC::Sender implementation: | |
| 57 virtual bool Send(IPC::Message* msg) OVERRIDE; | |
| 58 | |
| 59 // IPC::Listener implementation: | |
| 60 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
| 61 virtual void OnChannelError() OVERRIDE = 0; | |
| 62 | |
| 63 // Called over IPC by the viewer process to tell this host that it should be | |
| 64 // be drawing to |target_surface|. | |
| 65 virtual void OnSetTargetSurface(gfx::NativeViewId target_surface) = 0; | |
| 66 | |
| 67 void NotifyChannelConnected(); | |
| 68 | |
| 69 // Inner message filter used to handle connection event on the IPC channel | |
| 70 // proxy's background thread. This prevents consumers of | |
| 71 // MetroViewerProcessHost from having to pump messages on their own message | |
| 72 // loop. | |
| 73 class InternalMessageFilter : public IPC::ChannelProxy::MessageFilter { | |
| 74 public: | |
| 75 InternalMessageFilter(MetroViewerProcessHost* owner); | |
| 76 | |
| 77 // IPC::ChannelProxy::MessageFilter implementation. | |
| 78 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | |
| 79 | |
| 80 private: | |
| 81 MetroViewerProcessHost* owner_; | |
| 82 DISALLOW_COPY_AND_ASSIGN(InternalMessageFilter); | |
| 83 }; | |
| 84 | |
| 85 scoped_ptr<IPC::ChannelProxy> channel_; | |
| 86 scoped_ptr<base::WaitableEvent> channel_connected_event_; | |
| 87 | |
| 88 DISALLOW_COPY_AND_ASSIGN(MetroViewerProcessHost); | |
| 89 }; | |
| 90 | |
| 91 } // namespace win8 | |
| 92 | |
| 93 #endif // METRO_VIEWER_PROCESS_HOST_H_ | |
| OLD | NEW |