summaryrefslogtreecommitdiffstats
path: root/ash/test/test_metro_viewer_process_host.h
blob: de0969e3713ec261fe96b66bd7b815d1e89615d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// 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.

#ifndef ASH_TEST_TEST_METRO_VIEWER_PROCESS_HOST_H_
#define ASH_TEST_TEST_METRO_VIEWER_PROCESS_HOST_H_

#include <string>

#include "base/memory/scoped_ptr.h"
#include "base/synchronization/waitable_event.h"
#include "base/threading/non_thread_safe.h"
#include "base/threading/thread.h"
#include "ipc/ipc_channel_proxy.h"
#include "ipc/ipc_listener.h"
#include "ipc/ipc_sender.h"
#include "ui/gfx/native_widget_types.h"

class AcceleratedSurface;

namespace ash {
namespace test {

class TestMetroViewerProcessHost : public IPC::Listener,
                                   public IPC::Sender,
                                   public base::NonThreadSafe {
 public:
  explicit TestMetroViewerProcessHost(const std::string& ipc_channel_name);
  virtual ~TestMetroViewerProcessHost();

  // Launches the viewer process associated with the given |app_user_model_id|
  // and blocks until that viewer process connects or until a timeout is
  // reached. Returns true if the viewer process connects before the timeout is
  // reached.
  bool LaunchViewerAndWaitForConnection(const string16& app_user_model_id);

  // IPC::Sender implementation:
  virtual bool Send(IPC::Message* msg) OVERRIDE;

  // IPC::Listener implementation:
  virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
  virtual void OnChannelError() OVERRIDE;

  bool closed_unexpectedly() { return closed_unexpectedly_; }

 private:
  void OnSetTargetSurface(gfx::NativeViewId target_surface);

  void NotifyChannelConnected();

  // Inner message filter used to handle connection event on the IPC channel
  // proxy's background thread. This prevents consumers of
  // TestMetroViewerProcessHost from having to pump messages on their own
  // message loop.
  class InternalMessageFilter : public IPC::ChannelProxy::MessageFilter {
   public:
    InternalMessageFilter(TestMetroViewerProcessHost* owner);

    // IPC::ChannelProxy::MessageFilter implementation.
    virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;

   private:
    TestMetroViewerProcessHost* owner_;
    DISALLOW_COPY_AND_ASSIGN(InternalMessageFilter);
  };

  // Members related to the IPC channel. Note that the order is important
  // here as ipc_thread_ should be destroyed after channel_.
  base::Thread ipc_thread_;
  scoped_ptr<IPC::ChannelProxy> channel_;
  base::WaitableEvent channel_connected_event_;

  scoped_ptr<AcceleratedSurface> backing_surface;

  bool closed_unexpectedly_;

  DISALLOW_COPY_AND_ASSIGN(TestMetroViewerProcessHost);
};


}  // namespace test
}  // namespace ash

#endif  // ASH_TEST_TEST_METRO_VIEWER_PROCESS_HOST_H_