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