Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1587)

Unified Diff: chrome/browser/media/router/discovery/mdns/cast_media_sink_service.h

Issue 2965843002: [Media Router] Support dual discovery (Closed)
Patch Set: resovle code review comments from Derek and Mark Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..5b12f532e33ef68f0c5ca0fd493c7ebbf6d12a4d 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
@@ -11,6 +11,7 @@
#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
#include "base/threading/thread_checker.h"
+#include "chrome/browser/media/router/discovery/dial/dial_media_sink_service_impl.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"
@@ -31,10 +32,9 @@ namespace media_router {
// A service which can be used to start background discovery and resolution of
// Cast devices.
// Public APIs should be invoked on the UI thread.
-class CastMediaSinkService
- : public MediaSinkServiceBase,
- public DnsSdRegistry::DnsSdObserver,
- public base::RefCountedThreadSafe<CastMediaSinkService> {
+class CastMediaSinkService : public MediaSinkServiceBase,
+ public DialMediaSinkServiceDelegate,
+ public DnsSdRegistry::DnsSdObserver {
public:
CastMediaSinkService(const OnSinksDiscoveredCallback& callback,
content::BrowserContext* browser_context);
@@ -46,10 +46,17 @@ class CastMediaSinkService
// mDNS service types.
static const char kCastServiceType[];
+ // Default Cast control port to open Cast Socket from DIAL sink.
+ static const int kCastControlPort;
+
// MediaSinkService implementation
void Start() override;
void Stop() override;
+ // DialMediaSinkServiceDelegate implementation.
+ void OnDialSinkAdded(const MediaSinkInternal& sink) override;
+ void OnDialSinksRemoved() override;
+
protected:
// Used to mock out the DnsSdRegistry for testing.
void SetDnsSdRegistryForTest(DnsSdRegistry* registry);
@@ -85,45 +92,59 @@ 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;
+
+ // Returns cast sinks from |current_sinks_by_mdns_map_| and
+ // |current_sinks_by_dial_map_|.
+ std::set<MediaSinkInternal> GetCastSinksOnIOThread();
+
+ // Stores |cast_sinks| in |current_sinks_| and invokes
+ // MediaSinkServiceBase::OnFetchCompleted on the UI thread.
+ void OnFetchCompletedOnUIThread(std::set<MediaSinkInternal> cast_sinks);
// DnsSdRegistry::DnsSdObserver implementation
void OnDnsSdEvent(const std::string& service_type,
const DnsSdRegistry::DnsSdServiceList& services) override;
+ // Opens cast channels on the IO thread.
+ void OpenChannelsOnIOThread(std::vector<MediaSinkInternal> cast_sinks);
+
// Opens 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);
+ // |cast_sink|: Cast sink created from mDNS service description or DIAL sink.
+ void OpenChannelOnIOThread(const net::IPEndPoint& ip_endpoint,
+ MediaSinkInternal cast_sink);
// 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(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);
-
// 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_;
+
+ using MediaSinkInternalMap = std::map<net::IPEndPoint, MediaSinkInternal>;
+
+ // Map of sinks from current round of mDNS discovery keyed by IP address.
+ MediaSinkInternalMap current_sinks_by_mdns_;
+
+ // Map of sinks from current round of DIAL discovery keyed by IP address.
+ MediaSinkInternalMap current_sinks_by_dial_;
// Service managing creating and removing cast channels.
scoped_refptr<cast_channel::CastSocketService> cast_socket_service_;
- THREAD_CHECKER(thread_checker_);
-
DISALLOW_COPY_AND_ASSIGN(CastMediaSinkService);
};

Powered by Google App Engine
This is Rietveld 408576698