| 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 WIN8_VIEWER_METRO_VIEWER_PROCESS_HOST_H_ | |
| 6 #define WIN8_VIEWER_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. NOTE: this assumes that the app referred to by |app_user_model_id| | |
| 52 // is registered as the default browser. | |
| 53 bool LaunchViewerAndWaitForConnection( | |
| 54 const base::string16& app_user_model_id); | |
| 55 | |
| 56 private: | |
| 57 // IPC::Sender implementation: | |
| 58 virtual bool Send(IPC::Message* msg) OVERRIDE; | |
| 59 | |
| 60 // IPC::Listener implementation: | |
| 61 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
| 62 virtual void OnChannelError() OVERRIDE = 0; | |
| 63 | |
| 64 // Called over IPC by the viewer process to tell this host that it should be | |
| 65 // be drawing to |target_surface|. | |
| 66 virtual void OnSetTargetSurface(gfx::NativeViewId target_surface) = 0; | |
| 67 | |
| 68 void NotifyChannelConnected(); | |
| 69 | |
| 70 // Inner message filter used to handle connection event on the IPC channel | |
| 71 // proxy's background thread. This prevents consumers of | |
| 72 // MetroViewerProcessHost from having to pump messages on their own message | |
| 73 // loop. | |
| 74 class InternalMessageFilter : public IPC::ChannelProxy::MessageFilter { | |
| 75 public: | |
| 76 InternalMessageFilter(MetroViewerProcessHost* owner); | |
| 77 | |
| 78 // IPC::ChannelProxy::MessageFilter implementation. | |
| 79 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | |
| 80 | |
| 81 private: | |
| 82 MetroViewerProcessHost* owner_; | |
| 83 DISALLOW_COPY_AND_ASSIGN(InternalMessageFilter); | |
| 84 }; | |
| 85 | |
| 86 scoped_ptr<IPC::ChannelProxy> channel_; | |
| 87 scoped_ptr<base::WaitableEvent> channel_connected_event_; | |
| 88 | |
| 89 DISALLOW_COPY_AND_ASSIGN(MetroViewerProcessHost); | |
| 90 }; | |
| 91 | |
| 92 } // namespace win8 | |
| 93 | |
| 94 #endif // WIN8_VIEWER_METRO_VIEWER_PROCESS_HOST_H_ | |
| OLD | NEW |