| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_DISCOVERY_MEDIA_SINK_SERVICE_BASE_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MEDIA_SINK_SERVICE_BASE_H_ |
| 6 #define CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MEDIA_SINK_SERVICE_BASE_H_ | 6 #define CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MEDIA_SINK_SERVICE_BASE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/observer_list.h" |
| 12 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
| 13 #include "chrome/common/media_router/discovery/media_sink_internal.h" | 14 #include "chrome/common/media_router/discovery/media_sink_internal.h" |
| 14 #include "chrome/common/media_router/discovery/media_sink_service.h" | 15 #include "chrome/common/media_router/discovery/media_sink_service.h" |
| 15 | 16 |
| 16 namespace media_router { | 17 namespace media_router { |
| 17 | 18 |
| 18 class MediaSinkServiceBase : public MediaSinkService { | 19 class MediaSinkServiceBase : public MediaSinkService { |
| 19 public: | 20 public: |
| 20 explicit MediaSinkServiceBase(const OnSinksDiscoveredCallback& callback); | 21 explicit MediaSinkServiceBase(const OnSinksDiscoveredCallback& callback); |
| 21 ~MediaSinkServiceBase() override; | 22 ~MediaSinkServiceBase() override; |
| 22 | 23 |
| 24 // MediaSinkService implementation |
| 25 void AddObserver(Observer* observer) override; |
| 26 void RemoveObserver(Observer* observer) override; |
| 27 |
| 23 protected: | 28 protected: |
| 24 void SetTimerForTest(std::unique_ptr<base::Timer> timer); | 29 void SetTimerForTest(std::unique_ptr<base::Timer> timer); |
| 25 | 30 |
| 26 // Called when |finish_timer_| expires. | 31 // Called when |finish_timer_| expires. |
| 27 void OnFetchCompleted(); | 32 virtual void OnFetchCompleted(); |
| 28 | 33 |
| 29 // Helper function to start |finish_timer_|. Create a new timer if none | 34 // Helper function to start |finish_timer_|. Create a new timer if none |
| 30 // exists. | 35 // exists. |
| 31 void StartTimer(); | 36 void StartTimer(); |
| 32 | 37 |
| 33 // Helper function to stop |finish_timer_|. | 38 // Helper function to stop |finish_timer_|. |
| 34 void StopTimer(); | 39 void StopTimer(); |
| 35 | 40 |
| 36 // Helper function to restart |finish_timer|. No-op if timer does not exist or | 41 // Helper function to restart |finish_timer|. No-op if timer does not exist or |
| 37 // timer is currently running. | 42 // timer is currently running. |
| 38 void RestartTimer(); | 43 void RestartTimer(); |
| 39 | 44 |
| 40 // Overriden by subclass to report device counts. | 45 // Overriden by subclass to report device counts. |
| 41 virtual void RecordDeviceCounts() {} | 46 virtual void RecordDeviceCounts() {} |
| 42 | 47 |
| 48 // Adds media sink to current service. |
| 49 void AddSink(const MediaSinkInternal& sink); |
| 50 |
| 51 // Removes all media sinks from current service. |
| 52 void RemoveSinks(); |
| 53 |
| 54 // Returns size of media sinks in current service. |
| 55 size_t GetCurrentSinksSize(); |
| 56 |
| 43 // Time out value for |finish_timer_| | 57 // Time out value for |finish_timer_| |
| 44 int fetch_complete_timeout_secs_; | 58 int fetch_complete_timeout_secs_; |
| 45 | 59 |
| 60 base::ObserverList<MediaSinkService::Observer> observers_; |
| 61 |
| 62 private: |
| 63 friend class MediaSinkServiceBaseTest; |
| 64 FRIEND_TEST_ALL_PREFIXES(MediaSinkServiceBaseTest, |
| 65 TestFetchCompleted_SameSink); |
| 66 FRIEND_TEST_ALL_PREFIXES(MediaSinkServiceBaseTest, TestAddRemoveSinks); |
| 67 |
| 46 // Sorted sinks from current round of discovery. | 68 // Sorted sinks from current round of discovery. |
| 47 std::set<MediaSinkInternal> current_sinks_; | 69 std::set<MediaSinkInternal> current_sinks_; |
| 48 | 70 |
| 49 // Sorted sinks sent to Media Router Provider in last FetchCompleted(). | 71 // Sorted sinks sent to Media Router Provider in last FetchCompleted(). |
| 50 std::set<MediaSinkInternal> mrp_sinks_; | 72 std::set<MediaSinkInternal> mrp_sinks_; |
| 51 | 73 |
| 52 private: | |
| 53 friend class MediaSinkServiceBaseTest; | |
| 54 FRIEND_TEST_ALL_PREFIXES(MediaSinkServiceBaseTest, | |
| 55 TestFetchCompleted_SameSink); | |
| 56 | |
| 57 // Timer for finishing fetching. | 74 // Timer for finishing fetching. |
| 58 std::unique_ptr<base::Timer> finish_timer_; | 75 std::unique_ptr<base::Timer> finish_timer_; |
| 59 }; | 76 }; |
| 60 | 77 |
| 61 } // namespace media_router | 78 } // namespace media_router |
| 62 | 79 |
| 63 #endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MEDIA_SINK_SERVICE_BASE_H_ | 80 #endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MEDIA_SINK_SERVICE_BASE_H_ |
| OLD | NEW |