OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
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_ | |
7 | |
8 #include <memory> | |
9 #include <set> | |
10 | |
11 #include "base/memory/ref_counted.h" | |
12 #include "base/threading/thread_checker.h" | |
13 #include "chrome/browser/media/router/discovery/mdns/dns_sd_delegate.h" | |
14 #include "chrome/browser/media/router/discovery/mdns/dns_sd_registry.h" | |
15 #include "chrome/browser/media/router/discovery/media_sink_service_base.h" | |
16 #include "components/cast_channel/cast_channel_enum.h" | |
17 #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.
| |
18 | |
19 namespace extensions { | |
20 namespace api { | |
21 namespace cast_channel { | |
22 class CastSocketService; | |
23 } // namespace cast_channel | |
24 } // namespace api | |
25 } // namespace extensions | |
26 | |
27 namespace content { | |
28 class BrowserContext; | |
29 } // namespace content | |
30 | |
31 namespace media_router { | |
32 | |
33 // A service which can be used to start background discovery and resolution of | |
34 // 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.
| |
35 // Public APIs should be invoked on the UI thread. | |
36 class CastMediaSinkService | |
37 : public MediaSinkServiceBase, | |
38 public DnsSdRegistry::DnsSdObserver, | |
39 public base::RefCountedThreadSafe<CastMediaSinkService> { | |
40 public: | |
41 CastMediaSinkService(const OnSinksDiscoveredCallback& callback, | |
42 content::BrowserContext* browser_context); | |
43 | |
44 // MediaSinkService implementation | |
45 void Start() override; | |
46 void Stop() override; | |
47 | |
48 protected: | |
49 // Used to mock out the DnsSdRegistry for testing. | |
50 void SetDnsSdRegistryForTesting(DnsSdRegistry* registry); | |
51 | |
52 private: | |
53 friend class base::RefCountedThreadSafe<CastMediaSinkService>; | |
54 | |
55 ~CastMediaSinkService() override; | |
56 | |
57 // DnsSdRegistry::DnsSdObserver implementation | |
58 void OnDnsSdEvent(const std::string& service_type, | |
59 const DnsSdRegistry::DnsSdServiceList& services) override; | |
60 | |
61 // Open cast channel on IO thread. | |
62 // |service|: mDNS service description. | |
63 // |ip_endpoint|: cast channel's target IP endpoint. | |
64 void OpenChannelOnIOThread(const DnsSdService& service, | |
65 const net::IPEndPoint& ip_endpoint); | |
66 | |
67 // Invoked when opening cast channel on IO thread completes. | |
68 // |service|: mDNS service description. | |
69 // |channel_id|: channel id of newly created cast channel. | |
70 // |channel_error|: error encounted when opending cast channel. | |
71 void OnChannelOpenedOnIOThread(const DnsSdService& service, | |
72 int channel_id, | |
73 cast_channel::ChannelError channel_error); | |
74 | |
75 // Invoked by |OnChannelOpenedOnIOThread| to post task on UI thread. | |
76 // |service|: mDNS service description. | |
77 // |channel_id|: channel id of newly created cast channel. | |
78 // |audio_only|: if cast channel is audio only or not. | |
79 void OnChannelOpenOnUIThread(const DnsSdService& service, | |
80 int channel_id, | |
81 bool audio_only); | |
82 | |
83 // Raw pointer to DnsSdRegistry singleton. | |
84 DnsSdRegistry* dns_sd_registry_ = nullptr; | |
85 | |
86 // Service list from current round of discovery. | |
87 DnsSdRegistry::DnsSdServiceList current_services_; | |
88 | |
89 // Service managing creating and removing cast channels. | |
90 scoped_refptr<extensions::api::cast_channel::CastSocketService> | |
91 cast_socket_service_; | |
92 | |
93 THREAD_CHECKER(thread_checker_); | |
94 | |
95 DISALLOW_COPY_AND_ASSIGN(CastMediaSinkService); | |
96 }; | |
97 | |
98 } // namespace media_router | |
99 | |
100 #endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MDNS_CAST_MEDIA_SINK_SERVICE_H_ | |
OLD | NEW |