OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_IMPL_H_ |
| 6 #define CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_IMPL_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <queue> |
| 10 #include <string> |
| 11 #include <vector> |
| 12 |
| 13 #include "base/callback.h" |
| 14 #include "base/containers/hash_tables.h" |
| 15 #include "base/gtest_prod_util.h" |
| 16 #include "base/macros.h" |
| 17 #include "base/memory/scoped_vector.h" |
| 18 #include "base/threading/thread_checker.h" |
| 19 #include "chrome/browser/media/router/media_route_provider_manager_host.h" |
| 20 #include "chrome/browser/media/router/media_router.h" |
| 21 #include "chrome/browser/media/router/media_sinks_observer.h" |
| 22 #include "components/keyed_service/core/keyed_service.h" |
| 23 |
| 24 namespace base { |
| 25 template <typename T> |
| 26 struct DefaultLazyInstanceTraits; |
| 27 } // namespace base |
| 28 |
| 29 namespace media_router { |
| 30 |
| 31 class MediaRoute; |
| 32 class MediaRouterApiImpl; |
| 33 class MediaRoutesObserver; |
| 34 struct RoutesQueryResult; |
| 35 |
| 36 // Implementation of MediaRouter that delegates calls to |
| 37 // MediaRouteProviderManagerHost, which in turn handles communication |
| 38 // with the Media Route Provider Manager (MRPM) in the component extension. |
| 39 // In addition, responses from MRPM are delegated to this class which then |
| 40 // invokes the observers / callbacks. |
| 41 // Instances of this class are created through MediaRouterImplFactory. |
| 42 class MediaRouterImpl : public MediaRouter, |
| 43 public KeyedService, |
| 44 public MediaRouteProviderManagerHost::Delegate { |
| 45 public: |
| 46 ~MediaRouterImpl() override; |
| 47 |
| 48 // |mrpm_host_| must be null at the time this is called. |
| 49 // |mrpm_host| must not be null. |
| 50 // Does not take ownership of |mrpm_host_|. |
| 51 // This function can only be called once. |
| 52 void SetMRPMHost(MediaRouteProviderManagerHost* mrpm_host); |
| 53 |
| 54 // MediaRouter implementation. |
| 55 RouteRequestId StartRouteRequest( |
| 56 const MediaSource& source, |
| 57 const MediaSinkId& sink_id, |
| 58 const MediaRouteResponseCallback& callback) override; |
| 59 void UnregisterMediaRouteResponseCallback( |
| 60 const RouteRequestId& request_id) override; |
| 61 void CloseRoute(const MediaRouteId& route_id) override; |
| 62 bool RegisterObserver(MediaSinksObserver* observer) override; |
| 63 void UnregisterObserver(MediaSinksObserver* observer) override; |
| 64 void PostMessage(const MediaRouteId& route_id, |
| 65 const std::string& message, |
| 66 const std::string& extra_info_json) override; |
| 67 void AddMediaRoutesObserver(MediaRoutesObserver* observer) override; |
| 68 void RemoveMediaRoutesObserver(MediaRoutesObserver* observer) override; |
| 69 |
| 70 // MediaRouteProviderManagerHost::Delegate implementation. |
| 71 void OnMessage(const MediaRouteId& route_id, |
| 72 const std::string& message) override; |
| 73 void OnSinksReceived(const MediaSource& source, |
| 74 const std::vector<MediaSink>& sinks) override; |
| 75 void OnRouteResponseReceived(const RouteRequestId& request_id, |
| 76 const MediaRoute& route) override; |
| 77 void OnRouteResponseError(const RouteRequestId& request_id, |
| 78 const std::string& error_text) override; |
| 79 void OnRoutesUpdated( |
| 80 const std::vector<MediaRoute>& routes, |
| 81 const std::vector<MediaSink>& sinks) override; |
| 82 void OnHostDestroyed(MediaRouteProviderManagerHost* host) override; |
| 83 |
| 84 private: |
| 85 friend class MediaRouterImplFactory; |
| 86 |
| 87 // Use MediaRouterImplFactory::GetForBrowserContext(). |
| 88 MediaRouterImpl(); |
| 89 |
| 90 // MRPM host to forward calls to MRPM to. |
| 91 // Responses from MRPM are also received from this host. |
| 92 // Does not own this object. |
| 93 MediaRouteProviderManagerHost* mrpm_host_; |
| 94 |
| 95 DISALLOW_COPY_AND_ASSIGN(MediaRouterImpl); |
| 96 }; |
| 97 |
| 98 } // namespace media_router |
| 99 |
| 100 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_IMPL_H_ |
OLD | NEW |