Chromium Code Reviews| Index: chrome/browser/media/router/discovery/mdns/cast_media_sink_service.h |
| diff --git a/chrome/browser/media/router/discovery/mdns/cast_media_sink_service.h b/chrome/browser/media/router/discovery/mdns/cast_media_sink_service.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ac7bb0ddc075579e543f502be24d5a19b0aa44ff |
| --- /dev/null |
| +++ b/chrome/browser/media/router/discovery/mdns/cast_media_sink_service.h |
| @@ -0,0 +1,100 @@ |
| +// 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_MDNS_CAST_MEDIA_SINK_SERVICE_H_ |
| +#define CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MDNS_CAST_MEDIA_SINK_SERVICE_H_ |
| + |
| +#include <memory> |
| +#include <set> |
| + |
| +#include "base/memory/ref_counted.h" |
| +#include "base/threading/thread_checker.h" |
| +#include "chrome/browser/media/router/discovery/mdns/dns_sd_delegate.h" |
| +#include "chrome/browser/media/router/discovery/mdns/dns_sd_registry.h" |
| +#include "chrome/browser/media/router/discovery/media_sink_service_base.h" |
| +#include "components/cast_channel/cast_channel_enum.h" |
| +#include "extensions/browser/api/cast_channel/cast_socket_service.h" |
|
zhaobin
2017/06/07 18:41:12
This will become components/cast_channel/cast_sock
zhaobin
2017/06/10 02:19:35
Done.
|
| + |
| +namespace extensions { |
| +namespace api { |
| +namespace cast_channel { |
| +class CastSocketService; |
| +} // namespace cast_channel |
| +} // namespace api |
| +} // namespace extensions |
| + |
| +namespace content { |
| +class BrowserContext; |
| +} // namespace content |
| + |
| +namespace media_router { |
| + |
| +// A service which can be used to start background discovery and resolution of |
| +// Cast devices (Smart TVs, Game Consoles, etc.). |
|
mark a. foltz
2017/06/07 21:13:33
Cast isn't supported on most smart TVs or game con
zhaobin
2017/06/10 02:19:35
Done.
|
| +// Public APIs should be invoked on the UI thread. |
| +class CastMediaSinkService |
| + : public MediaSinkServiceBase, |
| + public DnsSdRegistry::DnsSdObserver, |
| + public base::RefCountedThreadSafe<CastMediaSinkService> { |
| + public: |
| + CastMediaSinkService(const OnSinksDiscoveredCallback& callback, |
| + content::BrowserContext* browser_context); |
| + |
| + // MediaSinkService implementation |
| + void Start() override; |
| + void Stop() override; |
| + |
| + protected: |
| + // Used to mock out the DnsSdRegistry for testing. |
| + void SetDnsSdRegistryForTesting(DnsSdRegistry* registry); |
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<CastMediaSinkService>; |
| + |
| + ~CastMediaSinkService() override; |
| + |
| + // DnsSdRegistry::DnsSdObserver implementation |
| + void OnDnsSdEvent(const std::string& service_type, |
| + const DnsSdRegistry::DnsSdServiceList& services) override; |
| + |
| + // Open cast channel on IO thread. |
| + // |service|: mDNS service description. |
| + // |ip_endpoint|: cast channel's target IP endpoint. |
| + void OpenChannelOnIOThread(const DnsSdService& service, |
| + const net::IPEndPoint& ip_endpoint); |
| + |
| + // Invoked when opening cast channel on IO thread completes. |
| + // |service|: mDNS service description. |
| + // |channel_id|: channel id of newly created cast channel. |
| + // |channel_error|: error encounted when opending cast channel. |
| + void OnChannelOpenedOnIOThread(const DnsSdService& service, |
| + int channel_id, |
| + cast_channel::ChannelError channel_error); |
| + |
| + // Invoked by |OnChannelOpenedOnIOThread| to post task on UI thread. |
| + // |service|: mDNS service description. |
| + // |channel_id|: channel id of newly created cast channel. |
| + // |audio_only|: if cast channel is audio only or not. |
| + void OnChannelOpenOnUIThread(const DnsSdService& service, |
| + int channel_id, |
| + bool audio_only); |
| + |
| + // Raw pointer to DnsSdRegistry singleton. |
| + DnsSdRegistry* dns_sd_registry_ = nullptr; |
| + |
| + // Service list from current round of discovery. |
| + DnsSdRegistry::DnsSdServiceList current_services_; |
| + |
| + // Service managing creating and removing cast channels. |
| + scoped_refptr<extensions::api::cast_channel::CastSocketService> |
| + cast_socket_service_; |
| + |
| + THREAD_CHECKER(thread_checker_); |
| + |
| + DISALLOW_COPY_AND_ASSIGN(CastMediaSinkService); |
| +}; |
| + |
| +} // namespace media_router |
| + |
| +#endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MDNS_CAST_MEDIA_SINK_SERVICE_H_ |