Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: content/browser/presentation/presentation_service_impl.h

Issue 2477573002: [Presentation API] (3rd) (1-UA) Split PresentationServiceDelegateImpl(PSDImpl) (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
(...skipping 30 matching lines...) Expand all
41 // It handles Presentation API requests coming from Blink / renderer process 41 // It handles Presentation API requests coming from Blink / renderer process
42 // and delegates the requests to the embedder's media router via 42 // and delegates the requests to the embedder's media router via
43 // PresentationServiceDelegate. 43 // PresentationServiceDelegate.
44 // An instance of this class tied to a RenderFrameHost and listens to events 44 // An instance of this class tied to a RenderFrameHost and listens to events
45 // related to the RFH via implementing WebContentsObserver. 45 // related to the RFH via implementing WebContentsObserver.
46 // This class is instantiated on-demand via Mojo's ConnectToRemoteService 46 // This class is instantiated on-demand via Mojo's ConnectToRemoteService
47 // from the renderer when the first presentation API request is handled. 47 // from the renderer when the first presentation API request is handled.
48 class CONTENT_EXPORT PresentationServiceImpl 48 class CONTENT_EXPORT PresentationServiceImpl
49 : public NON_EXPORTED_BASE(blink::mojom::PresentationService), 49 : public NON_EXPORTED_BASE(blink::mojom::PresentationService),
50 public WebContentsObserver, 50 public WebContentsObserver,
51 public PresentationServiceDelegate::Observer { 51 public PresentationServiceDelegateBase::Observer {
52 public: 52 public:
53 using NewSessionCallback = 53 using NewSessionCallback =
54 base::Callback<void(blink::mojom::PresentationSessionInfoPtr, 54 base::Callback<void(blink::mojom::PresentationSessionInfoPtr,
55 blink::mojom::PresentationErrorPtr)>; 55 blink::mojom::PresentationErrorPtr)>;
56 56
57 ~PresentationServiceImpl() override; 57 ~PresentationServiceImpl() override;
58 58
59 // Static factory method to create an instance of PresentationServiceImpl. 59 // Static factory method to create an instance of PresentationServiceImpl.
60 // |render_frame_host|: The RFH the instance is associated with. 60 // |render_frame_host|: The RFH the instance is associated with.
61 // |request|: The instance will be bound to this request. Used for Mojo setup. 61 // |request|: The instance will be bound to this request. Used for Mojo setup.
(...skipping 26 matching lines...) Expand all
88 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, 88 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest,
89 ReceiveSessionMessagesAfterReset); 89 ReceiveSessionMessagesAfterReset);
90 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, 90 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest,
91 MaxPendingStartSessionRequests); 91 MaxPendingStartSessionRequests);
92 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, 92 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest,
93 MaxPendingJoinSessionRequests); 93 MaxPendingJoinSessionRequests);
94 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, 94 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest,
95 ListenForConnectionStateChange); 95 ListenForConnectionStateChange);
96 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, 96 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest,
97 ListenForConnectionClose); 97 ListenForConnectionClose);
98 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest,
99 SetPresentationConnection);
100 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest,
101 ReceiverPresentationServiceDelegate);
98 102
99 // Maximum number of pending JoinSession requests at any given time. 103 // Maximum number of pending JoinSession requests at any given time.
100 static const int kMaxNumQueuedSessionRequests = 10; 104 static const int kMaxNumQueuedSessionRequests = 10;
101 105
102 using SessionMessagesCallback = 106 using SessionMessagesCallback =
103 base::Callback<void(mojo::Array<blink::mojom::SessionMessagePtr>)>; 107 base::Callback<void(mojo::Array<blink::mojom::SessionMessagePtr>)>;
104 using SendSessionMessageCallback = base::Callback<void(bool)>; 108 using SendSessionMessageCallback = base::Callback<void(bool)>;
105 109
106 // Listener implementation owned by PresentationServiceImpl. An instance of 110 // Listener implementation owned by PresentationServiceImpl. An instance of
107 // this is created when PresentationRequest.getAvailability() is resolved. 111 // this is created when PresentationRequest.getAvailability() is resolved.
(...skipping 28 matching lines...) Expand all
136 blink::mojom::PresentationErrorPtr error); 140 blink::mojom::PresentationErrorPtr error);
137 141
138 private: 142 private:
139 NewSessionCallback callback_; 143 NewSessionCallback callback_;
140 144
141 DISALLOW_COPY_AND_ASSIGN(NewSessionCallbackWrapper); 145 DISALLOW_COPY_AND_ASSIGN(NewSessionCallbackWrapper);
142 }; 146 };
143 147
144 // |render_frame_host|: The RFH this instance is associated with. 148 // |render_frame_host|: The RFH this instance is associated with.
145 // |web_contents|: The WebContents to observe. 149 // |web_contents|: The WebContents to observe.
146 // |delegate|: Where Presentation API requests are delegated to. Not owned 150 // |controller_delegate|: Where Presentation API requests are delegated to in
151 // controller frame. Set to null if current frame is receiver frame. Not owned
152 // by this class.
153 // |receiver_delegate|: Where Presentation API requests are delegated to in
154 // receiver frame. Set to null if current frame is controller frame. Not owned
147 // by this class. 155 // by this class.
148 PresentationServiceImpl( 156 PresentationServiceImpl(
mark a. foltz 2016/11/08 23:40:52 API design opinion: It would be better to make
zhaobin 2016/11/10 04:14:00 Done.
149 RenderFrameHost* render_frame_host, 157 RenderFrameHost* render_frame_host,
150 WebContents* web_contents, 158 WebContents* web_contents,
151 PresentationServiceDelegate* delegate); 159 ControllerPresentationServiceDelegate* controller_delegate,
160 ReceiverPresentationServiceDelegate* receiver_delegate);
152 161
153 // PresentationService implementation. 162 // PresentationService implementation.
154 void SetDefaultPresentationUrls( 163 void SetDefaultPresentationUrls(
155 const std::vector<GURL>& presentation_urls) override; 164 const std::vector<GURL>& presentation_urls) override;
156 void SetClient(blink::mojom::PresentationServiceClientPtr client) override; 165 void SetClient(blink::mojom::PresentationServiceClientPtr client) override;
157 void ListenForScreenAvailability(const GURL& url) override; 166 void ListenForScreenAvailability(const GURL& url) override;
158 void StopListeningForScreenAvailability(const GURL& url) override; 167 void StopListeningForScreenAvailability(const GURL& url) override;
159 void StartSession(const std::vector<GURL>& presentation_urls, 168 void StartSession(const std::vector<GURL>& presentation_urls,
160 const NewSessionCallback& callback) override; 169 const NewSessionCallback& callback) override;
161 void JoinSession(const std::vector<GURL>& presentation_urls, 170 void JoinSession(const std::vector<GURL>& presentation_urls,
162 const base::Optional<std::string>& presentation_id, 171 const base::Optional<std::string>& presentation_id,
163 const NewSessionCallback& callback) override; 172 const NewSessionCallback& callback) override;
164 void SendSessionMessage(blink::mojom::PresentationSessionInfoPtr session_info, 173 void SendSessionMessage(blink::mojom::PresentationSessionInfoPtr session_info,
165 blink::mojom::SessionMessagePtr session_message, 174 blink::mojom::SessionMessagePtr session_message,
166 const SendSessionMessageCallback& callback) override; 175 const SendSessionMessageCallback& callback) override;
167 void CloseConnection(const GURL& presentation_url, 176 void CloseConnection(const GURL& presentation_url,
168 const std::string& presentation_id) override; 177 const std::string& presentation_id) override;
169 void Terminate(const GURL& presentation_url, 178 void Terminate(const GURL& presentation_url,
170 const std::string& presentation_id) override; 179 const std::string& presentation_id) override;
171 void ListenForSessionMessages( 180 void ListenForSessionMessages(
172 blink::mojom::PresentationSessionInfoPtr session) override; 181 blink::mojom::PresentationSessionInfoPtr session) override;
182 void SetPresentationConnection(
183 blink::mojom::PresentationSessionInfoPtr session,
184 blink::mojom::PresentationConnectionPtr connection) override;
173 185
174 // Creates a binding between this object and |request|. 186 // Creates a binding between this object and |request|.
175 void Bind(mojo::InterfaceRequest<blink::mojom::PresentationService> request); 187 void Bind(mojo::InterfaceRequest<blink::mojom::PresentationService> request);
176 188
177 // WebContentsObserver override. 189 // WebContentsObserver override.
178 void DidNavigateAnyFrame( 190 void DidNavigateAnyFrame(
179 content::RenderFrameHost* render_frame_host, 191 content::RenderFrameHost* render_frame_host,
180 const content::LoadCommittedDetails& details, 192 const content::LoadCommittedDetails& details,
181 const content::FrameNavigateParams& params) override; 193 const content::FrameNavigateParams& params) override;
182 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; 194 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 void OnJoinSessionError( 231 void OnJoinSessionError(
220 int request_session_id, 232 int request_session_id,
221 const PresentationError& error); 233 const PresentationError& error);
222 void OnSendMessageCallback(bool sent); 234 void OnSendMessageCallback(bool sent);
223 235
224 // Calls to |delegate_| to start listening for state changes for |connection|. 236 // Calls to |delegate_| to start listening for state changes for |connection|.
225 // State changes will be returned via |OnConnectionStateChanged|. 237 // State changes will be returned via |OnConnectionStateChanged|.
226 void ListenForConnectionStateChange( 238 void ListenForConnectionStateChange(
227 const PresentationSessionInfo& connection); 239 const PresentationSessionInfo& connection);
228 240
229 // Passed to embedder's implementation of PresentationServiceDelegate for
230 // later invocation when session messages arrive.
231 void OnSessionMessages( 241 void OnSessionMessages(
232 const content::PresentationSessionInfo& session, 242 const content::PresentationSessionInfo& session,
233 const ScopedVector<PresentationSessionMessage>& messages, 243 const ScopedVector<PresentationSessionMessage>& messages,
234 bool pass_ownership); 244 bool pass_ownership);
235 245
246 // A callback registered to OffscreenPresentationManager when
247 // receiver PSImpl inits. Calls |client_| to create a new
mark a. foltz 2016/11/08 23:40:52 the PresentationServiceImpl for the presentation r
zhaobin 2016/11/10 04:14:00 Done.
248 // PresentationConnection on receiver page.
249 void OnReceiverConnectionAvailable(
250 const content::PresentationSessionInfo& session_info,
251 PresentationConnectionPtr&& controller_connection);
252
236 // Associates a JoinSession |callback| with a unique request ID and 253 // Associates a JoinSession |callback| with a unique request ID and
237 // stores it in a map. 254 // stores it in a map.
238 // Returns a positive value on success. 255 // Returns a positive value on success.
239 int RegisterJoinSessionCallback(const NewSessionCallback& callback); 256 int RegisterJoinSessionCallback(const NewSessionCallback& callback);
240 257
241 // Invoked by the embedder's PresentationServiceDelegate when a 258 // Invoked by the embedder's PresentationServiceDelegate when a
242 // PresentationConnection's state has changed. 259 // PresentationConnection's state has changed.
243 void OnConnectionStateChanged( 260 void OnConnectionStateChanged(
244 const PresentationSessionInfo& connection, 261 const PresentationSessionInfo& connection,
245 const PresentationConnectionStateChangeInfo& info); 262 const PresentationConnectionStateChangeInfo& info);
246 263
247 // Returns true if this object is associated with |render_frame_host|. 264 // Returns true if this object is associated with |render_frame_host|.
248 bool FrameMatches(content::RenderFrameHost* render_frame_host) const; 265 bool FrameMatches(content::RenderFrameHost* render_frame_host) const;
249 266
250 // Embedder-specific delegate to forward Presentation requests to. 267 // Returns |controller_delegate| if current frame is controller frame; Returns
251 // May be null if embedder does not support Presentation API. 268 // |receiver_delegate| if current frame is receiver frame.
252 PresentationServiceDelegate* delegate_; 269 PresentationServiceDelegateBase* GetPresentationServiceDelegate();
270
271 // Embedder-specific delegate for controller to forward Presentation requests
272 // to. Must be nullptr if current page is receiver page or
273 // embedder does not support Presentation API .
274 ControllerPresentationServiceDelegate* controller_delegate_;
275
276 // Embedder-specific delegate for receiver to forward Presentation requests
277 // to. Must be nullptr if current page is receiver page or
278 // embedder does not support Presentation API.
279 ReceiverPresentationServiceDelegate* receiver_delegate_;
253 280
254 // Proxy to the PresentationServiceClient to send results (e.g., screen 281 // Proxy to the PresentationServiceClient to send results (e.g., screen
255 // availability) to. 282 // availability) to.
256 blink::mojom::PresentationServiceClientPtr client_; 283 blink::mojom::PresentationServiceClientPtr client_;
257 284
258 std::vector<GURL> default_presentation_urls_; 285 std::vector<GURL> default_presentation_urls_;
259 286
260 using ScreenAvailabilityListenerMap = 287 using ScreenAvailabilityListenerMap =
261 std::map<GURL, std::unique_ptr<ScreenAvailabilityListenerImpl>>; 288 std::map<GURL, std::unique_ptr<ScreenAvailabilityListenerImpl>>;
262 ScreenAvailabilityListenerMap screen_availability_listeners_; 289 ScreenAvailabilityListenerMap screen_availability_listeners_;
(...skipping 22 matching lines...) Expand all
285 312
286 // NOTE: Weak pointers must be invalidated before all other member variables. 313 // NOTE: Weak pointers must be invalidated before all other member variables.
287 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; 314 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_;
288 315
289 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); 316 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl);
290 }; 317 };
291 318
292 } // namespace content 319 } // namespace content
293 320
294 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ 321 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698