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_DIAL_DIAL_MEDIA_SINK_SERVICE_PROXY _H_ | |
6 #define CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DIAL_MEDIA_SINK_SERVICE_PROXY _H_ | |
7 | |
8 #include <memory> | |
9 #include "chrome/common/media_router/discovery/media_sink_service.h" | |
10 #include "content/public/browser/browser_thread.h" | |
11 | |
12 namespace net { | |
13 class URLRequestContextGetter; | |
14 } | |
15 | |
16 namespace media_router { | |
17 | |
18 class DialMediaSinkService; | |
19 | |
20 // A wrapper class of DialMediaSinkService handling thread hopping between UI | |
21 // and IO threads. This class is thread safe. Public APIs should be invoked on | |
22 // UI thread. It then post tasks to IO thread and invoke them on underlying | |
23 // DialMediaSinkService instance. | |
24 class DialMediaSinkServiceProxy | |
25 : public MediaSinkService, | |
Kevin M
2017/05/15 19:56:58
Can MediaSinkService be made into a 100% pure virt
mark a. foltz
2017/05/15 21:36:28
I think refactoring the inheritance is in progress
zhaobin
2017/05/16 21:26:49
Both DialMediaSinkServiceProxy and DialMediaSinkSe
| |
26 public base::RefCountedThreadSafe<DialMediaSinkServiceProxy> { | |
27 public: | |
28 // |callback| is invoked on the UI thread when sinks are discovered. | |
29 // |request_context| is used for HTTP requests made for discovery. | |
30 DialMediaSinkServiceProxy( | |
31 const MediaSinkService::OnSinksDiscoveredCallback& callback, | |
32 net::URLRequestContextGetter* request_context); | |
Kevin M
2017/05/15 19:56:58
~DialMediaSinkServiceProxy = default;
mark a. foltz
2017/05/15 21:36:28
That should go in the .cc, as it will invoke the D
zhaobin
2017/05/16 21:26:49
RefCountedThreadSafe class needs private dtor.
| |
33 | |
34 // Starts discovery of DIAL devices on IO thread. | |
35 void Start() override; | |
36 | |
37 // Stops discovery of DIAL devices on IO thread. The callback passed to | |
38 // Start() is cleared. | |
39 void Stop(); | |
40 | |
41 void SetDialMediaSinkServiceForTest( | |
42 std::unique_ptr<DialMediaSinkService, | |
43 content::BrowserThread::DeleteOnIOThread> | |
44 dial_media_sink_service); | |
45 | |
46 private: | |
47 friend class DialMediaSinkServiceProxyTest; | |
48 friend class base::RefCountedThreadSafe<DialMediaSinkServiceProxy>; | |
49 ~DialMediaSinkServiceProxy() override; | |
50 | |
51 // Starts DIAL discovery. | |
52 void StartOnIOThread(); | |
53 | |
54 // Stops DIAL discovery. | |
55 void StopOnIOThread(); | |
56 | |
57 // Callback passed to |dial_media_sink_service_| ctor. When invoked, post task | |
58 // to UI thread and invoke |sink_discovery_callback_|; | |
59 void OnSinksDiscoveredOnIOThread(const std::vector<MediaSinkInternal>& sinks); | |
60 | |
61 // Invokes |sink_discovery_callback_| on UI thread. | |
62 void OnSinksDiscoveredOnUIThread(const std::vector<MediaSinkInternal>& sinks); | |
63 | |
64 private: | |
65 std::unique_ptr<DialMediaSinkService, | |
66 content::BrowserThread::DeleteOnIOThread> | |
67 dial_media_sink_service_; | |
68 }; | |
Kevin M
2017/05/15 19:56:58
nit: DISALLOW_COPY_AND_ASSIGN(DialMediaSinkService
zhaobin
2017/05/16 21:26:49
Done.
| |
69 | |
70 } // namespace media_router | |
71 | |
72 #endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DIAL_MEDIA_SINK_SERVICE_PR OXY_H_ | |
OLD | NEW |