| 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/command_line.h" |
| 10 #include "base/singleton.h" | 11 #include "base/singleton.h" |
| 11 #include "base/stats_counters.h" | 12 #include "base/stats_counters.h" |
| 12 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 13 #include "base/thread.h" | 14 #include "base/thread.h" |
| 14 #include "base/values.h" | 15 #include "base/values.h" |
| 15 #include "chrome/browser/browser.h" | 16 #include "chrome/browser/browser.h" |
| 16 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/net/dns_host_info.h" | 18 #include "chrome/browser/net/dns_host_info.h" |
| 18 #include "chrome/browser/net/referrer.h" | 19 #include "chrome/browser/net/referrer.h" |
| 19 #include "chrome/browser/profile.h" | 20 #include "chrome/browser/profile.h" |
| 20 #include "chrome/browser/session_startup_pref.h" | 21 #include "chrome/browser/session_startup_pref.h" |
| 21 #include "chrome/common/notification_registrar.h" | 22 #include "chrome/common/notification_registrar.h" |
| 22 #include "chrome/common/notification_service.h" | 23 #include "chrome/common/notification_service.h" |
| 23 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 24 #include "chrome/common/pref_service.h" | 25 #include "chrome/common/pref_service.h" |
| 25 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| 27 #include "net/base/fixed_host_resolver.h" |
| 26 #include "net/base/host_resolver.h" | 28 #include "net/base/host_resolver.h" |
| 27 #include "net/base/host_resolver_impl.h" | 29 #include "net/base/host_resolver_impl.h" |
| 28 | 30 |
| 29 using base::Time; | 31 using base::Time; |
| 30 using base::TimeDelta; | 32 using base::TimeDelta; |
| 31 | 33 |
| 32 namespace chrome_browser_net { | 34 namespace chrome_browser_net { |
| 33 | 35 |
| 34 static void DiscardAllPrefetchState(); | 36 static void DiscardAllPrefetchState(); |
| 35 static void DnsMotivatedPrefetch(const std::string& hostname, | 37 static void DnsMotivatedPrefetch(const std::string& hostname, |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 if (!dns_master) | 473 if (!dns_master) |
| 472 return; | 474 return; |
| 473 dns_master->DiscardAllResults(); | 475 dns_master->DiscardAllResults(); |
| 474 } | 476 } |
| 475 | 477 |
| 476 //------------------------------------------------------------------------------ | 478 //------------------------------------------------------------------------------ |
| 477 | 479 |
| 478 net::HostResolver* GetGlobalHostResolver() { | 480 net::HostResolver* GetGlobalHostResolver() { |
| 479 // Called from UI thread. | 481 // Called from UI thread. |
| 480 if (!global_host_resolver) { | 482 if (!global_host_resolver) { |
| 483 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 484 |
| 485 // The FixedHostResolver allows us to send all network requests through |
| 486 // a designated test server. |
| 487 if (command_line.HasSwitch(switches::kFixedServer)) { |
| 488 std::string host_and_port = |
| 489 WideToASCII(command_line.GetSwitchValue(switches::kFixedServer)); |
| 490 global_host_resolver = new net::FixedHostResolver(host_and_port); |
| 491 return global_host_resolver; |
| 492 } |
| 493 |
| 481 global_host_resolver = net::CreateSystemHostResolver(); | 494 global_host_resolver = net::CreateSystemHostResolver(); |
| 482 | 495 |
| 483 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableIPv6)) { | 496 if (command_line.HasSwitch(switches::kDisableIPv6)) |
| 484 global_host_resolver->SetDefaultAddressFamily( | 497 global_host_resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4); |
| 485 net::ADDRESS_FAMILY_IPV4); | |
| 486 } | |
| 487 } | 498 } |
| 488 return global_host_resolver; | 499 return global_host_resolver; |
| 489 } | 500 } |
| 490 | 501 |
| 491 //------------------------------------------------------------------------------ | 502 //------------------------------------------------------------------------------ |
| 492 // Functions to handle saving of hostnames from one session to the next, to | 503 // Functions to handle saving of hostnames from one session to the next, to |
| 493 // expedite startup times. | 504 // expedite startup times. |
| 494 | 505 |
| 495 void SaveHostNamesForNextStartup(PrefService* local_state) { | 506 void SaveHostNamesForNextStartup(PrefService* local_state) { |
| 496 if (!dns_prefetch_enabled) | 507 if (!dns_prefetch_enabled) |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 } | 633 } |
| 623 } | 634 } |
| 624 | 635 |
| 625 DnsPrefetcherInit::~DnsPrefetcherInit() { | 636 DnsPrefetcherInit::~DnsPrefetcherInit() { |
| 626 if (dns_master) | 637 if (dns_master) |
| 627 FreeDnsPrefetchResources(); | 638 FreeDnsPrefetchResources(); |
| 628 } | 639 } |
| 629 | 640 |
| 630 } // namespace chrome_browser_net | 641 } // namespace chrome_browser_net |
| 631 | 642 |
| OLD | NEW |