Chromium Code Reviews| 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_del egate.h" | |
| 6 | |
| 7 #include "chrome/browser/media/router/discovery/dial/dial_media_sink_service.h" | |
| 8 | |
| 9 using content::BrowserThread; | |
| 10 | |
| 11 namespace media_router { | |
| 12 | |
| 13 DialMediaSinkServiceDelegate::DialMediaSinkServiceDelegate() { | |
| 14 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 15 } | |
| 16 | |
| 17 DialMediaSinkServiceDelegate::~DialMediaSinkServiceDelegate() {} | |
| 18 | |
| 19 void DialMediaSinkServiceDelegate::Start( | |
| 20 const MediaSinkService::OnSinksDiscoveredCallback& callback, | |
| 21 net::URLRequestContextGetter* request_context) { | |
| 22 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 23 sink_discovery_ui_callback_ = callback; | |
| 24 | |
| 25 content::BrowserThread::PostTask( | |
| 26 content::BrowserThread::IO, FROM_HERE, | |
| 27 base::Bind(&DialMediaSinkServiceDelegate::StartOnIOThread, this, | |
| 28 request_context)); | |
| 29 } | |
| 30 | |
| 31 void DialMediaSinkServiceDelegate::Stop() { | |
| 32 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 33 sink_discovery_ui_callback_.Reset(); | |
| 34 | |
| 35 content::BrowserThread::PostTask( | |
| 36 content::BrowserThread::IO, FROM_HERE, | |
| 37 base::Bind(&DialMediaSinkServiceDelegate::StopOnIOThread, this)); | |
| 38 } | |
| 39 | |
| 40 void DialMediaSinkServiceDelegate::SetDialMediaSinkServiceForTest( | |
| 41 std::unique_ptr<DialMediaSinkService, | |
| 42 content::BrowserThread::DeleteOnIOThread> | |
| 43 dial_media_sink_service) { | |
| 44 dial_media_sink_service_ = std::move(dial_media_sink_service); | |
|
mark a. foltz
2017/05/12 21:37:37
Ensure this is set only once? E.g., before this li
zhaobin
2017/05/12 23:03:38
Done.
| |
| 45 } | |
| 46 | |
| 47 void DialMediaSinkServiceDelegate::StartOnIOThread( | |
| 48 net::URLRequestContextGetter* request_context) { | |
| 49 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
|
mark a. foltz
2017/05/12 21:37:36
Nit: as this is a private method, may not be neces
zhaobin
2017/05/12 23:03:38
Done.
| |
| 50 if (!dial_media_sink_service_) { | |
|
mark a. foltz
2017/05/12 21:37:36
Is Start()/Stop()/Start() okay?
zhaobin
2017/05/12 23:03:38
Yes. MediaRouterMojoImpl will only do Start()/Stop
| |
| 51 dial_media_sink_service_.reset(new DialMediaSinkService( | |
| 52 base::Bind(&DialMediaSinkServiceDelegate::OnSinksDiscoveredOnIOThread, | |
| 53 base::Unretained(this)), | |
| 54 request_context)); | |
| 55 } | |
| 56 dial_media_sink_service_->Start(); | |
|
mark a. foltz
2017/05/12 21:37:37
Do you need to check that the service is not alrea
zhaobin
2017/05/12 23:03:38
Handled in unserlying DialMediaSinkService.
| |
| 57 } | |
| 58 | |
| 59 void DialMediaSinkServiceDelegate::StopOnIOThread() { | |
| 60 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 61 DCHECK(dial_media_sink_service_); | |
| 62 dial_media_sink_service_->Stop(); | |
|
mark a. foltz
2017/05/12 21:37:37
Do you need to check that the service is not alrea
zhaobin
2017/05/12 23:03:38
Handled in unserlying DialMediaSinkService.
| |
| 63 } | |
| 64 | |
| 65 void DialMediaSinkServiceDelegate::OnSinksDiscoveredOnIOThread( | |
| 66 const std::vector<MediaSinkInternal>& sinks) { | |
| 67 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 68 content::BrowserThread::PostTask( | |
| 69 content::BrowserThread::UI, FROM_HERE, | |
| 70 base::Bind(&DialMediaSinkServiceDelegate::OnSinksDiscoveredOnUIThread, | |
| 71 this, | |
| 72 std::vector<MediaSinkInternal>(sinks.begin(), sinks.end()))); | |
| 73 } | |
| 74 | |
| 75 void DialMediaSinkServiceDelegate::OnSinksDiscoveredOnUIThread( | |
| 76 const std::vector<MediaSinkInternal>& sinks) { | |
| 77 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
|
mark a. foltz
2017/05/12 21:37:37
This is only called from a private callback - thre
zhaobin
2017/05/12 23:03:38
Done.
| |
| 78 if (sink_discovery_ui_callback_) | |
| 79 sink_discovery_ui_callback_.Run(sinks); | |
| 80 } | |
| 81 | |
| 82 } // namespace media_router | |
| OLD | NEW |