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

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

Issue 2477573002: [Presentation API] (3rd) (1-UA) Split PresentationServiceDelegateImpl(PSDImpl) (Closed)
Patch Set: resolve code review comments from dcheng 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 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/render_frame_host_id.h" 15 #include "chrome/browser/media/router/render_frame_host_id.h"
16 #include "components/keyed_service/core/keyed_service.h" 16 #include "components/keyed_service/core/keyed_service.h"
17 #include "content/public/browser/presentation_service_delegate.h" 17 #include "content/public/browser/presentation_service_delegate.h"
18 18
19 class GURL; 19 class GURL;
20 20
21 // TODO(zhaobin): move these back to
22 // content/public/browser/presentation_service_delegate.h when they are actually
23 // used in content.
24 namespace content {
25 // TODO(zhaobin): A class stub for blink::mojom::PresentationConnectionPtr.
26 // presentation.mojom is under security review. Change this to
27 // blink::mojom::PresentationConnectionPtr once that is done.
28 class PresentationConnectionPtr {};
29
30 using ReceiverConnectionAvailableCallback =
31 base::Callback<void(const content::PresentationSessionInfo&,
32 PresentationConnectionPtr)>;
33 } // namespace content
34
35 namespace media_router { 21 namespace media_router {
36 // Manages all offscreen presentations started in the associated Profile and 22 // Manages all offscreen presentations started in the associated Profile and
37 // facilitates communication between the controllers and the receiver of an 23 // facilitates communication between the controllers and the receiver of an
38 // offscreen presentation. 24 // offscreen presentation.
39 // 25 //
40 // Design doc: 26 // Design doc:
41 // https://docs.google.com/document/d/1XM3jhMJTQyhEC5PDAAJFNIaKh6UUEihqZDz_ztEe4 Co/edit#heading=h.hadpx5oi0gml 27 // https://docs.google.com/document/d/1XM3jhMJTQyhEC5PDAAJFNIaKh6UUEihqZDz_ztEe4 Co/edit#heading=h.hadpx5oi0gml
42 // 28 //
43 // Example usage: 29 // Example usage:
44 // 30 //
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 class OffscreenPresentationManager : public KeyedService { 93 class OffscreenPresentationManager : public KeyedService {
108 public: 94 public:
109 ~OffscreenPresentationManager() override; 95 ~OffscreenPresentationManager() override;
110 96
111 // Registers controller PresentationConnectionPtr to presentation 97 // Registers controller PresentationConnectionPtr to presentation
112 // with |presentation_id|, |render_frame_id|. 98 // with |presentation_id|, |render_frame_id|.
113 // Creates a new presentation if no presentation with |presentation_id| 99 // Creates a new presentation if no presentation with |presentation_id|
114 // exists. 100 // exists.
115 // |controller|: Not owned by this class. Ownership is transferred to the 101 // |controller|: Not owned by this class. Ownership is transferred to the
116 // presentation receiver via |receiver_callback| passed below. 102 // presentation receiver via |receiver_callback| passed below.
117 void RegisterOffscreenPresentationController( 103 virtual void RegisterOffscreenPresentationController(
118 const std::string& presentation_id, 104 const std::string& presentation_id,
119 const GURL& presentation_url, 105 const GURL& presentation_url,
120 const RenderFrameHostId& render_frame_id, 106 const RenderFrameHostId& render_frame_id,
121 content::PresentationConnectionPtr controller); 107 content::PresentationConnectionPtr controller_conn_ptr,
108 content::PresentationConnectionRequest receiver_conn_request);
122 109
123 // Unregisters controller PresentationConnectionPtr to presentation with 110 // Unregisters controller PresentationConnectionPtr to presentation with
124 // |presentation_id|, |render_frame_id|. It does nothing if there is no 111 // |presentation_id|, |render_frame_id|. It does nothing if there is no
125 // controller that matches the provided arguments. It removes presentation 112 // controller that matches the provided arguments. It removes presentation
126 // that matches the arguments if the presentation has no receiver_callback and 113 // that matches the arguments if the presentation has no receiver_callback and
127 // any other pending controller. 114 // any other pending controller.
128 void UnregisterOffscreenPresentationController( 115 virtual void UnregisterOffscreenPresentationController(
129 const std::string& presentation_id, 116 const std::string& presentation_id,
130 const RenderFrameHostId& render_frame_id); 117 const RenderFrameHostId& render_frame_id);
131 118
132 // Registers ReceiverConnectionAvailableCallback to presentation 119 // Registers ReceiverConnectionAvailableCallback to presentation
133 // with |presentation_id|. 120 // with |presentation_id|.
134 void OnOffscreenPresentationReceiverCreated( 121 virtual void OnOffscreenPresentationReceiverCreated(
135 const std::string& presentation_id, 122 const std::string& presentation_id,
136 const GURL& presentation_url, 123 const GURL& presentation_url,
137 const content::ReceiverConnectionAvailableCallback& receiver_callback); 124 const content::ReceiverConnectionAvailableCallback& receiver_callback);
138 125
139 // Unregisters the ReceiverConnectionAvailableCallback associated with 126 // Unregisters the ReceiverConnectionAvailableCallback associated with
140 // |presentation_id|. 127 // |presentation_id|.
141 void OnOffscreenPresentationReceiverTerminated( 128 virtual void OnOffscreenPresentationReceiverTerminated(
142 const std::string& presentation_id); 129 const std::string& presentation_id);
143 130
144 private: 131 private:
145 // Represents an offscreen presentation registered with 132 // Represents an offscreen presentation registered with
146 // OffscreenPresentationManager. 133 // OffscreenPresentationManager.
147 // Contains callback to the receiver to inform it of new connections 134 // Contains callback to the receiver to inform it of new connections
148 // established from a controller. 135 // established from a controller.
149 // Contains set of controllers registered to OffscreenPresentationManager 136 // Contains set of controllers registered to OffscreenPresentationManager
150 // before corresponding receiver. 137 // before corresponding receiver.
151 class OffscreenPresentation { 138 class OffscreenPresentation {
152 public: 139 public:
153 OffscreenPresentation(const std::string& presentation_id, 140 OffscreenPresentation(const std::string& presentation_id,
154 const GURL& presentation_url); 141 const GURL& presentation_url);
155 ~OffscreenPresentation(); 142 ~OffscreenPresentation();
156 143
157 // Register |controller| with |render_frame_id|. If |receiver_callback_| has 144 // Register |controller| with |render_frame_id|. If |receiver_callback_| has
158 // been set, invoke |receiver_callback_| with |controller| as parameter, 145 // been set, invoke |receiver_callback_| with |controller| as parameter,
159 // else store |controller| in |pending_controllers_| map. 146 // else store |controller| in |pending_controllers_| map.
160 void RegisterController(const RenderFrameHostId& render_frame_id, 147 void RegisterController(
161 content::PresentationConnectionPtr controller); 148 const RenderFrameHostId& render_frame_id,
149 content::PresentationConnectionPtr controller_conn_ptr,
150 content::PresentationConnectionRequest receiver_conn_request);
162 151
163 // Unregister controller with |render_frame_id|. Do nothing if there is no 152 // Unregister controller with |render_frame_id|. Do nothing if there is no
164 // pending controller with |render_frame_id|. 153 // pending controller with |render_frame_id|.
165 void UnregisterController(const RenderFrameHostId& render_frame_id); 154 void UnregisterController(const RenderFrameHostId& render_frame_id);
166 155
167 // Register |receiver_callback| to current offscreen_presentation object. 156 // Register |receiver_callback| to current offscreen_presentation object.
168 // For each controller in |pending_controllers_| map, invoke 157 // For each controller in |pending_controllers_| map, invoke
169 // |receiver_callback| with controller as parameter. Clear 158 // |receiver_callback| with controller as parameter. Clear
170 // |pending_controllers_| map afterwards. 159 // |pending_controllers_| map afterwards.
171 void RegisterReceiver( 160 void RegisterReceiver(
172 const content::ReceiverConnectionAvailableCallback& receiver_callback); 161 const content::ReceiverConnectionAvailableCallback& receiver_callback);
173 162
174 private: 163 private:
175 friend class OffscreenPresentationManagerTest; 164 friend class OffscreenPresentationManagerTest;
176 friend class OffscreenPresentationManager; 165 friend class OffscreenPresentationManager;
177 166
178 // Returns false if receiver_callback_ is null and there are no pending 167 // Returns false if receiver_callback_ is null and there are no pending
179 // controllers. 168 // controllers.
180 bool IsValid() const; 169 bool IsValid() const;
181 170
182 const std::string presentation_id_; 171 const std::string presentation_id_;
183 const GURL presentation_url_; 172 const GURL presentation_url_;
184 173
185 // Callback to invoke whenever a receiver connection is available. 174 // Callback to invoke whenever a receiver connection is available.
186 content::ReceiverConnectionAvailableCallback receiver_callback_; 175 content::ReceiverConnectionAvailableCallback receiver_callback_;
187 176
177 struct ControllerConnection {
178 public:
179 ControllerConnection(
180 content::PresentationConnectionPtr controller_conn_ptr,
181 content::PresentationConnectionRequest receiver_conn_request);
182 ~ControllerConnection();
183
184 content::PresentationConnectionPtr controller_conn_ptr;
185 content::PresentationConnectionRequest receiver_conn_request;
186 };
187
188 // Contains Mojo pointers to controller PresentationConnections registered 188 // Contains Mojo pointers to controller PresentationConnections registered
189 // via |RegisterController()| before |receiver_callback_| is set. 189 // via |RegisterController()| before |receiver_callback_| is set.
190 std::unordered_map<RenderFrameHostId, 190 std::unordered_map<RenderFrameHostId,
191 content::PresentationConnectionPtr, 191 std::unique_ptr<ControllerConnection>,
192 RenderFrameHostIdHasher> 192 RenderFrameHostIdHasher>
193 pending_controllers_; 193 pending_controllers_;
194 194
195 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentation); 195 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentation);
196 }; 196 };
197 197
198 private: 198 private:
199 friend class OffscreenPresentationManagerFactory; 199 friend class OffscreenPresentationManagerFactory;
200 friend class OffscreenPresentationManagerTest; 200 friend class OffscreenPresentationManagerTest;
201 friend class MockOffscreenPresentationManager;
202 FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest,
203 ConnectToOffscreenPresentation);
201 204
202 // Used by OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext. 205 // Used by OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext.
203 OffscreenPresentationManager(); 206 OffscreenPresentationManager();
204 207
205 using OffscreenPresentationMap = 208 using OffscreenPresentationMap =
206 std::map<std::string, std::unique_ptr<OffscreenPresentation>>; 209 std::map<std::string, std::unique_ptr<OffscreenPresentation>>;
207 210
208 // Creates an offscreen presentation with |presentation_id| and 211 // Creates an offscreen presentation with |presentation_id| and
209 // |presentation_url|. 212 // |presentation_url|.
210 OffscreenPresentation* GetOrCreateOffscreenPresentation( 213 OffscreenPresentation* GetOrCreateOffscreenPresentation(
211 const std::string& presentation_id, 214 const std::string& presentation_id,
212 const GURL& presentation_url); 215 const GURL& presentation_url);
213 216
214 // Maps from presentation ID to OffscreenPresentation. 217 // Maps from presentation ID to OffscreenPresentation.
215 OffscreenPresentationMap offscreen_presentations_; 218 OffscreenPresentationMap offscreen_presentations_;
216 219
217 base::ThreadChecker thread_checker_; 220 base::ThreadChecker thread_checker_;
218 221
219 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentationManager); 222 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentationManager);
220 }; 223 };
221 224
222 } // namespace media_router 225 } // namespace media_router
223 226
224 #endif // CHROME_BROWSER_MEDIA_ROUTER_OFFSCREEN_PRESENTATION_MANAGER_H_ 227 #endif // CHROME_BROWSER_MEDIA_ROUTER_OFFSCREEN_PRESENTATION_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698