Index: chrome/browser/media/router/discovery/dial/dial_media_sink_service_proxy.h |
diff --git a/chrome/browser/media/router/discovery/dial/dial_media_sink_service_proxy.h b/chrome/browser/media/router/discovery/dial/dial_media_sink_service_proxy.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b32fd88609e9273aad4920e65e36a9d046c31c7c |
--- /dev/null |
+++ b/chrome/browser/media/router/discovery/dial/dial_media_sink_service_proxy.h |
@@ -0,0 +1,81 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DIAL_MEDIA_SINK_SERVICE_PROXY_H_ |
+#define CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DIAL_MEDIA_SINK_SERVICE_PROXY_H_ |
+ |
+#include <memory> |
+ |
+#include "base/macros.h" |
mark a. foltz
2017/05/19 18:56:57
You need #includes for base::RefCountedThreadSafe
zhaobin
2017/05/22 20:21:31
Done.
|
+#include "chrome/common/media_router/discovery/media_sink_service.h" |
+#include "content/public/browser/browser_thread.h" |
+ |
+namespace content { |
+class BrowserContext; |
+} |
+ |
+namespace net { |
+class URLRequestContextGetter; |
+} |
+ |
+namespace media_router { |
+ |
+class DialMediaSinkServiceImpl; |
+ |
+// A wrapper class of DialMediaSinkService handling thread hopping between UI |
+// and IO threads. This class is thread safe. Public APIs should be invoked on |
+// UI thread. It then post tasks to IO thread and invoke them on underlying |
+// DialMediaSinkService instance. |
+class DialMediaSinkServiceProxy |
+ : public MediaSinkService, |
+ public base::RefCountedThreadSafe< |
+ DialMediaSinkServiceProxy, |
+ content::BrowserThread::DeleteOnIOThread> { |
+ public: |
+ // |callback| is invoked on the UI thread when sinks are discovered. |
+ // |context| is browser context. |
+ DialMediaSinkServiceProxy( |
+ const MediaSinkService::OnSinksDiscoveredCallback& callback, |
+ content::BrowserContext* context); |
+ |
+ // Starts discovery of DIAL devices on IO thread. |
+ void Start() override; |
+ |
+ // Stops discovery of DIAL devices on IO thread. The callback passed to |
+ // Start() is cleared. |
+ void Stop() override; |
+ |
+ void SetDialMediaSinkServiceForTest( |
+ std::unique_ptr<DialMediaSinkServiceImpl> dial_media_sink_service); |
+ |
+ private: |
+ friend class DialMediaSinkServiceProxyTest; |
+ friend class base::DeleteHelper<DialMediaSinkServiceProxy>; |
+ friend struct content::BrowserThread::DeleteOnThread< |
+ content::BrowserThread::IO>; |
+ friend class base::RefCountedThreadSafe<DialMediaSinkServiceProxy>; |
+ |
+ ~DialMediaSinkServiceProxy() override; |
+ |
+ // Starts DIAL discovery. |
+ void StartOnIOThread(); |
+ |
+ // Stops DIAL discovery. |
+ void StopOnIOThread(); |
+ |
+ // Callback passed to |dial_media_sink_service_| ctor. When invoked, post task |
+ // to UI thread and invoke |sink_discovery_callback_|; |
mark a. foltz
2017/05/19 18:56:57
Nit: s/;/./
zhaobin
2017/05/22 20:21:31
Done.
|
+ void OnSinksDiscoveredOnIOThread(const std::vector<MediaSinkInternal>& sinks); |
+ |
+ private: |
+ std::unique_ptr<DialMediaSinkServiceImpl> dial_media_sink_service_; |
+ |
+ net::URLRequestContextGetter* request_context_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(DialMediaSinkServiceProxy); |
+}; |
+ |
+} // namespace media_router |
+ |
+#endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DIAL_MEDIA_SINK_SERVICE_PROXY_H_ |