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

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

Issue 10873018: [net] Move DnsConfigService to NetworkChangeNotifier. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix null-dereference Created 8 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 | Annotate | Revision Log
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 "net/dns/dns_config_service.h" 5 #include "net/dns/dns_config_service.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "net/base/ip_endpoint.h" 10 #include "net/base/ip_endpoint.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 74 }
75 75
76 76
77 DnsConfigService::DnsConfigService() 77 DnsConfigService::DnsConfigService()
78 : have_config_(false), 78 : have_config_(false),
79 have_hosts_(false), 79 have_hosts_(false),
80 need_update_(false), 80 need_update_(false),
81 last_sent_empty_(true) {} 81 last_sent_empty_(true) {}
82 82
83 DnsConfigService::~DnsConfigService() { 83 DnsConfigService::~DnsConfigService() {
84 // Must always clean up.
85 NetworkChangeNotifier::RemoveDNSObserver(this);
86 } 84 }
87 85
88 void DnsConfigService::Read(const CallbackType& callback) { 86 void DnsConfigService::ReadConfig(const CallbackType& callback) {
89 DCHECK(CalledOnValidThread()); 87 DCHECK(CalledOnValidThread());
90 DCHECK(!callback.is_null()); 88 DCHECK(!callback.is_null());
91 DCHECK(callback_.is_null()); 89 DCHECK(callback_.is_null());
92 callback_ = callback; 90 callback_ = callback;
93 OnDNSChanged(NetworkChangeNotifier::CHANGE_DNS_WATCH_STARTED); 91 this->ReadNow();
mmenke 2012/08/28 15:18:40 You don't need "this->" here, or below.
94 } 92 }
95 93
96 void DnsConfigService::Watch(const CallbackType& callback) { 94 void DnsConfigService::WatchConfig(const CallbackType& callback) {
97 DCHECK(CalledOnValidThread()); 95 DCHECK(CalledOnValidThread());
98 DCHECK(!callback.is_null()); 96 DCHECK(!callback.is_null());
99 DCHECK(callback_.is_null()); 97 DCHECK(callback_.is_null());
100 NetworkChangeNotifier::AddDNSObserver(this);
101 callback_ = callback; 98 callback_ = callback;
102 if (NetworkChangeNotifier::IsWatchingDNS()) 99 this->StartWatching();
103 OnDNSChanged(NetworkChangeNotifier::CHANGE_DNS_WATCH_STARTED); 100 this->ReadNow();
104 // else: Wait until signal before reading.
105 } 101 }
106 102
107 void DnsConfigService::InvalidateConfig() { 103 void DnsConfigService::InvalidateConfig() {
108 DCHECK(CalledOnValidThread()); 104 DCHECK(CalledOnValidThread());
109 base::TimeTicks now = base::TimeTicks::Now(); 105 base::TimeTicks now = base::TimeTicks::Now();
110 if (!last_invalidate_config_time_.is_null()) { 106 if (!last_invalidate_config_time_.is_null()) {
111 UMA_HISTOGRAM_LONG_TIMES("AsyncDNS.ConfigNotifyInterval", 107 UMA_HISTOGRAM_LONG_TIMES("AsyncDNS.ConfigNotifyInterval",
112 now - last_invalidate_config_time_); 108 now - last_invalidate_config_time_);
113 } 109 }
114 last_invalidate_config_time_ = now; 110 last_invalidate_config_time_ = now;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 timer_.Stop(); 210 timer_.Stop();
215 if (!need_update_) 211 if (!need_update_)
216 return; 212 return;
217 need_update_ = false; 213 need_update_ = false;
218 last_sent_empty_ = false; 214 last_sent_empty_ = false;
219 callback_.Run(dns_config_); 215 callback_.Run(dns_config_);
220 } 216 }
221 217
222 } // namespace net 218 } // namespace net
223 219
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698