| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/command_line.h" |
| 8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 DCHECK(fetchers_.empty() && resulting_origins_.empty()); | 75 DCHECK(fetchers_.empty() && resulting_origins_.empty()); |
| 76 | 76 |
| 77 // Start three fetchers on random hostnames. | 77 // Start three fetchers on random hostnames. |
| 78 for (size_t i = 0; i < 3; ++i) { | 78 for (size_t i = 0; i < 3; ++i) { |
| 79 std::string url_string("http://"); | 79 std::string url_string("http://"); |
| 80 for (size_t j = 0; j < kNumCharsInHostnames; ++j) | 80 for (size_t j = 0; j < kNumCharsInHostnames; ++j) |
| 81 url_string += ('a' + base::RandInt(0, 'z' - 'a')); | 81 url_string += ('a' + base::RandInt(0, 'z' - 'a')); |
| 82 GURL random_url(url_string + '/'); | 82 GURL random_url(url_string + '/'); |
| 83 URLFetcher* fetcher = new URLFetcher(random_url, URLFetcher::HEAD, this); | 83 URLFetcher* fetcher = new URLFetcher(random_url, URLFetcher::HEAD, this); |
| 84 // We don't want these fetches to affect existing state in the profile. | 84 // We don't want these fetches to affect existing state in the profile. |
| 85 fetcher->set_load_flags(net::LOAD_DISABLE_CACHE | | 85 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE | |
| 86 net::LOAD_DO_NOT_SAVE_COOKIES); | 86 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 87 fetcher->set_request_context(g_browser_process->system_request_context()); | 87 fetcher->SetRequestContext(g_browser_process->system_request_context()); |
| 88 fetcher->Start(); | 88 fetcher->Start(); |
| 89 fetchers_.insert(fetcher); | 89 fetchers_.insert(fetcher); |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 | 92 |
| 93 void IntranetRedirectDetector::OnURLFetchComplete(const URLFetcher* source) { | 93 void IntranetRedirectDetector::OnURLFetchComplete( |
| 94 const content::URLFetcher* source) { |
| 94 // Delete the fetcher on this function's exit. | 95 // Delete the fetcher on this function's exit. |
| 95 Fetchers::iterator fetcher = fetchers_.find(const_cast<URLFetcher*>(source)); | 96 Fetchers::iterator fetcher = fetchers_.find( |
| 97 const_cast<content::URLFetcher*>(source)); |
| 96 DCHECK(fetcher != fetchers_.end()); | 98 DCHECK(fetcher != fetchers_.end()); |
| 97 scoped_ptr<URLFetcher> clean_up_fetcher(*fetcher); | 99 scoped_ptr<content::URLFetcher> clean_up_fetcher(*fetcher); |
| 98 fetchers_.erase(fetcher); | 100 fetchers_.erase(fetcher); |
| 99 | 101 |
| 100 // If any two fetches result in the same domain/host, we set the redirect | 102 // If any two fetches result in the same domain/host, we set the redirect |
| 101 // origin to that; otherwise we set it to nothing. | 103 // origin to that; otherwise we set it to nothing. |
| 102 if (!source->status().is_success() || (source->response_code() != 200)) { | 104 if (!source->GetStatus().is_success() || (source->GetResponseCode() != 200)) { |
| 103 if ((resulting_origins_.empty()) || | 105 if ((resulting_origins_.empty()) || |
| 104 ((resulting_origins_.size() == 1) && | 106 ((resulting_origins_.size() == 1) && |
| 105 resulting_origins_.front().is_valid())) { | 107 resulting_origins_.front().is_valid())) { |
| 106 resulting_origins_.push_back(GURL()); | 108 resulting_origins_.push_back(GURL()); |
| 107 return; | 109 return; |
| 108 } | 110 } |
| 109 redirect_origin_ = GURL(); | 111 redirect_origin_ = GURL(); |
| 110 } else { | 112 } else { |
| 111 DCHECK(source->url().is_valid()); | 113 DCHECK(source->GetUrl().is_valid()); |
| 112 GURL origin(source->url().GetOrigin()); | 114 GURL origin(source->GetUrl().GetOrigin()); |
| 113 if (resulting_origins_.empty()) { | 115 if (resulting_origins_.empty()) { |
| 114 resulting_origins_.push_back(origin); | 116 resulting_origins_.push_back(origin); |
| 115 return; | 117 return; |
| 116 } | 118 } |
| 117 if (net::RegistryControlledDomainService::SameDomainOrHost( | 119 if (net::RegistryControlledDomainService::SameDomainOrHost( |
| 118 resulting_origins_.front(), origin)) { | 120 resulting_origins_.front(), origin)) { |
| 119 redirect_origin_ = origin; | 121 redirect_origin_ = origin; |
| 120 if (!fetchers_.empty()) { | 122 if (!fetchers_.empty()) { |
| 121 // Cancel remaining fetch, we don't need it. | 123 // Cancel remaining fetch, we don't need it. |
| 122 DCHECK(fetchers_.size() == 1); | 124 DCHECK(fetchers_.size() == 1); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 // the same thread. So just use the heuristic that any all-lowercase a-z | 170 // the same thread. So just use the heuristic that any all-lowercase a-z |
| 169 // hostname with the right number of characters is likely from the detector | 171 // hostname with the right number of characters is likely from the detector |
| 170 // (and thus should be blocked). | 172 // (and thus should be blocked). |
| 171 return ((host.length() == IntranetRedirectDetector::kNumCharsInHostnames) && | 173 return ((host.length() == IntranetRedirectDetector::kNumCharsInHostnames) && |
| 172 (host.find_first_not_of("abcdefghijklmnopqrstuvwxyz") == | 174 (host.find_first_not_of("abcdefghijklmnopqrstuvwxyz") == |
| 173 std::string::npos)) ? | 175 std::string::npos)) ? |
| 174 net::ERR_NAME_NOT_RESOLVED : | 176 net::ERR_NAME_NOT_RESOLVED : |
| 175 ResolveUsingPrevious(host, address_family, host_resolver_flags, addrlist, | 177 ResolveUsingPrevious(host, address_family, host_resolver_flags, addrlist, |
| 176 os_error); | 178 os_error); |
| 177 } | 179 } |
| OLD | NEW |