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