Chromium Code Reviews| Index: chrome/browser/media/router/discovery/dial/dial_media_sink_service.h |
| diff --git a/chrome/browser/media/router/discovery/dial/dial_media_sink_service.h b/chrome/browser/media/router/discovery/dial/dial_media_sink_service.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..edf626641fc512545cbf8dc3720619a45f1daa36 |
| --- /dev/null |
| +++ b/chrome/browser/media/router/discovery/dial/dial_media_sink_service.h |
| @@ -0,0 +1,93 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DIAL_MEDIA_SINK_SERVICE_H_ |
| +#define CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DIAL_MEDIA_SINK_SERVICE_H_ |
| + |
| +#include <memory> |
| +#include <set> |
| + |
| +#include "chrome/browser/media/router/discovery/dial/device_description_service.h" |
| +#include "chrome/browser/media/router/discovery/dial/dial_registry.h" |
| +#include "chrome/common/media_router/discovery/media_sink_internal.h" |
| +#include "chrome/common/media_router/discovery/media_sink_service.h" |
| + |
| +namespace content { |
| +class BrowserContext; |
| +} |
| + |
| +namespace media_router { |
| + |
| +class DeviceDescriptionService; |
| +class DialRegistry; |
| + |
| +class DialMediaSinkService : public MediaSinkService, |
|
imcheng
2017/04/26 22:52:16
Could you please backfill class comments here?
zhaobin
2017/04/27 01:41:20
Done.
|
| + public DialRegistry::Observer { |
| + public: |
| + DialMediaSinkService(const OnSinksDiscoveredCallback& callback, |
| + content::BrowserContext* browser_context, |
| + net::URLRequestContextGetter* request_context); |
| + ~DialMediaSinkService() override; |
| + |
| + // MediaSinkService implementation |
| + void Start() override; |
| + void AddSinkQuery(MediaSinksObserver* observer) override; |
| + void RemoveSinkQuery(MediaSinksObserver* observer) override; |
| + |
| + void Stop(); |
| + |
| + protected: |
| + virtual DialRegistry* dial_registry(); |
| + |
| + // Returns instance of device description service. Create a new one if none |
| + // exists. |
| + virtual DeviceDescriptionService* GetDescriptionService(); |
| + |
| + private: |
| + friend class DialMediaSinkServiceTest; |
| + FRIEND_TEST_ALL_PREFIXES(DialMediaSinkServiceTest, TestStart); |
| + FRIEND_TEST_ALL_PREFIXES(DialMediaSinkServiceTest, TestFetchCompleted); |
| + FRIEND_TEST_ALL_PREFIXES(DialMediaSinkServiceTest, TestIsDifferent); |
| + FRIEND_TEST_ALL_PREFIXES(DialMediaSinkServiceTest, |
| + TestOnDeviceDescriptionAvailable); |
| + |
| + // api::dial::DialRegistry::Observer implementation |
| + void OnDialDeviceEvent(const DialRegistry::DeviceList& devices) override; |
| + void OnDialError(DialRegistry::DialErrorCode type) override; |
| + |
| + // Called when description service successfully fetches and parses device |
| + // description XML. |
| + void OnDeviceDescriptionAvailable( |
| + const DialDeviceData& device_data, |
| + const ParsedDialDeviceDescription& description_data); |
| + |
| + // Called when fails to fetch or parse device description XML. |
| + void OnDeviceDescriptionError(const DialDeviceData& device, |
| + const std::string& error_message); |
| + |
| + // Called when |finish_timer_| expires. |
| + void OnFetchCompleted(); |
| + |
| + // Timer for finishing fetching for the first time (returns some devices to |
| + // user ASAP). |
| + std::unique_ptr<base::OneShotTimer> finish_timer_; |
| + |
| + std::unique_ptr<DeviceDescriptionService> description_service_; |
| + |
| + // Sorted sinks from current round of discovery. |
| + std::set<MediaSinkInternal> current_sinks_; |
| + |
| + // Sorted sinks sent to Media Router Provider in last FetchCompleted(). |
| + std::set<MediaSinkInternal> mrp_sinks_; |
| + |
| + // Device data list from current round of discovery. |
| + DialRegistry::DeviceList current_devices_; |
| + |
| + content::BrowserContext* browser_context_; |
| + scoped_refptr<net::URLRequestContextGetter> request_context_; |
| +}; |
| + |
| +} // namespace media_router |
| + |
| +#endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DIAL_MEDIA_SINK_SERVICE_H_ |