OLD | NEW |
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> |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 class OffscreenPresentationManager : public KeyedService { | 93 class OffscreenPresentationManager : public KeyedService { |
94 public: | 94 public: |
95 ~OffscreenPresentationManager() override; | 95 ~OffscreenPresentationManager() override; |
96 | 96 |
97 // Registers controller PresentationConnectionPtr to presentation | 97 // Registers controller PresentationConnectionPtr to presentation |
98 // with |presentation_id|, |render_frame_id|. | 98 // with |presentation_id|, |render_frame_id|. |
99 // Creates a new presentation if no presentation with |presentation_id| | 99 // Creates a new presentation if no presentation with |presentation_id| |
100 // exists. | 100 // exists. |
101 // |controller|: Not owned by this class. Ownership is transferred to the | 101 // |controller|: Not owned by this class. Ownership is transferred to the |
102 // presentation receiver via |receiver_callback| passed below. | 102 // presentation receiver via |receiver_callback| passed below. |
103 void RegisterOffscreenPresentationController( | 103 virtual void RegisterOffscreenPresentationController( |
104 const std::string& presentation_id, | 104 const std::string& presentation_id, |
105 const GURL& presentation_url, | 105 const GURL& presentation_url, |
106 const RenderFrameHostId& render_frame_id, | 106 const RenderFrameHostId& render_frame_id, |
107 content::PresentationConnectionPtr controller); | 107 content::PresentationConnectionPtr controller); |
108 | 108 |
109 // Unregisters controller PresentationConnectionPtr to presentation with | 109 // Unregisters controller PresentationConnectionPtr to presentation with |
110 // |presentation_id|, |render_frame_id|. It does nothing if there is no | 110 // |presentation_id|, |render_frame_id|. It does nothing if there is no |
111 // controller that matches the provided arguments. It removes presentation | 111 // controller that matches the provided arguments. It removes presentation |
112 // that matches the arguments if the presentation has no receiver_callback and | 112 // that matches the arguments if the presentation has no receiver_callback and |
113 // any other pending controller. | 113 // any other pending controller. |
114 void UnregisterOffscreenPresentationController( | 114 virtual void UnregisterOffscreenPresentationController( |
115 const std::string& presentation_id, | 115 const std::string& presentation_id, |
116 const RenderFrameHostId& render_frame_id); | 116 const RenderFrameHostId& render_frame_id); |
117 | 117 |
118 // Registers ReceiverConnectionAvailableCallback to presentation | 118 // Registers ReceiverConnectionAvailableCallback to presentation |
119 // with |presentation_id|. | 119 // with |presentation_id|. |
120 void OnOffscreenPresentationReceiverCreated( | 120 virtual void OnOffscreenPresentationReceiverCreated( |
121 const std::string& presentation_id, | 121 const std::string& presentation_id, |
122 const GURL& presentation_url, | 122 const GURL& presentation_url, |
123 const content::ReceiverConnectionAvailableCallback& receiver_callback); | 123 const content::ReceiverConnectionAvailableCallback& receiver_callback); |
124 | 124 |
125 // Unregisters the ReceiverConnectionAvailableCallback associated with | 125 // Unregisters the ReceiverConnectionAvailableCallback associated with |
126 // |presentation_id|. | 126 // |presentation_id|. |
127 void OnOffscreenPresentationReceiverTerminated( | 127 virtual void OnOffscreenPresentationReceiverTerminated( |
128 const std::string& presentation_id); | 128 const std::string& presentation_id); |
129 | 129 |
130 private: | 130 private: |
131 // Represents an offscreen presentation registered with | 131 // Represents an offscreen presentation registered with |
132 // OffscreenPresentationManager. | 132 // OffscreenPresentationManager. |
133 // Contains callback to the receiver to inform it of new connections | 133 // Contains callback to the receiver to inform it of new connections |
134 // established from a controller. | 134 // established from a controller. |
135 // Contains set of controllers registered to OffscreenPresentationManager | 135 // Contains set of controllers registered to OffscreenPresentationManager |
136 // before corresponding receiver. | 136 // before corresponding receiver. |
137 class OffscreenPresentation { | 137 class OffscreenPresentation { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 content::PresentationConnectionPtr, | 177 content::PresentationConnectionPtr, |
178 RenderFrameHostIdHasher> | 178 RenderFrameHostIdHasher> |
179 pending_controllers_; | 179 pending_controllers_; |
180 | 180 |
181 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentation); | 181 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentation); |
182 }; | 182 }; |
183 | 183 |
184 private: | 184 private: |
185 friend class OffscreenPresentationManagerFactory; | 185 friend class OffscreenPresentationManagerFactory; |
186 friend class OffscreenPresentationManagerTest; | 186 friend class OffscreenPresentationManagerTest; |
| 187 friend class MockOffscreenPresentationManager; |
187 FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest, | 188 FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest, |
188 ConnectToOffscreenPresentation); | 189 ConnectToOffscreenPresentation); |
189 | 190 |
190 // Used by OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext. | 191 // Used by OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext. |
191 OffscreenPresentationManager(); | 192 OffscreenPresentationManager(); |
192 | 193 |
193 using OffscreenPresentationMap = | 194 using OffscreenPresentationMap = |
194 std::map<std::string, std::unique_ptr<OffscreenPresentation>>; | 195 std::map<std::string, std::unique_ptr<OffscreenPresentation>>; |
195 | 196 |
196 // Creates an offscreen presentation with |presentation_id| and | 197 // Creates an offscreen presentation with |presentation_id| and |
197 // |presentation_url|. | 198 // |presentation_url|. |
198 OffscreenPresentation* GetOrCreateOffscreenPresentation( | 199 OffscreenPresentation* GetOrCreateOffscreenPresentation( |
199 const std::string& presentation_id, | 200 const std::string& presentation_id, |
200 const GURL& presentation_url); | 201 const GURL& presentation_url); |
201 | 202 |
202 // Maps from presentation ID to OffscreenPresentation. | 203 // Maps from presentation ID to OffscreenPresentation. |
203 OffscreenPresentationMap offscreen_presentations_; | 204 OffscreenPresentationMap offscreen_presentations_; |
204 | 205 |
205 base::ThreadChecker thread_checker_; | 206 base::ThreadChecker thread_checker_; |
206 | 207 |
207 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentationManager); | 208 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentationManager); |
208 }; | 209 }; |
209 | 210 |
210 } // namespace media_router | 211 } // namespace media_router |
211 | 212 |
212 #endif // CHROME_BROWSER_MEDIA_ROUTER_OFFSCREEN_PRESENTATION_MANAGER_H_ | 213 #endif // CHROME_BROWSER_MEDIA_ROUTER_OFFSCREEN_PRESENTATION_MANAGER_H_ |
OLD | NEW |