| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/prefs/pref_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "base/profiler/scoped_profile.h" |
| 11 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 12 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 17 #include "net/base/load_flags.h" | 18 #include "net/base/load_flags.h" |
| 18 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
| 19 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 20 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 20 #include "net/url_request/url_fetcher.h" | 21 #include "net/url_request/url_fetcher.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 net::LOAD_DO_NOT_SAVE_COOKIES | | 88 net::LOAD_DO_NOT_SAVE_COOKIES | |
| 88 net::LOAD_DO_NOT_SEND_COOKIES); | 89 net::LOAD_DO_NOT_SEND_COOKIES); |
| 89 fetcher->SetRequestContext(g_browser_process->system_request_context()); | 90 fetcher->SetRequestContext(g_browser_process->system_request_context()); |
| 90 fetcher->Start(); | 91 fetcher->Start(); |
| 91 fetchers_.insert(fetcher); | 92 fetchers_.insert(fetcher); |
| 92 } | 93 } |
| 93 } | 94 } |
| 94 | 95 |
| 95 void IntranetRedirectDetector::OnURLFetchComplete( | 96 void IntranetRedirectDetector::OnURLFetchComplete( |
| 96 const net::URLFetcher* source) { | 97 const net::URLFetcher* source) { |
| 98 // TODO(vadimt): Remove ScopedProfile below once crbug.com/422577 is fixed. |
| 99 tracked_objects::ScopedProfile tracking_profile( |
| 100 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 101 "422577 IntranetRedirectDetector::OnURLFetchComplete")); |
| 102 |
| 97 // Delete the fetcher on this function's exit. | 103 // Delete the fetcher on this function's exit. |
| 98 Fetchers::iterator fetcher = fetchers_.find( | 104 Fetchers::iterator fetcher = fetchers_.find( |
| 99 const_cast<net::URLFetcher*>(source)); | 105 const_cast<net::URLFetcher*>(source)); |
| 100 DCHECK(fetcher != fetchers_.end()); | 106 DCHECK(fetcher != fetchers_.end()); |
| 101 scoped_ptr<net::URLFetcher> clean_up_fetcher(*fetcher); | 107 scoped_ptr<net::URLFetcher> clean_up_fetcher(*fetcher); |
| 102 fetchers_.erase(fetcher); | 108 fetchers_.erase(fetcher); |
| 103 | 109 |
| 104 // If any two fetches result in the same domain/host, we set the redirect | 110 // If any two fetches result in the same domain/host, we set the redirect |
| 105 // origin to that; otherwise we set it to nothing. | 111 // origin to that; otherwise we set it to nothing. |
| 106 if (!source->GetStatus().is_success() || (source->GetResponseCode() != 200)) { | 112 if (!source->GetStatus().is_success() || (source->GetResponseCode() != 200)) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 161 |
| 156 // Since presumably many programs open connections after network changes, | 162 // Since presumably many programs open connections after network changes, |
| 157 // delay this a little bit. | 163 // delay this a little bit. |
| 158 in_sleep_ = true; | 164 in_sleep_ = true; |
| 159 static const int kNetworkSwitchDelayMS = 1000; | 165 static const int kNetworkSwitchDelayMS = 1000; |
| 160 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, | 166 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 161 base::Bind(&IntranetRedirectDetector::FinishSleep, | 167 base::Bind(&IntranetRedirectDetector::FinishSleep, |
| 162 weak_ptr_factory_.GetWeakPtr()), | 168 weak_ptr_factory_.GetWeakPtr()), |
| 163 base::TimeDelta::FromMilliseconds(kNetworkSwitchDelayMS)); | 169 base::TimeDelta::FromMilliseconds(kNetworkSwitchDelayMS)); |
| 164 } | 170 } |
| OLD | NEW |