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

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

Issue 2714783002: [Presentation API] (browser side) Implement reconnect() for 1-UA mode (Closed)
Patch Set: resolve code review comments from Derek and Mark Created 3 years, 9 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 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/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
15 #include "chrome/browser/media/router/media_route.h"
15 #include "chrome/browser/media/router/render_frame_host_id.h" 16 #include "chrome/browser/media/router/render_frame_host_id.h"
16 #include "components/keyed_service/core/keyed_service.h" 17 #include "components/keyed_service/core/keyed_service.h"
17 #include "content/public/browser/presentation_service_delegate.h" 18 #include "content/public/browser/presentation_service_delegate.h"
18 19
19 class GURL; 20 class GURL;
20 21
21 namespace media_router { 22 namespace media_router {
22 // Manages all offscreen presentations started in the associated Profile and 23 // Manages all offscreen presentations started in the associated Profile and
23 // facilitates communication between the controllers and the receiver of an 24 // facilitates communication between the controllers and the receiver of an
24 // offscreen presentation. 25 // offscreen presentation.
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 // Creates a new presentation if no presentation with |presentation_id| 104 // Creates a new presentation if no presentation with |presentation_id|
104 // exists. 105 // exists.
105 // |controller_connection_ptr|, |receiver_connection_request|: Not owned by 106 // |controller_connection_ptr|, |receiver_connection_request|: Not owned by
106 // this class. Ownership is transferred to presentation receiver via 107 // this class. Ownership is transferred to presentation receiver via
107 // |receiver_callback| passed below. 108 // |receiver_callback| passed below.
108 virtual void RegisterOffscreenPresentationController( 109 virtual void RegisterOffscreenPresentationController(
109 const std::string& presentation_id, 110 const std::string& presentation_id,
110 const GURL& presentation_url, 111 const GURL& presentation_url,
111 const RenderFrameHostId& render_frame_id, 112 const RenderFrameHostId& render_frame_id,
112 content::PresentationConnectionPtr controller_connection_ptr, 113 content::PresentationConnectionPtr controller_connection_ptr,
113 content::PresentationConnectionRequest receiver_connection_request); 114 content::PresentationConnectionRequest receiver_connection_request,
115 const MediaRoute& route);
114 116
115 // Unregisters controller PresentationConnectionPtr to presentation with 117 // Unregisters controller PresentationConnectionPtr to presentation with
116 // |presentation_id|, |render_frame_id|. It does nothing if there is no 118 // |presentation_id|, |render_frame_id|. It does nothing if there is no
117 // controller that matches the provided arguments. It removes presentation 119 // controller that matches the provided arguments. It removes presentation
118 // that matches the arguments if the presentation has no |receiver_callback| 120 // that matches the arguments if the presentation has no |receiver_callback|
119 // and any other pending controller. 121 // and any other pending controller.
120 virtual void UnregisterOffscreenPresentationController( 122 virtual void UnregisterOffscreenPresentationController(
121 const std::string& presentation_id, 123 const std::string& presentation_id,
122 const RenderFrameHostId& render_frame_id); 124 const RenderFrameHostId& render_frame_id);
123 125
124 // Registers |receiver_callback| to presentation with |presentation_id| and 126 // Registers |receiver_callback| to presentation with |presentation_id| and
125 // |presentation_url|. 127 // |presentation_url|.
126 virtual void OnOffscreenPresentationReceiverCreated( 128 virtual void OnOffscreenPresentationReceiverCreated(
127 const std::string& presentation_id, 129 const std::string& presentation_id,
128 const GURL& presentation_url, 130 const GURL& presentation_url,
129 const content::ReceiverConnectionAvailableCallback& receiver_callback); 131 const content::ReceiverConnectionAvailableCallback& receiver_callback);
130 132
131 // Unregisters ReceiverConnectionAvailableCallback associated with 133 // Unregisters ReceiverConnectionAvailableCallback associated with
132 // |presentation_id|. 134 // |presentation_id|.
133 virtual void OnOffscreenPresentationReceiverTerminated( 135 virtual void OnOffscreenPresentationReceiverTerminated(
134 const std::string& presentation_id); 136 const std::string& presentation_id);
135 137
138 // Returns true if this class has an offscreen presentation with
139 // |presentation_id|.
140 virtual bool IsOffscreenPresentation(const std::string& presentation_id);
141
142 // Returns nullptr if |presentation_id| is not associated with an offscreen
143 // presentation.
144 virtual const MediaRoute* GetRoute(const std::string& presentation_id);
145
136 private: 146 private:
137 // Represents an offscreen presentation registered with 147 // Represents an offscreen presentation registered with
138 // OffscreenPresentationManager. Contains callback to the receiver to inform 148 // OffscreenPresentationManager. Contains callback to the receiver to inform
139 // it of new connections established from a controller. Contains set of 149 // it of new connections established from a controller. Contains set of
140 // controllers registered to OffscreenPresentationManager before corresponding 150 // controllers registered to OffscreenPresentationManager before corresponding
141 // receiver. 151 // receiver.
142 class OffscreenPresentation { 152 class OffscreenPresentation {
143 public: 153 public:
144 OffscreenPresentation(const std::string& presentation_id, 154 OffscreenPresentation(const std::string& presentation_id,
145 const GURL& presentation_url); 155 const GURL& presentation_url);
146 ~OffscreenPresentation(); 156 ~OffscreenPresentation();
147 157
148 // Register controller with |render_frame_id|. If |receiver_callback_| has 158 // Register controller with |render_frame_id|. If |receiver_callback_| has
149 // been set, invoke |receiver_callback_| with |controller_connection_ptr| 159 // been set, invoke |receiver_callback_| with |controller_connection_ptr|
150 // and |receiver_connection_request| as parameter, else creates a 160 // and |receiver_connection_request| as parameter, else creates a
151 // ControllerConnection object with |controller_connection_ptr| and 161 // ControllerConnection object with |controller_connection_ptr| and
152 // |receiver_connection_request|, and store it in |pending_controllers_| 162 // |receiver_connection_request|, and store it in |pending_controllers_|
153 // map. 163 // map.
154 void RegisterController( 164 void RegisterController(
155 const RenderFrameHostId& render_frame_id, 165 const RenderFrameHostId& render_frame_id,
156 content::PresentationConnectionPtr controller_connection_ptr, 166 content::PresentationConnectionPtr controller_connection_ptr,
157 content::PresentationConnectionRequest receiver_connection_request); 167 content::PresentationConnectionRequest receiver_connection_request,
168 const MediaRoute& route);
158 169
159 // Unregister controller with |render_frame_id|. Do nothing if there is no 170 // Unregister controller with |render_frame_id|. Do nothing if there is no
160 // pending controller with |render_frame_id|. 171 // pending controller with |render_frame_id|.
161 void UnregisterController(const RenderFrameHostId& render_frame_id); 172 void UnregisterController(const RenderFrameHostId& render_frame_id);
162 173
163 // Register |receiver_callback| to current offscreen_presentation object. 174 // Register |receiver_callback| to current offscreen_presentation object.
164 // For each controller in |pending_controllers_| map, invoke 175 // For each controller in |pending_controllers_| map, invoke
165 // |receiver_callback| with controller as parameter. Clear 176 // |receiver_callback| with controller as parameter. Clear
166 // |pending_controllers_| map afterwards. 177 // |pending_controllers_| map afterwards.
167 void RegisterReceiver( 178 void RegisterReceiver(
168 const content::ReceiverConnectionAvailableCallback& receiver_callback); 179 const content::ReceiverConnectionAvailableCallback& receiver_callback);
169 180
170 private: 181 private:
171 friend class OffscreenPresentationManagerTest; 182 friend class OffscreenPresentationManagerTest;
172 friend class OffscreenPresentationManager; 183 friend class OffscreenPresentationManager;
173 184
174 // Returns false if receiver_callback_ is null and there are no pending 185 // Returns false if receiver_callback_ is null and there are no pending
175 // controllers. 186 // controllers.
176 bool IsValid() const; 187 bool IsValid() const;
177 188
178 const std::string presentation_id_; 189 const std::string presentation_id_;
179 const GURL presentation_url_; 190 const GURL presentation_url_;
191 MediaRoute route_;
180 192
181 // Callback to invoke whenever a receiver connection is available. 193 // Callback to invoke whenever a receiver connection is available.
182 content::ReceiverConnectionAvailableCallback receiver_callback_; 194 content::ReceiverConnectionAvailableCallback receiver_callback_;
183 195
184 // Stores controller information. 196 // Stores controller information.
185 // |controller_connection_ptr|: Mojo::InterfacePtr to 197 // |controller_connection_ptr|: Mojo::InterfacePtr to
186 // blink::PresentationConnection object in controlling frame; 198 // blink::PresentationConnection object in controlling frame;
187 // |receiver_connection_request|: Mojo::InterfaceRequest to be bind to 199 // |receiver_connection_request|: Mojo::InterfaceRequest to be bind to
188 // blink::PresentationConnection object in receiver frame. 200 // blink::PresentationConnection object in receiver frame.
189 struct ControllerConnection { 201 struct ControllerConnection {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 OffscreenPresentationMap offscreen_presentations_; 242 OffscreenPresentationMap offscreen_presentations_;
231 243
232 base::ThreadChecker thread_checker_; 244 base::ThreadChecker thread_checker_;
233 245
234 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentationManager); 246 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentationManager);
235 }; 247 };
236 248
237 } // namespace media_router 249 } // namespace media_router
238 250
239 #endif // CHROME_BROWSER_MEDIA_ROUTER_OFFSCREEN_PRESENTATION_MANAGER_H_ 251 #endif // CHROME_BROWSER_MEDIA_ROUTER_OFFSCREEN_PRESENTATION_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698