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

Side by Side Diff: net/dns/host_resolver_impl.h

Issue 1898033006: DNS: Add stubs for persisting data across restarts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase and fix bad merge. Created 4 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 (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 #ifndef NET_DNS_HOST_RESOLVER_IMPL_H_ 5 #ifndef NET_DNS_HOST_RESOLVER_IMPL_H_
6 #define NET_DNS_HOST_RESOLVER_IMPL_H_ 6 #define NET_DNS_HOST_RESOLVER_IMPL_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <map> 11 #include <map>
12 #include <memory> 12 #include <memory>
13 13
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/strings/string_piece.h" 16 #include "base/strings/string_piece.h"
17 #include "base/threading/non_thread_safe.h" 17 #include "base/threading/non_thread_safe.h"
18 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "base/timer/timer.h"
19 #include "net/base/net_export.h" 20 #include "net/base/net_export.h"
20 #include "net/base/network_change_notifier.h" 21 #include "net/base/network_change_notifier.h"
21 #include "net/dns/host_cache.h" 22 #include "net/dns/host_cache.h"
22 #include "net/dns/host_resolver.h" 23 #include "net/dns/host_resolver.h"
23 #include "net/dns/host_resolver_proc.h" 24 #include "net/dns/host_resolver_proc.h"
24 25
25 namespace net { 26 namespace net {
26 27
27 class AddressList; 28 class AddressList;
28 class BoundNetLog; 29 class BoundNetLog;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 std::unique_ptr<base::Value> GetDnsConfigAsValue() const override; 150 std::unique_ptr<base::Value> GetDnsConfigAsValue() const override;
150 151
151 // Like |ResolveFromCache()|, but can return a stale result if the 152 // Like |ResolveFromCache()|, but can return a stale result if the
152 // implementation supports it. Fills in |*stale_info| if a response is 153 // implementation supports it. Fills in |*stale_info| if a response is
153 // returned to indicate how stale (or not) it is. 154 // returned to indicate how stale (or not) it is.
154 int ResolveStaleFromCache(const RequestInfo& info, 155 int ResolveStaleFromCache(const RequestInfo& info,
155 AddressList* addresses, 156 AddressList* addresses,
156 HostCache::EntryStaleness* stale_info, 157 HostCache::EntryStaleness* stale_info,
157 const BoundNetLog& source_net_log); 158 const BoundNetLog& source_net_log);
158 159
160 void InitializePersistence(
161 const PersistCallback& persist_callback,
162 std::unique_ptr<const base::Value> old_data) override;
163
159 void set_proc_params_for_test(const ProcTaskParams& proc_params) { 164 void set_proc_params_for_test(const ProcTaskParams& proc_params) {
160 proc_params_ = proc_params; 165 proc_params_ = proc_params;
161 } 166 }
162 167
163 protected: 168 protected:
164 // Just like the public constructor, but allows the task runner used for 169 // Just like the public constructor, but allows the task runner used for
165 // blocking tasks to be specified. Intended for testing only. 170 // blocking tasks to be specified. Intended for testing only.
166 HostResolverImpl(const Options& options, 171 HostResolverImpl(const Options& options,
167 NetLog* net_log, 172 NetLog* net_log,
168 scoped_refptr<base::TaskRunner> worker_task_runner); 173 scoped_refptr<base::TaskRunner> worker_task_runner);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 295
291 void UpdateDNSConfig(bool config_changed); 296 void UpdateDNSConfig(bool config_changed);
292 297
293 // True if have a DnsClient with a valid DnsConfig. 298 // True if have a DnsClient with a valid DnsConfig.
294 bool HaveDnsConfig() const; 299 bool HaveDnsConfig() const;
295 300
296 // Called when a host name is successfully resolved and DnsTask was run on it 301 // Called when a host name is successfully resolved and DnsTask was run on it
297 // and resulted in |net_error|. 302 // and resulted in |net_error|.
298 void OnDnsTaskResolve(int net_error); 303 void OnDnsTaskResolve(int net_error);
299 304
305 void SchedulePersist();
306 void DoPersist();
307
308 void ApplyPersistentData(std::unique_ptr<const base::Value>);
309 std::unique_ptr<const base::Value> GetPersistentData();
310
300 // Allows the tests to catch slots leaking out of the dispatcher. One 311 // Allows the tests to catch slots leaking out of the dispatcher. One
301 // HostResolverImpl::Job could occupy multiple PrioritizedDispatcher job 312 // HostResolverImpl::Job could occupy multiple PrioritizedDispatcher job
302 // slots. 313 // slots.
303 size_t num_running_dispatcher_jobs_for_tests() const { 314 size_t num_running_dispatcher_jobs_for_tests() const {
304 return dispatcher_->num_running_jobs(); 315 return dispatcher_->num_running_jobs();
305 } 316 }
306 317
307 // Cache of host resolution results. 318 // Cache of host resolution results.
308 std::unique_ptr<HostCache> cache_; 319 std::unique_ptr<HostCache> cache_;
309 320
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 HostResolverFlags additional_resolver_flags_; 357 HostResolverFlags additional_resolver_flags_;
347 358
348 // Allow fallback to ProcTask if DnsTask fails. 359 // Allow fallback to ProcTask if DnsTask fails.
349 bool fallback_to_proctask_; 360 bool fallback_to_proctask_;
350 361
351 // Task runner used for DNS lookups using the platform resolver, and other 362 // Task runner used for DNS lookups using the platform resolver, and other
352 // blocking operations. Usually just the WorkerPool's task runner for slow 363 // blocking operations. Usually just the WorkerPool's task runner for slow
353 // tasks, but can be overridden for tests. 364 // tasks, but can be overridden for tests.
354 scoped_refptr<base::TaskRunner> worker_task_runner_; 365 scoped_refptr<base::TaskRunner> worker_task_runner_;
355 366
367 bool persist_initialized_;
368 PersistCallback persist_callback_;
369 base::OneShotTimer persist_timer_;
370
356 base::WeakPtrFactory<HostResolverImpl> weak_ptr_factory_; 371 base::WeakPtrFactory<HostResolverImpl> weak_ptr_factory_;
357 372
358 base::WeakPtrFactory<HostResolverImpl> probe_weak_ptr_factory_; 373 base::WeakPtrFactory<HostResolverImpl> probe_weak_ptr_factory_;
359 374
360 DISALLOW_COPY_AND_ASSIGN(HostResolverImpl); 375 DISALLOW_COPY_AND_ASSIGN(HostResolverImpl);
361 }; 376 };
362 377
363 // Resolves a local hostname (such as "localhost" or "localhost6") into 378 // Resolves a local hostname (such as "localhost" or "localhost6") into
364 // IP endpoints with the given port. Returns true if |host| is a local 379 // IP endpoints with the given port. Returns true if |host| is a local
365 // hostname and false otherwise. Special IPv6 names (e.g. "localhost6") 380 // hostname and false otherwise. Special IPv6 names (e.g. "localhost6")
366 // will resolve to an IPv6 address only, whereas other names will 381 // will resolve to an IPv6 address only, whereas other names will
367 // resolve to both IPv4 and IPv6. 382 // resolve to both IPv4 and IPv6.
368 // This function is only exposed so it can be unit-tested. 383 // This function is only exposed so it can be unit-tested.
369 // TODO(tfarina): It would be better to change the tests so this function 384 // TODO(tfarina): It would be better to change the tests so this function
370 // gets exercised indirectly through HostResolverImpl. 385 // gets exercised indirectly through HostResolverImpl.
371 NET_EXPORT_PRIVATE bool ResolveLocalHostname(base::StringPiece host, 386 NET_EXPORT_PRIVATE bool ResolveLocalHostname(base::StringPiece host,
372 uint16_t port, 387 uint16_t port,
373 AddressList* address_list); 388 AddressList* address_list);
374 389
375 } // namespace net 390 } // namespace net
376 391
377 #endif // NET_DNS_HOST_RESOLVER_IMPL_H_ 392 #endif // NET_DNS_HOST_RESOLVER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698