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