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

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 #include and OWNERS 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
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 18 matching lines...) Expand all
93 MaxPendingJoinSessionRequests); 93 MaxPendingJoinSessionRequests);
94 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, 94 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest,
95 ListenForConnectionStateChangeAndChangeState); 95 ListenForConnectionStateChangeAndChangeState);
96 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, 96 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest,
97 ListenForConnectionClose); 97 ListenForConnectionClose);
98 98
99 // Maximum number of pending JoinSession requests at any given time. 99 // Maximum number of pending JoinSession requests at any given time.
100 static const int kMaxNumQueuedSessionRequests = 10; 100 static const int kMaxNumQueuedSessionRequests = 10;
101 101
102 using ConnectionMessagesCallback = 102 using ConnectionMessagesCallback =
103 base::Callback<void(std::vector<blink::mojom::ConnectionMessagePtr>)>; 103 base::Callback<void(std::vector<content::mojom::ConnectionMessagePtr>)>;
104 using SendConnectionMessageCallback = base::Callback<void(bool)>; 104 using SendConnectionMessageCallback = base::Callback<void(bool)>;
105 105
106 // Listener implementation owned by PresentationServiceImpl. An instance of 106 // Listener implementation owned by PresentationServiceImpl. An instance of
107 // this is created when PresentationRequest.getAvailability() is resolved. 107 // this is created when PresentationRequest.getAvailability() is resolved.
108 // The instance receives screen availability results from the embedder and 108 // The instance receives screen availability results from the embedder and
109 // propagates results back to PresentationServiceImpl. 109 // propagates results back to PresentationServiceImpl.
110 class CONTENT_EXPORT ScreenAvailabilityListenerImpl 110 class CONTENT_EXPORT ScreenAvailabilityListenerImpl
111 : public PresentationScreenAvailabilityListener { 111 : public PresentationScreenAvailabilityListener {
112 public: 112 public:
113 ScreenAvailabilityListenerImpl(const GURL& availability_url, 113 ScreenAvailabilityListenerImpl(const GURL& availability_url,
(...skipping 11 matching lines...) Expand all
125 }; 125 };
126 126
127 // Ensures the provided NewSessionCallback is invoked exactly once 127 // Ensures the provided NewSessionCallback is invoked exactly once
128 // before it goes out of scope. 128 // before it goes out of scope.
129 class NewSessionCallbackWrapper { 129 class NewSessionCallbackWrapper {
130 public: 130 public:
131 explicit NewSessionCallbackWrapper( 131 explicit NewSessionCallbackWrapper(
132 const NewSessionCallback& callback); 132 const NewSessionCallback& callback);
133 ~NewSessionCallbackWrapper(); 133 ~NewSessionCallbackWrapper();
134 134
135 void Run(blink::mojom::PresentationSessionInfoPtr session, 135 void Run(content::mojom::PresentationSessionInfoPtr session,
136 blink::mojom::PresentationErrorPtr error); 136 content::mojom::PresentationErrorPtr error);
137 137
138 private: 138 private:
139 NewSessionCallback callback_; 139 NewSessionCallback callback_;
140 140
141 DISALLOW_COPY_AND_ASSIGN(NewSessionCallbackWrapper); 141 DISALLOW_COPY_AND_ASSIGN(NewSessionCallbackWrapper);
142 }; 142 };
143 143
144 // |render_frame_host|: The RFH this instance is associated with. 144 // |render_frame_host|: The RFH this instance is associated with.
145 // |web_contents|: The WebContents to observe. 145 // |web_contents|: The WebContents to observe.
146 // |delegate|: Where Presentation API requests are delegated to. Not owned 146 // |delegate|: Where Presentation API requests are delegated to. Not owned
147 // by this class. 147 // by this class.
148 PresentationServiceImpl( 148 PresentationServiceImpl(
149 RenderFrameHost* render_frame_host, 149 RenderFrameHost* render_frame_host,
150 WebContents* web_contents, 150 WebContents* web_contents,
151 PresentationServiceDelegate* delegate); 151 PresentationServiceDelegate* delegate);
152 152
153 // PresentationService implementation. 153 // PresentationService implementation.
154 void SetDefaultPresentationUrls( 154 void SetDefaultPresentationUrls(
155 const std::vector<GURL>& presentation_urls) override; 155 const std::vector<GURL>& presentation_urls) override;
156 void SetClient(blink::mojom::PresentationServiceClientPtr client) override; 156 void SetClient(content::mojom::PresentationServiceClientPtr client) override;
157 void ListenForScreenAvailability(const GURL& url) override; 157 void ListenForScreenAvailability(const GURL& url) override;
158 void StopListeningForScreenAvailability(const GURL& url) override; 158 void StopListeningForScreenAvailability(const GURL& url) override;
159 void StartSession(const std::vector<GURL>& presentation_urls, 159 void StartSession(const std::vector<GURL>& presentation_urls,
160 const NewSessionCallback& callback) override; 160 const NewSessionCallback& callback) override;
161 void JoinSession(const std::vector<GURL>& presentation_urls, 161 void JoinSession(const std::vector<GURL>& presentation_urls,
162 const base::Optional<std::string>& presentation_id, 162 const base::Optional<std::string>& presentation_id,
163 const NewSessionCallback& callback) override; 163 const NewSessionCallback& callback) override;
164 void SendConnectionMessage( 164 void SendConnectionMessage(
165 blink::mojom::PresentationSessionInfoPtr session_info, 165 content::mojom::PresentationSessionInfoPtr session_info,
166 blink::mojom::ConnectionMessagePtr connection_message, 166 content::mojom::ConnectionMessagePtr connection_message,
167 const SendConnectionMessageCallback& callback) override; 167 const SendConnectionMessageCallback& callback) override;
168 void CloseConnection(const GURL& presentation_url, 168 void CloseConnection(const GURL& presentation_url,
169 const std::string& presentation_id) override; 169 const std::string& presentation_id) override;
170 void Terminate(const GURL& presentation_url, 170 void Terminate(const GURL& presentation_url,
171 const std::string& presentation_id) override; 171 const std::string& presentation_id) override;
172 void ListenForConnectionMessages( 172 void ListenForConnectionMessages(
173 blink::mojom::PresentationSessionInfoPtr session) override; 173 content::mojom::PresentationSessionInfoPtr session) override;
174 174
175 // Creates a binding between this object and |request|. 175 // Creates a binding between this object and |request|.
176 void Bind(mojo::InterfaceRequest<blink::mojom::PresentationService> request); 176 void Bind(
177 mojo::InterfaceRequest<content::mojom::PresentationService> request);
177 178
178 // WebContentsObserver override. 179 // WebContentsObserver override.
179 void DidNavigateAnyFrame( 180 void DidNavigateAnyFrame(
180 content::RenderFrameHost* render_frame_host, 181 content::RenderFrameHost* render_frame_host,
181 const content::LoadCommittedDetails& details, 182 const content::LoadCommittedDetails& details,
182 const content::FrameNavigateParams& params) override; 183 const content::FrameNavigateParams& params) override;
183 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; 184 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
184 void WebContentsDestroyed() override; 185 void WebContentsDestroyed() override;
185 186
186 // PresentationServiceDelegate::Observer 187 // PresentationServiceDelegate::Observer
187 void OnDelegateDestroyed() override; 188 void OnDelegateDestroyed() override;
188 189
189 // Passed to embedder's implementation of PresentationServiceDelegate for 190 // Passed to embedder's implementation of PresentationServiceDelegate for
190 // later invocation when default presentation has started. 191 // later invocation when default presentation has started.
191 void OnDefaultPresentationStarted( 192 void OnDefaultPresentationStarted(
192 const PresentationSessionInfo& session_info); 193 const PresentationSessionInfo& session_info);
193 194
194 // Finds the callback from |pending_join_session_cbs_| using 195 // Finds the callback from |pending_join_session_cbs_| using
195 // |request_session_id|. 196 // |request_session_id|.
196 // If it exists, invoke it with |session| and |error|, then erase it from 197 // If it exists, invoke it with |session| and |error|, then erase it from
197 // |pending_join_session_cbs_|. 198 // |pending_join_session_cbs_|.
198 // Returns true if the callback was found. 199 // Returns true if the callback was found.
199 bool RunAndEraseJoinSessionMojoCallback( 200 bool RunAndEraseJoinSessionMojoCallback(
200 int request_session_id, 201 int request_session_id,
201 blink::mojom::PresentationSessionInfoPtr session, 202 content::mojom::PresentationSessionInfoPtr session,
202 blink::mojom::PresentationErrorPtr error); 203 content::mojom::PresentationErrorPtr error);
203 204
204 // Removes all listeners and resets default presentation URL on this instance 205 // Removes all listeners and resets default presentation URL on this instance
205 // and informs the PresentationServiceDelegate of such. 206 // and informs the PresentationServiceDelegate of such.
206 void Reset(); 207 void Reset();
207 208
208 // These functions are bound as base::Callbacks and passed to 209 // These functions are bound as base::Callbacks and passed to
209 // embedder's implementation of PresentationServiceDelegate for later 210 // embedder's implementation of PresentationServiceDelegate for later
210 // invocation. 211 // invocation.
211 void OnStartSessionSucceeded( 212 void OnStartSessionSucceeded(
212 int request_session_id, 213 int request_session_id,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 250
250 // Returns true if this object is associated with |render_frame_host|. 251 // Returns true if this object is associated with |render_frame_host|.
251 bool FrameMatches(content::RenderFrameHost* render_frame_host) const; 252 bool FrameMatches(content::RenderFrameHost* render_frame_host) const;
252 253
253 // Embedder-specific delegate to forward Presentation requests to. 254 // Embedder-specific delegate to forward Presentation requests to.
254 // May be null if embedder does not support Presentation API. 255 // May be null if embedder does not support Presentation API.
255 PresentationServiceDelegate* delegate_; 256 PresentationServiceDelegate* delegate_;
256 257
257 // Proxy to the PresentationServiceClient to send results (e.g., screen 258 // Proxy to the PresentationServiceClient to send results (e.g., screen
258 // availability) to. 259 // availability) to.
259 blink::mojom::PresentationServiceClientPtr client_; 260 content::mojom::PresentationServiceClientPtr client_;
260 261
261 std::vector<GURL> default_presentation_urls_; 262 std::vector<GURL> default_presentation_urls_;
262 263
263 using ScreenAvailabilityListenerMap = 264 using ScreenAvailabilityListenerMap =
264 std::map<GURL, std::unique_ptr<ScreenAvailabilityListenerImpl>>; 265 std::map<GURL, std::unique_ptr<ScreenAvailabilityListenerImpl>>;
265 ScreenAvailabilityListenerMap screen_availability_listeners_; 266 ScreenAvailabilityListenerMap screen_availability_listeners_;
266 267
267 // For StartSession requests. 268 // For StartSession requests.
268 // Set to a positive value when a StartSession request is being processed. 269 // Set to a positive value when a StartSession request is being processed.
269 int start_session_request_id_; 270 int start_session_request_id_;
270 std::unique_ptr<NewSessionCallbackWrapper> pending_start_session_cb_; 271 std::unique_ptr<NewSessionCallbackWrapper> pending_start_session_cb_;
271 272
272 // For JoinSession requests. 273 // For JoinSession requests.
273 base::hash_map<int, linked_ptr<NewSessionCallbackWrapper>> 274 base::hash_map<int, linked_ptr<NewSessionCallbackWrapper>>
274 pending_join_session_cbs_; 275 pending_join_session_cbs_;
275 276
276 // RAII binding of |this| to an Presentation interface request. 277 // RAII binding of |this| to an Presentation interface request.
277 // The binding is removed when binding_ is cleared or goes out of scope. 278 // The binding is removed when binding_ is cleared or goes out of scope.
278 std::unique_ptr<mojo::Binding<blink::mojom::PresentationService>> binding_; 279 std::unique_ptr<mojo::Binding<content::mojom::PresentationService>> binding_;
279 280
280 // There can be only one send message request at a time. 281 // There can be only one send message request at a time.
281 std::unique_ptr<SendConnectionMessageCallback> send_message_callback_; 282 std::unique_ptr<SendConnectionMessageCallback> send_message_callback_;
282 283
283 std::unique_ptr<ConnectionMessagesCallback> on_connection_messages_callback_; 284 std::unique_ptr<ConnectionMessagesCallback> on_connection_messages_callback_;
284 285
285 // ID of the RenderFrameHost this object is associated with. 286 // ID of the RenderFrameHost this object is associated with.
286 int render_process_id_; 287 int render_process_id_;
287 int render_frame_id_; 288 int render_frame_id_;
288 289
289 // NOTE: Weak pointers must be invalidated before all other member variables. 290 // NOTE: Weak pointers must be invalidated before all other member variables.
290 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; 291 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_;
291 292
292 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); 293 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl);
293 }; 294 };
294 295
295 } // namespace content 296 } // namespace content
296 297
297 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ 298 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698