| 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_CAST_REMOTING_CONNECTOR_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_CAST_REMOTING_CONNECTOR_H_ |
| 6 #define CHROME_BROWSER_MEDIA_CAST_REMOTING_CONNECTOR_H_ | 6 #define CHROME_BROWSER_MEDIA_CAST_REMOTING_CONNECTOR_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/supports_user_data.h" | 11 #include "base/supports_user_data.h" |
| 12 #include "chrome/browser/media/router/media_routes_observer.h" | 12 #include "chrome/browser/media/router/media_routes_observer.h" |
| 13 #include "chrome/browser/media/router/route_message.h" | 13 #include "chrome/browser/media/router/route_message.h" |
| 14 #include "media/mojo/interfaces/remoting.mojom.h" | 14 #include "media/mojo/interfaces/remoting.mojom.h" |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 class RenderFrameHost; | 17 class RenderFrameHost; |
| 18 class WebContents; | 18 class WebContents; |
| 19 } | 19 } |
| 20 | 20 |
| 21 // CastRemotingConnector connects a single source (a media element in a render | 21 // CastRemotingConnector connects a single source (a media element in a render |
| 22 // frame) with a single sink (a media player in a remote device). There is one | 22 // frame) with a single sink (a media player in a remote device). There is one |
| 23 // instance of a CastRemotingConnector per source WebContents (representing a | 23 // instance of a CastRemotingConnector per source WebContents (representing a |
| 24 // collection of render frames), and it is created on-demand. The source in the | 24 // collection of render frames), and it is created on-demand. The source in the |
| 25 // render process represents itself by providing a media::mojom::RemotingSource | 25 // render process represents itself by providing a media::mojom::RemotingSource |
| 26 // service instance. The sink is represented by the Media Router Cast Provider. | 26 // service instance. The sink is represented by the Media Router Cast Provider. |
| 27 // | 27 // |
| 28 // Whenever a RenderFrameHost is created, ChromeContentBrowserClient will call | 28 // Whenever a candidate media source is created in a render frame, |
| 29 // CreateRemoterFactory() to instantiate an implementation of | 29 // ChromeContentBrowserClient will call CreateMediaRemoter() to instantiate a |
| 30 // media::mojom::RemoterFactory associated with the connector. This allows one | 30 // media::mojom::Remoter associated with the connector. A corresponding |
| 31 // or more media sources in a render frame to create a media::mojom::Remoter to | 31 // media::mojom::RemotingSource is provided by the caller for communications |
| 32 // start/stop and execute media remoting. Media sources also provide a | 32 // back to the media source in the render frame: The connector uses this to |
| 33 // media::mojom::RemotingSource so that the connector may notify them when a | 33 // notify when a sink becomes available for remoting, and to pass binary |
| 34 // sink becomes available for remoting and pass binary messages from the sink | 34 // messages from the sink back to the source. |
| 35 // back to the source. | |
| 36 // | 35 // |
| 37 // At any time before or after the CastRemotingConnector is created, the | 36 // At any time before or after the CastRemotingConnector is created, the |
| 38 // Media Router Cast Provider may create a tab remoting media route. This | 37 // Media Router Cast Provider may create a tab remoting media route. This |
| 39 // indicates that the provider has found a sink that is capable of remoting and | 38 // indicates that the provider has found a sink that is capable of remoting and |
| 40 // is available for use. At this point, CastRemotingConnector notifies all | 39 // is available for use. At this point, CastRemotingConnector notifies all |
| 41 // RemotingSources that a sink is available, and some time later a | 40 // RemotingSources that a sink is available, and some time later a |
| 42 // RemotingSource can request the start of a remoting session. Once the sink is | 41 // RemotingSource can request the start of a remoting session. Once the sink is |
| 43 // no longer available, the provider terminates the route and | 42 // no longer available, the provider terminates the route and |
| 44 // CastRemotingConnector notifies all RemotingSources that the sink is gone. | 43 // CastRemotingConnector notifies all RemotingSources that the sink is gone. |
| 45 // | 44 // |
| (...skipping 19 matching lines...) Expand all Loading... |
| 65 // start/execute/stop remoting sessions. | 64 // start/execute/stop remoting sessions. |
| 66 class CastRemotingConnector | 65 class CastRemotingConnector |
| 67 : public base::SupportsUserData::Data, | 66 : public base::SupportsUserData::Data, |
| 68 public media_router::MediaRoutesObserver { | 67 public media_router::MediaRoutesObserver { |
| 69 public: | 68 public: |
| 70 // Returns the instance of the CastRemotingConnector associated with | 69 // Returns the instance of the CastRemotingConnector associated with |
| 71 // |source_contents|, creating a new instance if needed. | 70 // |source_contents|, creating a new instance if needed. |
| 72 static CastRemotingConnector* Get(content::WebContents* source_contents); | 71 static CastRemotingConnector* Get(content::WebContents* source_contents); |
| 73 | 72 |
| 74 // Used by ChromeContentBrowserClient to request a binding to a new | 73 // Used by ChromeContentBrowserClient to request a binding to a new |
| 75 // RemoterFactory for each new render frame. | 74 // Remoter for each new source in a render frame. |
| 76 static void CreateRemoterFactory(content::RenderFrameHost* render_frame_host, | 75 static void CreateMediaRemoter(content::RenderFrameHost* render_frame_host, |
| 77 media::mojom::RemoterFactoryRequest request); | 76 media::mojom::RemotingSourcePtr source, |
| 77 media::mojom::RemoterRequest request); |
| 78 | 78 |
| 79 private: | 79 private: |
| 80 // Allow unit tests access to the private constructor and CreateBridge() | 80 // Allow unit tests access to the private constructor and CreateBridge() |
| 81 // method, since unit tests don't have a complete browser (i.e., with a | 81 // method, since unit tests don't have a complete browser (i.e., with a |
| 82 // WebContents and RenderFrameHost) to work with. | 82 // WebContents and RenderFrameHost) to work with. |
| 83 friend class CastRemotingConnectorTest; | 83 friend class CastRemotingConnectorTest; |
| 84 | 84 |
| 85 // Implementation of the media::mojom::RemoterFactory, with one instance | |
| 86 // created per content::RenderFrameHost. An instance of this class is owned by | |
| 87 // its mojo message pipe. | |
| 88 class FrameRemoterFactory; | |
| 89 | |
| 90 // Implementation of the media::mojom::Remoter service for a single source in | 85 // Implementation of the media::mojom::Remoter service for a single source in |
| 91 // a render frame. This is just a "lightweight bridge" that delegates calls | 86 // a render frame. This is just a "lightweight bridge" that delegates calls |
| 92 // back-and-forth between a CastRemotingConnector and a | 87 // back-and-forth between a CastRemotingConnector and a |
| 93 // media::mojom::RemotingSource. An instance of this class is owned by its | 88 // media::mojom::RemotingSource. An instance of this class is owned by its |
| 94 // mojo message pipe. | 89 // mojo message pipe. |
| 95 class RemotingBridge; | 90 class RemotingBridge; |
| 96 | 91 |
| 97 // A RouteMessageObserver for the remoting route that passes messages from the | 92 // A RouteMessageObserver for the remoting route that passes messages from the |
| 98 // Cast Provider back to this connector. An instance of this class only exists | 93 // Cast Provider back to this connector. An instance of this class only exists |
| 99 // while a remoting route is available, and is owned by CastRemotingConnector. | 94 // while a remoting route is available, and is owned by CastRemotingConnector. |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 base::WeakPtrFactory<CastRemotingConnector> weak_factory_; | 193 base::WeakPtrFactory<CastRemotingConnector> weak_factory_; |
| 199 | 194 |
| 200 // Key used with the base::SupportsUserData interface to search for an | 195 // Key used with the base::SupportsUserData interface to search for an |
| 201 // instance of CastRemotingConnector owned by a WebContents. | 196 // instance of CastRemotingConnector owned by a WebContents. |
| 202 static const void* const kUserDataKey; | 197 static const void* const kUserDataKey; |
| 203 | 198 |
| 204 DISALLOW_COPY_AND_ASSIGN(CastRemotingConnector); | 199 DISALLOW_COPY_AND_ASSIGN(CastRemotingConnector); |
| 205 }; | 200 }; |
| 206 | 201 |
| 207 #endif // CHROME_BROWSER_MEDIA_CAST_REMOTING_CONNECTOR_H_ | 202 #endif // CHROME_BROWSER_MEDIA_CAST_REMOTING_CONNECTOR_H_ |
| OLD | NEW |