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

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 Kevin 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_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), weak_factory_(this) {
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_) {
imcheng 2017/05/26 01:25:59 Consider adding a DCHECK_CURRENTLY_ON(BrowserThrea
zhaobin 2017/05/26 20:59:40 Mark suggests no check for private methods.
51 // Need to explicitly delete |dial_media_sink_service_| outside dtor to
imcheng 2017/05/26 01:25:59 Does this comment mean that we should always call
zhaobin 2017/05/26 20:59:40 Done.
52 // avoid circular dependency.
53 dial_media_sink_service_ = base::MakeUnique<DialMediaSinkServiceImpl>(
54 base::Bind(&DialMediaSinkServiceProxy::OnSinksDiscoveredOnIOThread,
55 weak_factory_.GetWeakPtr()),
56 request_context_);
57 }
58
59 dial_media_sink_service_->Start();
60 }
61
62 void DialMediaSinkServiceProxy::StopOnIOThread() {
63 if (!dial_media_sink_service_)
imcheng 2017/05/26 01:25:59 ditto on DCHECK_CURRENTLY_ON.
zhaobin 2017/05/26 20:59:40 Mark suggests no check for private methods.
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)));
imcheng 2017/05/26 01:25:59 Why do we need std::move here? base::Bind by defau
zhaobin 2017/05/26 20:59:40 Acknowledged.
76 }
77
78 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698