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 | |
10 #include "base/macros.h" | |
11 #include "base/memory/ref_counted.h" | |
12 #include "base/sequenced_task_runner_helpers.h" | |
13 #include "chrome/common/media_router/discovery/media_sink_service.h" | |
14 #include "content/public/browser/browser_thread.h" | |
15 | |
16 namespace content { | |
17 class BrowserContext; | |
18 } | |
19 | |
20 namespace net { | |
21 class URLRequestContextGetter; | |
22 } | |
23 | |
24 namespace media_router { | |
25 | |
26 class DialMediaSinkServiceImpl; | |
27 | |
28 // A wrapper class of DialMediaSinkService handling thread hopping between UI | |
29 // and IO threads. This class is thread safe. Public APIs should be invoked on | |
30 // UI thread. It then post tasks to IO thread and invoke them on underlying | |
31 // DialMediaSinkService instance. | |
32 class DialMediaSinkServiceProxy | |
33 : public MediaSinkService, | |
34 public base::RefCountedThreadSafe< | |
35 DialMediaSinkServiceProxy, | |
36 content::BrowserThread::DeleteOnIOThread> { | |
37 public: | |
38 // |callback| is invoked on the UI thread when sinks are discovered. | |
39 // |context| is browser context. | |
40 DialMediaSinkServiceProxy( | |
41 const MediaSinkService::OnSinksDiscoveredCallback& callback, | |
42 content::BrowserContext* context); | |
43 | |
44 // Starts discovery of DIAL devices on IO thread. | |
45 void Start() override; | |
46 | |
47 // Stops discovery of DIAL devices on IO thread. The callback passed to | |
48 // Start() is cleared. | |
Kevin M
2017/05/24 00:52:55
We should document somewhere in this header (maybe
zhaobin
2017/05/24 17:45:51
Done.
| |
49 void Stop() override; | |
50 | |
51 void SetDialMediaSinkServiceForTest( | |
52 std::unique_ptr<DialMediaSinkServiceImpl> dial_media_sink_service); | |
53 | |
54 private: | |
55 friend class DialMediaSinkServiceProxyTest; | |
56 friend class base::DeleteHelper<DialMediaSinkServiceProxy>; | |
57 friend struct content::BrowserThread::DeleteOnThread< | |
58 content::BrowserThread::IO>; | |
59 friend class base::RefCountedThreadSafe<DialMediaSinkServiceProxy>; | |
60 | |
61 ~DialMediaSinkServiceProxy() override; | |
62 | |
63 // Starts DIAL discovery. | |
64 void StartOnIOThread(); | |
65 | |
66 // Stops DIAL discovery. | |
67 void StopOnIOThread(); | |
68 | |
69 // Callback passed to |dial_media_sink_service_| ctor. When invoked, post task | |
70 // to UI thread and invoke |sink_discovery_callback_|. | |
71 void OnSinksDiscoveredOnIOThread(std::vector<MediaSinkInternal> sinks); | |
72 | |
73 private: | |
74 std::unique_ptr<DialMediaSinkServiceImpl> dial_media_sink_service_; | |
75 | |
76 net::URLRequestContextGetter* request_context_; | |
77 | |
78 DISALLOW_COPY_AND_ASSIGN(DialMediaSinkServiceProxy); | |
79 }; | |
80 | |
81 } // namespace media_router | |
82 | |
83 #endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DIAL_MEDIA_SINK_SERVICE_PR OXY_H_ | |
OLD | NEW |