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..92df589752ca9d52ed79f8e7ad9e21876ac82007 |
| --- /dev/null |
| +++ b/chrome/browser/media/router/discovery/dial/dial_media_sink_service.h |
| @@ -0,0 +1,88 @@ |
| +// 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/browser/media/router/media_sink_service.h" |
| +#include "chrome/common/media_router/discovery/media_sink_internal.h" |
| + |
| +namespace content { |
| +class BrowserContext; |
| +} |
| + |
| +namespace media_router { |
| + |
| +class DeviceDescriptionService; |
| +class DialRegistry; |
| + |
| +class DialMediaSinkService : public MediaSinkService, |
| + public DialRegistry::Observer { |
| + public: |
| + DialMediaSinkService(const OnSinksDiscoveredCallback& callback, |
| + content::BrowserContext* browser_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); |
| + |
| + // 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, content::BrowserThread::DeleteOnIOThread> |
| + finish_timer_; |
| + |
| + std::unique_ptr<DeviceDescriptionService> description_service_; |
|
imcheng
2017/04/25 01:40:13
Does this need DeleteOnIOThread?
zhaobin
2017/04/26 18:50:05
Will make DialMediaSinkService DeleteOnIOThread (h
|
| + |
| + // 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_; |
| + |
| + content::BrowserContext* browser_context_; |
| + net::URLRequestContextGetter* request_context_; |
| +}; |
| + |
| +} // namespace media_router |
| + |
| +#endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DIAL_MEDIA_SINK_SERVICE_H_ |