| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_MOJO_MEDIA_ROUTER_MOJO_IMPL_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_IMPL_H_ |
| 6 #define CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_IMPL_H_ | 6 #define CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_IMPL_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <deque> | 10 #include <deque> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "base/observer_list.h" | 22 #include "base/observer_list.h" |
| 23 #include "base/optional.h" | 23 #include "base/optional.h" |
| 24 #include "base/threading/thread_task_runner_handle.h" | 24 #include "base/threading/thread_task_runner_handle.h" |
| 25 #include "build/build_config.h" | 25 #include "build/build_config.h" |
| 26 #include "chrome/browser/media/router/issue_manager.h" | 26 #include "chrome/browser/media/router/issue_manager.h" |
| 27 #include "chrome/browser/media/router/media_router_base.h" | 27 #include "chrome/browser/media/router/media_router_base.h" |
| 28 #include "chrome/browser/media/router/media_routes_observer.h" | 28 #include "chrome/browser/media/router/media_routes_observer.h" |
| 29 #include "chrome/common/media_router/issue.h" | 29 #include "chrome/common/media_router/issue.h" |
| 30 #include "chrome/common/media_router/mojo/media_router.mojom.h" | 30 #include "chrome/common/media_router/mojo/media_router.mojom.h" |
| 31 #include "chrome/common/media_router/route_request_result.h" | 31 #include "chrome/common/media_router/route_request_result.h" |
| 32 #include "content/public/browser/browser_thread.h" |
| 32 #include "mojo/public/cpp/bindings/binding.h" | 33 #include "mojo/public/cpp/bindings/binding.h" |
| 33 #include "services/service_manager/public/cpp/bind_source_info.h" | 34 #include "services/service_manager/public/cpp/bind_source_info.h" |
| 34 | 35 |
| 35 namespace content { | 36 namespace content { |
| 36 class BrowserContext; | 37 class BrowserContext; |
| 37 } | 38 } |
| 38 | 39 |
| 39 namespace extensions { | 40 namespace extensions { |
| 40 class EventPageTracker; | 41 class EventPageTracker; |
| 41 class Extension; | 42 class Extension; |
| 42 } | 43 } |
| 43 | 44 |
| 44 namespace media_router { | 45 namespace media_router { |
| 45 | 46 |
| 46 enum class MediaRouteProviderWakeReason; | 47 enum class MediaRouteProviderWakeReason; |
| 48 class DialMediaSinkServiceProxy; |
| 47 | 49 |
| 48 // MediaRouter implementation that delegates calls to the component extension. | 50 // MediaRouter implementation that delegates calls to the component extension. |
| 49 // Also handles the suspension and wakeup of the component extension. | 51 // Also handles the suspension and wakeup of the component extension. |
| 50 // Lives on the UI thread. | 52 // Lives on the UI thread. |
| 51 class MediaRouterMojoImpl : public MediaRouterBase, | 53 class MediaRouterMojoImpl : public MediaRouterBase, |
| 52 public mojom::MediaRouter { | 54 public mojom::MediaRouter { |
| 53 public: | 55 public: |
| 54 ~MediaRouterMojoImpl() override; | 56 ~MediaRouterMojoImpl() override; |
| 55 | 57 |
| 56 // Sets up the MediaRouterMojoImpl instance owned by |context| to handle | 58 // Sets up the MediaRouterMojoImpl instance owned by |context| to handle |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 void AddIssue(const IssueInfo& issue_info) override; | 106 void AddIssue(const IssueInfo& issue_info) override; |
| 105 void ClearIssue(const Issue::Id& issue_id) override; | 107 void ClearIssue(const Issue::Id& issue_id) override; |
| 106 void OnUserGesture() override; | 108 void OnUserGesture() override; |
| 107 void SearchSinks( | 109 void SearchSinks( |
| 108 const MediaSink::Id& sink_id, | 110 const MediaSink::Id& sink_id, |
| 109 const MediaSource::Id& source_id, | 111 const MediaSource::Id& source_id, |
| 110 const std::string& search_input, | 112 const std::string& search_input, |
| 111 const std::string& domain, | 113 const std::string& domain, |
| 112 const MediaSinkSearchResponseCallback& sink_callback) override; | 114 const MediaSinkSearchResponseCallback& sink_callback) override; |
| 113 void ProvideSinks(const std::string& provider_name, | 115 void ProvideSinks(const std::string& provider_name, |
| 114 const std::vector<MediaSinkInternal>& sinks) override; | 116 std::vector<MediaSinkInternal> sinks) override; |
| 115 scoped_refptr<MediaRouteController> GetRouteController( | 117 scoped_refptr<MediaRouteController> GetRouteController( |
| 116 const MediaRoute::Id& route_id) override; | 118 const MediaRoute::Id& route_id) override; |
| 117 | 119 |
| 118 const std::string& media_route_provider_extension_id() const { | 120 const std::string& media_route_provider_extension_id() const { |
| 119 return media_route_provider_extension_id_; | 121 return media_route_provider_extension_id_; |
| 120 } | 122 } |
| 121 | 123 |
| 122 void set_instance_id_for_test(const std::string& instance_id) { | 124 void set_instance_id_for_test(const std::string& instance_id) { |
| 123 instance_id_ = instance_id; | 125 instance_id_ = instance_id; |
| 124 } | 126 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 std::vector<std::string> joinable_route_ids; | 209 std::vector<std::string> joinable_route_ids; |
| 208 | 210 |
| 209 base::ObserverList<MediaRoutesObserver> observers; | 211 base::ObserverList<MediaRoutesObserver> observers; |
| 210 | 212 |
| 211 private: | 213 private: |
| 212 DISALLOW_COPY_AND_ASSIGN(MediaRoutesQuery); | 214 DISALLOW_COPY_AND_ASSIGN(MediaRoutesQuery); |
| 213 }; | 215 }; |
| 214 | 216 |
| 215 // Standard constructor, used by | 217 // Standard constructor, used by |
| 216 // MediaRouterMojoImplFactory::GetApiForBrowserContext. | 218 // MediaRouterMojoImplFactory::GetApiForBrowserContext. |
| 217 explicit MediaRouterMojoImpl( | 219 MediaRouterMojoImpl(extensions::EventPageTracker* event_page_tracker, |
| 218 extensions::EventPageTracker* event_page_tracker); | 220 content::BrowserContext* context); |
| 219 | 221 |
| 220 // Binds |this| to a Mojo interface request, so that clients can acquire a | 222 // Binds |this| to a Mojo interface request, so that clients can acquire a |
| 221 // handle to a MediaRouterMojoImpl instance via the Mojo service connector. | 223 // handle to a MediaRouterMojoImpl instance via the Mojo service connector. |
| 222 // Stores the ID of |extension| in |media_route_provider_extension_id_|. | 224 // Stores the ID of |extension| in |media_route_provider_extension_id_|. |
| 223 void BindToMojoRequest( | 225 void BindToMojoRequest( |
| 224 mojo::InterfaceRequest<mojom::MediaRouter> request, | 226 mojo::InterfaceRequest<mojom::MediaRouter> request, |
| 225 const extensions::Extension& extension); | 227 const extensions::Extension& extension); |
| 226 | 228 |
| 227 // Enqueues a closure for later execution by ExecutePendingRequests(). | 229 // Enqueues a closure for later execution by ExecutePendingRequests(). |
| 228 void EnqueueTask(base::OnceClosure closure); | 230 void EnqueueTask(base::OnceClosure closure); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 const MediaSource::Id& source_id, | 299 const MediaSource::Id& source_id, |
| 298 const std::string& search_input, | 300 const std::string& search_input, |
| 299 const std::string& domain, | 301 const std::string& domain, |
| 300 const MediaSinkSearchResponseCallback& sink_callback); | 302 const MediaSinkSearchResponseCallback& sink_callback); |
| 301 void DoCreateMediaRouteController( | 303 void DoCreateMediaRouteController( |
| 302 const MediaRoute::Id& route_id, | 304 const MediaRoute::Id& route_id, |
| 303 mojom::MediaControllerRequest mojo_media_controller_request, | 305 mojom::MediaControllerRequest mojo_media_controller_request, |
| 304 mojom::MediaStatusObserverPtr mojo_observer); | 306 mojom::MediaStatusObserverPtr mojo_observer); |
| 305 | 307 |
| 306 void DoProvideSinks(const std::string& provider_name, | 308 void DoProvideSinks(const std::string& provider_name, |
| 307 const std::vector<MediaSinkInternal>& sinks); | 309 std::vector<MediaSinkInternal> sinks); |
| 308 | 310 |
| 309 // Error handler callback for |binding_| and |media_route_provider_|. | 311 // Error handler callback for |binding_| and |media_route_provider_|. |
| 310 void OnConnectionError(); | 312 void OnConnectionError(); |
| 311 | 313 |
| 312 // Issues 0+ calls to |media_route_provider_| to ensure its state is in sync | 314 // Issues 0+ calls to |media_route_provider_| to ensure its state is in sync |
| 313 // with MediaRouter on a best-effort basis. This method can be only called if | 315 // with MediaRouter on a best-effort basis. This method can be only called if |
| 314 // |media_route_provider_| is a valid handle. | 316 // |media_route_provider_| is a valid handle. |
| 315 // The extension might have become out of sync with MediaRouter due to one | 317 // The extension might have become out of sync with MediaRouter due to one |
| 316 // of few reasons: | 318 // of few reasons: |
| 317 // (1) The extension crashed and lost unpersisted changes. | 319 // (1) The extension crashed and lost unpersisted changes. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 // period. | 395 // period. |
| 394 void EnsureMdnsDiscoveryEnabled(); | 396 void EnsureMdnsDiscoveryEnabled(); |
| 395 void DoEnsureMdnsDiscoveryEnabled(); | 397 void DoEnsureMdnsDiscoveryEnabled(); |
| 396 | 398 |
| 397 // Callback used to enabled mDNS in the MRPM if a firewall prompt will not be | 399 // Callback used to enabled mDNS in the MRPM if a firewall prompt will not be |
| 398 // triggered. If a firewall prompt would be triggered, enabling mDNS won't | 400 // triggered. If a firewall prompt would be triggered, enabling mDNS won't |
| 399 // happen until the user is clearly interacting with MR. | 401 // happen until the user is clearly interacting with MR. |
| 400 void OnFirewallCheckComplete(bool firewall_can_use_local_ports); | 402 void OnFirewallCheckComplete(bool firewall_can_use_local_ports); |
| 401 #endif | 403 #endif |
| 402 | 404 |
| 405 // Start browser side sink discovery. |
| 406 void StartDiscovery(); |
| 407 |
| 403 // Requests MRPM to update media sinks. This allows MRPs that only do | 408 // Requests MRPM to update media sinks. This allows MRPs that only do |
| 404 // discovery on sink queries an opportunity to update discovery results | 409 // discovery on sink queries an opportunity to update discovery results |
| 405 // even if the MRP SinkAvailability is marked UNAVAILABLE. | 410 // even if the MRP SinkAvailability is marked UNAVAILABLE. |
| 406 void UpdateMediaSinks(const MediaSource::Id& source_id); | 411 void UpdateMediaSinks(const MediaSource::Id& source_id); |
| 407 void DoUpdateMediaSinks(const MediaSource::Id& source_id); | 412 void DoUpdateMediaSinks(const MediaSource::Id& source_id); |
| 408 | 413 |
| 409 // Invalidates and removes controllers from |route_controllers_| whose media | 414 // Invalidates and removes controllers from |route_controllers_| whose media |
| 410 // routes do not appear in |routes|. | 415 // routes do not appear in |routes|. |
| 411 void RemoveInvalidRouteControllers(const std::vector<MediaRoute>& routes); | 416 void RemoveInvalidRouteControllers(const std::vector<MediaRoute>& routes); |
| 412 | 417 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 MediaRouteProviderWakeReason current_wake_reason_; | 468 MediaRouteProviderWakeReason current_wake_reason_; |
| 464 | 469 |
| 465 // A flag to ensure that we record the provider version once, during the | 470 // A flag to ensure that we record the provider version once, during the |
| 466 // initial event page wakeup attempt. | 471 // initial event page wakeup attempt. |
| 467 bool provider_version_was_recorded_ = false; | 472 bool provider_version_was_recorded_ = false; |
| 468 | 473 |
| 469 // Stores route controllers that can be used to send media commands to the | 474 // Stores route controllers that can be used to send media commands to the |
| 470 // extension. | 475 // extension. |
| 471 std::unordered_map<MediaRoute::Id, MediaRouteController*> route_controllers_; | 476 std::unordered_map<MediaRoute::Id, MediaRouteController*> route_controllers_; |
| 472 | 477 |
| 478 // Media sink service for DIAL devices. |
| 479 scoped_refptr<DialMediaSinkServiceProxy> dial_media_sink_service_proxy_; |
| 480 |
| 481 content::BrowserContext* const context_; |
| 482 |
| 473 #if defined(OS_WIN) | 483 #if defined(OS_WIN) |
| 474 // A pair of flags to ensure that mDNS discovery is only enabled on Windows | 484 // A pair of flags to ensure that mDNS discovery is only enabled on Windows |
| 475 // when there will be appropriate context for the user to associate a firewall | 485 // when there will be appropriate context for the user to associate a firewall |
| 476 // prompt with Media Router. |should_enable_mdns_discovery_| can only go from | 486 // prompt with Media Router. |should_enable_mdns_discovery_| can only go from |
| 477 // |false| to |true|. On Windows, |is_mdns_enabled_| is set to |false| in | 487 // |false| to |true|. On Windows, |is_mdns_enabled_| is set to |false| in |
| 478 // RegisterMediaRouteProvider and only set to |true| when we successfully call | 488 // RegisterMediaRouteProvider and only set to |true| when we successfully call |
| 479 // the extension to enable mDNS. | 489 // the extension to enable mDNS. |
| 480 bool is_mdns_enabled_ = false; | 490 bool is_mdns_enabled_ = false; |
| 481 bool should_enable_mdns_discovery_ = false; | 491 bool should_enable_mdns_discovery_ = false; |
| 482 #endif | 492 #endif |
| 483 | 493 |
| 484 base::WeakPtrFactory<MediaRouterMojoImpl> weak_factory_; | 494 base::WeakPtrFactory<MediaRouterMojoImpl> weak_factory_; |
| 485 | 495 |
| 486 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoImpl); | 496 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoImpl); |
| 487 }; | 497 }; |
| 488 | 498 |
| 489 } // namespace media_router | 499 } // namespace media_router |
| 490 | 500 |
| 491 #endif // CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_IMPL_H_ | 501 #endif // CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_IMPL_H_ |
| OLD | NEW |