Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(787)

Side by Side Diff: chrome/browser/intranet_redirect_detector.cc

Issue 9185026: Convert use of int ms to TimeDelta in files owned by brettw. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Explicitly include base/time.h in header file. Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/images_uitest.cc ('k') | chrome/browser/media_uitest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/rand_util.h" 9 #include "base/rand_util.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 15 matching lines...) Expand all
26 : redirect_origin_(g_browser_process->local_state()->GetString( 26 : redirect_origin_(g_browser_process->local_state()->GetString(
27 prefs::kLastKnownIntranetRedirectOrigin)), 27 prefs::kLastKnownIntranetRedirectOrigin)),
28 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), 28 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
29 in_sleep_(true) { 29 in_sleep_(true) {
30 // Because this function can be called during startup, when kicking off a URL 30 // Because this function can be called during startup, when kicking off a URL
31 // fetch can eat up 20 ms of time, we delay seven seconds, which is hopefully 31 // fetch can eat up 20 ms of time, we delay seven seconds, which is hopefully
32 // long enough to be after startup, but still get results back quickly. 32 // long enough to be after startup, but still get results back quickly.
33 // Ideally, instead of this timer, we'd do something like "check if the 33 // Ideally, instead of this timer, we'd do something like "check if the
34 // browser is starting up, and if so, come back later", but there is currently 34 // browser is starting up, and if so, come back later", but there is currently
35 // no function to do this. 35 // no function to do this.
36 static const int kStartFetchDelayMS = 7000; 36 static const int kStartFetchDelaySeconds = 7;
37 MessageLoop::current()->PostDelayedTask(FROM_HERE, 37 MessageLoop::current()->PostDelayedTask(FROM_HERE,
38 base::Bind(&IntranetRedirectDetector::FinishSleep, 38 base::Bind(&IntranetRedirectDetector::FinishSleep,
39 weak_factory_.GetWeakPtr()), 39 weak_factory_.GetWeakPtr()),
40 kStartFetchDelayMS); 40 base::TimeDelta::FromSeconds(kStartFetchDelaySeconds));
41 41
42 net::NetworkChangeNotifier::AddIPAddressObserver(this); 42 net::NetworkChangeNotifier::AddIPAddressObserver(this);
43 } 43 }
44 44
45 IntranetRedirectDetector::~IntranetRedirectDetector() { 45 IntranetRedirectDetector::~IntranetRedirectDetector() {
46 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); 46 net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
47 STLDeleteElements(&fetchers_); 47 STLDeleteElements(&fetchers_);
48 } 48 }
49 49
50 // static 50 // static
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 if (in_sleep_) 147 if (in_sleep_)
148 return; 148 return;
149 149
150 // Since presumably many programs open connections after network changes, 150 // Since presumably many programs open connections after network changes,
151 // delay this a little bit. 151 // delay this a little bit.
152 in_sleep_ = true; 152 in_sleep_ = true;
153 static const int kNetworkSwitchDelayMS = 1000; 153 static const int kNetworkSwitchDelayMS = 1000;
154 MessageLoop::current()->PostDelayedTask(FROM_HERE, 154 MessageLoop::current()->PostDelayedTask(FROM_HERE,
155 base::Bind(&IntranetRedirectDetector::FinishSleep, 155 base::Bind(&IntranetRedirectDetector::FinishSleep,
156 weak_factory_.GetWeakPtr()), 156 weak_factory_.GetWeakPtr()),
157 kNetworkSwitchDelayMS); 157 base::TimeDelta::FromMilliseconds(kNetworkSwitchDelayMS));
158 } 158 }
159 159
160 IntranetRedirectHostResolverProc::IntranetRedirectHostResolverProc( 160 IntranetRedirectHostResolverProc::IntranetRedirectHostResolverProc(
161 net::HostResolverProc* previous) 161 net::HostResolverProc* previous)
162 : net::HostResolverProc(previous) { 162 : net::HostResolverProc(previous) {
163 } 163 }
164 164
165 int IntranetRedirectHostResolverProc::Resolve( 165 int IntranetRedirectHostResolverProc::Resolve(
166 const std::string& host, 166 const std::string& host,
167 net::AddressFamily address_family, 167 net::AddressFamily address_family,
168 net::HostResolverFlags host_resolver_flags, 168 net::HostResolverFlags host_resolver_flags,
169 net::AddressList* addrlist, 169 net::AddressList* addrlist,
170 int* os_error) { 170 int* os_error) {
171 // We'd love to just ask the IntranetRedirectDetector, but we may not be on 171 // We'd love to just ask the IntranetRedirectDetector, but we may not be on
172 // the same thread. So just use the heuristic that any all-lowercase a-z 172 // the same thread. So just use the heuristic that any all-lowercase a-z
173 // hostname with the right number of characters is likely from the detector 173 // hostname with the right number of characters is likely from the detector
174 // (and thus should be blocked). 174 // (and thus should be blocked).
175 return ((host.length() == IntranetRedirectDetector::kNumCharsInHostnames) && 175 return ((host.length() == IntranetRedirectDetector::kNumCharsInHostnames) &&
176 (host.find_first_not_of("abcdefghijklmnopqrstuvwxyz") == 176 (host.find_first_not_of("abcdefghijklmnopqrstuvwxyz") ==
177 std::string::npos)) ? 177 std::string::npos)) ?
178 net::ERR_NAME_NOT_RESOLVED : 178 net::ERR_NAME_NOT_RESOLVED :
179 ResolveUsingPrevious(host, address_family, host_resolver_flags, addrlist, 179 ResolveUsingPrevious(host, address_family, host_resolver_flags, addrlist,
180 os_error); 180 os_error);
181 } 181 }
OLDNEW
« no previous file with comments | « chrome/browser/images_uitest.cc ('k') | chrome/browser/media_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698