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

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.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
mark a. foltz 2017/05/17 18:16:20 Do you need to reset |sink_discovery_callback_| he
zhaobin 2017/05/17 22:36:47 Leave |sink_discovery_callback| so we can support
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<DialMediaSinkService> 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 dial_media_sink_service_ = base::MakeUnique<DialMediaSinkService>(
52 base::Bind(&DialMediaSinkServiceProxy::OnSinksDiscoveredOnIOThread,
53 base::Unretained(this)),
mark a. foltz 2017/05/17 18:16:20 It would be more consistent IMO to pass |this| to
zhaobin 2017/05/17 22:36:48 Changed to |this| and reset in StopOnIOThread().
54 request_context_);
55 }
56
57 dial_media_sink_service_->Start();
58 }
59
60 void DialMediaSinkServiceProxy::StopOnIOThread() {
61 DCHECK(dial_media_sink_service_);
62 dial_media_sink_service_->Stop();
mark a. foltz 2017/05/17 18:16:20 Should you delete dial_media_sink_service_?
zhaobin 2017/05/17 22:36:47 Done.
63 }
64
65 void DialMediaSinkServiceProxy::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(&DialMediaSinkServiceProxy::OnSinksDiscoveredOnUIThread, this,
71 std::vector<MediaSinkInternal>(sinks.begin(), sinks.end())));
72 }
73
74 void DialMediaSinkServiceProxy::OnSinksDiscoveredOnUIThread(
75 const std::vector<MediaSinkInternal>& sinks) {
76 if (sink_discovery_callback_)
77 sink_discovery_callback_.Run(sinks);
78 }
79
80 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698