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 |
index 2030c055fb8ae148ab6724d52968c79c34f86a9f..63f1e3095b537ab301daf481e553ecf82ba3e5d4 100644 |
--- a/chrome/browser/media/router/discovery/mdns/cast_media_sink_service.h |
+++ b/chrome/browser/media/router/discovery/mdns/cast_media_sink_service.h |
@@ -33,6 +33,7 @@ namespace media_router { |
// Public APIs should be invoked on the UI thread. |
class CastMediaSinkService |
: public MediaSinkServiceBase, |
+ public MediaSinkService::Observer, |
public DnsSdRegistry::DnsSdObserver, |
public base::RefCountedThreadSafe<CastMediaSinkService> { |
public: |
@@ -46,10 +47,17 @@ class CastMediaSinkService |
// mDNS service types. |
static const char kCastServiceType[]; |
imcheng
2017/07/06 22:53:30
Can this and kCastControlPort be constexpr and be
zhaobin
2017/07/10 20:21:15
Yes, but still need to define it again in .cc file
|
+ // Default Cast control port to open Cast Socket from DIAL sink. |
+ static int kCastControlPort; |
+ |
// MediaSinkService implementation |
void Start() override; |
void Stop() override; |
+ // MediaSinkService::Observer implementation |
+ void OnMediaSinkAdded(const MediaSinkInternal& sink) override; |
+ void OnMediaSinksRemoved() override; |
+ |
protected: |
// Used to mock out the DnsSdRegistry for testing. |
void SetDnsSdRegistryForTest(DnsSdRegistry* registry); |
@@ -85,39 +93,48 @@ class CastMediaSinkService |
FRIEND_TEST_ALL_PREFIXES(CastMediaSinkServiceTest, TestOnDnsSdEvent); |
FRIEND_TEST_ALL_PREFIXES(CastMediaSinkServiceTest, TestMultipleOnDnsSdEvent); |
FRIEND_TEST_ALL_PREFIXES(CastMediaSinkServiceTest, TestTimer); |
+ FRIEND_TEST_ALL_PREFIXES(CastMediaSinkServiceTest, TestOnDialSinkAdded); |
+ FRIEND_TEST_ALL_PREFIXES(CastMediaSinkServiceTest, TestOnFetchCompleted); |
+ |
+ // MediaSinkServiceBase implementation |
+ void OnFetchCompleted() override; |
// DnsSdRegistry::DnsSdObserver implementation |
void OnDnsSdEvent(const std::string& service_type, |
const DnsSdRegistry::DnsSdServiceList& services) override; |
- // Opens cast channel on IO thread. |
- // |service|: mDNS service description. |
+ // Open cast channel on IO thread. |
// |ip_endpoint|: cast channel's target IP endpoint. |
- void OpenChannelOnIOThread(const DnsSdService& service, |
- const net::IPEndPoint& ip_endpoint); |
+ // |on_open_callback|: callback to be invoked on the IO thread when Cast |
+ // socket opens. |
+ void OpenChannelOnIOThread( |
+ const net::IPEndPoint& ip_endpoint, |
+ const cast_channel::CastSocket::OnOpenCallback& on_open_callback); |
// Invoked when opening cast channel on IO thread completes. |
- // |service|: mDNS service description. |
+ // |cast_sink|: Cast sink created from mDNS service description or DIAL sink. |
// |channel_id|: channel id of newly created cast channel. |
// |channel_error|: error encounted when opending cast channel. |
- void OnChannelOpenedOnIOThread(const DnsSdService& service, |
+ void OnChannelOpenedOnIOThread(const MediaSinkInternal& cast_sink, |
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 OnChannelOpenedOnUIThread(const DnsSdService& service, |
- int channel_id, |
- bool audio_only); |
+ // |cast_sink|: Cast sink created from mDNS service description or DIAL sink. |
+ void OnChannelOpenedOnUIThread(const MediaSinkInternal& cast_sink); |
// Raw pointer to DnsSdRegistry instance, which is a global leaky singleton |
// and lives as long as the browser process. |
DnsSdRegistry* dns_sd_registry_ = nullptr; |
- // Service list from current round of discovery. |
- DnsSdRegistry::DnsSdServiceList current_services_; |
+ // Set of mDNS service ip addresses from current round of discovery. |
+ std::set<net::IPEndPoint> current_service_ip_endpoints_; |
+ |
+ // Map of sinks from current round of mDNS discovery keyed by IP address. |
+ std::map<net::IPEndPoint, MediaSinkInternal> current_sinks_by_mdns_map_; |
+ |
+ // Map of sinks from current round of DIAL discovery keyed by IP address. |
+ std::map<net::IPEndPoint, MediaSinkInternal> current_sinks_by_dial_map_; |
// Service managing creating and removing cast channels. |
scoped_refptr<cast_channel::CastSocketService> cast_socket_service_; |