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

Side by Side Diff: chrome/browser/media/router/offscreen_presentation_manager.h

Issue 2962623002: [Media Router] Clean up OffscreenPresentationManager params. (Closed)
Patch Set: Addressed Bin's comments Created 3 years, 5 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 | « no previous file | chrome/browser/media/router/offscreen_presentation_manager.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 CHROME_BROWSER_MEDIA_ROUTER_OFFSCREEN_PRESENTATION_MANAGER_H_ 5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_OFFSCREEN_PRESENTATION_MANAGER_H_
6 #define CHROME_BROWSER_MEDIA_ROUTER_OFFSCREEN_PRESENTATION_MANAGER_H_ 6 #define CHROME_BROWSER_MEDIA_ROUTER_OFFSCREEN_PRESENTATION_MANAGER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 #include <unordered_map> 11 #include <unordered_map>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/optional.h" 14 #include "base/optional.h"
15 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
16 #include "chrome/browser/media/router/render_frame_host_id.h" 16 #include "chrome/browser/media/router/render_frame_host_id.h"
17 #include "chrome/common/media_router/media_route.h" 17 #include "chrome/common/media_router/media_route.h"
18 #include "components/keyed_service/core/keyed_service.h" 18 #include "components/keyed_service/core/keyed_service.h"
19 #include "content/public/browser/presentation_service_delegate.h" 19 #include "content/public/browser/presentation_service_delegate.h"
20 20
21 class GURL; 21 namespace content {
22 struct PresentationInfo;
23 }
22 24
23 namespace media_router { 25 namespace media_router {
24 // Manages all offscreen presentations started in the associated Profile and 26 // Manages all offscreen presentations started in the associated Profile and
25 // facilitates communication between the controllers and the receiver of an 27 // facilitates communication between the controllers and the receiver of an
26 // offscreen presentation. 28 // offscreen presentation.
27 // 29 //
28 // Design doc: 30 // Design doc:
29 // https://docs.google.com/document/d/1XM3jhMJTQyhEC5PDAAJFNIaKh6UUEihqZDz_ztEe4 Co/edit#heading=h.hadpx5oi0gml 31 // https://docs.google.com/document/d/1XM3jhMJTQyhEC5PDAAJFNIaKh6UUEihqZDz_ztEe4 Co/edit#heading=h.hadpx5oi0gml
30 // 32 //
31 // Example usage: 33 // Example usage:
32 // 34 //
33 // Receiver is created to host the offscreen presentation and registers itself 35 // Receiver is created to host the offscreen presentation and registers itself
34 // so that controller frames can connect to it: 36 // so that controller frames can connect to it:
35 // 37 //
36 // OffscreenPresentationManager* manager = 38 // OffscreenPresentationManager* manager =
37 // OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext( 39 // OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext(
38 // web_contents_->GetBrowserContext()); 40 // web_contents_->GetBrowserContext());
39 // manager->OnOffscreenPresentationReceiverCreated(presentation_id, 41 // manager->OnOffscreenPresentationReceiverCreated(presentation_info,
40 // base::Bind(&PresentationServiceImpl::OnReceiverConnectionAvailable)); 42 // base::Bind(&PresentationServiceImpl::OnReceiverConnectionAvailable));
41 // 43 //
42 // Controlling frame establishes connection with the receiver side, resulting 44 // Controlling frame establishes connection with the receiver side, resulting
43 // in a connection with the two endpoints being the controller 45 // in a connection with the two endpoints being the controller
44 // PresentationConnectionPtr and receiver PresentationConnectionPtr. 46 // PresentationConnectionPtr and receiver PresentationConnectionPtr.
45 // Note calling this will trigger receiver frame's 47 // Note calling this will trigger receiver frame's
46 // PresentationServiceImpl::OnReceiverConnectionAvailable. 48 // PresentationServiceImpl::OnReceiverConnectionAvailable.
47 // 49 //
48 // manager->RegisterOffscreenPresentationController( 50 // manager->RegisterOffscreenPresentationController(
49 // presentation_id, controller_frame_id, controller_connection_ptr, 51 // presentation_info,
50 // receiver_connection_request); 52 // std::move(controller_connection_ptr,
53 // std::move(receiver_connection_request));
51 // 54 //
52 // Invoked on receiver's PresentationServiceImpl when controller connection is 55 // Invoked on receiver's PresentationServiceImpl when controller connection is
53 // established. 56 // established.
54 // 57 //
55 // |presentation_receiver_client_|: blink::mojom::PresentationServiceClienPtr 58 // |presentation_receiver_client_|: blink::mojom::PresentationServiceClienPtr
56 // for the presentation receiver. 59 // for the presentation receiver.
57 // |controller_connection_ptr|: blink::mojom::PresentationConnectionPtr for 60 // |controller_connection_ptr|: blink::mojom::PresentationConnectionPtr for
58 // blink::PresentationConnection object in controlling frame's render process. 61 // blink::PresentationConnection object in controlling frame's render process.
59 // |receiver_connection_request|: Mojo InterfaceRequest to be bind to 62 // |receiver_connection_request|: Mojo InterfaceRequest to be bind to
60 // blink::PresentationConnection object in receiver frame's render process. 63 // blink::PresentationConnection object in receiver frame's render process.
61 // void PresentationServiceImpl::OnReceiverConnectionAvailable( 64 // void PresentationServiceImpl::OnReceiverConnectionAvailable(
62 // const content::PresentationInfo& presentation_info, 65 // const content::PresentationInfo& presentation_info,
63 // PresentationConnectionPtr controller_connection_ptr, 66 // PresentationConnectionPtr controller_connection_ptr,
64 // PresentationConnectionRequest receiver_connection_request) { 67 // PresentationConnectionRequest receiver_connection_request) {
65 // presentation_receiver_client_->OnReceiverConnectionAvailable( 68 // presentation_receiver_client_->OnReceiverConnectionAvailable(
66 // blink::mojom::PresentationInfo::From(presentation_info), 69 // blink::mojom::PresentationInfo::From(presentation_info),
67 // std::move(controller_connection_ptr), 70 // std::move(controller_connection_ptr),
68 // std::move(receiver_connection_request)); 71 // std::move(receiver_connection_request));
69 // } 72 // }
70 // 73 //
71 // Send message from controlling/receiver frame to receiver/controlling frame: 74 // Send message from controlling/receiver frame to receiver/controlling frame:
72 // 75 //
73 // |target_connection_|: member variable of 76 // |target_connection_|: member variable of
74 // blink::mojom::PresentationConnectionPtr type, 77 // blink::mojom::PresentationConnectionPtr type,
75 // refering to remote PresentationConnectionProxy 78 // refering to remote PresentationConnectionProxy
76 // object on receiver/controlling frame. 79 // object on receiver/controlling frame.
77 // |message|: Text message to be sent. 80 // |message|: Text message to be sent.
78 // PresentationConnctionPtr::SendString( 81 // PresentationConnctionPtr::SendString(
79 // const blink::WebString& message) { 82 // const blink::WebString& message) {
80 // target_connection_->OnConnectionMessageReceived( 83 // target_connection_->OnMessage(
81 // std::move(connection_message)); 84 // content::PresentationConnectionMessage(message.Utf8()),
85 // base::Bind(&OnMessageReceived));
82 // } 86 // }
83 // 87 //
84 // A controller or receiver leaves the offscreen presentation (e.g., due to 88 // A controller or receiver leaves the offscreen presentation (e.g., due to
85 // navigation) by unregistering themselves from OffscreenPresentation object. 89 // navigation) by unregistering themselves from OffscreenPresentation object.
86 // 90 //
87 // When the receiver is no longer associated with an offscreen presentation, it 91 // When the receiver is no longer associated with an offscreen presentation, it
88 // shall unregister itself with OffscreenPresentationManager. Unregistration 92 // shall unregister itself with OffscreenPresentationManager. Unregistration
89 // will prevent additional controllers from establishing a connection with the 93 // will prevent additional controllers from establishing a connection with the
90 // receiver: 94 // receiver:
91 // 95 //
(...skipping 10 matching lines...) Expand all
102 ~OffscreenPresentationManager() override; 106 ~OffscreenPresentationManager() override;
103 107
104 // Registers controller PresentationConnectionPtr to presentation with 108 // Registers controller PresentationConnectionPtr to presentation with
105 // |presentation_id| and |render_frame_id|. 109 // |presentation_id| and |render_frame_id|.
106 // Creates a new presentation if no presentation with |presentation_id| 110 // Creates a new presentation if no presentation with |presentation_id|
107 // exists. 111 // exists.
108 // |controller_connection_ptr|, |receiver_connection_request|: Not owned by 112 // |controller_connection_ptr|, |receiver_connection_request|: Not owned by
109 // this class. Ownership is transferred to presentation receiver via 113 // this class. Ownership is transferred to presentation receiver via
110 // |receiver_callback| passed below. 114 // |receiver_callback| passed below.
111 virtual void RegisterOffscreenPresentationController( 115 virtual void RegisterOffscreenPresentationController(
112 const std::string& presentation_id, 116 const content::PresentationInfo& presentation_info,
113 const GURL& presentation_url,
114 const RenderFrameHostId& render_frame_id, 117 const RenderFrameHostId& render_frame_id,
115 content::PresentationConnectionPtr controller_connection_ptr, 118 content::PresentationConnectionPtr controller_connection_ptr,
116 content::PresentationConnectionRequest receiver_connection_request, 119 content::PresentationConnectionRequest receiver_connection_request,
117 const MediaRoute& route); 120 const MediaRoute& route);
118 121
119 // Unregisters controller PresentationConnectionPtr to presentation with 122 // Unregisters controller PresentationConnectionPtr to presentation with
120 // |presentation_id|, |render_frame_id|. It does nothing if there is no 123 // |presentation_id|, |render_frame_id|. It does nothing if there is no
121 // controller that matches the provided arguments. It removes presentation 124 // controller that matches the provided arguments. It removes presentation
122 // that matches the arguments if the presentation has no |receiver_callback| 125 // that matches the arguments if the presentation has no |receiver_callback|
123 // and any other pending controller. 126 // and any other pending controller.
124 virtual void UnregisterOffscreenPresentationController( 127 virtual void UnregisterOffscreenPresentationController(
125 const std::string& presentation_id, 128 const std::string& presentation_id,
126 const RenderFrameHostId& render_frame_id); 129 const RenderFrameHostId& render_frame_id);
127 130
128 // Registers |receiver_callback| to presentation with |presentation_id| and 131 // Registers |receiver_callback| to presentation with |presentation_info|.
129 // |presentation_url|.
130 virtual void OnOffscreenPresentationReceiverCreated( 132 virtual void OnOffscreenPresentationReceiverCreated(
131 const std::string& presentation_id, 133 const content::PresentationInfo& presentation_info,
132 const GURL& presentation_url,
133 const content::ReceiverConnectionAvailableCallback& receiver_callback); 134 const content::ReceiverConnectionAvailableCallback& receiver_callback);
134 135
135 // Unregisters ReceiverConnectionAvailableCallback associated with 136 // Unregisters ReceiverConnectionAvailableCallback associated with
136 // |presentation_id|. 137 // |presentation_id|.
137 virtual void OnOffscreenPresentationReceiverTerminated( 138 virtual void OnOffscreenPresentationReceiverTerminated(
138 const std::string& presentation_id); 139 const std::string& presentation_id);
139 140
140 // Returns true if this class has an offscreen presentation with 141 // Returns true if this class has an offscreen presentation with
141 // |presentation_id|. 142 // |presentation_id|.
142 virtual bool IsOffscreenPresentation(const std::string& presentation_id); 143 virtual bool IsOffscreenPresentation(const std::string& presentation_id);
143 144
144 // Returns nullptr if |presentation_id| is not associated with an offscreen 145 // Returns nullptr if |presentation_id| is not associated with an offscreen
145 // presentation. 146 // presentation.
146 virtual const MediaRoute* GetRoute(const std::string& presentation_id); 147 virtual const MediaRoute* GetRoute(const std::string& presentation_id);
147 148
148 private: 149 private:
149 // Represents an offscreen presentation registered with 150 // Represents an offscreen presentation registered with
150 // OffscreenPresentationManager. Contains callback to the receiver to inform 151 // OffscreenPresentationManager. Contains callback to the receiver to inform
151 // it of new connections established from a controller. Contains set of 152 // it of new connections established from a controller. Contains set of
152 // controllers registered to OffscreenPresentationManager before corresponding 153 // controllers registered to OffscreenPresentationManager before corresponding
153 // receiver. 154 // receiver.
154 class OffscreenPresentation { 155 class OffscreenPresentation {
155 public: 156 public:
156 OffscreenPresentation(const std::string& presentation_id, 157 explicit OffscreenPresentation(
157 const GURL& presentation_url); 158 const content::PresentationInfo& presentation_info);
158 ~OffscreenPresentation(); 159 ~OffscreenPresentation();
159 160
160 // Register controller with |render_frame_id|. If |receiver_callback_| has 161 // Register controller with |render_frame_id|. If |receiver_callback_| has
161 // been set, invoke |receiver_callback_| with |controller_connection_ptr| 162 // been set, invoke |receiver_callback_| with |controller_connection_ptr|
162 // and |receiver_connection_request| as parameter, else creates a 163 // and |receiver_connection_request| as parameter, else creates a
163 // ControllerConnection object with |controller_connection_ptr| and 164 // ControllerConnection object with |controller_connection_ptr| and
164 // |receiver_connection_request|, and store it in |pending_controllers_| 165 // |receiver_connection_request|, and store it in |pending_controllers_|
165 // map. 166 // map.
166 void RegisterController( 167 void RegisterController(
167 const RenderFrameHostId& render_frame_id, 168 const RenderFrameHostId& render_frame_id,
(...skipping 13 matching lines...) Expand all
181 const content::ReceiverConnectionAvailableCallback& receiver_callback); 182 const content::ReceiverConnectionAvailableCallback& receiver_callback);
182 183
183 private: 184 private:
184 friend class OffscreenPresentationManagerTest; 185 friend class OffscreenPresentationManagerTest;
185 friend class OffscreenPresentationManager; 186 friend class OffscreenPresentationManager;
186 187
187 // Returns false if receiver_callback_ is null and there are no pending 188 // Returns false if receiver_callback_ is null and there are no pending
188 // controllers. 189 // controllers.
189 bool IsValid() const; 190 bool IsValid() const;
190 191
191 const std::string presentation_id_; 192 const content::PresentationInfo presentation_info_;
192 const GURL presentation_url_;
193 base::Optional<MediaRoute> route_; 193 base::Optional<MediaRoute> route_;
194 194
195 // Callback to invoke whenever a receiver connection is available. 195 // Callback to invoke whenever a receiver connection is available.
196 content::ReceiverConnectionAvailableCallback receiver_callback_; 196 content::ReceiverConnectionAvailableCallback receiver_callback_;
197 197
198 // Stores controller information. 198 // Stores controller information.
199 // |controller_connection_ptr|: Mojo::InterfacePtr to 199 // |controller_connection_ptr|: Mojo::InterfacePtr to
200 // blink::PresentationConnection object in controlling frame; 200 // blink::PresentationConnection object in controlling frame;
201 // |receiver_connection_request|: Mojo::InterfaceRequest to be bind to 201 // |receiver_connection_request|: Mojo::InterfaceRequest to be bind to
202 // blink::PresentationConnection object in receiver frame. 202 // blink::PresentationConnection object in receiver frame.
(...skipping 24 matching lines...) Expand all
227 friend class MockOffscreenPresentationManager; 227 friend class MockOffscreenPresentationManager;
228 FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest, 228 FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest,
229 ConnectToOffscreenPresentation); 229 ConnectToOffscreenPresentation);
230 230
231 // Used by OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext. 231 // Used by OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext.
232 OffscreenPresentationManager(); 232 OffscreenPresentationManager();
233 233
234 using OffscreenPresentationMap = 234 using OffscreenPresentationMap =
235 std::map<std::string, std::unique_ptr<OffscreenPresentation>>; 235 std::map<std::string, std::unique_ptr<OffscreenPresentation>>;
236 236
237 // Creates an offscreen presentation with |presentation_id| and 237 // Creates an offscreen presentation with |presentation_info|.
238 // |presentation_url|.
239 OffscreenPresentation* GetOrCreateOffscreenPresentation( 238 OffscreenPresentation* GetOrCreateOffscreenPresentation(
240 const std::string& presentation_id, 239 const content::PresentationInfo& presentation_info);
241 const GURL& presentation_url);
242 240
243 // Maps from presentation ID to OffscreenPresentation. 241 // Maps from presentation ID to OffscreenPresentation.
244 OffscreenPresentationMap offscreen_presentations_; 242 OffscreenPresentationMap offscreen_presentations_;
245 243
246 base::ThreadChecker thread_checker_; 244 base::ThreadChecker thread_checker_;
247 245
248 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentationManager); 246 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentationManager);
249 }; 247 };
250 248
251 } // namespace media_router 249 } // namespace media_router
252 250
253 #endif // CHROME_BROWSER_MEDIA_ROUTER_OFFSCREEN_PRESENTATION_MANAGER_H_ 251 #endif // CHROME_BROWSER_MEDIA_ROUTER_OFFSCREEN_PRESENTATION_MANAGER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/media/router/offscreen_presentation_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698