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

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

Issue 2927833002: [Media Router] Add CastMediaSinkService (Closed)
Patch Set: add unit tests Created 3 years, 6 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
(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/gtest_prod_util.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/threading/thread_checker.h"
14 #include "chrome/browser/media/router/discovery/mdns/dns_sd_delegate.h"
15 #include "chrome/browser/media/router/discovery/mdns/dns_sd_registry.h"
16 #include "chrome/browser/media/router/discovery/media_sink_service_base.h"
17 #include "components/cast_channel/cast_channel_enum.h"
18 #include "net/base/ip_endpoint.h"
19
20 namespace cast_channel {
21 class CastSocketService;
22 } // namespace cast_channel
23
24 namespace content {
25 class BrowserContext;
26 } // namespace content
27
28 namespace media_router {
29
30 // A service which can be used to start background discovery and resolution of
31 // Cast devices.
32 // Public APIs should be invoked on the UI thread.
33 class CastMediaSinkService
34 : public MediaSinkServiceBase,
35 public DnsSdRegistry::DnsSdObserver,
36 public base::RefCountedThreadSafe<CastMediaSinkService> {
37 public:
38 CastMediaSinkService(const OnSinksDiscoveredCallback& callback,
39 content::BrowserContext* browser_context);
40
41 // MediaSinkService implementation
42 void Start() override;
43 void Stop() override;
44
45 protected:
46 // Used to mock out the DnsSdRegistry for testing.
47 void SetDnsSdRegistryForTesting(DnsSdRegistry* registry);
imcheng 2017/06/15 00:51:00 super nit: s/Testing/Test, here and below.
zhaobin 2017/06/20 02:30:28 Done.
48
49 // Used to mock out the CastSocketService for testing.
50 void SetCastSocketServiceForTesting(
51 cast_channel::CastSocketService* cast_socket_service);
52
53 ~CastMediaSinkService() override;
54
55 private:
56 friend class base::RefCountedThreadSafe<CastMediaSinkService>;
57 friend class CastMediaSinkServiceTest;
58
59 FRIEND_TEST_ALL_PREFIXES(CastMediaSinkServiceTest, TestReStartAfterStop);
60 FRIEND_TEST_ALL_PREFIXES(CastMediaSinkServiceTest,
61 TestOnChannelOpenedOnIOThread);
62 FRIEND_TEST_ALL_PREFIXES(CastMediaSinkServiceTest,
63 TestMultipleOnChannelOpenedOnIOThread);
64 FRIEND_TEST_ALL_PREFIXES(CastMediaSinkServiceTest, TestOnDnsSdEvent);
65 FRIEND_TEST_ALL_PREFIXES(CastMediaSinkServiceTest, TestMultipleOnDnsSdEvent);
66 FRIEND_TEST_ALL_PREFIXES(CastMediaSinkServiceTest, TestTimer);
67
68 // DnsSdRegistry::DnsSdObserver implementation
69 void OnDnsSdEvent(const std::string& service_type,
70 const DnsSdRegistry::DnsSdServiceList& services) override;
71
72 // Open cast channel on IO thread.
73 // |service|: mDNS service description.
74 // |ip_endpoint|: cast channel's target IP endpoint.
75 void OpenChannelOnIOThread(const DnsSdService& service,
76 const net::IPEndPoint& ip_endpoint);
77
78 // Invoked when opening cast channel on IO thread completes.
79 // |service|: mDNS service description.
80 // |channel_id|: channel id of newly created cast channel.
81 // |channel_error|: error encounted when opending cast channel.
82 void OnChannelOpenedOnIOThread(const DnsSdService& service,
83 int channel_id,
84 cast_channel::ChannelError channel_error);
85
86 // Invoked by |OnChannelOpenedOnIOThread| to post task on UI thread.
87 // |service|: mDNS service description.
88 // |channel_id|: channel id of newly created cast channel.
89 // |audio_only|: if cast channel is audio only or not.
90 void OnChannelOpenedOnUIThread(const DnsSdService& service,
91 int channel_id,
92 bool audio_only);
93
94 // Raw pointer to DnsSdRegistry singleton.
95 DnsSdRegistry* dns_sd_registry_ = nullptr;
96
97 // DnsSdRegistry for test.
98 DnsSdRegistry* test_dns_sd_registry_ = nullptr;
99
100 // Service list from current round of discovery.
101 DnsSdRegistry::DnsSdServiceList current_services_;
102
103 // Service managing creating and removing cast channels.
104 scoped_refptr<cast_channel::CastSocketService> cast_socket_service_;
105
106 THREAD_CHECKER(thread_checker_);
107
108 DISALLOW_COPY_AND_ASSIGN(CastMediaSinkService);
109 };
110
111 } // namespace media_router
112
113 #endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MDNS_CAST_MEDIA_SINK_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698