 Chromium Code Reviews
 Chromium Code Reviews Issue 2701633002:
  [Media Router] Add DialMediaSinkService and DeviceDescriptionService  (Closed)
    
  
    Issue 2701633002:
  [Media Router] Add DialMediaSinkService and DeviceDescriptionService  (Closed) 
  | OLD | NEW | 
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DIAL_MEDIA_SINK_SERVICE_H_ | |
| 6 #define CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DIAL_MEDIA_SINK_SERVICE_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <set> | |
| 10 | |
| 11 #include "chrome/browser/media/router/discovery/dial/device_description_service. h" | |
| 12 #include "chrome/browser/media/router/discovery/dial/dial_registry.h" | |
| 13 #include "chrome/browser/media/router/discovery/media_sink_internal.h" | |
| 14 #include "chrome/browser/media/router/media_sink_service.h" | |
| 15 | |
| 16 namespace content { | |
| 17 class BrowserContext; | |
| 18 } | |
| 19 | |
| 20 namespace media_router { | |
| 21 | |
| 22 class DeviceDescriptionService; | |
| 23 class DialRegistry; | |
| 24 | |
| 25 class DialMediaSinkService : public MediaSinkService, | |
| 26 public DialRegistry::Observer { | |
| 27 public: | |
| 28 DialMediaSinkService(const OnSinksDiscoveredCallback& callback, | |
| 29 content::BrowserContext* browser_context); | |
| 30 ~DialMediaSinkService() override; | |
| 31 | |
| 32 // MediaSinkService implementation | |
| 33 void Start() override; | |
| 34 void AddSinkQuery(MediaSinksObserver* observer) override; | |
| 35 void RemoveSinkQuery(MediaSinksObserver* observer) override; | |
| 36 | |
| 37 void Stop(); | |
| 38 | |
| 39 protected: | |
| 40 virtual DialRegistry* dial_registry(); | |
| 41 | |
| 42 // Returns instance of device description service. Create a new one if null | |
| 
mark a. foltz
2017/04/18 18:16:27
s/null/none/ ?
 
zhaobin
2017/04/21 23:12:59
Done.
 | |
| 43 // exists. | |
| 44 virtual DeviceDescriptionService* GetDescriptionService(); | |
| 45 | |
| 46 private: | |
| 47 friend class DialMediaSinkServiceTest; | |
| 48 FRIEND_TEST_ALL_PREFIXES(DialMediaSinkServiceTest, TestStart); | |
| 49 FRIEND_TEST_ALL_PREFIXES(DialMediaSinkServiceTest, TestFetchCompleted); | |
| 50 FRIEND_TEST_ALL_PREFIXES(DialMediaSinkServiceTest, TestIsDifferent); | |
| 51 | |
| 52 // api::dial::DialRegistry::Observer implementation | |
| 53 void OnDialDeviceEvent(const DialRegistry::DeviceList& devices) override; | |
| 54 void OnDialError(DialRegistry::DialErrorCode type) override; | |
| 55 | |
| 56 // Called when description service successfully fetches and parses device | |
| 57 // description XML. | |
| 58 void OnDeviceDescriptionAvailable( | |
| 59 const DialDeviceData& device_data, | |
| 60 const ParsedDialDeviceDescription& description_data); | |
| 61 | |
| 62 // Called when fails to fetch or parse device description XML. | |
| 63 void OnDeviceDescriptionError(const DialDeviceData& device, | |
| 64 const std::string& error_message); | |
| 65 | |
| 66 // Called when |finish_timer_| expires. | |
| 67 void FetchCompleted(); | |
| 
mark a. foltz
2017/04/18 18:16:27
OnFetchCompleted?
 
zhaobin
2017/04/21 23:12:59
Done.
 | |
| 68 | |
| 69 // Timer for finishing fetching for the first time (returns some devices to | |
| 70 // user ASAP). | |
| 71 std::unique_ptr<base::OneShotTimer, content::BrowserThread::DeleteOnIOThread> | |
| 72 finish_timer_; | |
| 73 | |
| 74 std::unique_ptr<DeviceDescriptionService> description_service_; | |
| 75 | |
| 76 // Sorted sinks from current round of discovery. | |
| 77 std::set<MediaSinkInternal> current_sinks_; | |
| 78 | |
| 79 // Sorted sinks sent to Media Router Provider in last FetchCompleted(). | |
| 80 std::set<MediaSinkInternal> mrp_sinks_; | |
| 81 | |
| 82 content::BrowserContext* browser_context_; | |
| 83 net::URLRequestContextGetter* request_context_; | |
| 84 }; | |
| 85 | |
| 86 } // namespace media_router | |
| 87 | |
| 88 #endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DIAL_MEDIA_SINK_SERVICE_H_ | |
| OLD | NEW |