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