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. This function will bind | |
45 // |this| to underlying DialMediaSinkService and increase ref counter. Needs | |
Kevin M
2017/05/24 18:13:29
Nit: that level of detail is unnecessary, you can
zhaobin
2017/05/25 21:27:06
Done.
| |
46 // to call Stop() outside of dtor to decrease ref counter and destroy this | |
47 // object or it will never die. | |
48 void Start() override; | |
49 | |
50 // Stops discovery of DIAL devices on IO thread. The callback passed to | |
51 // Start() is cleared. | |
52 void Stop() override; | |
53 | |
54 void SetDialMediaSinkServiceForTest( | |
55 std::unique_ptr<DialMediaSinkServiceImpl> dial_media_sink_service); | |
56 | |
57 private: | |
58 friend class DialMediaSinkServiceProxyTest; | |
59 friend class base::DeleteHelper<DialMediaSinkServiceProxy>; | |
60 friend struct content::BrowserThread::DeleteOnThread< | |
61 content::BrowserThread::IO>; | |
62 friend class base::RefCountedThreadSafe<DialMediaSinkServiceProxy>; | |
63 | |
64 ~DialMediaSinkServiceProxy() override; | |
65 | |
66 // Starts DIAL discovery. | |
67 void StartOnIOThread(); | |
68 | |
69 // Stops DIAL discovery. | |
70 void StopOnIOThread(); | |
71 | |
72 // Callback passed to |dial_media_sink_service_| ctor. When invoked, post task | |
73 // to UI thread and invoke |sink_discovery_callback_|. | |
74 void OnSinksDiscoveredOnIOThread(std::vector<MediaSinkInternal> sinks); | |
75 | |
76 private: | |
77 std::unique_ptr<DialMediaSinkServiceImpl> dial_media_sink_service_; | |
78 | |
79 net::URLRequestContextGetter* request_context_; | |
80 | |
81 DISALLOW_COPY_AND_ASSIGN(DialMediaSinkServiceProxy); | |
82 }; | |
83 | |
84 } // namespace media_router | |
85 | |
86 #endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DIAL_MEDIA_SINK_SERVICE_PR OXY_H_ | |
OLD | NEW |