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/timer/timer.h" | 12 #include "base/timer/timer.h" |
13 #include "chrome/common/media_router/discovery/media_sink_internal.h" | 13 #include "chrome/common/media_router/discovery/media_sink_internal.h" |
14 #include "chrome/common/media_router/discovery/media_sink_service.h" | 14 #include "chrome/common/media_router/discovery/media_sink_service.h" |
15 | 15 |
16 namespace media_router { | 16 namespace media_router { |
17 | 17 |
18 class MediaSinkServiceBase : public MediaSinkService { | 18 class MediaSinkServiceBase : public MediaSinkService { |
19 public: | 19 public: |
20 explicit MediaSinkServiceBase(const OnSinksDiscoveredCallback& callback); | 20 explicit MediaSinkServiceBase(const OnSinksDiscoveredCallback& callback); |
21 ~MediaSinkServiceBase() override; | 21 ~MediaSinkServiceBase() override; |
22 | 22 |
23 protected: | 23 protected: |
24 void SetTimerForTest(std::unique_ptr<base::Timer> timer); | 24 void SetTimerForTest(std::unique_ptr<base::Timer> timer); |
25 | 25 |
26 // Called when |finish_timer_| expires. | 26 // Called when |finish_timer_| expires. |
27 void OnFetchCompleted(); | 27 void OnFetchCompleted(); |
28 | 28 |
29 // Helper function to start |finish_timer_|. | 29 // Helper function to start |finish_timer_|. Create a new timer if none |
| 30 // exists. |
30 void StartTimer(); | 31 void StartTimer(); |
31 | 32 |
32 // Timer for finishing fetching. | 33 // Helper function to stop |finish_timer_|. |
33 std::unique_ptr<base::Timer> finish_timer_; | 34 void StopTimer(); |
| 35 |
| 36 // Helper function to restart |finish_timer|. No-op if timer does not exist or |
| 37 // timer is currently running. |
| 38 void RestartTimer(); |
34 | 39 |
35 // Time out value for |finish_timer_| | 40 // Time out value for |finish_timer_| |
36 int fetch_complete_timeout_secs_; | 41 int fetch_complete_timeout_secs_; |
37 | 42 |
38 // Sorted sinks from current round of discovery. | 43 // Sorted sinks from current round of discovery. |
39 std::set<MediaSinkInternal> current_sinks_; | 44 std::set<MediaSinkInternal> current_sinks_; |
40 | 45 |
41 // Sorted sinks sent to Media Router Provider in last FetchCompleted(). | 46 // Sorted sinks sent to Media Router Provider in last FetchCompleted(). |
42 std::set<MediaSinkInternal> mrp_sinks_; | 47 std::set<MediaSinkInternal> mrp_sinks_; |
43 | 48 |
44 private: | 49 private: |
45 friend class MediaSinkServiceBaseTest; | 50 friend class MediaSinkServiceBaseTest; |
46 FRIEND_TEST_ALL_PREFIXES(MediaSinkServiceBaseTest, | 51 FRIEND_TEST_ALL_PREFIXES(MediaSinkServiceBaseTest, |
47 TestFetchCompleted_SameSink); | 52 TestFetchCompleted_SameSink); |
| 53 |
| 54 // Timer for finishing fetching. |
| 55 std::unique_ptr<base::Timer> finish_timer_; |
48 }; | 56 }; |
49 | 57 |
50 } // namespace media_router | 58 } // namespace media_router |
51 | 59 |
52 #endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MEDIA_SINK_SERVICE_BASE_H_ | 60 #endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MEDIA_SINK_SERVICE_BASE_H_ |
OLD | NEW |