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

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

Issue 2965843002: [Media Router] Support dual discovery (Closed)
Patch Set: resovle code review comments from Derek and Mark Created 3 years, 4 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/media/router/discovery/dial/dial_media_sink_service_imp l.h" 5 #include "chrome/browser/media/router/discovery/dial/dial_media_sink_service_imp l.h"
6 6
7 #include "chrome/browser/media/router/discovery/dial/dial_device_data.h" 7 #include "chrome/browser/media/router/discovery/dial/dial_device_data.h"
8 #include "chrome/browser/media/router/discovery/mdns/cast_media_sink_service.h"
8 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
9 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
10 #include "net/url_request/url_request_context_getter.h" 11 #include "net/url_request/url_request_context_getter.h"
11 12
12 using content::BrowserThread; 13 using content::BrowserThread;
13 14
14 namespace media_router { 15 namespace media_router {
15 16
16 DialMediaSinkServiceImpl::DialMediaSinkServiceImpl( 17 DialMediaSinkServiceImpl::DialMediaSinkServiceImpl(
17 const OnSinksDiscoveredCallback& callback, 18 const OnSinksDiscoveredCallback& callback,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 if (!description_service_.get()) { 55 if (!description_service_.get()) {
55 description_service_.reset(new DeviceDescriptionService( 56 description_service_.reset(new DeviceDescriptionService(
56 base::Bind(&DialMediaSinkServiceImpl::OnDeviceDescriptionAvailable, 57 base::Bind(&DialMediaSinkServiceImpl::OnDeviceDescriptionAvailable,
57 base::Unretained(this)), 58 base::Unretained(this)),
58 base::Bind(&DialMediaSinkServiceImpl::OnDeviceDescriptionError, 59 base::Bind(&DialMediaSinkServiceImpl::OnDeviceDescriptionError,
59 base::Unretained(this)))); 60 base::Unretained(this))));
60 } 61 }
61 return description_service_.get(); 62 return description_service_.get();
62 } 63 }
63 64
65 void DialMediaSinkServiceImpl::SetDialMediaSinkServiceDelegate(
66 scoped_refptr<DialMediaSinkServiceDelegate> delegate) {
67 delegate_ = delegate;
68 }
69
64 void DialMediaSinkServiceImpl::SetDialRegistryForTest( 70 void DialMediaSinkServiceImpl::SetDialRegistryForTest(
65 DialRegistry* dial_registry) { 71 DialRegistry* dial_registry) {
66 DCHECK(!test_dial_registry_); 72 DCHECK(!test_dial_registry_);
67 test_dial_registry_ = dial_registry; 73 test_dial_registry_ = dial_registry;
68 } 74 }
69 75
70 void DialMediaSinkServiceImpl::SetDescriptionServiceForTest( 76 void DialMediaSinkServiceImpl::SetDescriptionServiceForTest(
71 std::unique_ptr<DeviceDescriptionService> description_service) { 77 std::unique_ptr<DeviceDescriptionService> description_service) {
72 DCHECK(!description_service_); 78 DCHECK(!description_service_);
73 description_service_ = std::move(description_service); 79 description_service_ = std::move(description_service);
74 } 80 }
75 81
76 void DialMediaSinkServiceImpl::OnDialDeviceEvent( 82 void DialMediaSinkServiceImpl::OnDialDeviceEvent(
77 const DialRegistry::DeviceList& devices) { 83 const DialRegistry::DeviceList& devices) {
78 DCHECK_CURRENTLY_ON(BrowserThread::IO); 84 DCHECK_CURRENTLY_ON(BrowserThread::IO);
79 DVLOG(2) << "DialMediaSinkServiceImpl::OnDialDeviceEvent found " 85 DVLOG(2) << "DialMediaSinkServiceImpl::OnDialDeviceEvent found "
80 << devices.size() << " devices"; 86 << devices.size() << " devices";
81 87
82 current_sinks_.clear(); 88 current_sinks_.clear();
83 current_devices_ = devices; 89 current_devices_ = devices;
90 if (delegate_)
91 delegate_->OnDialSinksRemoved();
84 92
85 GetDescriptionService()->GetDeviceDescriptions(devices, 93 GetDescriptionService()->GetDeviceDescriptions(devices,
86 request_context_.get()); 94 request_context_.get());
87 } 95 }
88 96
89 void DialMediaSinkServiceImpl::OnDialError(DialRegistry::DialErrorCode type) { 97 void DialMediaSinkServiceImpl::OnDialError(DialRegistry::DialErrorCode type) {
90 DCHECK_CURRENTLY_ON(BrowserThread::IO); 98 DCHECK_CURRENTLY_ON(BrowserThread::IO);
91 DVLOG(2) << "OnDialError [DialErrorCode]: " << static_cast<int>(type); 99 DVLOG(2) << "OnDialError [DialErrorCode]: " << static_cast<int>(type);
92 } 100 }
93 101
(...skipping 14 matching lines...) Expand all
108 MediaSink::IconType::GENERIC); 116 MediaSink::IconType::GENERIC);
109 DialSinkExtraData extra_data; 117 DialSinkExtraData extra_data;
110 extra_data.app_url = description_data.app_url; 118 extra_data.app_url = description_data.app_url;
111 extra_data.model_name = description_data.model_name; 119 extra_data.model_name = description_data.model_name;
112 std::string ip_address = device_data.device_description_url().host(); 120 std::string ip_address = device_data.device_description_url().host();
113 if (!extra_data.ip_address.AssignFromIPLiteral(ip_address)) { 121 if (!extra_data.ip_address.AssignFromIPLiteral(ip_address)) {
114 DVLOG(1) << "Invalid ip_address: " << ip_address; 122 DVLOG(1) << "Invalid ip_address: " << ip_address;
115 return; 123 return;
116 } 124 }
117 125
118 current_sinks_.insert(MediaSinkInternal(sink, extra_data)); 126 MediaSinkInternal dial_sink(sink, extra_data);
127 current_sinks_.insert(dial_sink);
128 if (delegate_)
129 delegate_->OnDialSinkAdded(dial_sink);
119 130
120 // Start fetch timer again if device description comes back after 131 // Start fetch timer again if device description comes back after
121 // |finish_timer_| fires. 132 // |finish_timer_| fires.
122 MediaSinkServiceBase::RestartTimer(); 133 MediaSinkServiceBase::RestartTimer();
123 } 134 }
124 135
125 void DialMediaSinkServiceImpl::OnDeviceDescriptionError( 136 void DialMediaSinkServiceImpl::OnDeviceDescriptionError(
126 const DialDeviceData& device, 137 const DialDeviceData& device,
127 const std::string& error_message) { 138 const std::string& error_message) {
128 DCHECK_CURRENTLY_ON(BrowserThread::IO); 139 DCHECK_CURRENTLY_ON(BrowserThread::IO);
129 DVLOG(2) << "OnDescriptionFetchesError [message]: " << error_message; 140 DVLOG(2) << "OnDescriptionFetchesError [message]: " << error_message;
130 } 141 }
131 142
132 void DialMediaSinkServiceImpl::RecordDeviceCounts() { 143 void DialMediaSinkServiceImpl::RecordDeviceCounts() {
133 metrics_.RecordDialDeviceCounts(current_sinks_.size(), 144 metrics_.RecordDialDeviceCounts(current_sinks_.size(),
134 current_devices_.size()); 145 current_devices_.size());
135 } 146 }
136 147
137 } // namespace media_router 148 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698