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 #include "chrome/browser/media/router/discovery/dial/dial_media_sink_service_pro
xy.h" |
| 6 |
| 7 #include "chrome/browser/media/router/discovery/dial/dial_media_sink_service_imp
l.h" |
| 8 #include "content/public/browser/browser_context.h" |
| 9 |
| 10 using content::BrowserThread; |
| 11 |
| 12 namespace media_router { |
| 13 |
| 14 DialMediaSinkServiceProxy::DialMediaSinkServiceProxy( |
| 15 const MediaSinkService::OnSinksDiscoveredCallback& callback, |
| 16 content::BrowserContext* context) |
| 17 : MediaSinkService(callback) { |
| 18 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 19 auto* profile = Profile::FromBrowserContext(context); |
| 20 request_context_ = profile->GetRequestContext(); |
| 21 DCHECK(request_context_); |
| 22 } |
| 23 |
| 24 DialMediaSinkServiceProxy::~DialMediaSinkServiceProxy() = default; |
| 25 |
| 26 void DialMediaSinkServiceProxy::Start() { |
| 27 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 28 |
| 29 content::BrowserThread::PostTask( |
| 30 content::BrowserThread::IO, FROM_HERE, |
| 31 base::Bind(&DialMediaSinkServiceProxy::StartOnIOThread, this)); |
| 32 } |
| 33 |
| 34 void DialMediaSinkServiceProxy::Stop() { |
| 35 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 36 |
| 37 content::BrowserThread::PostTask( |
| 38 content::BrowserThread::IO, FROM_HERE, |
| 39 base::Bind(&DialMediaSinkServiceProxy::StopOnIOThread, this)); |
| 40 } |
| 41 |
| 42 void DialMediaSinkServiceProxy::SetDialMediaSinkServiceForTest( |
| 43 std::unique_ptr<DialMediaSinkServiceImpl> dial_media_sink_service) { |
| 44 DCHECK(dial_media_sink_service); |
| 45 DCHECK(!dial_media_sink_service_); |
| 46 dial_media_sink_service_ = std::move(dial_media_sink_service); |
| 47 } |
| 48 |
| 49 void DialMediaSinkServiceProxy::StartOnIOThread() { |
| 50 if (!dial_media_sink_service_) { |
| 51 // Need to explicitly delete |dial_media_sink_service_| outside dtor to |
| 52 // avoid circular dependency. |
| 53 dial_media_sink_service_ = base::MakeUnique<DialMediaSinkServiceImpl>( |
| 54 base::Bind(&DialMediaSinkServiceProxy::OnSinksDiscoveredOnIOThread, |
| 55 this), |
| 56 request_context_.get()); |
| 57 } |
| 58 |
| 59 dial_media_sink_service_->Start(); |
| 60 } |
| 61 |
| 62 void DialMediaSinkServiceProxy::StopOnIOThread() { |
| 63 if (!dial_media_sink_service_) |
| 64 return; |
| 65 |
| 66 dial_media_sink_service_->Stop(); |
| 67 dial_media_sink_service_.reset(); |
| 68 } |
| 69 |
| 70 void DialMediaSinkServiceProxy::OnSinksDiscoveredOnIOThread( |
| 71 std::vector<MediaSinkInternal> sinks) { |
| 72 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 73 content::BrowserThread::PostTask( |
| 74 content::BrowserThread::UI, FROM_HERE, |
| 75 base::Bind(sink_discovery_callback_, std::move(sinks))); |
| 76 } |
| 77 |
| 78 } // namespace media_router |
OLD | NEW |