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

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

Issue 2756483007: [Device Discovery] Move files from browser/extensions/api/dial to browser/media/router/discovery/di… (Closed)
Patch Set: add deps to extension/api/DEPS Created 3 years, 9 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extensions/api/dial/dial_registry.h" 5 #include "chrome/browser/media/router/discovery/dial/dial_registry.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/extensions/api/dial/dial_api.h" 16 #include "chrome/browser/media/router/discovery/dial/dial_device_data.h"
17 #include "chrome/browser/extensions/api/dial/dial_device_data.h" 17 #include "chrome/browser/media/router/discovery/dial/dial_service.h"
18 #include "chrome/browser/extensions/api/dial/dial_service.h"
19 #include "chrome/common/extensions/api/dial.h" 18 #include "chrome/common/extensions/api/dial.h"
imcheng 2017/03/20 23:48:10 Can this be removed?
zhaobin 2017/03/21 21:20:50 Done.
20 #include "components/net_log/chrome_net_log.h" 19 #include "components/net_log/chrome_net_log.h"
21 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
22 21
23 using base::Time; 22 using base::Time;
24 using base::TimeDelta; 23 using base::TimeDelta;
25 using content::BrowserThread; 24 using content::BrowserThread;
26 using net::NetworkChangeNotifier; 25 using net::NetworkChangeNotifier;
27 26
28 namespace extensions { 27 namespace media_router {
29 namespace api {
30 namespace dial {
31 28
32 DialRegistry::DialRegistry(base::TimeDelta refresh_interval, 29 DialRegistry::DialRegistry(base::TimeDelta refresh_interval,
33 base::TimeDelta expiration, 30 base::TimeDelta expiration,
34 const size_t max_devices) 31 const size_t max_devices)
35 : num_listeners_(0), 32 : num_listeners_(0),
36 registry_generation_(0), 33 registry_generation_(0),
37 last_event_registry_generation_(0), 34 last_event_registry_generation_(0),
38 label_count_(0), 35 label_count_(0),
39 refresh_interval_delta_(refresh_interval), 36 refresh_interval_delta_(refresh_interval),
40 expiration_delta_(expiration), 37 expiration_delta_(expiration),
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 } 147 }
151 148
152 void DialRegistry::StartPeriodicDiscovery() { 149 void DialRegistry::StartPeriodicDiscovery() {
153 DCHECK_CURRENTLY_ON(BrowserThread::IO); 150 DCHECK_CURRENTLY_ON(BrowserThread::IO);
154 if (!ReadyToDiscover() || dial_) 151 if (!ReadyToDiscover() || dial_)
155 return; 152 return;
156 153
157 dial_ = CreateDialService(); 154 dial_ = CreateDialService();
158 dial_->AddObserver(this); 155 dial_->AddObserver(this);
159 DoDiscovery(); 156 DoDiscovery();
160 repeating_timer_.Start(FROM_HERE, 157 repeating_timer_.Start(FROM_HERE, refresh_interval_delta_, this,
161 refresh_interval_delta_,
162 this,
163 &DialRegistry::DoDiscovery); 158 &DialRegistry::DoDiscovery);
164 } 159 }
165 160
166 void DialRegistry::DoDiscovery() { 161 void DialRegistry::DoDiscovery() {
167 DCHECK_CURRENTLY_ON(BrowserThread::IO); 162 DCHECK_CURRENTLY_ON(BrowserThread::IO);
168 DCHECK(dial_); 163 DCHECK(dial_);
169 VLOG(2) << "About to discover!"; 164 VLOG(2) << "About to discover!";
170 dial_->Discover(); 165 dial_->Discover();
171 } 166 }
172 167
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 Time now = Now(); 202 Time now = Now();
208 203
209 // Check against our default expiration timeout. 204 // Check against our default expiration timeout.
210 Time default_expiration_time = device.response_time() + expiration_delta_; 205 Time default_expiration_time = device.response_time() + expiration_delta_;
211 if (now > default_expiration_time) 206 if (now > default_expiration_time)
212 return true; 207 return true;
213 208
214 // Check against the device's cache-control header, if set. 209 // Check against the device's cache-control header, if set.
215 if (device.has_max_age()) { 210 if (device.has_max_age()) {
216 Time max_age_expiration_time = 211 Time max_age_expiration_time =
217 device.response_time() + TimeDelta::FromSeconds(device.max_age()); 212 device.response_time() + TimeDelta::FromSeconds(device.max_age());
218 if (now > max_age_expiration_time) 213 if (now > max_age_expiration_time)
219 return true; 214 return true;
220 } 215 }
221 return false; 216 return false;
222 } 217 }
223 218
224 void DialRegistry::Clear() { 219 void DialRegistry::Clear() {
225 DCHECK_CURRENTLY_ON(BrowserThread::IO); 220 DCHECK_CURRENTLY_ON(BrowserThread::IO);
226 device_by_id_map_.clear(); 221 device_by_id_map_.clear();
227 device_by_label_map_.clear(); 222 device_by_label_map_.clear();
228 registry_generation_++; 223 registry_generation_++;
229 } 224 }
230 225
231 void DialRegistry::MaybeSendEvent() { 226 void DialRegistry::MaybeSendEvent() {
232 // Send an event if the device list has changed since the last event. 227 // Send an event if the device list has changed since the last event.
233 bool needs_event = last_event_registry_generation_ < registry_generation_; 228 bool needs_event = last_event_registry_generation_ < registry_generation_;
234 VLOG(2) << "lerg = " << last_event_registry_generation_ << ", rg = " 229 VLOG(2) << "lerg = " << last_event_registry_generation_
235 << registry_generation_ << ", needs_event = " << needs_event; 230 << ", rg = " << registry_generation_
231 << ", needs_event = " << needs_event;
236 if (needs_event) 232 if (needs_event)
237 SendEvent(); 233 SendEvent();
238 } 234 }
239 235
240 void DialRegistry::SendEvent() { 236 void DialRegistry::SendEvent() {
241 DeviceList device_list; 237 DeviceList device_list;
242 for (DeviceByLabelMap::const_iterator it = device_by_label_map_.begin(); 238 for (DeviceByLabelMap::const_iterator it = device_by_label_map_.begin();
243 it != device_by_label_map_.end(); ++it) { 239 it != device_by_label_map_.end(); ++it) {
244 device_list.push_back(*(it->second)); 240 device_list.push_back(*(it->second));
245 } 241 }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 void DialRegistry::OnDialDeviceEvent(const DeviceList& devices) { 361 void DialRegistry::OnDialDeviceEvent(const DeviceList& devices) {
366 for (auto& observer : observers_) 362 for (auto& observer : observers_)
367 observer.OnDialDeviceEvent(devices); 363 observer.OnDialDeviceEvent(devices);
368 } 364 }
369 365
370 void DialRegistry::OnDialError(DialErrorCode type) { 366 void DialRegistry::OnDialError(DialErrorCode type) {
371 for (auto& observer : observers_) 367 for (auto& observer : observers_)
372 observer.OnDialError(type); 368 observer.OnDialError(type);
373 } 369 }
374 370
375 } // namespace dial 371 } // namespace media_router
376 } // namespace api
377 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698