OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 REMOTING_HOST_DESKTOP_SESSION_AGENT_H_ | 5 #ifndef REMOTING_HOST_DESKTOP_SESSION_AGENT_H_ |
6 #define REMOTING_HOST_DESKTOP_SESSION_AGENT_H_ | 6 #define REMOTING_HOST_DESKTOP_SESSION_AGENT_H_ |
7 | 7 |
| 8 #include <list> |
| 9 |
8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
9 #include "base/callback.h" | 11 #include "base/callback.h" |
10 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
11 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
13 #include "ipc/ipc_listener.h" | 15 #include "ipc/ipc_listener.h" |
14 #include "ipc/ipc_platform_file.h" | 16 #include "ipc/ipc_platform_file.h" |
| 17 #include "remoting/base/shared_buffer.h" |
| 18 #include "remoting/base/shared_buffer_factory.h" |
| 19 #include "remoting/host/video_frame_capturer.h" |
| 20 #include "third_party/skia/include/core/SkRect.h" |
15 | 21 |
16 namespace IPC { | 22 namespace IPC { |
17 class ChannelProxy; | 23 class ChannelProxy; |
18 class Message; | 24 class Message; |
19 } // namespace IPC | 25 } // namespace IPC |
20 | 26 |
21 namespace remoting { | 27 namespace remoting { |
22 | 28 |
23 class AutoThreadTaskRunner; | 29 class AutoThreadTaskRunner; |
24 | 30 |
25 // Provides screen/audio capturing and input injection services for | 31 // Provides screen/audio capturing and input injection services for |
26 // the network process. | 32 // the network process. |
27 class DesktopSessionAgent : public IPC::Listener { | 33 class DesktopSessionAgent |
| 34 : public base::RefCountedThreadSafe<DesktopSessionAgent>, |
| 35 public IPC::Listener, |
| 36 public SharedBufferFactory, |
| 37 public VideoFrameCapturer::Delegate { |
28 public: | 38 public: |
29 static scoped_ptr<DesktopSessionAgent> Create( | 39 static scoped_refptr<DesktopSessionAgent> Create( |
30 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, | 40 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, |
31 scoped_refptr<AutoThreadTaskRunner> io_task_runner); | 41 scoped_refptr<AutoThreadTaskRunner> io_task_runner, |
32 | 42 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner); |
33 virtual ~DesktopSessionAgent(); | |
34 | 43 |
35 // IPC::Listener implementation. | 44 // IPC::Listener implementation. |
36 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 45 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
37 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | 46 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
38 virtual void OnChannelError() OVERRIDE; | 47 virtual void OnChannelError() OVERRIDE; |
39 | 48 |
40 // Creates the screen/audio recorders, input stubs and the IPC channel to be | 49 // SharedBufferFactory implementation. |
41 // used to access them. Returns a handle of the client end of the IPC channel | 50 virtual scoped_refptr<SharedBuffer> CreateSharedBuffer(uint32 size) OVERRIDE; |
42 // pipe to be forwarder to the corresponding desktop environment. | 51 virtual void ReleaseSharedBuffer(scoped_refptr<SharedBuffer> buffer) OVERRIDE; |
43 bool Start(const base::Closure& done_task, | 52 |
| 53 // VideoFrameCapturer::Delegate implementation. |
| 54 virtual void OnCaptureCompleted( |
| 55 scoped_refptr<CaptureData> capture_data) OVERRIDE; |
| 56 virtual void OnCursorShapeChanged( |
| 57 scoped_ptr<protocol::CursorShapeInfo> cursor_shape) OVERRIDE; |
| 58 |
| 59 // Creates desktop integration components and a connected IPC channel to be |
| 60 // used to access them. The client end of the channel is returned in |
| 61 // the variable pointed by |desktop_pipe_out|. |
| 62 // |
| 63 // |disconnected_task| is invoked on |caller_task_runner_| to notify |
| 64 // the caller that the network-to-desktop channel has been disconnected. |
| 65 bool Start(const base::Closure& disconnected_task, |
44 IPC::PlatformFileForTransit* desktop_pipe_out); | 66 IPC::PlatformFileForTransit* desktop_pipe_out); |
45 | 67 |
| 68 // Stops the agent asynchronously. |
| 69 void Stop(); |
| 70 |
46 protected: | 71 protected: |
47 DesktopSessionAgent( | 72 DesktopSessionAgent( |
48 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, | 73 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, |
49 scoped_refptr<AutoThreadTaskRunner> io_task_runner); | 74 scoped_refptr<AutoThreadTaskRunner> io_task_runner, |
| 75 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner); |
50 | 76 |
51 // Creates a pre-connected IPC channel to be used to access the screen/audio | 77 friend class base::RefCountedThreadSafe<DesktopSessionAgent>; |
| 78 virtual ~DesktopSessionAgent(); |
| 79 |
| 80 // Creates a connected IPC channel to be used to access the screen/audio |
52 // recorders and input stubs. | 81 // recorders and input stubs. |
53 virtual bool DoCreateNetworkChannel( | 82 virtual bool CreateChannelForNetworkProcess( |
54 IPC::PlatformFileForTransit* client_out, | 83 IPC::PlatformFileForTransit* client_out, |
55 scoped_ptr<IPC::ChannelProxy>* server_out) = 0; | 84 scoped_ptr<IPC::ChannelProxy>* server_out) = 0; |
56 | 85 |
| 86 // Handles CaptureFrame requests from the client. |
| 87 void OnCaptureFrame(); |
| 88 |
| 89 // Handles InvalidateRegion requests from the client. |
| 90 void OnInvalidateRegion(const std::vector<SkIRect>& invalid_rects); |
| 91 |
| 92 // Handles SharedBufferCreated notification from the client. |
| 93 void OnSharedBufferCreated(int id); |
| 94 |
| 95 // Sends a message to the network process. |
| 96 void SendToNetwork(IPC::Message* message); |
| 97 |
| 98 // Posted to |video_capture_task_runner_| task runner to start the video |
| 99 // capturer. |
| 100 void StartVideoCapturer(); |
| 101 |
| 102 // Posted to |video_capture_task_runner_| task runner to stop the video |
| 103 // capturer. |
| 104 void StopVideoCapturer(); |
| 105 |
| 106 // Getters providing access to the task runners for platform-specific derived |
| 107 // classes. |
57 scoped_refptr<AutoThreadTaskRunner> caller_task_runner() const { | 108 scoped_refptr<AutoThreadTaskRunner> caller_task_runner() const { |
58 return caller_task_runner_; | 109 return caller_task_runner_; |
59 } | 110 } |
60 | 111 |
61 scoped_refptr<AutoThreadTaskRunner> io_task_runner() const { | 112 scoped_refptr<AutoThreadTaskRunner> io_task_runner() const { |
62 return io_task_runner_; | 113 return io_task_runner_; |
63 } | 114 } |
64 | 115 |
| 116 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner() const { |
| 117 return video_capture_task_runner_; |
| 118 } |
| 119 |
65 private: | 120 private: |
66 // Task runner on which public methods of this class should be called. | 121 // Task runner on which public methods of this class should be called. |
67 scoped_refptr<AutoThreadTaskRunner> caller_task_runner_; | 122 scoped_refptr<AutoThreadTaskRunner> caller_task_runner_; |
68 | 123 |
69 // Message loop used by the IPC channel. | 124 // Message loop used by the IPC channel. |
70 scoped_refptr<AutoThreadTaskRunner> io_task_runner_; | 125 scoped_refptr<AutoThreadTaskRunner> io_task_runner_; |
71 | 126 |
72 // Run on |caller_task_runner_| to notify the caller that |this| has been | 127 // Task runner dedicated to running themethods of the video capturer. |
73 // stopped. | 128 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner_; |
74 base::Closure done_task_; | 129 |
| 130 // Runs on |caller_task_runner_| to notify the caller that the network-to- |
| 131 // desktop channel has been disconnected. |
| 132 base::Closure disconnected_task_; |
75 | 133 |
76 // IPC channel connecting the desktop process with the network process. | 134 // IPC channel connecting the desktop process with the network process. |
77 scoped_ptr<IPC::ChannelProxy> network_channel_; | 135 scoped_ptr<IPC::ChannelProxy> network_channel_; |
78 | 136 |
| 137 // Next shared buffer ID to be used. |
| 138 int next_shared_buffer_id_; |
| 139 |
| 140 // List of the shared buffers registered via |SharedBufferFactory| interface. |
| 141 typedef std::list<scoped_refptr<SharedBuffer> > SharedBuffers; |
| 142 SharedBuffers shared_buffers_; |
| 143 |
| 144 scoped_ptr<VideoFrameCapturer> video_capturer_; |
| 145 |
79 DISALLOW_COPY_AND_ASSIGN(DesktopSessionAgent); | 146 DISALLOW_COPY_AND_ASSIGN(DesktopSessionAgent); |
80 }; | 147 }; |
81 | 148 |
82 } // namespace remoting | 149 } // namespace remoting |
83 | 150 |
84 #endif // REMOTING_HOST_DESKTOP_SESSION_AGENT_H_ | 151 #endif // REMOTING_HOST_DESKTOP_SESSION_AGENT_H_ |
OLD | NEW |