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