| 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 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 // can ensure its deletion. | 375 // can ensure its deletion. |
| 376 static PrefetchObserver dns_resolution_observer; | 376 static PrefetchObserver dns_resolution_observer; |
| 377 | 377 |
| 378 void InitDnsPrefetch(PrefService* user_prefs) { | 378 void InitDnsPrefetch(PrefService* user_prefs) { |
| 379 // Use a large shutdown time so that UI tests (that instigate lookups, and | 379 // Use a large shutdown time so that UI tests (that instigate lookups, and |
| 380 // then try to shutdown the browser) don't instigate the CHECK about | 380 // then try to shutdown the browser) don't instigate the CHECK about |
| 381 // "some slaves have not finished" | 381 // "some slaves have not finished" |
| 382 const TimeDelta kAllowableShutdownTime(TimeDelta::FromSeconds(10)); | 382 const TimeDelta kAllowableShutdownTime(TimeDelta::FromSeconds(10)); |
| 383 DCHECK(NULL == dns_master); | 383 DCHECK(NULL == dns_master); |
| 384 if (!dns_master) { | 384 if (!dns_master) { |
| 385 dns_master = new DnsMaster(kAllowableShutdownTime); | 385 dns_master = new DnsMaster(); |
| 386 // We did the initialization, so we should prime the pump, and set up | 386 // We did the initialization, so we should prime the pump, and set up |
| 387 // the DNS resolution system to run. | 387 // the DNS resolution system to run. |
| 388 off_the_record_observer.Register(); | 388 off_the_record_observer.Register(); |
| 389 | 389 |
| 390 if (user_prefs) { | 390 if (user_prefs) { |
| 391 bool enabled = user_prefs->GetBoolean(prefs::kDnsPrefetchingEnabled); | 391 bool enabled = user_prefs->GetBoolean(prefs::kDnsPrefetchingEnabled); |
| 392 EnableDnsPrefetch(enabled); | 392 EnableDnsPrefetch(enabled); |
| 393 } | 393 } |
| 394 | 394 |
| 395 DLOG(INFO) << "DNS Prefetch service started"; | 395 DLOG(INFO) << "DNS Prefetch service started"; |
| 396 | 396 |
| 397 // Start observing real HTTP stack resolutions. | 397 // Start observing real HTTP stack resolutions. |
| 398 net::AddDnsResolutionObserver(&dns_resolution_observer); | 398 net::AddDnsResolutionObserver(&dns_resolution_observer); |
| 399 } | 399 } |
| 400 } | 400 } |
| 401 | 401 |
| 402 void ShutdownDnsPrefetch() { | 402 void ShutdownDnsPrefetch() { |
| 403 DCHECK(NULL != dns_master); | 403 DCHECK(NULL != dns_master); |
| 404 DnsMaster* master = dns_master; | 404 dns_master->Shutdown(); |
| 405 } |
| 406 |
| 407 void FreeDnsPrefetchResources() { |
| 408 DCHECK(NULL != dns_master); |
| 409 delete dns_master; |
| 405 dns_master = NULL; | 410 dns_master = NULL; |
| 406 if (master->ShutdownSlaves()) { | |
| 407 delete master; | |
| 408 } else { | |
| 409 // Leak instance if shutdown problem. | |
| 410 DCHECK(0); | |
| 411 } | |
| 412 } | 411 } |
| 413 | 412 |
| 414 static void DiscardAllPrefetchState() { | 413 static void DiscardAllPrefetchState() { |
| 415 if (!dns_master) | 414 if (!dns_master) |
| 416 return; | 415 return; |
| 417 dns_master->DiscardAllResults(); | 416 dns_master->DiscardAllResults(); |
| 418 } | 417 } |
| 419 | 418 |
| 420 //------------------------------------------------------------------------------ | 419 //------------------------------------------------------------------------------ |
| 421 // Functions to handle saving of hostnames from one session to the next, to | 420 // Functions to handle saving of hostnames from one session to the next, to |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 } | 486 } |
| 488 | 487 |
| 489 void TrimSubresourceReferrers() { | 488 void TrimSubresourceReferrers() { |
| 490 if (NULL == dns_master) | 489 if (NULL == dns_master) |
| 491 return; | 490 return; |
| 492 dns_master->TrimReferrers(); | 491 dns_master->TrimReferrers(); |
| 493 } | 492 } |
| 494 | 493 |
| 495 } // namespace chrome_browser_net | 494 } // namespace chrome_browser_net |
| 496 | 495 |
| OLD | NEW |