Chromium Code Reviews| Index: chrome/browser/ui/webui/media_router/query_result_manager.h |
| diff --git a/chrome/browser/ui/webui/media_router/query_result_manager.h b/chrome/browser/ui/webui/media_router/query_result_manager.h |
| index ecffaec94c339f576f76942035983278fcca9dea..c08779344fd71646da464b2f5e4aa3a9cf6ce9fc 100644 |
| --- a/chrome/browser/ui/webui/media_router/query_result_manager.h |
| +++ b/chrome/browser/ui/webui/media_router/query_result_manager.h |
| @@ -8,6 +8,7 @@ |
| #include <map> |
| #include <memory> |
| #include <set> |
| +#include <unordered_set> |
| #include <vector> |
| #include "base/gtest_prod_util.h" |
| @@ -28,9 +29,9 @@ struct SinksQueryResult; |
| // The Media Router dialog allows the user to initiate casting using one of |
| // several actions (each represented by a cast mode). Each cast mode is |
| -// associated with a media source. This class allows the dialog to receive |
| -// lists of MediaSinks compatible with the cast modes available through the |
| -// dialog. |
| +// associated with a vector of media sources. This class allows the dialog to |
| +// receive lists of MediaSinks compatible with the cast modes available through |
| +// the dialog. |
| // |
| // Typical use: |
| // |
| @@ -39,17 +40,17 @@ struct SinksQueryResult; |
| // QueryResultManager result_manager(router); |
| // result_manager.AddObserver(observer); |
| // result_manager.StartSinksQuery(MediaCastMode::DEFAULT, |
| -// MediaSourceForPresentationUrl("http://google.com"), origin); |
| +// {MediaSourceForPresentationUrl("http://google.com")}, origin); |
| // result_manager.StartSinksQuery(MediaCastMode::TAB_MIRROR, |
| -// MediaSourceForTab(123), origin); |
| +// {MediaSourceForTab(123)}, origin); |
| // ... |
| // [Updates will be received by observer via OnResultsUpdated()] |
| // ... |
| // [When info on MediaSource is needed, i.e. when requesting route for a mode] |
| // CastModeSet cast_modes = result_manager.GetSupportedCastModes(); |
| // [Logic to select a MediaCastMode from the set] |
| -// MediaSource source = result_manager.GetSourceForCastMode( |
| -// MediaCastMode::TAB_MIRROR); |
| +// MediaSource source = result_manager.GetSourceForCastModeAndSink( |
| +// MediaCastMode::TAB_MIRROR, sink_of_interest); |
| // if (!source.Empty()) { |
| // ... |
| // } |
| @@ -74,17 +75,17 @@ class QueryResultManager { |
| void AddObserver(Observer* observer); |
| void RemoveObserver(Observer* observer); |
| - // Requests a list of MediaSinks compatible with |source| for |cast_mode| |
| - // from |origin|. |
| + // Requests a list of MediaSinks compatible with |sources| for |cast_mode| |
| + // from |origin|. |sources| should be in descending order of priority. |
| // Results are sent to all observers registered with AddObserver(). |
| // |
| - // May start a new query in the Media Router for the registered source if |
| - // there is no existing query for it. If there is an existing query for |
| - // |cast_mode|, it is stopped. |
| + // May start new queries in the Media Router for the registered sources if |
| + // there are no existing queries for it. If there are existing queries for |
| + // |cast_mode|, they are stopped. |
| // |
| - // If |source| is empty, no new queries are begun. |
| + // If |sources| is empty, no new queries are begun. |
| void StartSinksQuery(MediaCastMode cast_mode, |
| - const MediaSource& source, |
| + const std::vector<MediaSource>& sources, |
| const GURL& origin); |
| // Stops notifying observers for |cast_mode|. |
| @@ -93,9 +94,14 @@ class QueryResultManager { |
| // Gets the set of cast modes that are being actively queried. |
| CastModeSet GetSupportedCastModes() const; |
| - // Returns the MediaSource registered for |cast_mode|. Returns an empty |
| - // MediaSource if there is none. |
| - MediaSource GetSourceForCastMode(MediaCastMode cast_mode) const; |
| + // Gets the highest-priority source for the cast mode that is supported by |
| + // the sink. Returns an empty MediaSource if there isn't any. |
| + MediaSource GetSourceForCastModeAndSink( |
| + MediaCastMode cast_mode, MediaSink::Id sink_id) const; |
| + |
| + // Returns all the sources registered for |cast_mode|. Returns an empty |
| + // vector if there is none. |
| + std::vector<MediaSource> GetSourcesForCastMode(MediaCastMode cast_mode) const; |
| private: |
| class CastModeMediaSinksObserver; |
| @@ -103,35 +109,51 @@ class QueryResultManager { |
| FRIEND_TEST_ALL_PREFIXES(QueryResultManagerTest, Observers); |
| FRIEND_TEST_ALL_PREFIXES(QueryResultManagerTest, StartRoutesDiscovery); |
| FRIEND_TEST_ALL_PREFIXES(QueryResultManagerTest, MultipleQueries); |
| + FRIEND_TEST_ALL_PREFIXES(QueryResultManagerTest, MultipleUrls); |
| - // Sets the media source for |cast_mode|. |
| - void SetSourceForCastMode(MediaCastMode cast_mode, const MediaSource& source); |
| + // Sets the media sources for |cast_mode|. |
| + void SetSourcesForCastMode( |
|
mark a. foltz
2016/08/23 20:46:47
Doesn't this depend on the sink? Or is this to ke
takumif
2016/08/23 22:13:09
It's the latter.
|
| + MediaCastMode cast_mode, const std::vector<MediaSource>& source); |
| - // Stops and destroys the MediaSinksObserver for |cast_mode|. |
| - void RemoveObserverForCastMode(MediaCastMode cast_mode); |
| + // Stops and destroys the MediaSinksObservers for |cast_mode|. |
| + void RemoveObserversForCastMode(MediaCastMode cast_mode); |
| - // Returns true if the |entry|'s sink is compatible with at least one cast |
| - // mode. |
| - bool IsValid(const MediaSinkWithCastModes& entry) const; |
| + // Set all the sinks to not support the cast mode. |
| + void ResetSinkCompatibilityForCastMode(MediaCastMode cast_mode); |
| // Modifies the current set of results with |result| associated with |
| - // |cast_mode|. |
| + // |cast_mode| and |source|. |
| void UpdateWithSinksQueryResult(MediaCastMode cast_mode, |
| - const std::vector<MediaSink>& result); |
| + const MediaSource source, |
| + const std::vector<MediaSink>& result_sinks); |
| // Notifies observers that results have been updated. |
| void NotifyOnResultsUpdated(); |
| + // Returns the first source on the vector supported by the sink. Returns an |
| + // empty |MediaSource| if none exists. |
| + MediaSource GetFirstSourceSupportedBySink( |
|
mark a. foltz
2016/08/23 20:46:47
Doesn't this depend on the cast mode?
Also, this
|
| + std::vector<MediaSource> sources, MediaSink::Id sink_id) const; |
| + |
| + // Returns true if the source is in the set of sources supported by the sink. |
| + bool SinkSupportsSource(MediaSink sink, MediaSource source) const; |
|
mark a. foltz
2016/08/23 20:46:47
This could be a method on MediaSinkWithCastModes.
|
| + |
| + // Creates a MediaSinkWithCastModes that contains the sink and the cast modes |
| + // it supports. |
| + MediaSinkWithCastModes GetMediaSinkWithCastModes(const MediaSink& sink); |
|
mark a. foltz
2016/08/23 20:46:47
return const ref
|
| + |
| // MediaSinksObservers that listens for compatible MediaSink updates. |
| // Each observer is associated with a MediaCastMode. Results received by |
| // observers are propagated back to this class. |
| - std::map<MediaCastMode, std::unique_ptr<MediaSinksObserver>> sinks_observers_; |
| + std::map<MediaCastMode, std::vector<std::unique_ptr<MediaSinksObserver>>> |
| + sinks_observers_; |
| // Holds registrations of MediaSources for cast modes. |
| - std::map<MediaCastMode, MediaSource> cast_mode_sources_; |
| + std::map<MediaCastMode, std::vector<MediaSource>> cast_mode_sources_; |
| - // Holds all known sinks and their associated cast modes. |
| - std::map<MediaSink::Id, MediaSinkWithCastModes> all_sinks_; |
| + // Holds all known sinks along with the cast modes and sources they support. |
| + std::map<MediaSink, std::map<MediaCastMode, |
|
mark a. foltz
2016/08/23 20:46:47
These nested data structures are really hard to un
takumif
2016/08/23 22:13:09
This could be a map from sink to unordered set of
|
| + std::unordered_set<MediaSource::Id>>, MediaSink::Compare> all_sinks_; |
| // Registered observers. |
| base::ObserverList<Observer> observers_; |