| 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> |
| 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 Loading... |
| 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); |
| 122 | 108 |
| 123 // Unregisters controller PresentationConnectionPtr to presentation with | 109 // Unregisters controller PresentationConnectionPtr to presentation with |
| 124 // |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 |
| 125 // controller that matches the provided arguments. It removes presentation | 111 // controller that matches the provided arguments. It removes presentation |
| 126 // 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 |
| 127 // any other pending controller. | 113 // any other pending controller. |
| 128 void UnregisterOffscreenPresentationController( | 114 virtual void UnregisterOffscreenPresentationController( |
| 129 const std::string& presentation_id, | 115 const std::string& presentation_id, |
| 130 const RenderFrameHostId& render_frame_id); | 116 const RenderFrameHostId& render_frame_id); |
| 131 | 117 |
| 132 // Registers ReceiverConnectionAvailableCallback to presentation | 118 // Registers ReceiverConnectionAvailableCallback to presentation |
| 133 // with |presentation_id|. | 119 // with |presentation_id|. |
| 134 void OnOffscreenPresentationReceiverCreated( | 120 virtual void OnOffscreenPresentationReceiverCreated( |
| 135 const std::string& presentation_id, | 121 const std::string& presentation_id, |
| 136 const GURL& presentation_url, | 122 const GURL& presentation_url, |
| 137 const content::ReceiverConnectionAvailableCallback& receiver_callback); | 123 const content::ReceiverConnectionAvailableCallback& receiver_callback); |
| 138 | 124 |
| 139 // Unregisters the ReceiverConnectionAvailableCallback associated with | 125 // Unregisters the ReceiverConnectionAvailableCallback associated with |
| 140 // |presentation_id|. | 126 // |presentation_id|. |
| 141 void OnOffscreenPresentationReceiverTerminated( | 127 virtual void OnOffscreenPresentationReceiverTerminated( |
| 142 const std::string& presentation_id); | 128 const std::string& presentation_id); |
| 143 | 129 |
| 144 private: | 130 private: |
| 145 // Represents an offscreen presentation registered with | 131 // Represents an offscreen presentation registered with |
| 146 // OffscreenPresentationManager. | 132 // OffscreenPresentationManager. |
| 147 // Contains callback to the receiver to inform it of new connections | 133 // Contains callback to the receiver to inform it of new connections |
| 148 // established from a controller. | 134 // established from a controller. |
| 149 // Contains set of controllers registered to OffscreenPresentationManager | 135 // Contains set of controllers registered to OffscreenPresentationManager |
| 150 // before corresponding receiver. | 136 // before corresponding receiver. |
| 151 class OffscreenPresentation { | 137 class OffscreenPresentation { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 content::PresentationConnectionPtr, | 177 content::PresentationConnectionPtr, |
| 192 RenderFrameHostIdHasher> | 178 RenderFrameHostIdHasher> |
| 193 pending_controllers_; | 179 pending_controllers_; |
| 194 | 180 |
| 195 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentation); | 181 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentation); |
| 196 }; | 182 }; |
| 197 | 183 |
| 198 private: | 184 private: |
| 199 friend class OffscreenPresentationManagerFactory; | 185 friend class OffscreenPresentationManagerFactory; |
| 200 friend class OffscreenPresentationManagerTest; | 186 friend class OffscreenPresentationManagerTest; |
| 187 friend class MockOffscreenPresentationManager; |
| 188 FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest, |
| 189 ConnectToOffscreenPresentation); |
| 201 | 190 |
| 202 // Used by OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext. | 191 // Used by OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext. |
| 203 OffscreenPresentationManager(); | 192 OffscreenPresentationManager(); |
| 204 | 193 |
| 205 using OffscreenPresentationMap = | 194 using OffscreenPresentationMap = |
| 206 std::map<std::string, std::unique_ptr<OffscreenPresentation>>; | 195 std::map<std::string, std::unique_ptr<OffscreenPresentation>>; |
| 207 | 196 |
| 208 // Creates an offscreen presentation with |presentation_id| and | 197 // Creates an offscreen presentation with |presentation_id| and |
| 209 // |presentation_url|. | 198 // |presentation_url|. |
| 210 OffscreenPresentation* GetOrCreateOffscreenPresentation( | 199 OffscreenPresentation* GetOrCreateOffscreenPresentation( |
| 211 const std::string& presentation_id, | 200 const std::string& presentation_id, |
| 212 const GURL& presentation_url); | 201 const GURL& presentation_url); |
| 213 | 202 |
| 214 // Maps from presentation ID to OffscreenPresentation. | 203 // Maps from presentation ID to OffscreenPresentation. |
| 215 OffscreenPresentationMap offscreen_presentations_; | 204 OffscreenPresentationMap offscreen_presentations_; |
| 216 | 205 |
| 217 base::ThreadChecker thread_checker_; | 206 base::ThreadChecker thread_checker_; |
| 218 | 207 |
| 219 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentationManager); | 208 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentationManager); |
| 220 }; | 209 }; |
| 221 | 210 |
| 222 } // namespace media_router | 211 } // namespace media_router |
| 223 | 212 |
| 224 #endif // CHROME_BROWSER_MEDIA_ROUTER_OFFSCREEN_PRESENTATION_MANAGER_H_ | 213 #endif // CHROME_BROWSER_MEDIA_ROUTER_OFFSCREEN_PRESENTATION_MANAGER_H_ |
| OLD | NEW |