| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef ASH_TEST_TEST_METRO_VIEWER_PROCESS_HOST_H_ | 5 #ifndef ASH_TEST_TEST_METRO_VIEWER_PROCESS_HOST_H_ |
| 6 #define ASH_TEST_TEST_METRO_VIEWER_PROCESS_HOST_H_ | 6 #define ASH_TEST_TEST_METRO_VIEWER_PROCESS_HOST_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "win8/viewer/metro_viewer_process_host.h" |
| 11 #include "base/synchronization/waitable_event.h" | |
| 12 #include "base/threading/non_thread_safe.h" | |
| 13 #include "base/threading/thread.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 | 11 |
| 19 class AcceleratedSurface; | 12 class AcceleratedSurface; |
| 20 | 13 |
| 21 namespace ash { | 14 namespace ash { |
| 22 namespace test { | 15 namespace test { |
| 23 | 16 |
| 24 class TestMetroViewerProcessHost : public IPC::Listener, | 17 class TestMetroViewerProcessHost : public win8::MetroViewerProcessHost { |
| 25 public IPC::Sender, | |
| 26 public base::NonThreadSafe { | |
| 27 public: | 18 public: |
| 28 explicit TestMetroViewerProcessHost(const std::string& ipc_channel_name); | 19 TestMetroViewerProcessHost(const std::string& ipc_channel_name, |
| 20 base::SingleThreadTaskRunner* ipc_task_runner); |
| 29 virtual ~TestMetroViewerProcessHost(); | 21 virtual ~TestMetroViewerProcessHost(); |
| 30 | 22 |
| 31 // Launches the viewer process associated with the given |app_user_model_id| | |
| 32 // and blocks until that viewer process connects or until a timeout is | |
| 33 // reached. Returns true if the viewer process connects before the timeout is | |
| 34 // reached. | |
| 35 bool LaunchViewerAndWaitForConnection( | |
| 36 const base::string16& app_user_model_id); | |
| 37 | |
| 38 // IPC::Sender implementation: | |
| 39 virtual bool Send(IPC::Message* msg) OVERRIDE; | |
| 40 | |
| 41 // IPC::Listener implementation: | |
| 42 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
| 43 virtual void OnChannelError() OVERRIDE; | |
| 44 | |
| 45 bool closed_unexpectedly() { return closed_unexpectedly_; } | 23 bool closed_unexpectedly() { return closed_unexpectedly_; } |
| 46 | 24 |
| 47 private: | 25 private: |
| 48 void OnSetTargetSurface(gfx::NativeViewId target_surface); | 26 // win8::MetroViewerProcessHost implementation |
| 49 | 27 virtual void OnChannelError() OVERRIDE; |
| 50 void NotifyChannelConnected(); | 28 virtual void OnSetTargetSurface(gfx::NativeViewId target_surface) OVERRIDE; |
| 51 | |
| 52 // Inner message filter used to handle connection event on the IPC channel | |
| 53 // proxy's background thread. This prevents consumers of | |
| 54 // TestMetroViewerProcessHost from having to pump messages on their own | |
| 55 // message loop. | |
| 56 class InternalMessageFilter : public IPC::ChannelProxy::MessageFilter { | |
| 57 public: | |
| 58 InternalMessageFilter(TestMetroViewerProcessHost* owner); | |
| 59 | |
| 60 // IPC::ChannelProxy::MessageFilter implementation. | |
| 61 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | |
| 62 | |
| 63 private: | |
| 64 TestMetroViewerProcessHost* owner_; | |
| 65 DISALLOW_COPY_AND_ASSIGN(InternalMessageFilter); | |
| 66 }; | |
| 67 | |
| 68 // Members related to the IPC channel. Note that the order is important | |
| 69 // here as ipc_thread_ should be destroyed after channel_. | |
| 70 base::Thread ipc_thread_; | |
| 71 scoped_ptr<IPC::ChannelProxy> channel_; | |
| 72 base::WaitableEvent channel_connected_event_; | |
| 73 | 29 |
| 74 scoped_ptr<AcceleratedSurface> backing_surface; | 30 scoped_ptr<AcceleratedSurface> backing_surface; |
| 75 | 31 |
| 76 bool closed_unexpectedly_; | 32 bool closed_unexpectedly_; |
| 77 | 33 |
| 78 DISALLOW_COPY_AND_ASSIGN(TestMetroViewerProcessHost); | 34 DISALLOW_COPY_AND_ASSIGN(TestMetroViewerProcessHost); |
| 79 }; | 35 }; |
| 80 | 36 |
| 81 | 37 |
| 82 } // namespace test | 38 } // namespace test |
| 83 } // namespace ash | 39 } // namespace ash |
| 84 | 40 |
| 85 #endif // ASH_TEST_TEST_METRO_VIEWER_PROCESS_HOST_H_ | 41 #endif // ASH_TEST_TEST_METRO_VIEWER_PROCESS_HOST_H_ |
| OLD | NEW |