Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: chrome/browser/media/router/discovery/dial/dial_media_sink_service_proxy.cc

Issue 2837363002: [Media Router] Use DialMediaSinkService in MediaRouterMojoImpl (Closed)
Patch Set: resolve code review comments from Mark Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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.h"
8
9 using content::BrowserThread;
10
11 namespace media_router {
12
13 DialMediaSinkServiceProxy::DialMediaSinkServiceProxy(
14 const MediaSinkService::OnSinksDiscoveredCallback& callback,
15 net::URLRequestContextGetter* request_context)
16 : MediaSinkService(callback) {
Kevin M 2017/05/15 19:56:58 This is what I was referring to about making Media
mark a. foltz 2017/05/15 21:36:27 The main purpose is to isolate threading.
zhaobin 2017/05/16 21:26:49 Besides, we are going to have CastMediaSinkService
17 DCHECK_CURRENTLY_ON(BrowserThread::UI);
18 dial_media_sink_service_.reset(new DialMediaSinkService(
19 base::Bind(&DialMediaSinkServiceProxy::OnSinksDiscoveredOnIOThread,
Kevin M 2017/05/15 19:56:58 I think there might be a deletion race condition h
zhaobin 2017/05/16 21:26:49 I think it is safe. |this| owns dial_media_sink_se
20 base::Unretained(this)),
21 request_context));
22 }
23
24 DialMediaSinkServiceProxy::~DialMediaSinkServiceProxy() {}
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 sink_discovery_callback_.Reset();
37
38 content::BrowserThread::PostTask(
39 content::BrowserThread::IO, FROM_HERE,
40 base::Bind(&DialMediaSinkServiceProxy::StopOnIOThread, this));
41 }
42
43 void DialMediaSinkServiceProxy::SetDialMediaSinkServiceForTest(
44 std::unique_ptr<DialMediaSinkService,
45 content::BrowserThread::DeleteOnIOThread>
46 dial_media_sink_service) {
47 DCHECK(dial_media_sink_service);
48 dial_media_sink_service_ = std::move(dial_media_sink_service);
49 }
50
51 void DialMediaSinkServiceProxy::StartOnIOThread() {
52 DCHECK(dial_media_sink_service_);
Kevin M 2017/05/15 19:56:58 What is the benefit of these methods vs. just post
zhaobin 2017/05/16 21:26:49 |this| is RefCountedThreadSafe, MediaSinkService i
53 dial_media_sink_service_->Start();
54 }
55
56 void DialMediaSinkServiceProxy::StopOnIOThread() {
57 DCHECK(dial_media_sink_service_);
58 dial_media_sink_service_->Stop();
59 }
60
61 void DialMediaSinkServiceProxy::OnSinksDiscoveredOnIOThread(
62 const std::vector<MediaSinkInternal>& sinks) {
63 DCHECK_CURRENTLY_ON(BrowserThread::IO);
64 content::BrowserThread::PostTask(
65 content::BrowserThread::UI, FROM_HERE,
66 base::Bind(&DialMediaSinkServiceProxy::OnSinksDiscoveredOnUIThread, this,
67 std::vector<MediaSinkInternal>(sinks.begin(), sinks.end())));
68 }
69
70 void DialMediaSinkServiceProxy::OnSinksDiscoveredOnUIThread(
71 const std::vector<MediaSinkInternal>& sinks) {
72 if (sink_discovery_callback_)
Kevin M 2017/05/15 19:56:58 Can we PostTask to sink_discovery_callback_ direct
zhaobin 2017/05/16 21:26:49 Similar to above. sink_discovery_callback_ binds t
73 sink_discovery_callback_.Run(sinks);
74 }
75
76 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698