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

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

Issue 2965843002: [Media Router] Support dual discovery (Closed)
Patch Set: resolve code review comments from Derek 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MDNS_CAST_MEDIA_SINK_SERVICE_H_ 5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MDNS_CAST_MEDIA_SINK_SERVICE_H_
6 #define CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MDNS_CAST_MEDIA_SINK_SERVICE_H_ 6 #define CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MDNS_CAST_MEDIA_SINK_SERVICE_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 10
(...skipping 28 matching lines...) Expand all
39 CastMediaSinkService(const OnSinksDiscoveredCallback& callback, 39 CastMediaSinkService(const OnSinksDiscoveredCallback& callback,
40 content::BrowserContext* browser_context); 40 content::BrowserContext* browser_context);
41 41
42 // Used by unit tests. 42 // Used by unit tests.
43 CastMediaSinkService(const OnSinksDiscoveredCallback& callback, 43 CastMediaSinkService(const OnSinksDiscoveredCallback& callback,
44 cast_channel::CastSocketService* cast_socket_service); 44 cast_channel::CastSocketService* cast_socket_service);
45 45
46 // mDNS service types. 46 // mDNS service types.
47 static const char kCastServiceType[]; 47 static const char kCastServiceType[];
48 48
49 // Default Cast control port to open Cast Socket from DIAL sink.
50 static const int kCastControlPort;
51
49 // MediaSinkService implementation 52 // MediaSinkService implementation
50 void Start() override; 53 void Start() override;
51 void Stop() override; 54 void Stop() override;
52 55
56 // Invoked when |sink| is added to DialMediaSinkServiceImpl instance.
57 void OnDialSinkAdded(const MediaSinkInternal& sink);
58
59 // Invoked when dial sinks are removed from DialMediaSinkServiceImpl instance.
60 void OnDialSinksRemoved();
61
53 protected: 62 protected:
54 // Used to mock out the DnsSdRegistry for testing. 63 // Used to mock out the DnsSdRegistry for testing.
55 void SetDnsSdRegistryForTest(DnsSdRegistry* registry); 64 void SetDnsSdRegistryForTest(DnsSdRegistry* registry);
56 65
57 ~CastMediaSinkService() override; 66 ~CastMediaSinkService() override;
58 67
59 private: 68 private:
60 // Receives incoming messages and errors and provides additional API context. 69 // Receives incoming messages and errors and provides additional API context.
61 class CastSocketObserver : public cast_channel::CastSocket::Observer { 70 class CastSocketObserver : public cast_channel::CastSocket::Observer {
62 public: 71 public:
(...skipping 15 matching lines...) Expand all
78 87
79 FRIEND_TEST_ALL_PREFIXES(CastMediaSinkServiceTest, TestReStartAfterStop); 88 FRIEND_TEST_ALL_PREFIXES(CastMediaSinkServiceTest, TestReStartAfterStop);
80 FRIEND_TEST_ALL_PREFIXES(CastMediaSinkServiceTest, TestMultipleStartAndStop); 89 FRIEND_TEST_ALL_PREFIXES(CastMediaSinkServiceTest, TestMultipleStartAndStop);
81 FRIEND_TEST_ALL_PREFIXES(CastMediaSinkServiceTest, 90 FRIEND_TEST_ALL_PREFIXES(CastMediaSinkServiceTest,
82 TestOnChannelOpenedOnIOThread); 91 TestOnChannelOpenedOnIOThread);
83 FRIEND_TEST_ALL_PREFIXES(CastMediaSinkServiceTest, 92 FRIEND_TEST_ALL_PREFIXES(CastMediaSinkServiceTest,
84 TestMultipleOnChannelOpenedOnIOThread); 93 TestMultipleOnChannelOpenedOnIOThread);
85 FRIEND_TEST_ALL_PREFIXES(CastMediaSinkServiceTest, TestOnDnsSdEvent); 94 FRIEND_TEST_ALL_PREFIXES(CastMediaSinkServiceTest, TestOnDnsSdEvent);
86 FRIEND_TEST_ALL_PREFIXES(CastMediaSinkServiceTest, TestMultipleOnDnsSdEvent); 95 FRIEND_TEST_ALL_PREFIXES(CastMediaSinkServiceTest, TestMultipleOnDnsSdEvent);
87 FRIEND_TEST_ALL_PREFIXES(CastMediaSinkServiceTest, TestTimer); 96 FRIEND_TEST_ALL_PREFIXES(CastMediaSinkServiceTest, TestTimer);
97 FRIEND_TEST_ALL_PREFIXES(CastMediaSinkServiceTest, TestOnDialSinkAdded);
98 FRIEND_TEST_ALL_PREFIXES(CastMediaSinkServiceTest, TestOnFetchCompleted);
99
100 // MediaSinkServiceBase implementation
101 void OnFetchCompleted() override;
102
103 // Returns cast sinks from |current_sinks_by_mdns_map_| and
104 // |current_sinks_by_dial_map_|.
105 std::set<MediaSinkInternal> GetCastSinksOnIOThread();
106
107 // Stores |cast_sinks| in |current_sinks_| and invokes
108 // MediaSinkServiceBase::OnFetchCompleted on the UI thread.
109 void OnFetchCompletedOnUIThread(std::set<MediaSinkInternal> cast_sinks);
88 110
89 // DnsSdRegistry::DnsSdObserver implementation 111 // DnsSdRegistry::DnsSdObserver implementation
90 void OnDnsSdEvent(const std::string& service_type, 112 void OnDnsSdEvent(const std::string& service_type,
91 const DnsSdRegistry::DnsSdServiceList& services) override; 113 const DnsSdRegistry::DnsSdServiceList& services) override;
92 114
115 // Opens cast channels on the IO thread.
116 void OpenChannelsOnIOThread(std::vector<MediaSinkInternal> cast_sinks);
117
93 // Opens cast channel on IO thread. 118 // Opens cast channel on IO thread.
94 // |service|: mDNS service description.
95 // |ip_endpoint|: cast channel's target IP endpoint. 119 // |ip_endpoint|: cast channel's target IP endpoint.
96 void OpenChannelOnIOThread(const DnsSdService& service, 120 // |cast_sink|: Cast sink created from mDNS service description or DIAL sink.
97 const net::IPEndPoint& ip_endpoint); 121 void OpenChannelOnIOThread(const net::IPEndPoint& ip_endpoint,
122 const MediaSinkInternal& cast_sink);
98 123
99 // Invoked when opening cast channel on IO thread completes. 124 // Invoked when opening cast channel on IO thread completes.
100 // |service|: mDNS service description. 125 // |cast_sink|: Cast sink created from mDNS service description or DIAL sink.
101 // |channel_id|: channel id of newly created cast channel. 126 // |channel_id|: channel id of newly created cast channel.
102 // |channel_error|: error encounted when opending cast channel. 127 // |channel_error|: error encounted when opending cast channel.
103 void OnChannelOpenedOnIOThread(const DnsSdService& service, 128 void OnChannelOpenedOnIOThread(MediaSinkInternal cast_sink,
104 int channel_id, 129 int channel_id,
105 cast_channel::ChannelError channel_error); 130 cast_channel::ChannelError channel_error);
106 131
107 // Invoked by |OnChannelOpenedOnIOThread| to post task on UI thread.
108 // |service|: mDNS service description.
109 // |channel_id|: channel id of newly created cast channel.
110 // |audio_only|: if cast channel is audio only or not.
111 void OnChannelOpenedOnUIThread(const DnsSdService& service,
112 int channel_id,
113 bool audio_only);
114
115 // Raw pointer to DnsSdRegistry instance, which is a global leaky singleton 132 // Raw pointer to DnsSdRegistry instance, which is a global leaky singleton
116 // and lives as long as the browser process. 133 // and lives as long as the browser process.
117 DnsSdRegistry* dns_sd_registry_ = nullptr; 134 DnsSdRegistry* dns_sd_registry_ = nullptr;
118 135
119 // Service list from current round of discovery. 136 // Set of mDNS service ip addresses from current round of discovery.
120 DnsSdRegistry::DnsSdServiceList current_services_; 137 std::set<net::IPEndPoint> current_service_ip_endpoints_;
mark a. foltz 2017/07/11 23:52:51 Can this be derived by iterating over current_sink
138
139 // Map of sinks from current round of mDNS discovery keyed by IP address.
140 std::map<net::IPEndPoint, MediaSinkInternal> current_sinks_by_mdns_map_;
mark a. foltz 2017/07/11 23:52:51 Nit: I would drop the 'map_' at end.
141
142 // Map of sinks from current round of DIAL discovery keyed by IP address.
143 std::map<net::IPEndPoint, MediaSinkInternal> current_sinks_by_dial_map_;
mark a. foltz 2017/07/11 23:52:51 Consider defining a type alias (e.g. MediaSinkInte
121 144
122 // Service managing creating and removing cast channels. 145 // Service managing creating and removing cast channels.
123 scoped_refptr<cast_channel::CastSocketService> cast_socket_service_; 146 scoped_refptr<cast_channel::CastSocketService> cast_socket_service_;
124 147
125 THREAD_CHECKER(thread_checker_); 148 THREAD_CHECKER(thread_checker_);
126 149
127 DISALLOW_COPY_AND_ASSIGN(CastMediaSinkService); 150 DISALLOW_COPY_AND_ASSIGN(CastMediaSinkService);
128 }; 151 };
129 152
130 } // namespace media_router 153 } // namespace media_router
131 154
132 #endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MDNS_CAST_MEDIA_SINK_SERVICE_H_ 155 #endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MDNS_CAST_MEDIA_SINK_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698