| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/net/dns_global.h" | 5 #include "chrome/browser/net/dns_global.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/stats_counters.h" | 10 #include "base/stats_counters.h" |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 //------------------------------------------------------------------------------ | 370 //------------------------------------------------------------------------------ |
| 371 // This section intializes and tears down global DNS prefetch services. | 371 // This section intializes and tears down global DNS prefetch services. |
| 372 //------------------------------------------------------------------------------ | 372 //------------------------------------------------------------------------------ |
| 373 | 373 |
| 374 // Note: We have explicit permission to create the following global static | 374 // Note: We have explicit permission to create the following global static |
| 375 // object (in opposition to Google style rules). By making it a static, we | 375 // object (in opposition to Google style rules). By making it a static, we |
| 376 // can ensure its deletion. | 376 // can ensure its deletion. |
| 377 static PrefetchObserver dns_resolution_observer; | 377 static PrefetchObserver dns_resolution_observer; |
| 378 | 378 |
| 379 void InitDnsPrefetch(PrefService* user_prefs) { | 379 void InitDnsPrefetch(PrefService* user_prefs) { |
| 380 // Use a large shutdown time so that UI tests (that instigate lookups, and |
| 381 // then try to shutdown the browser) don't instigate the CHECK about |
| 382 // "some slaves have not finished" |
| 383 const TimeDelta kAllowableShutdownTime(TimeDelta::FromSeconds(10)); |
| 380 DCHECK(NULL == dns_master); | 384 DCHECK(NULL == dns_master); |
| 381 if (!dns_master) { | 385 if (!dns_master) { |
| 382 dns_master = new DnsMaster(); | 386 dns_master = new DnsMaster(kAllowableShutdownTime); |
| 383 // We did the initialization, so we should prime the pump, and set up | 387 // We did the initialization, so we should prime the pump, and set up |
| 384 // the DNS resolution system to run. | 388 // the DNS resolution system to run. |
| 385 off_the_record_observer.Register(); | 389 off_the_record_observer.Register(); |
| 386 | 390 |
| 387 if (user_prefs) { | 391 if (user_prefs) { |
| 388 bool enabled = user_prefs->GetBoolean(prefs::kDnsPrefetchingEnabled); | 392 bool enabled = user_prefs->GetBoolean(prefs::kDnsPrefetchingEnabled); |
| 389 EnableDnsPrefetch(enabled); | 393 EnableDnsPrefetch(enabled); |
| 390 } | 394 } |
| 391 | 395 |
| 392 DLOG(INFO) << "DNS Prefetch service started"; | 396 DLOG(INFO) << "DNS Prefetch service started"; |
| 393 | 397 |
| 394 // Start observing real HTTP stack resolutions. | 398 // Start observing real HTTP stack resolutions. |
| 395 net::AddDnsResolutionObserver(&dns_resolution_observer); | 399 net::AddDnsResolutionObserver(&dns_resolution_observer); |
| 396 } | 400 } |
| 397 } | 401 } |
| 398 | 402 |
| 399 void ShutdownDnsPrefetch() { | 403 void ShutdownDnsPrefetch() { |
| 400 DCHECK(NULL != dns_master); | 404 DCHECK(NULL != dns_master); |
| 401 delete dns_master; | 405 DnsMaster* master = dns_master; |
| 402 dns_master = NULL; | 406 dns_master = NULL; |
| 407 if (master->ShutdownSlaves()) { |
| 408 delete master; |
| 409 } else { |
| 410 // Leak instance if shutdown problem. |
| 411 DCHECK(0); |
| 412 } |
| 403 } | 413 } |
| 404 | 414 |
| 405 static void DiscardAllPrefetchState() { | 415 static void DiscardAllPrefetchState() { |
| 406 if (!dns_master) | 416 if (!dns_master) |
| 407 return; | 417 return; |
| 408 dns_master->DiscardAllResults(); | 418 dns_master->DiscardAllResults(); |
| 409 } | 419 } |
| 410 | 420 |
| 411 //------------------------------------------------------------------------------ | 421 //------------------------------------------------------------------------------ |
| 412 // Functions to handle saving of hostnames from one session to the next, to | 422 // Functions to handle saving of hostnames from one session to the next, to |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 if (hostnames.size() > 0) | 462 if (hostnames.size() > 0) |
| 453 DnsPrefetchMotivatedList(hostnames, DnsHostInfo::STARTUP_LIST_MOTIVATED); | 463 DnsPrefetchMotivatedList(hostnames, DnsHostInfo::STARTUP_LIST_MOTIVATED); |
| 454 else // Start a thread. | 464 else // Start a thread. |
| 455 DnsMotivatedPrefetch(std::string("www.google.com"), | 465 DnsMotivatedPrefetch(std::string("www.google.com"), |
| 456 DnsHostInfo::STARTUP_LIST_MOTIVATED); | 466 DnsHostInfo::STARTUP_LIST_MOTIVATED); |
| 457 } | 467 } |
| 458 | 468 |
| 459 | 469 |
| 460 } // namespace chrome_browser_net | 470 } // namespace chrome_browser_net |
| 461 | 471 |
| OLD | NEW |