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" | |
21 #include "third_party/skia/include/core/SkRegion.h" | |
15 | 22 |
16 namespace IPC { | 23 namespace IPC { |
17 class ChannelProxy; | 24 class ChannelProxy; |
18 class Message; | 25 class Message; |
19 } // namespace IPC | 26 } // namespace IPC |
20 | 27 |
21 namespace remoting { | 28 namespace remoting { |
22 | 29 |
23 class AutoThreadTaskRunner; | 30 class AutoThreadTaskRunner; |
24 | 31 |
25 // Provides screen/audio capturing and input injection services for | 32 // Provides screen/audio capturing and input injection services for |
26 // the network process. | 33 // the network process. |
27 class DesktopSessionAgent : public IPC::Listener { | 34 class DesktopSessionAgent |
35 : public base::RefCountedThreadSafe<DesktopSessionAgent>, | |
36 public IPC::Listener, | |
37 public SharedBufferFactory, | |
38 public VideoFrameCapturer::Delegate { | |
28 public: | 39 public: |
29 static scoped_ptr<DesktopSessionAgent> Create( | 40 static scoped_refptr<DesktopSessionAgent> Create( |
30 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, | 41 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, |
31 scoped_refptr<AutoThreadTaskRunner> io_task_runner); | 42 scoped_refptr<AutoThreadTaskRunner> io_task_runner, |
32 | 43 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner); |
33 virtual ~DesktopSessionAgent(); | |
34 | 44 |
35 // IPC::Listener implementation. | 45 // IPC::Listener implementation. |
36 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 46 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
37 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | 47 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
38 virtual void OnChannelError() OVERRIDE; | 48 virtual void OnChannelError() OVERRIDE; |
39 | 49 |
40 // Creates the screen/audio recorders, input stubs and the IPC channel to be | 50 // SharedBufferFactory implementation. |
41 // used to access them. Returns a handle of the client end of the IPC channel | 51 virtual scoped_refptr<SharedBuffer> CreateSharedBuffer(uint32 size) OVERRIDE; |
42 // pipe to be forwarder to the corresponding desktop environment. | 52 virtual void ReleaseSharedBuffer(scoped_refptr<SharedBuffer> buffer) OVERRIDE; |
43 bool Start(const base::Closure& done_task, | 53 |
54 // VideoFrameCapturer::Delegate implementation. | |
55 virtual void OnCaptureCompleted( | |
56 scoped_refptr<CaptureData> capture_data) OVERRIDE; | |
57 virtual void OnCursorShapeChanged( | |
58 scoped_ptr<protocol::CursorShapeInfo> cursor_shape) OVERRIDE; | |
59 | |
60 // Creates desktop integration components and a connected IPC channel to be | |
61 // used to access them. The client end of the channel is returned in | |
62 // the variable pointed by |desktop_pipe_out|. | |
63 // | |
64 // |stopped_task| is invoked on |caller_task_runner_| to notify the caller | |
Wez
2012/11/20 07:05:39
nit: Update this comment.
alexeypa (please no reviews)
2012/11/20 20:15:17
Done.
| |
65 // that the network-to-desktop channel has been disconnected. | |
66 bool Start(const base::Closure& disconnected_task, | |
44 IPC::PlatformFileForTransit* desktop_pipe_out); | 67 IPC::PlatformFileForTransit* desktop_pipe_out); |
45 | 68 |
69 // Stops the agent asynchronously. | |
70 void Stop(); | |
71 | |
46 protected: | 72 protected: |
47 DesktopSessionAgent( | 73 DesktopSessionAgent( |
48 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, | 74 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, |
49 scoped_refptr<AutoThreadTaskRunner> io_task_runner); | 75 scoped_refptr<AutoThreadTaskRunner> io_task_runner, |
76 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner); | |
50 | 77 |
51 // Creates a pre-connected IPC channel to be used to access the screen/audio | 78 friend class base::RefCountedThreadSafe<DesktopSessionAgent>; |
79 virtual ~DesktopSessionAgent(); | |
80 | |
81 // Creates a connected IPC channel to be used to access the screen/audio | |
52 // recorders and input stubs. | 82 // recorders and input stubs. |
53 virtual bool DoCreateNetworkChannel( | 83 virtual bool CreateChannelForNetworkProcess( |
54 IPC::PlatformFileForTransit* client_out, | 84 IPC::PlatformFileForTransit* client_out, |
55 scoped_ptr<IPC::ChannelProxy>* server_out) = 0; | 85 scoped_ptr<IPC::ChannelProxy>* server_out) = 0; |
56 | 86 |
87 void InvalidateRegion(scoped_ptr<SkRegion> invalid_region); | |
88 | |
89 // Handles CaptureInvalidRegion requests from the client. | |
Wez
2012/11/20 07:05:39
nit: Update this comment.
alexeypa (please no reviews)
2012/11/20 20:15:17
Done.
| |
90 void OnCaptureFrame(); | |
91 | |
92 // Handles InvalidateRegion requests from the client. | |
93 void OnInvalidateRegion(const std::vector<SkIRect>& invalid_rects); | |
94 | |
95 // Handles the ChromotingNetworkDesktopMsg_SharedBufferCreated notification | |
96 // from the network process. | |
97 void OnSharedBufferCreated(intptr_t id); | |
98 | |
99 // Sends a message to the network process. | |
100 void SendToNetwork(IPC::Message* message); | |
101 | |
102 // Starts the video capturer asynchronously. | |
103 void StartVideoCapturer(); | |
104 | |
105 // Stops the video capturer asynchronously. | |
106 void StopVideoCapturer(); | |
107 | |
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 // List of the shared buffers registered via |SharedBufferFactory| interface. | |
138 typedef std::list<scoped_refptr<SharedBuffer> > SharedBuffers; | |
139 SharedBuffers shared_buffers_; | |
140 | |
141 scoped_ptr<VideoFrameCapturer> video_capturer_; | |
142 | |
79 DISALLOW_COPY_AND_ASSIGN(DesktopSessionAgent); | 143 DISALLOW_COPY_AND_ASSIGN(DesktopSessionAgent); |
80 }; | 144 }; |
81 | 145 |
82 } // namespace remoting | 146 } // namespace remoting |
83 | 147 |
84 #endif // REMOTING_HOST_DESKTOP_SESSION_AGENT_H_ | 148 #endif // REMOTING_HOST_DESKTOP_SESSION_AGENT_H_ |
OLD | NEW |