OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ |
6 #define CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ | 6 #define CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <map> | 9 #include <map> |
10 #include <memory> | 10 #include <memory> |
11 #include <set> | |
11 #include <string> | 12 #include <string> |
12 #include <vector> | 13 #include <vector> |
13 | 14 |
14 #include "base/callback.h" | 15 #include "base/callback.h" |
15 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
16 #include "base/containers/hash_tables.h" | 17 #include "base/containers/hash_tables.h" |
17 #include "base/gtest_prod_util.h" | 18 #include "base/gtest_prod_util.h" |
18 #include "base/macros.h" | 19 #include "base/macros.h" |
19 #include "base/memory/linked_ptr.h" | 20 #include "base/memory/linked_ptr.h" |
20 #include "base/memory/scoped_vector.h" | 21 #include "base/memory/scoped_vector.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
41 // It handles Presentation API requests coming from Blink / renderer process | 42 // It handles Presentation API requests coming from Blink / renderer process |
42 // and delegates the requests to the embedder's media router via | 43 // and delegates the requests to the embedder's media router via |
43 // PresentationServiceDelegate. | 44 // PresentationServiceDelegate. |
44 // An instance of this class tied to a RenderFrameHost and listens to events | 45 // An instance of this class tied to a RenderFrameHost and listens to events |
45 // related to the RFH via implementing WebContentsObserver. | 46 // related to the RFH via implementing WebContentsObserver. |
46 // This class is instantiated on-demand via Mojo's ConnectToRemoteService | 47 // This class is instantiated on-demand via Mojo's ConnectToRemoteService |
47 // from the renderer when the first presentation API request is handled. | 48 // from the renderer when the first presentation API request is handled. |
48 class CONTENT_EXPORT PresentationServiceImpl | 49 class CONTENT_EXPORT PresentationServiceImpl |
49 : public NON_EXPORTED_BASE(blink::mojom::PresentationService), | 50 : public NON_EXPORTED_BASE(blink::mojom::PresentationService), |
50 public WebContentsObserver, | 51 public WebContentsObserver, |
51 public PresentationServiceDelegate::Observer { | 52 public PresentationServiceDelegateBase::Observer { |
52 public: | 53 public: |
53 using NewSessionCallback = | 54 using NewSessionCallback = |
54 base::Callback<void(blink::mojom::PresentationSessionInfoPtr, | 55 base::Callback<void(blink::mojom::PresentationSessionInfoPtr, |
55 blink::mojom::PresentationErrorPtr)>; | 56 blink::mojom::PresentationErrorPtr)>; |
56 | 57 |
57 ~PresentationServiceImpl() override; | 58 ~PresentationServiceImpl() override; |
58 | 59 |
59 // Static factory method to create an instance of PresentationServiceImpl. | 60 // Static factory method to create an instance of PresentationServiceImpl. |
60 // |render_frame_host|: The RFH the instance is associated with. | 61 // |render_frame_host|: The RFH the instance is associated with. |
61 // |request|: The instance will be bound to this request. Used for Mojo setup. | 62 // |request|: The instance will be bound to this request. Used for Mojo setup. |
(...skipping 26 matching lines...) Expand all Loading... | |
88 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 89 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
89 ReceiveSessionMessagesAfterReset); | 90 ReceiveSessionMessagesAfterReset); |
90 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 91 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
91 MaxPendingStartSessionRequests); | 92 MaxPendingStartSessionRequests); |
92 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 93 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
93 MaxPendingJoinSessionRequests); | 94 MaxPendingJoinSessionRequests); |
94 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 95 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
95 ListenForConnectionStateChange); | 96 ListenForConnectionStateChange); |
96 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 97 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
97 ListenForConnectionClose); | 98 ListenForConnectionClose); |
99 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | |
100 SetPresentationConnection); | |
101 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | |
102 ReceiverPresentationServiceDelegate); | |
98 | 103 |
99 // Maximum number of pending JoinSession requests at any given time. | 104 // Maximum number of pending JoinSession requests at any given time. |
100 static const int kMaxNumQueuedSessionRequests = 10; | 105 static const int kMaxNumQueuedSessionRequests = 10; |
101 | 106 |
102 using SessionMessagesCallback = | 107 using SessionMessagesCallback = |
103 base::Callback<void(mojo::Array<blink::mojom::SessionMessagePtr>)>; | 108 base::Callback<void(mojo::Array<blink::mojom::SessionMessagePtr>)>; |
104 using SendSessionMessageCallback = base::Callback<void(bool)>; | 109 using SendSessionMessageCallback = base::Callback<void(bool)>; |
105 | 110 |
106 // Listener implementation owned by PresentationServiceImpl. An instance of | 111 // Listener implementation owned by PresentationServiceImpl. An instance of |
107 // this is created when PresentationRequest.getAvailability() is resolved. | 112 // this is created when PresentationRequest.getAvailability() is resolved. |
(...skipping 29 matching lines...) Expand all Loading... | |
137 | 142 |
138 private: | 143 private: |
139 NewSessionCallback callback_; | 144 NewSessionCallback callback_; |
140 | 145 |
141 DISALLOW_COPY_AND_ASSIGN(NewSessionCallbackWrapper); | 146 DISALLOW_COPY_AND_ASSIGN(NewSessionCallbackWrapper); |
142 }; | 147 }; |
143 | 148 |
144 // |render_frame_host|: The RFH this instance is associated with. | 149 // |render_frame_host|: The RFH this instance is associated with. |
145 // |web_contents|: The WebContents to observe. | 150 // |web_contents|: The WebContents to observe. |
146 // |delegate|: Where Presentation API requests are delegated to. Not owned | 151 // |delegate|: Where Presentation API requests are delegated to. Not owned |
147 // by this class. | 152 // by this class. |
imcheng
2016/11/01 17:20:29
Please add documentation for |controller_delegate|
zhaobin
2016/11/02 03:55:47
Done.
| |
148 PresentationServiceImpl( | 153 PresentationServiceImpl( |
149 RenderFrameHost* render_frame_host, | 154 RenderFrameHost* render_frame_host, |
150 WebContents* web_contents, | 155 WebContents* web_contents, |
151 PresentationServiceDelegate* delegate); | 156 ControllerPresentationServiceDelegate* controller_delegate, |
157 ReceiverPresentationServiceDelegate* receiver_delegate); | |
152 | 158 |
153 // PresentationService implementation. | 159 // PresentationService implementation. |
154 void SetDefaultPresentationUrls( | 160 void SetDefaultPresentationUrls( |
155 const std::vector<GURL>& presentation_urls) override; | 161 const std::vector<GURL>& presentation_urls) override; |
156 void SetClient(blink::mojom::PresentationServiceClientPtr client) override; | 162 void SetClient(blink::mojom::PresentationServiceClientPtr client) override; |
157 void ListenForScreenAvailability(const GURL& url) override; | 163 void ListenForScreenAvailability(const GURL& url) override; |
158 void StopListeningForScreenAvailability(const GURL& url) override; | 164 void StopListeningForScreenAvailability(const GURL& url) override; |
159 void StartSession(const std::vector<GURL>& presentation_urls, | 165 void StartSession(const std::vector<GURL>& presentation_urls, |
160 const NewSessionCallback& callback) override; | 166 const NewSessionCallback& callback) override; |
161 void JoinSession(const std::vector<GURL>& presentation_urls, | 167 void JoinSession(const std::vector<GURL>& presentation_urls, |
162 const base::Optional<std::string>& presentation_id, | 168 const base::Optional<std::string>& presentation_id, |
163 const NewSessionCallback& callback) override; | 169 const NewSessionCallback& callback) override; |
164 void SendSessionMessage(blink::mojom::PresentationSessionInfoPtr session_info, | 170 void SendSessionMessage(blink::mojom::PresentationSessionInfoPtr session_info, |
165 blink::mojom::SessionMessagePtr session_message, | 171 blink::mojom::SessionMessagePtr session_message, |
166 const SendSessionMessageCallback& callback) override; | 172 const SendSessionMessageCallback& callback) override; |
167 void CloseConnection(const GURL& presentation_url, | 173 void CloseConnection(const GURL& presentation_url, |
168 const std::string& presentation_id) override; | 174 const std::string& presentation_id) override; |
169 void Terminate(const GURL& presentation_url, | 175 void Terminate(const GURL& presentation_url, |
170 const std::string& presentation_id) override; | 176 const std::string& presentation_id) override; |
171 void ListenForSessionMessages( | 177 void ListenForSessionMessages( |
172 blink::mojom::PresentationSessionInfoPtr session) override; | 178 blink::mojom::PresentationSessionInfoPtr session) override; |
179 void SetPresentationConnection( | |
180 blink::mojom::PresentationSessionInfoPtr session, | |
181 blink::mojom::PresentationConnectionPtr connection) override; | |
173 | 182 |
174 // Creates a binding between this object and |request|. | 183 // Creates a binding between this object and |request|. |
175 void Bind(mojo::InterfaceRequest<blink::mojom::PresentationService> request); | 184 void Bind(mojo::InterfaceRequest<blink::mojom::PresentationService> request); |
176 | 185 |
177 // WebContentsObserver override. | 186 // WebContentsObserver override. |
178 void DidNavigateAnyFrame( | 187 void DidNavigateAnyFrame( |
179 content::RenderFrameHost* render_frame_host, | 188 content::RenderFrameHost* render_frame_host, |
180 const content::LoadCommittedDetails& details, | 189 const content::LoadCommittedDetails& details, |
181 const content::FrameNavigateParams& params) override; | 190 const content::FrameNavigateParams& params) override; |
182 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; | 191 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 void OnJoinSessionError( | 228 void OnJoinSessionError( |
220 int request_session_id, | 229 int request_session_id, |
221 const PresentationError& error); | 230 const PresentationError& error); |
222 void OnSendMessageCallback(bool sent); | 231 void OnSendMessageCallback(bool sent); |
223 | 232 |
224 // Calls to |delegate_| to start listening for state changes for |connection|. | 233 // Calls to |delegate_| to start listening for state changes for |connection|. |
225 // State changes will be returned via |OnConnectionStateChanged|. | 234 // State changes will be returned via |OnConnectionStateChanged|. |
226 void ListenForConnectionStateChange( | 235 void ListenForConnectionStateChange( |
227 const PresentationSessionInfo& connection); | 236 const PresentationSessionInfo& connection); |
228 | 237 |
229 // Passed to embedder's implementation of PresentationServiceDelegate for | |
230 // later invocation when session messages arrive. | |
231 void OnSessionMessages( | 238 void OnSessionMessages( |
232 const content::PresentationSessionInfo& session, | 239 const content::PresentationSessionInfo& session, |
233 const ScopedVector<PresentationSessionMessage>& messages, | 240 const ScopedVector<PresentationSessionMessage>& messages, |
234 bool pass_ownership); | 241 bool pass_ownership); |
235 | 242 |
243 // A callback registered to OffscreenPresentationManager when | |
244 // receiver PSImpl inits. Calls |client_| to create a new | |
245 // PresentationConnection on receiver page. | |
246 void OnReceiverConnectionAvailable( | |
247 const content::PresentationSessionInfo& session_info, | |
248 PresentationConnectionPtr&& controller_connection); | |
249 | |
236 // Associates a JoinSession |callback| with a unique request ID and | 250 // Associates a JoinSession |callback| with a unique request ID and |
237 // stores it in a map. | 251 // stores it in a map. |
238 // Returns a positive value on success. | 252 // Returns a positive value on success. |
239 int RegisterJoinSessionCallback(const NewSessionCallback& callback); | 253 int RegisterJoinSessionCallback(const NewSessionCallback& callback); |
240 | 254 |
241 // Invoked by the embedder's PresentationServiceDelegate when a | 255 // Invoked by the embedder's PresentationServiceDelegate when a |
242 // PresentationConnection's state has changed. | 256 // PresentationConnection's state has changed. |
243 void OnConnectionStateChanged( | 257 void OnConnectionStateChanged( |
244 const PresentationSessionInfo& connection, | 258 const PresentationSessionInfo& connection, |
245 const PresentationConnectionStateChangeInfo& info); | 259 const PresentationConnectionStateChangeInfo& info); |
246 | 260 |
247 // Returns true if this object is associated with |render_frame_host|. | 261 // Returns true if this object is associated with |render_frame_host|. |
248 bool FrameMatches(content::RenderFrameHost* render_frame_host) const; | 262 bool FrameMatches(content::RenderFrameHost* render_frame_host) const; |
249 | 263 |
250 // Embedder-specific delegate to forward Presentation requests to. | 264 PresentationServiceDelegateBase* GetPresentationServiceDelegate(); |
imcheng
2016/11/01 17:20:29
Please add documentation.
zhaobin
2016/11/02 03:55:47
Done.
| |
251 // May be null if embedder does not support Presentation API. | 265 |
252 PresentationServiceDelegate* delegate_; | 266 // Embedder-specific delegate for controller to forward Presentation requests |
267 // to. | |
268 // May be null if current page is receiver page or | |
imcheng
2016/11/01 17:20:29
nit: It is definitely nullptr if either of those a
zhaobin
2016/11/02 03:55:47
Done.
| |
269 // embedder does not support Presentation API . | |
270 ControllerPresentationServiceDelegate* controller_delegate_; | |
imcheng
2016/11/01 17:20:29
* const
zhaobin
2016/11/02 03:55:47
Cannot be const since we set them to nullptr in Re
| |
271 | |
272 // Embedder-specific delegate for receiver to forward Presentation requests | |
273 // to. | |
274 // May be null if current page is receiver page or | |
imcheng
2016/11/01 17:20:29
ditto about nullptr
zhaobin
2016/11/02 03:55:47
Done.
| |
275 // embedder does not support Presentation API. | |
276 ReceiverPresentationServiceDelegate* receiver_delegate_; | |
imcheng
2016/11/01 17:20:29
* const
zhaobin
2016/11/02 03:55:47
Cannot be const since we set them to nullptr in Re
| |
253 | 277 |
254 // Proxy to the PresentationServiceClient to send results (e.g., screen | 278 // Proxy to the PresentationServiceClient to send results (e.g., screen |
255 // availability) to. | 279 // availability) to. |
256 blink::mojom::PresentationServiceClientPtr client_; | 280 blink::mojom::PresentationServiceClientPtr client_; |
257 | 281 |
258 std::vector<GURL> default_presentation_urls_; | 282 std::vector<GURL> default_presentation_urls_; |
259 | 283 |
260 using ScreenAvailabilityListenerMap = | 284 using ScreenAvailabilityListenerMap = |
261 std::map<GURL, std::unique_ptr<ScreenAvailabilityListenerImpl>>; | 285 std::map<GURL, std::unique_ptr<ScreenAvailabilityListenerImpl>>; |
262 ScreenAvailabilityListenerMap screen_availability_listeners_; | 286 ScreenAvailabilityListenerMap screen_availability_listeners_; |
(...skipping 22 matching lines...) Expand all Loading... | |
285 | 309 |
286 // NOTE: Weak pointers must be invalidated before all other member variables. | 310 // NOTE: Weak pointers must be invalidated before all other member variables. |
287 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; | 311 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; |
288 | 312 |
289 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); | 313 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); |
290 }; | 314 }; |
291 | 315 |
292 } // namespace content | 316 } // namespace content |
293 | 317 |
294 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ | 318 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ |
OLD | NEW |