| 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 <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <unordered_set> | 11 #include <unordered_set> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/observer_list.h" | 16 #include "base/observer_list.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/cast_modes_with_media_sources.h" | 20 #include "chrome/browser/ui/webui/media_router/cast_modes_with_media_sources.h" |
| 21 #include "chrome/browser/ui/webui/media_router/media_cast_mode.h" | 21 #include "chrome/browser/ui/webui/media_router/media_cast_mode.h" |
| 22 #include "chrome/browser/ui/webui/media_router/media_sink_with_cast_modes.h" | 22 #include "chrome/browser/ui/webui/media_router/media_sink_with_cast_modes.h" |
| 23 | 23 |
| 24 class GURL; | 24 namespace url { |
| 25 class Origin; |
| 26 } // namespace url |
| 25 | 27 |
| 26 namespace media_router { | 28 namespace media_router { |
| 27 | 29 |
| 28 class MediaRouter; | 30 class MediaRouter; |
| 29 class MediaSinksObserver; | 31 class MediaSinksObserver; |
| 30 | 32 |
| 31 // The Media Router dialog allows the user to initiate casting using one of | 33 // The Media Router dialog allows the user to initiate casting using one of |
| 32 // several actions (each represented by a cast mode). Each cast mode is | 34 // several actions (each represented by a cast mode). Each cast mode is |
| 33 // associated with a vector of media sources. This class allows the dialog to | 35 // associated with a vector of media sources. This class allows the dialog to |
| 34 // receive lists of MediaSinks compatible with the cast modes available through | 36 // receive lists of MediaSinks compatible with the cast modes available through |
| 35 // the dialog. | 37 // the dialog. |
| 36 // | 38 // |
| 37 // Typical use: | 39 // Typical use: |
| 38 // | 40 // |
| 39 // GURL origin("https://origin.com"); | 41 // url::Origin origin{GURL("https://origin.com")}; |
| 40 // QueryResultManager::Observer* observer = ...; | 42 // QueryResultManager::Observer* observer = ...; |
| 41 // QueryResultManager result_manager(router); | 43 // QueryResultManager result_manager(router); |
| 42 // result_manager.AddObserver(observer); | 44 // result_manager.AddObserver(observer); |
| 43 // result_manager.SetSourcesForCastMode(MediaCastMode::DEFAULT, | 45 // result_manager.SetSourcesForCastMode(MediaCastMode::DEFAULT, |
| 44 // {MediaSourceForPresentationUrl("http://google.com")}, origin); | 46 // {MediaSourceForPresentationUrl("http://google.com")}, origin); |
| 45 // result_manager.SetSourcesForCastMode(MediaCastMode::TAB_MIRROR, | 47 // result_manager.SetSourcesForCastMode(MediaCastMode::TAB_MIRROR, |
| 46 // {MediaSourceForTab(123)}, origin); | 48 // {MediaSourceForTab(123)}, origin); |
| 47 // ... | 49 // ... |
| 48 // [Updates will be received by observer via OnResultsUpdated()] | 50 // [Updates will be received by observer via OnResultsUpdated()] |
| 49 // ... | 51 // ... |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 // Results are sent to all observers registered with AddObserver(). | 84 // Results are sent to all observers registered with AddObserver(). |
| 83 // | 85 // |
| 84 // Starts new queries in the Media Router for sources that we have no existing | 86 // Starts new queries in the Media Router for sources that we have no existing |
| 85 // queries for, and stops queries for sources no longer associated with any | 87 // queries for, and stops queries for sources no longer associated with any |
| 86 // cast mode. | 88 // cast mode. |
| 87 // | 89 // |
| 88 // If |sources| is empty or contains a source that has already been registered | 90 // If |sources| is empty or contains a source that has already been registered |
| 89 // with another cast mode, no new queries are begun. | 91 // with another cast mode, no new queries are begun. |
| 90 void SetSourcesForCastMode(MediaCastMode cast_mode, | 92 void SetSourcesForCastMode(MediaCastMode cast_mode, |
| 91 const std::vector<MediaSource>& sources, | 93 const std::vector<MediaSource>& sources, |
| 92 const GURL& origin); | 94 const url::Origin& origin); |
| 93 | 95 |
| 94 // Stops notifying observers for |cast_mode|, and removes it from the set of | 96 // Stops notifying observers for |cast_mode|, and removes it from the set of |
| 95 // supported cast modes. | 97 // supported cast modes. |
| 96 void RemoveSourcesForCastMode(MediaCastMode cast_mode); | 98 void RemoveSourcesForCastMode(MediaCastMode cast_mode); |
| 97 | 99 |
| 98 // Gets the set of cast modes that are being actively queried. | 100 // Gets the set of cast modes that are being actively queried. |
| 99 CastModeSet GetSupportedCastModes() const; | 101 CastModeSet GetSupportedCastModes() const; |
| 100 | 102 |
| 101 // Gets the highest-priority source for the cast mode that is supported by | 103 // Gets the highest-priority source for the cast mode that is supported by |
| 102 // the sink. Returns an empty unique_ptr if there isn't any. | 104 // the sink. Returns an empty unique_ptr if there isn't any. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 120 // Stops and destroys the MediaSinksObservers for media sources that | 122 // Stops and destroys the MediaSinksObservers for media sources that |
| 121 // |cast_mode| used to support, but isn't in |new_sources|, and disassociates | 123 // |cast_mode| used to support, but isn't in |new_sources|, and disassociates |
| 122 // them from sinks. | 124 // them from sinks. |
| 123 void RemoveOldSourcesForCastMode(MediaCastMode cast_mode, | 125 void RemoveOldSourcesForCastMode(MediaCastMode cast_mode, |
| 124 const std::vector<MediaSource>& new_sources); | 126 const std::vector<MediaSource>& new_sources); |
| 125 | 127 |
| 126 // Creates observers and starts queries for each source in |sources| that | 128 // Creates observers and starts queries for each source in |sources| that |
| 127 // doesn't already have an associated observer. | 129 // doesn't already have an associated observer. |
| 128 void AddObserversForCastMode(MediaCastMode cast_mode, | 130 void AddObserversForCastMode(MediaCastMode cast_mode, |
| 129 const std::vector<MediaSource>& sources, | 131 const std::vector<MediaSource>& sources, |
| 130 const GURL& origin); | 132 const url::Origin& origin); |
| 131 | 133 |
| 132 // Modifies the set of sinks compatible with |cast_mode| and |source| | 134 // Modifies the set of sinks compatible with |cast_mode| and |source| |
| 133 // to |new_sinks|. | 135 // to |new_sinks|. |
| 134 void SetSinksCompatibleWithSource(MediaCastMode cast_mode, | 136 void SetSinksCompatibleWithSource(MediaCastMode cast_mode, |
| 135 const MediaSource& source, | 137 const MediaSource& source, |
| 136 const std::vector<MediaSink>& new_sinks); | 138 const std::vector<MediaSink>& new_sinks); |
| 137 | 139 |
| 138 // Returns the highest-priority source for |cast_mode| contained in | 140 // Returns the highest-priority source for |cast_mode| contained in |
| 139 // |sources_for_sink|. Returns an empty unique_ptr if none exists. | 141 // |sources_for_sink|. Returns an empty unique_ptr if none exists. |
| 140 std::unique_ptr<MediaSource> GetHighestPrioritySourceForCastModeAndSink( | 142 std::unique_ptr<MediaSource> GetHighestPrioritySourceForCastModeAndSink( |
| (...skipping 29 matching lines...) Expand all Loading... |
| 170 | 172 |
| 171 // Not owned by this object. | 173 // Not owned by this object. |
| 172 MediaRouter* const router_; | 174 MediaRouter* const router_; |
| 173 | 175 |
| 174 DISALLOW_COPY_AND_ASSIGN(QueryResultManager); | 176 DISALLOW_COPY_AND_ASSIGN(QueryResultManager); |
| 175 }; | 177 }; |
| 176 | 178 |
| 177 } // namespace media_router | 179 } // namespace media_router |
| 178 | 180 |
| 179 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_QUERY_RESULT_MANAGER_H_ | 181 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_QUERY_RESULT_MANAGER_H_ |
| OLD | NEW |