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

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

Issue 2622993002: [Presentation API] Move presentation.mojom to content/common/presentation (Closed)
Patch Set: Fix presentation_service_delegate. DEPS failure Created 3 years, 11 months 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
« no previous file with comments | « content/browser/DEPS ('k') | content/browser/presentation/presentation_service_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
16 #include "base/containers/hash_tables.h" 16 #include "base/containers/hash_tables.h"
17 #include "base/gtest_prod_util.h" 17 #include "base/gtest_prod_util.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/memory/linked_ptr.h" 19 #include "base/memory/linked_ptr.h"
20 #include "base/memory/scoped_vector.h" 20 #include "base/memory/scoped_vector.h"
21 #include "base/memory/weak_ptr.h" 21 #include "base/memory/weak_ptr.h"
22 #include "base/optional.h" 22 #include "base/optional.h"
23 #include "content/common/content_export.h" 23 #include "content/common/content_export.h"
24 #include "content/common/presentation/presentation.mojom.h"
24 #include "content/public/browser/navigation_details.h" 25 #include "content/public/browser/navigation_details.h"
25 #include "content/public/browser/presentation_screen_availability_listener.h" 26 #include "content/public/browser/presentation_screen_availability_listener.h"
26 #include "content/public/browser/presentation_service_delegate.h" 27 #include "content/public/browser/presentation_service_delegate.h"
27 #include "content/public/browser/web_contents_observer.h" 28 #include "content/public/browser/web_contents_observer.h"
28 #include "content/public/common/frame_navigate_params.h" 29 #include "content/public/common/frame_navigate_params.h"
29 #include "mojo/public/cpp/bindings/binding.h" 30 #include "mojo/public/cpp/bindings/binding.h"
30 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m ojom.h"
31 #include "url/gurl.h" 31 #include "url/gurl.h"
32 32
33 namespace content { 33 namespace content {
34 34
35 struct FrameNavigateParams; 35 struct FrameNavigateParams;
36 struct LoadCommittedDetails; 36 struct LoadCommittedDetails;
37 struct PresentationConnectionMessage; 37 struct PresentationConnectionMessage;
38 class RenderFrameHost; 38 class RenderFrameHost;
39 39
40 // Implementation of Mojo PresentationService. 40 // Implementation of Mojo PresentationService.
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(content::mojom::PresentationService),
50 public WebContentsObserver, 50 public WebContentsObserver,
51 public PresentationServiceDelegate::Observer { 51 public PresentationServiceDelegate::Observer {
52 public: 52 public:
53 using NewSessionCallback = 53 using NewSessionCallback =
54 base::Callback<void(blink::mojom::PresentationSessionInfoPtr, 54 base::Callback<void(content::mojom::PresentationSessionInfoPtr,
55 blink::mojom::PresentationErrorPtr)>; 55 content::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.
62 static void CreateMojoService( 62 static void CreateMojoService(
63 RenderFrameHost* render_frame_host, 63 RenderFrameHost* render_frame_host,
64 mojo::InterfaceRequest<blink::mojom::PresentationService> request); 64 mojo::InterfaceRequest<content::mojom::PresentationService> request);
65 65
66 private: 66 private:
67 friend class PresentationServiceImplTest; 67 friend class PresentationServiceImplTest;
68 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, Reset); 68 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, Reset);
69 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, DidNavigateThisFrame); 69 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, DidNavigateThisFrame);
70 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, 70 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest,
71 DidNavigateOtherFrame); 71 DidNavigateOtherFrame);
72 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, ThisRenderFrameDeleted); 72 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, ThisRenderFrameDeleted);
73 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, 73 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest,
74 OtherRenderFrameDeleted); 74 OtherRenderFrameDeleted);
(...skipping 22 matching lines...) Expand all
97 ListenForConnectionClose); 97 ListenForConnectionClose);
98 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, 98 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest,
99 SetPresentationConnection); 99 SetPresentationConnection);
100 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, 100 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest,
101 ReceiverPresentationServiceDelegate); 101 ReceiverPresentationServiceDelegate);
102 102
103 // Maximum number of pending JoinSession requests at any given time. 103 // Maximum number of pending JoinSession requests at any given time.
104 static const int kMaxNumQueuedSessionRequests = 10; 104 static const int kMaxNumQueuedSessionRequests = 10;
105 105
106 using ConnectionMessagesCallback = 106 using ConnectionMessagesCallback =
107 base::Callback<void(std::vector<blink::mojom::ConnectionMessagePtr>)>; 107 base::Callback<void(std::vector<content::mojom::ConnectionMessagePtr>)>;
108 using SendConnectionMessageCallback = base::Callback<void(bool)>; 108 using SendConnectionMessageCallback = base::Callback<void(bool)>;
109 109
110 // Listener implementation owned by PresentationServiceImpl. An instance of 110 // Listener implementation owned by PresentationServiceImpl. An instance of
111 // this is created when PresentationRequest.getAvailability() is resolved. 111 // this is created when PresentationRequest.getAvailability() is resolved.
112 // The instance receives screen availability results from the embedder and 112 // The instance receives screen availability results from the embedder and
113 // propagates results back to PresentationServiceImpl. 113 // propagates results back to PresentationServiceImpl.
114 class CONTENT_EXPORT ScreenAvailabilityListenerImpl 114 class CONTENT_EXPORT ScreenAvailabilityListenerImpl
115 : public PresentationScreenAvailabilityListener { 115 : public PresentationScreenAvailabilityListener {
116 public: 116 public:
117 ScreenAvailabilityListenerImpl(const GURL& availability_url, 117 ScreenAvailabilityListenerImpl(const GURL& availability_url,
(...skipping 11 matching lines...) Expand all
129 }; 129 };
130 130
131 // Ensures the provided NewSessionCallback is invoked exactly once 131 // Ensures the provided NewSessionCallback is invoked exactly once
132 // before it goes out of scope. 132 // before it goes out of scope.
133 class NewSessionCallbackWrapper { 133 class NewSessionCallbackWrapper {
134 public: 134 public:
135 explicit NewSessionCallbackWrapper( 135 explicit NewSessionCallbackWrapper(
136 const NewSessionCallback& callback); 136 const NewSessionCallback& callback);
137 ~NewSessionCallbackWrapper(); 137 ~NewSessionCallbackWrapper();
138 138
139 void Run(blink::mojom::PresentationSessionInfoPtr session, 139 void Run(content::mojom::PresentationSessionInfoPtr session,
140 blink::mojom::PresentationErrorPtr error); 140 content::mojom::PresentationErrorPtr error);
141 141
142 private: 142 private:
143 NewSessionCallback callback_; 143 NewSessionCallback callback_;
144 144
145 DISALLOW_COPY_AND_ASSIGN(NewSessionCallbackWrapper); 145 DISALLOW_COPY_AND_ASSIGN(NewSessionCallbackWrapper);
146 }; 146 };
147 147
148 // |render_frame_host|: The RFH this instance is associated with. 148 // |render_frame_host|: The RFH this instance is associated with.
149 // |web_contents|: The WebContents to observe. 149 // |web_contents|: The WebContents to observe.
150 // |controller_delegate|: Where Presentation API requests are delegated to in 150 // |controller_delegate|: Where Presentation API requests are delegated to in
151 // controller frame. Set to nullptr if current frame is receiver frame. Not 151 // controller frame. Set to nullptr if current frame is receiver frame. Not
152 // owned by this class. 152 // owned by this class.
153 // |receiver_delegate|: Where Presentation API requests are delegated to in 153 // |receiver_delegate|: Where Presentation API requests are delegated to in
154 // receiver frame. Set to nullptr if current frame is controller frame. Not 154 // receiver frame. Set to nullptr if current frame is controller frame. Not
155 // owned by this class. 155 // owned by this class.
156 PresentationServiceImpl( 156 PresentationServiceImpl(
157 RenderFrameHost* render_frame_host, 157 RenderFrameHost* render_frame_host,
158 WebContents* web_contents, 158 WebContents* web_contents,
159 ControllerPresentationServiceDelegate* controller_delegate, 159 ControllerPresentationServiceDelegate* controller_delegate,
160 ReceiverPresentationServiceDelegate* receiver_delegate); 160 ReceiverPresentationServiceDelegate* receiver_delegate);
161 161
162 // PresentationService implementation. 162 // PresentationService implementation.
163 void SetDefaultPresentationUrls( 163 void SetDefaultPresentationUrls(
164 const std::vector<GURL>& presentation_urls) override; 164 const std::vector<GURL>& presentation_urls) override;
165 void SetClient(blink::mojom::PresentationServiceClientPtr client) override; 165 void SetClient(content::mojom::PresentationServiceClientPtr client) override;
166 void ListenForScreenAvailability(const GURL& url) override; 166 void ListenForScreenAvailability(const GURL& url) override;
167 void StopListeningForScreenAvailability(const GURL& url) override; 167 void StopListeningForScreenAvailability(const GURL& url) override;
168 void StartSession(const std::vector<GURL>& presentation_urls, 168 void StartSession(const std::vector<GURL>& presentation_urls,
169 const NewSessionCallback& callback) override; 169 const NewSessionCallback& callback) override;
170 void JoinSession(const std::vector<GURL>& presentation_urls, 170 void JoinSession(const std::vector<GURL>& presentation_urls,
171 const base::Optional<std::string>& presentation_id, 171 const base::Optional<std::string>& presentation_id,
172 const NewSessionCallback& callback) override; 172 const NewSessionCallback& callback) override;
173 void SendConnectionMessage( 173 void SendConnectionMessage(
174 blink::mojom::PresentationSessionInfoPtr session_info, 174 content::mojom::PresentationSessionInfoPtr session_info,
175 blink::mojom::ConnectionMessagePtr connection_message, 175 content::mojom::ConnectionMessagePtr connection_message,
176 const SendConnectionMessageCallback& callback) override; 176 const SendConnectionMessageCallback& callback) override;
177 void CloseConnection(const GURL& presentation_url, 177 void CloseConnection(const GURL& presentation_url,
178 const std::string& presentation_id) override; 178 const std::string& presentation_id) override;
179 void Terminate(const GURL& presentation_url, 179 void Terminate(const GURL& presentation_url,
180 const std::string& presentation_id) override; 180 const std::string& presentation_id) override;
181 void ListenForConnectionMessages( 181 void ListenForConnectionMessages(
182 blink::mojom::PresentationSessionInfoPtr session) override; 182 content::mojom::PresentationSessionInfoPtr session) override;
183 void SetPresentationConnection( 183 void SetPresentationConnection(
184 blink::mojom::PresentationSessionInfoPtr session, 184 content::mojom::PresentationSessionInfoPtr session,
185 blink::mojom::PresentationConnectionPtr controller_connection_ptr, 185 content::mojom::PresentationConnectionPtr controller_connection_ptr,
186 blink::mojom::PresentationConnectionRequest receiver_connection_request) 186 content::mojom::PresentationConnectionRequest receiver_connection_request)
187 override; 187 override;
188 188
189 // Creates a binding between this object and |request|. 189 // Creates a binding between this object and |request|.
190 void Bind(mojo::InterfaceRequest<blink::mojom::PresentationService> request); 190 void Bind(
191 mojo::InterfaceRequest<content::mojom::PresentationService> request);
191 192
192 // WebContentsObserver override. 193 // WebContentsObserver override.
193 void DidNavigateAnyFrame( 194 void DidNavigateAnyFrame(
194 content::RenderFrameHost* render_frame_host, 195 content::RenderFrameHost* render_frame_host,
195 const content::LoadCommittedDetails& details, 196 const content::LoadCommittedDetails& details,
196 const content::FrameNavigateParams& params) override; 197 const content::FrameNavigateParams& params) override;
197 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; 198 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
198 void WebContentsDestroyed() override; 199 void WebContentsDestroyed() override;
199 200
200 // PresentationServiceDelegate::Observer 201 // PresentationServiceDelegate::Observer
201 void OnDelegateDestroyed() override; 202 void OnDelegateDestroyed() override;
202 203
203 // Passed to embedder's implementation of PresentationServiceDelegate for 204 // Passed to embedder's implementation of PresentationServiceDelegate for
204 // later invocation when default presentation has started. 205 // later invocation when default presentation has started.
205 void OnDefaultPresentationStarted( 206 void OnDefaultPresentationStarted(
206 const PresentationSessionInfo& session_info); 207 const PresentationSessionInfo& session_info);
207 208
208 // Finds the callback from |pending_join_session_cbs_| using 209 // Finds the callback from |pending_join_session_cbs_| using
209 // |request_session_id|. 210 // |request_session_id|.
210 // If it exists, invoke it with |session| and |error|, then erase it from 211 // If it exists, invoke it with |session| and |error|, then erase it from
211 // |pending_join_session_cbs_|. 212 // |pending_join_session_cbs_|.
212 // Returns true if the callback was found. 213 // Returns true if the callback was found.
213 bool RunAndEraseJoinSessionMojoCallback( 214 bool RunAndEraseJoinSessionMojoCallback(
214 int request_session_id, 215 int request_session_id,
215 blink::mojom::PresentationSessionInfoPtr session, 216 content::mojom::PresentationSessionInfoPtr session,
216 blink::mojom::PresentationErrorPtr error); 217 content::mojom::PresentationErrorPtr error);
217 218
218 // Removes all listeners and resets default presentation URL on this instance 219 // Removes all listeners and resets default presentation URL on this instance
219 // and informs the PresentationServiceDelegate of such. 220 // and informs the PresentationServiceDelegate of such.
220 void Reset(); 221 void Reset();
221 222
222 // These functions are bound as base::Callbacks and passed to 223 // These functions are bound as base::Callbacks and passed to
223 // embedder's implementation of PresentationServiceDelegate for later 224 // embedder's implementation of PresentationServiceDelegate for later
224 // invocation. 225 // invocation.
225 void OnStartSessionSucceeded( 226 void OnStartSessionSucceeded(
226 int request_session_id, 227 int request_session_id,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 // embedder does not support Presentation API . 282 // embedder does not support Presentation API .
282 ControllerPresentationServiceDelegate* controller_delegate_; 283 ControllerPresentationServiceDelegate* controller_delegate_;
283 284
284 // Embedder-specific delegate for receiver to forward Presentation requests 285 // Embedder-specific delegate for receiver to forward Presentation requests
285 // to. Must be nullptr if current page is receiver page or 286 // to. Must be nullptr if current page is receiver page or
286 // embedder does not support Presentation API. 287 // embedder does not support Presentation API.
287 ReceiverPresentationServiceDelegate* receiver_delegate_; 288 ReceiverPresentationServiceDelegate* receiver_delegate_;
288 289
289 // Proxy to the PresentationServiceClient to send results (e.g., screen 290 // Proxy to the PresentationServiceClient to send results (e.g., screen
290 // availability) to. 291 // availability) to.
291 blink::mojom::PresentationServiceClientPtr client_; 292 content::mojom::PresentationServiceClientPtr client_;
292 293
293 std::vector<GURL> default_presentation_urls_; 294 std::vector<GURL> default_presentation_urls_;
294 295
295 using ScreenAvailabilityListenerMap = 296 using ScreenAvailabilityListenerMap =
296 std::map<GURL, std::unique_ptr<ScreenAvailabilityListenerImpl>>; 297 std::map<GURL, std::unique_ptr<ScreenAvailabilityListenerImpl>>;
297 ScreenAvailabilityListenerMap screen_availability_listeners_; 298 ScreenAvailabilityListenerMap screen_availability_listeners_;
298 299
299 // For StartSession requests. 300 // For StartSession requests.
300 // Set to a positive value when a StartSession request is being processed. 301 // Set to a positive value when a StartSession request is being processed.
301 int start_session_request_id_; 302 int start_session_request_id_;
302 std::unique_ptr<NewSessionCallbackWrapper> pending_start_session_cb_; 303 std::unique_ptr<NewSessionCallbackWrapper> pending_start_session_cb_;
303 304
304 // For JoinSession requests. 305 // For JoinSession requests.
305 base::hash_map<int, linked_ptr<NewSessionCallbackWrapper>> 306 base::hash_map<int, linked_ptr<NewSessionCallbackWrapper>>
306 pending_join_session_cbs_; 307 pending_join_session_cbs_;
307 308
308 // RAII binding of |this| to an Presentation interface request. 309 // RAII binding of |this| to an Presentation interface request.
309 // The binding is removed when binding_ is cleared or goes out of scope. 310 // The binding is removed when binding_ is cleared or goes out of scope.
310 std::unique_ptr<mojo::Binding<blink::mojom::PresentationService>> binding_; 311 std::unique_ptr<mojo::Binding<content::mojom::PresentationService>> binding_;
311 312
312 // There can be only one send message request at a time. 313 // There can be only one send message request at a time.
313 std::unique_ptr<SendConnectionMessageCallback> send_message_callback_; 314 std::unique_ptr<SendConnectionMessageCallback> send_message_callback_;
314 315
315 std::unique_ptr<ConnectionMessagesCallback> on_connection_messages_callback_; 316 std::unique_ptr<ConnectionMessagesCallback> on_connection_messages_callback_;
316 317
317 // ID of the RenderFrameHost this object is associated with. 318 // ID of the RenderFrameHost this object is associated with.
318 int render_process_id_; 319 int render_process_id_;
319 int render_frame_id_; 320 int render_frame_id_;
320 321
321 // NOTE: Weak pointers must be invalidated before all other member variables. 322 // NOTE: Weak pointers must be invalidated before all other member variables.
322 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; 323 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_;
323 324
324 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); 325 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl);
325 }; 326 };
326 327
327 } // namespace content 328 } // namespace content
328 329
329 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ 330 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_
OLDNEW
« no previous file with comments | « content/browser/DEPS ('k') | content/browser/presentation/presentation_service_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698