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/host/shared_buffer_sender.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 SharedBufferSender, | |
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 |
50 // SharedBufferSender implementation. | |
51 virtual void RegisterSharedBuffer( | |
52 scoped_refptr<SharedBuffer> buffer) OVERRIDE; | |
53 virtual void DropSharedBuffer(intptr_t id) OVERRIDE; | |
54 | |
55 // VideoFrameCapturer::Delegate implementation. | |
Wez
2012/11/16 23:37:31
We should follow up to re-name VideoFrameCapturer:
alexeypa (please no reviews)
2012/11/19 21:46:25
Ack.
| |
56 virtual void OnCaptureCompleted( | |
57 scoped_refptr<CaptureData> capture_data) OVERRIDE; | |
58 virtual void OnCursorShapeChanged( | |
59 scoped_ptr<protocol::CursorShapeInfo> cursor_shape) OVERRIDE; | |
60 | |
40 // Creates the screen/audio recorders, input stubs and the IPC channel to be | 61 // Creates the screen/audio recorders, input stubs and the IPC channel to be |
41 // used to access them. Returns a handle of the client end of the IPC channel | 62 // used to access them. Returns a handle of the client end of the IPC channel |
42 // pipe to be forwarder to the corresponding desktop environment. | 63 // pipe to be forwarder to the corresponding desktop environment. |
Wez
2012/11/16 23:37:31
typo: forwarded.
I'd suggest rewording this to ma
alexeypa (please no reviews)
2012/11/19 21:46:25
Done.
| |
43 bool Start(const base::Closure& done_task, | 64 bool Start(const base::Closure& done_task, |
44 IPC::PlatformFileForTransit* desktop_pipe_out); | 65 IPC::PlatformFileForTransit* desktop_pipe_out); |
45 | 66 |
67 // Stops the agent asynchronously. | |
Wez
2012/11/16 23:37:31
How does the caller know when this object is compl
alexeypa (please no reviews)
2012/11/19 21:46:25
I renamed |done_task| so it is not getting associa
| |
68 void Stop(); | |
69 | |
46 protected: | 70 protected: |
47 DesktopSessionAgent( | 71 DesktopSessionAgent( |
48 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, | 72 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, |
49 scoped_refptr<AutoThreadTaskRunner> io_task_runner); | 73 scoped_refptr<AutoThreadTaskRunner> io_task_runner, |
74 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner); | |
75 | |
76 friend class base::RefCountedThreadSafe<DesktopSessionAgent>; | |
77 virtual ~DesktopSessionAgent(); | |
50 | 78 |
51 // Creates a pre-connected IPC channel to be used to access the screen/audio | 79 // Creates a pre-connected IPC channel to be used to access the screen/audio |
Wez
2012/11/16 23:37:31
nit: What does "pre-connected" mean? Do you just
alexeypa (please no reviews)
2012/11/19 21:46:25
Done.
| |
52 // recorders and input stubs. | 80 // recorders and input stubs. |
53 virtual bool DoCreateNetworkChannel( | 81 virtual bool DoCreateNetworkChannel( |
Wez
2012/11/16 23:37:31
nit: CreateChannelForNetworkProcess or similar?
alexeypa (please no reviews)
2012/11/19 21:46:25
Done.
| |
54 IPC::PlatformFileForTransit* client_out, | 82 IPC::PlatformFileForTransit* client_out, |
55 scoped_ptr<IPC::ChannelProxy>* server_out) = 0; | 83 scoped_ptr<IPC::ChannelProxy>* server_out) = 0; |
56 | 84 |
85 void InvalidateRegion(scoped_ptr<SkRegion> invalid_region); | |
Wez
2012/11/16 23:37:31
Why not fold this in to OnInvalidateRegion?
alexeypa (please no reviews)
2012/11/19 21:46:25
To avoid creating a copy of a bunch of rects. OnIn
| |
86 | |
87 // Implements VideoFrameCapturer::CaptureInvalidRegion. | |
Wez
2012/11/16 23:37:31
nit: You mean "Implements the CaptureInvalidRegion
alexeypa (please no reviews)
2012/11/19 21:46:25
Done.
| |
88 void OnCaptureFrame(); | |
89 | |
90 // Implements VideoFrameCapturer::InvalidateRegion. | |
91 void OnInvalidateRegion(const std::vector<SkIRect>& invalid_region); | |
92 | |
93 // Handles the ChromotingNetworkDesktopMsg_SharedBufferRegistered notification | |
94 // from the network process. | |
95 void OnSharedBufferRegistered(intptr_t id); | |
96 | |
97 // Sends a message to the network process. | |
98 void SendToNetwork(IPC::Message* message); | |
99 | |
100 void StartVideoCapturer(); | |
101 void StopVideoCapturer(); | |
Wez
2012/11/16 23:37:31
nit: Add comments to explain the function of these
alexeypa (please no reviews)
2012/11/19 21:46:25
Done. What there methods do is documented by their
Wez
2012/11/20 07:05:39
You only need these methods so you have something
alexeypa (please no reviews)
2012/11/20 20:15:17
Done.
| |
102 | |
57 scoped_refptr<AutoThreadTaskRunner> caller_task_runner() const { | 103 scoped_refptr<AutoThreadTaskRunner> caller_task_runner() const { |
Wez
2012/11/16 23:37:31
Add a comment explaining that these getters provid
alexeypa (please no reviews)
2012/11/19 21:46:25
I don't see any value in such a comment. There are
Wez
2012/11/20 07:05:39
Right; a comment should describe why we need them,
alexeypa (please no reviews)
2012/11/20 20:15:17
I added the comment but I still think it is not su
| |
58 return caller_task_runner_; | 104 return caller_task_runner_; |
59 } | 105 } |
60 | 106 |
61 scoped_refptr<AutoThreadTaskRunner> io_task_runner() const { | 107 scoped_refptr<AutoThreadTaskRunner> io_task_runner() const { |
62 return io_task_runner_; | 108 return io_task_runner_; |
63 } | 109 } |
64 | 110 |
111 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner() const { | |
112 return video_capture_task_runner_; | |
113 } | |
114 | |
65 private: | 115 private: |
66 // Task runner on which public methods of this class should be called. | 116 // Task runner on which public methods of this class should be called. |
67 scoped_refptr<AutoThreadTaskRunner> caller_task_runner_; | 117 scoped_refptr<AutoThreadTaskRunner> caller_task_runner_; |
68 | 118 |
69 // Message loop used by the IPC channel. | 119 // Message loop used by the IPC channel. |
70 scoped_refptr<AutoThreadTaskRunner> io_task_runner_; | 120 scoped_refptr<AutoThreadTaskRunner> io_task_runner_; |
71 | 121 |
122 // Task runner on which video public methods of this class should be called. | |
Wez
2012/11/16 23:37:31
Is this correct? Isn't this the thread on which th
alexeypa (please no reviews)
2012/11/19 21:46:25
Done.
| |
123 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner_; | |
124 | |
72 // Run on |caller_task_runner_| to notify the caller that |this| has been | 125 // Run on |caller_task_runner_| to notify the caller that |this| has been |
73 // stopped. | 126 // stopped. |
74 base::Closure done_task_; | 127 base::Closure done_task_; |
75 | 128 |
76 // IPC channel connecting the desktop process with the network process. | 129 // IPC channel connecting the desktop process with the network process. |
77 scoped_ptr<IPC::ChannelProxy> network_channel_; | 130 scoped_ptr<IPC::ChannelProxy> network_channel_; |
78 | 131 |
132 // List of the shared buffers registered via |SharedBufferSender| interface. | |
133 typedef std::list<scoped_refptr<SharedBuffer> > SharedBuffers; | |
134 SharedBuffers shared_buffers_; | |
135 | |
136 scoped_ptr<VideoFrameCapturer> video_capturer_; | |
137 | |
79 DISALLOW_COPY_AND_ASSIGN(DesktopSessionAgent); | 138 DISALLOW_COPY_AND_ASSIGN(DesktopSessionAgent); |
80 }; | 139 }; |
81 | 140 |
82 } // namespace remoting | 141 } // namespace remoting |
83 | 142 |
84 #endif // REMOTING_HOST_DESKTOP_SESSION_AGENT_H_ | 143 #endif // REMOTING_HOST_DESKTOP_SESSION_AGENT_H_ |
OLD | NEW |