Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/intranet_redirect_detector.h" | 5 #include "chrome/browser/intranet_redirect_detector.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | |
| 7 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
| 8 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
| 9 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
| 12 #include "chrome/browser/profile.h" | 13 #include "chrome/browser/profile.h" |
| 14 #include "chrome/common/chrome_switches.h" | |
| 13 #include "chrome/common/notification_service.h" | 15 #include "chrome/common/notification_service.h" |
| 14 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 15 #include "net/base/load_flags.h" | 17 #include "net/base/load_flags.h" |
| 16 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
| 17 #include "net/base/registry_controlled_domain.h" | 19 #include "net/base/registry_controlled_domain.h" |
| 18 #include "net/url_request/url_request_status.h" | 20 #include "net/url_request/url_request_status.h" |
| 19 | 21 |
| 20 const size_t IntranetRedirectDetector::kNumCharsInHostnames = 10; | 22 const size_t IntranetRedirectDetector::kNumCharsInHostnames = 10; |
| 21 | 23 |
| 22 IntranetRedirectDetector::IntranetRedirectDetector() | 24 IntranetRedirectDetector::IntranetRedirectDetector() |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 StartFetchesIfPossible(); | 73 StartFetchesIfPossible(); |
| 72 } | 74 } |
| 73 | 75 |
| 74 void IntranetRedirectDetector::StartFetchesIfPossible() { | 76 void IntranetRedirectDetector::StartFetchesIfPossible() { |
| 75 // Bail if a fetch isn't appropriate right now. This function will be called | 77 // Bail if a fetch isn't appropriate right now. This function will be called |
| 76 // again each time one of the preconditions changes, so we'll fetch | 78 // again each time one of the preconditions changes, so we'll fetch |
| 77 // immediately once all of them are met. | 79 // immediately once all of them are met. |
| 78 if (in_sleep_ || !request_context_available_) | 80 if (in_sleep_ || !request_context_available_) |
| 79 return; | 81 return; |
| 80 | 82 |
| 83 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
|
Peter Kasting
2010/09/08 19:38:45
Nit: I'd put this at the end of the above conditio
| |
| 84 switches::kDisableBackgroundNetworking)) | |
| 85 return; | |
| 86 | |
| 81 DCHECK(fetchers_.empty() && resulting_origins_.empty()); | 87 DCHECK(fetchers_.empty() && resulting_origins_.empty()); |
| 82 | 88 |
| 83 // Start three fetchers on random hostnames. | 89 // Start three fetchers on random hostnames. |
| 84 for (size_t i = 0; i < 3; ++i) { | 90 for (size_t i = 0; i < 3; ++i) { |
| 85 std::string url_string("http://"); | 91 std::string url_string("http://"); |
| 86 for (size_t j = 0; j < kNumCharsInHostnames; ++j) | 92 for (size_t j = 0; j < kNumCharsInHostnames; ++j) |
| 87 url_string += ('a' + base::RandInt(0, 'z' - 'a')); | 93 url_string += ('a' + base::RandInt(0, 'z' - 'a')); |
| 88 GURL random_url(url_string + '/'); | 94 GURL random_url(url_string + '/'); |
| 89 URLFetcher* fetcher = new URLFetcher(random_url, URLFetcher::HEAD, this); | 95 URLFetcher* fetcher = new URLFetcher(random_url, URLFetcher::HEAD, this); |
| 90 // We don't want these fetches to affect existing state in the profile. | 96 // We don't want these fetches to affect existing state in the profile. |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 // the same thread. So just use the heuristic that any all-lowercase a-z | 194 // the same thread. So just use the heuristic that any all-lowercase a-z |
| 189 // hostname with the right number of characters is likely from the detector | 195 // hostname with the right number of characters is likely from the detector |
| 190 // (and thus should be blocked). | 196 // (and thus should be blocked). |
| 191 return ((host.length() == IntranetRedirectDetector::kNumCharsInHostnames) && | 197 return ((host.length() == IntranetRedirectDetector::kNumCharsInHostnames) && |
| 192 (host.find_first_not_of("abcdefghijklmnopqrstuvwxyz") == | 198 (host.find_first_not_of("abcdefghijklmnopqrstuvwxyz") == |
| 193 std::string::npos)) ? | 199 std::string::npos)) ? |
| 194 net::ERR_NAME_NOT_RESOLVED : | 200 net::ERR_NAME_NOT_RESOLVED : |
| 195 ResolveUsingPrevious(host, address_family, host_resolver_flags, addrlist, | 201 ResolveUsingPrevious(host, address_family, host_resolver_flags, addrlist, |
| 196 os_error); | 202 os_error); |
| 197 } | 203 } |
| OLD | NEW |