Chromium Code Reviews| 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..f7e5c509ed9268303142aa760664ea9061b30fbf |
| --- /dev/null |
| +++ b/chrome/browser/media/router/discovery/dial/dial_media_sink_service_proxy.h |
| @@ -0,0 +1,87 @@ |
| +// 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" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/sequenced_task_runner_helpers.h" |
| +#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. Caller is responsible for |
| + // calling Stop() before destroying this object.. |
| + 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_|. |
| + void OnSinksDiscoveredOnIOThread(std::vector<MediaSinkInternal> sinks); |
| + |
| + private: |
| + std::unique_ptr<DialMediaSinkServiceImpl> dial_media_sink_service_; |
| + |
| + 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.
|
| + |
| + base::WeakPtrFactory<DialMediaSinkServiceProxy> weak_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DialMediaSinkServiceProxy); |
| +}; |
| + |
| +} // namespace media_router |
| + |
| +#endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DIAL_MEDIA_SINK_SERVICE_PROXY_H_ |