OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DIAL_MEDIA_SINK_SERVICE_PROXY
_H_ | 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_ | 6 #define CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DIAL_MEDIA_SINK_SERVICE_PROXY
_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/sequenced_task_runner_helpers.h" | 12 #include "base/sequenced_task_runner_helpers.h" |
13 #include "chrome/common/media_router/discovery/media_sink_service.h" | 13 #include "chrome/common/media_router/discovery/media_sink_service.h" |
14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
15 #include "net/url_request/url_request_context_getter.h" | 15 #include "net/url_request/url_request_context_getter.h" |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 class BrowserContext; | 18 class BrowserContext; |
19 } | 19 } |
20 | 20 |
21 namespace net { | 21 namespace net { |
22 class URLRequestContextGetter; | 22 class URLRequestContextGetter; |
23 } | 23 } |
24 | 24 |
25 namespace media_router { | 25 namespace media_router { |
26 | 26 |
27 class DialMediaSinkServiceImpl; | 27 class DialMediaSinkServiceImpl; |
| 28 class DialMediaSinkServiceDelegate; |
28 | 29 |
29 // A wrapper class of DialMediaSinkService handling thread hopping between UI | 30 // 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 // 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 // UI thread. It then post tasks to IO thread and invoke them on underlying |
32 // DialMediaSinkService instance. | 33 // DialMediaSinkService instance. |
33 class DialMediaSinkServiceProxy | 34 class DialMediaSinkServiceProxy |
34 : public MediaSinkService, | 35 : public MediaSinkService, |
35 public base::RefCountedThreadSafe< | 36 public base::RefCountedThreadSafe< |
36 DialMediaSinkServiceProxy, | 37 DialMediaSinkServiceProxy, |
37 content::BrowserThread::DeleteOnIOThread> { | 38 content::BrowserThread::DeleteOnIOThread> { |
38 public: | 39 public: |
39 // |callback| is invoked on the UI thread when sinks are discovered. | 40 // |callback| is invoked on the UI thread when sinks are discovered. |
40 // |context| is browser context. | 41 // |context| is browser context. |
41 DialMediaSinkServiceProxy( | 42 DialMediaSinkServiceProxy( |
42 const MediaSinkService::OnSinksDiscoveredCallback& callback, | 43 const MediaSinkService::OnSinksDiscoveredCallback& callback, |
43 content::BrowserContext* context); | 44 content::BrowserContext* context); |
44 | 45 |
45 // Starts discovery of DIAL devices on IO thread. Caller is responsible for | 46 // Starts discovery of DIAL devices on IO thread. Caller is responsible for |
46 // calling Stop() before destroying this object.. | 47 // calling Stop() before destroying this object.. |
47 void Start() override; | 48 void Start() override; |
48 | 49 |
49 // Stops discovery of DIAL devices on IO thread. The callback passed to | 50 // Stops discovery of DIAL devices on IO thread. The callback passed to |
50 // Start() is cleared. | 51 // Start() is cleared. |
51 void Stop() override; | 52 void Stop() override; |
52 | 53 |
| 54 void SetDialMediaSinkServiceDelegate( |
| 55 scoped_refptr<DialMediaSinkServiceDelegate> delegate); |
| 56 |
53 void SetDialMediaSinkServiceForTest( | 57 void SetDialMediaSinkServiceForTest( |
54 std::unique_ptr<DialMediaSinkServiceImpl> dial_media_sink_service); | 58 std::unique_ptr<DialMediaSinkServiceImpl> dial_media_sink_service); |
55 | 59 |
56 private: | 60 private: |
57 friend class DialMediaSinkServiceProxyTest; | 61 friend class DialMediaSinkServiceProxyTest; |
58 friend class base::DeleteHelper<DialMediaSinkServiceProxy>; | 62 friend class base::DeleteHelper<DialMediaSinkServiceProxy>; |
59 friend struct content::BrowserThread::DeleteOnThread< | 63 friend struct content::BrowserThread::DeleteOnThread< |
60 content::BrowserThread::IO>; | 64 content::BrowserThread::IO>; |
61 friend class base::RefCountedThreadSafe<DialMediaSinkServiceProxy>; | 65 friend class base::RefCountedThreadSafe<DialMediaSinkServiceProxy>; |
62 | 66 |
63 ~DialMediaSinkServiceProxy() override; | 67 ~DialMediaSinkServiceProxy() override; |
64 | 68 |
65 // Starts DIAL discovery. | 69 // Starts DIAL discovery. |
66 void StartOnIOThread(); | 70 void StartOnIOThread(); |
67 | 71 |
68 // Stops DIAL discovery. | 72 // Stops DIAL discovery. |
69 void StopOnIOThread(); | 73 void StopOnIOThread(); |
70 | 74 |
71 // Callback passed to |dial_media_sink_service_| ctor. When invoked, post task | 75 // Callback passed to |dial_media_sink_service_| ctor. When invoked, post task |
72 // to UI thread and invoke |sink_discovery_callback_|. | 76 // to UI thread and invoke |sink_discovery_callback_|. |
73 void OnSinksDiscoveredOnIOThread(std::vector<MediaSinkInternal> sinks); | 77 void OnSinksDiscoveredOnIOThread(std::vector<MediaSinkInternal> sinks); |
74 | 78 |
75 private: | 79 private: |
76 std::unique_ptr<DialMediaSinkServiceImpl> dial_media_sink_service_; | 80 std::unique_ptr<DialMediaSinkServiceImpl> dial_media_sink_service_; |
77 | 81 |
| 82 scoped_refptr<DialMediaSinkServiceDelegate> delegate_; |
| 83 |
78 scoped_refptr<net::URLRequestContextGetter> request_context_; | 84 scoped_refptr<net::URLRequestContextGetter> request_context_; |
79 | 85 |
80 DISALLOW_COPY_AND_ASSIGN(DialMediaSinkServiceProxy); | 86 DISALLOW_COPY_AND_ASSIGN(DialMediaSinkServiceProxy); |
81 }; | 87 }; |
82 | 88 |
83 } // namespace media_router | 89 } // namespace media_router |
84 | 90 |
85 #endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DIAL_MEDIA_SINK_SERVICE_PR
OXY_H_ | 91 #endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DIAL_MEDIA_SINK_SERVICE_PR
OXY_H_ |
OLD | NEW |