| 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_UI_WEBUI_MEDIA_ROUTER_QUERY_RESULT_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_QUERY_RESULT_MANAGER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_QUERY_RESULT_MANAGER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_QUERY_RESULT_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
| 16 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
| 17 #include "chrome/browser/media/router/media_routes_observer.h" | 17 #include "chrome/browser/media/router/media_routes_observer.h" |
| 18 #include "chrome/browser/media/router/media_sink.h" | 18 #include "chrome/browser/media/router/media_sink.h" |
| 19 #include "chrome/browser/media/router/media_source.h" | 19 #include "chrome/browser/media/router/media_source.h" |
| 20 #include "chrome/browser/ui/webui/media_router/media_cast_mode.h" | 20 #include "chrome/browser/ui/webui/media_router/media_cast_mode.h" |
| 21 #include "chrome/browser/ui/webui/media_router/media_sink_with_cast_modes.h" | 21 #include "chrome/browser/ui/webui/media_router/media_sink_with_cast_modes.h" |
| 22 | 22 |
| 23 namespace media_router { | 23 namespace media_router { |
| 24 | 24 |
| 25 class MediaRouter; | 25 class MediaRouter; |
| 26 class MediaSinksObserver; | 26 class MediaSinksObserver; |
| 27 class MediaSinksSearchRequest; |
| 27 struct RoutesQueryResult; | 28 struct RoutesQueryResult; |
| 28 struct SinksQueryResult; | 29 struct SinksQueryResult; |
| 29 | 30 |
| 30 // The Media Router dialog allows the user to initiate casting using one of | 31 // The Media Router dialog allows the user to initiate casting using one of |
| 31 // several actions (each represented by a cast mode). Each cast mode is | 32 // several actions (each represented by a cast mode). Each cast mode is |
| 32 // associated with a media source. This class allows the dialog to receive | 33 // associated with a media source. This class allows the dialog to receive |
| 33 // lists of MediaSinks compatible with the cast modes available through the | 34 // lists of MediaSinks compatible with the cast modes available through the |
| 34 // dialog. | 35 // dialog. |
| 35 // | 36 // |
| 36 // Typical use: | 37 // Typical use: |
| (...skipping 22 matching lines...) Expand all Loading... |
| 59 class QueryResultManager { | 60 class QueryResultManager { |
| 60 public: | 61 public: |
| 61 class Observer { | 62 class Observer { |
| 62 public: | 63 public: |
| 63 virtual ~Observer() {} | 64 virtual ~Observer() {} |
| 64 | 65 |
| 65 // Updated results have been received. | 66 // Updated results have been received. |
| 66 // |sinks|: List of sinks and the cast modes they are compatible with. | 67 // |sinks|: List of sinks and the cast modes they are compatible with. |
| 67 virtual void OnResultsUpdated( | 68 virtual void OnResultsUpdated( |
| 68 const std::vector<MediaSinkWithCastModes>& sinks) = 0; | 69 const std::vector<MediaSinkWithCastModes>& sinks) = 0; |
| 70 virtual void OnSearchResultsReceived( |
| 71 const MediaSink::Id& sink_id, |
| 72 const std::vector<MediaSinkWithCastModes>& sinks) = 0; |
| 69 }; | 73 }; |
| 70 | 74 |
| 71 explicit QueryResultManager(MediaRouter* media_router); | 75 explicit QueryResultManager(MediaRouter* media_router); |
| 72 ~QueryResultManager(); | 76 ~QueryResultManager(); |
| 73 | 77 |
| 74 // Adds/removes an observer that is notified with query results. | 78 // Adds/removes an observer that is notified with query results. |
| 75 void AddObserver(Observer* observer); | 79 void AddObserver(Observer* observer); |
| 76 void RemoveObserver(Observer* observer); | 80 void RemoveObserver(Observer* observer); |
| 77 | 81 |
| 78 // Requests a list of MediaSinks compatible with |source| for |cast_mode|. | 82 // Requests a list of MediaSinks compatible with |source| for |cast_mode|. |
| 79 // Results are sent to all observers registered with AddObserver(). | 83 // Results are sent to all observers registered with AddObserver(). |
| 80 // | 84 // |
| 81 // May start a new query in the Media Router for the registered source if | 85 // May start a new query in the Media Router for the registered source if |
| 82 // there is no existing query for it. If there is an existing query for | 86 // there is no existing query for it. If there is an existing query for |
| 83 // |cast_mode|, it is stopped. | 87 // |cast_mode|, it is stopped. |
| 84 // | 88 // |
| 85 // If |source| is empty, no new queries are begun. | 89 // If |source| is empty, no new queries are begun. |
| 86 void StartSinksQuery(MediaCastMode cast_mode, const MediaSource& source); | 90 void StartSinksQuery(MediaCastMode cast_mode, const MediaSource& source); |
| 87 | 91 |
| 88 // Stops notifying observers for |cast_mode|. | 92 // Stops notifying observers for |cast_mode|. |
| 89 void StopSinksQuery(MediaCastMode cast_mode); | 93 void StopSinksQuery(MediaCastMode cast_mode); |
| 90 | 94 |
| 95 // Requests a list of MediaSinks compatible the current source associated with |
| 96 // |cast_mode| that have an ID matching |sink_id|. Results are sent to all |
| 97 // observers registered with AddObserver(). |
| 98 void StartSinkSearch(MediaCastMode cast_mode, const MediaSink::Id& sink_id); |
| 99 |
| 91 // Gets the set of cast modes that are being actively queried. |cast_mode_set| | 100 // Gets the set of cast modes that are being actively queried. |cast_mode_set| |
| 92 // should be empty. | 101 // should be empty. |
| 93 void GetSupportedCastModes(CastModeSet* cast_modes) const; | 102 void GetSupportedCastModes(CastModeSet* cast_modes) const; |
| 94 | 103 |
| 95 // Returns the MediaSource registered for |cast_mode|. Returns an empty | 104 // Returns the MediaSource registered for |cast_mode|. Returns an empty |
| 96 // MediaSource if there is none. | 105 // MediaSource if there is none. |
| 97 MediaSource GetSourceForCastMode(MediaCastMode cast_mode) const; | 106 MediaSource GetSourceForCastMode(MediaCastMode cast_mode) const; |
| 98 | 107 |
| 99 private: | 108 private: |
| 100 class CastModeMediaSinksObserver; | 109 class CastModeMediaSinksObserver; |
| 110 class SearchSinksRequest; |
| 101 | 111 |
| 102 FRIEND_TEST_ALL_PREFIXES(QueryResultManagerTest, Observers); | 112 FRIEND_TEST_ALL_PREFIXES(QueryResultManagerTest, Observers); |
| 103 FRIEND_TEST_ALL_PREFIXES(QueryResultManagerTest, StartRoutesDiscovery); | 113 FRIEND_TEST_ALL_PREFIXES(QueryResultManagerTest, StartRoutesDiscovery); |
| 104 FRIEND_TEST_ALL_PREFIXES(QueryResultManagerTest, MultipleQueries); | 114 FRIEND_TEST_ALL_PREFIXES(QueryResultManagerTest, MultipleQueries); |
| 105 | 115 |
| 106 // Sets the media source for |cast_mode|. | 116 // Sets the media source for |cast_mode|. |
| 107 void SetSourceForCastMode(MediaCastMode cast_mode, const MediaSource& source); | 117 void SetSourceForCastMode(MediaCastMode cast_mode, const MediaSource& source); |
| 108 | 118 |
| 109 // Stops and destroys the MediaSinksObserver for |cast_mode|. | 119 // Stops and destroys the MediaSinksObserver for |cast_mode|. |
| 110 void RemoveObserverForCastMode(MediaCastMode cast_mode); | 120 void RemoveObserverForCastMode(MediaCastMode cast_mode); |
| 111 | 121 |
| 112 // Returns true if the |entry|'s sink is compatible with at least one cast | 122 // Returns true if the |entry|'s sink is compatible with at least one cast |
| 113 // mode. | 123 // mode. |
| 114 bool IsValid(const MediaSinkWithCastModes& entry) const; | 124 bool IsValid(const MediaSinkWithCastModes& entry) const; |
| 115 | 125 |
| 116 // Modifies the current set of results with |result| associated with | 126 // Modifies the current set of results with |result| associated with |
| 117 // |cast_mode|. | 127 // |cast_mode|. |
| 118 void UpdateWithSinksQueryResult(MediaCastMode cast_mode, | 128 void UpdateWithSinksQueryResult(MediaCastMode cast_mode, |
| 119 const std::vector<MediaSink>& result); | 129 const std::vector<MediaSink>& result); |
| 120 | 130 |
| 121 // Notifies observers that results have been updated. | 131 // Notifies observers that results have been updated. |
| 122 void NotifyOnResultsUpdated(); | 132 void NotifyOnResultsUpdated(); |
| 133 void NotifyOnSearchResults(const MediaSink::Id& sink_id, |
| 134 const std::vector<MediaSink>& sinks); |
| 123 | 135 |
| 124 // MediaSinksObservers that listens for compatible MediaSink updates. | 136 // MediaSinksObservers that listens for compatible MediaSink updates. |
| 125 // Each observer is associated with a MediaCastMode. Results received by | 137 // Each observer is associated with a MediaCastMode. Results received by |
| 126 // observers are propagated back to this class. | 138 // observers are propagated back to this class. |
| 127 std::map<MediaCastMode, scoped_ptr<MediaSinksObserver>> sinks_observers_; | 139 std::map<MediaCastMode, scoped_ptr<MediaSinksObserver>> sinks_observers_; |
| 128 | 140 |
| 129 // Holds registrations of MediaSources for cast modes. | 141 // Holds registrations of MediaSources for cast modes. |
| 130 std::map<MediaCastMode, MediaSource> cast_mode_sources_; | 142 std::map<MediaCastMode, MediaSource> cast_mode_sources_; |
| 131 | 143 |
| 132 // Holds all known sinks and their associated cast modes. | 144 // Holds all known sinks and their associated cast modes. |
| 133 std::map<MediaSink::Id, MediaSinkWithCastModes> all_sinks_; | 145 std::map<MediaSink::Id, MediaSinkWithCastModes> all_sinks_; |
| 134 | 146 |
| 135 // Registered observers. | 147 // Registered observers. |
| 136 base::ObserverList<Observer> observers_; | 148 base::ObserverList<Observer> observers_; |
| 137 | 149 |
| 138 // Not owned by this object. | 150 // Not owned by this object. |
| 139 MediaRouter* router_; | 151 MediaRouter* router_; |
| 140 | 152 |
| 141 base::ThreadChecker thread_checker_; | 153 base::ThreadChecker thread_checker_; |
| 142 | 154 |
| 143 DISALLOW_COPY_AND_ASSIGN(QueryResultManager); | 155 DISALLOW_COPY_AND_ASSIGN(QueryResultManager); |
| 144 }; | 156 }; |
| 145 | 157 |
| 146 } // namespace media_router | 158 } // namespace media_router |
| 147 | 159 |
| 148 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_QUERY_RESULT_MANAGER_H_ | 160 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_QUERY_RESULT_MANAGER_H_ |
| OLD | NEW |