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

Side by Side Diff: net/dns/mdns_client_impl.cc

Issue 578703003: use base::Time constants in net module instead of using static constants (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: changed as per review comment Created 6 years, 3 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
« no previous file with comments | « AUTHORS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "net/dns/mdns_client_impl.h" 5 #include "net/dns/mdns_client_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop_proxy.h" 8 #include "base/message_loop/message_loop_proxy.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/time/default_clock.h" 10 #include "base/time/default_clock.h"
11 #include "base/time/time.h"
11 #include "net/base/dns_util.h" 12 #include "net/base/dns_util.h"
12 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
13 #include "net/base/net_log.h" 14 #include "net/base/net_log.h"
14 #include "net/base/rand_callback.h" 15 #include "net/base/rand_callback.h"
15 #include "net/dns/dns_protocol.h" 16 #include "net/dns/dns_protocol.h"
16 #include "net/dns/record_rdata.h" 17 #include "net/dns/record_rdata.h"
17 #include "net/udp/datagram_socket.h" 18 #include "net/udp/datagram_socket.h"
18 19
19 // TODO(gene): Remove this temporary method of disabling NSEC support once it 20 // TODO(gene): Remove this temporary method of disabling NSEC support once it
20 // becomes clear whether this feature should be 21 // becomes clear whether this feature should be
21 // supported. http://crbug.com/255232 22 // supported. http://crbug.com/255232
22 #define ENABLE_NSEC 23 #define ENABLE_NSEC
23 24
24 namespace net { 25 namespace net {
25 26
26 namespace { 27 namespace {
27 28
28 const unsigned MDnsTransactionTimeoutSeconds = 3; 29 const unsigned MDnsTransactionTimeoutSeconds = 3;
29 // The fractions of the record's original TTL after which an active listener 30 // The fractions of the record's original TTL after which an active listener
30 // (one that had |SetActiveRefresh(true)| called) will send a query to refresh 31 // (one that had |SetActiveRefresh(true)| called) will send a query to refresh
31 // its cache. This happens both at 85% of the original TTL and again at 95% of 32 // its cache. This happens both at 85% of the original TTL and again at 95% of
32 // the original TTL. 33 // the original TTL.
33 const double kListenerRefreshRatio1 = 0.85; 34 const double kListenerRefreshRatio1 = 0.85;
34 const double kListenerRefreshRatio2 = 0.95; 35 const double kListenerRefreshRatio2 = 0.95;
35 const unsigned kMillisecondsPerSecond = 1000;
36 36
37 } // namespace 37 } // namespace
38 38
39 void MDnsSocketFactoryImpl::CreateSockets( 39 void MDnsSocketFactoryImpl::CreateSockets(
40 ScopedVector<DatagramServerSocket>* sockets) { 40 ScopedVector<DatagramServerSocket>* sockets) {
41 InterfaceIndexFamilyList interfaces(GetMDnsInterfacesToBind()); 41 InterfaceIndexFamilyList interfaces(GetMDnsInterfacesToBind());
42 for (size_t i = 0; i < interfaces.size(); ++i) { 42 for (size_t i = 0; i < interfaces.size(); ++i) {
43 DCHECK(interfaces[i].second == net::ADDRESS_FAMILY_IPV4 || 43 DCHECK(interfaces[i].second == net::ADDRESS_FAMILY_IPV4 ||
44 interfaces[i].second == net::ADDRESS_FAMILY_IPV6); 44 interfaces[i].second == net::ADDRESS_FAMILY_IPV6);
45 scoped_ptr<DatagramServerSocket> socket( 45 scoped_ptr<DatagramServerSocket> socket(
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 return; 531 return;
532 } 532 }
533 533
534 next_refresh_.Reset(base::Bind(&MDnsListenerImpl::DoRefresh, 534 next_refresh_.Reset(base::Bind(&MDnsListenerImpl::DoRefresh,
535 AsWeakPtr())); 535 AsWeakPtr()));
536 536
537 // Schedule refreshes at both 85% and 95% of the original TTL. These will both 537 // Schedule refreshes at both 85% and 95% of the original TTL. These will both
538 // be canceled and rescheduled if the record's TTL is updated due to a 538 // be canceled and rescheduled if the record's TTL is updated due to a
539 // response being received. 539 // response being received.
540 base::Time next_refresh1 = last_update_ + base::TimeDelta::FromMilliseconds( 540 base::Time next_refresh1 = last_update_ + base::TimeDelta::FromMilliseconds(
541 static_cast<int>(kMillisecondsPerSecond * 541 static_cast<int>(base::Time::kMillisecondsPerSecond *
542 kListenerRefreshRatio1 * ttl_)); 542 kListenerRefreshRatio1 * ttl_));
543 543
544 base::Time next_refresh2 = last_update_ + base::TimeDelta::FromMilliseconds( 544 base::Time next_refresh2 = last_update_ + base::TimeDelta::FromMilliseconds(
545 static_cast<int>(kMillisecondsPerSecond * 545 static_cast<int>(base::Time::kMillisecondsPerSecond *
546 kListenerRefreshRatio2 * ttl_)); 546 kListenerRefreshRatio2 * ttl_));
547 547
548 base::MessageLoop::current()->PostDelayedTask( 548 base::MessageLoop::current()->PostDelayedTask(
549 FROM_HERE, 549 FROM_HERE,
550 next_refresh_.callback(), 550 next_refresh_.callback(),
551 next_refresh1 - base::Time::Now()); 551 next_refresh1 - base::Time::Now());
552 552
553 base::MessageLoop::current()->PostDelayedTask( 553 base::MessageLoop::current()->PostDelayedTask(
554 FROM_HERE, 554 FROM_HERE,
555 next_refresh_.callback(), 555 next_refresh_.callback(),
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 701
702 void MDnsTransactionImpl::OnNsecRecord(const std::string& name, unsigned type) { 702 void MDnsTransactionImpl::OnNsecRecord(const std::string& name, unsigned type) {
703 TriggerCallback(RESULT_NSEC, NULL); 703 TriggerCallback(RESULT_NSEC, NULL);
704 } 704 }
705 705
706 void MDnsTransactionImpl::OnCachePurged() { 706 void MDnsTransactionImpl::OnCachePurged() {
707 // TODO(noamsml): Cache purge situations not yet implemented 707 // TODO(noamsml): Cache purge situations not yet implemented
708 } 708 }
709 709
710 } // namespace net 710 } // namespace net
OLDNEW
« no previous file with comments | « AUTHORS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698