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

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

Issue 11620007: Switch from OnIPAddressChanged and OnConnectionTypeChange to OnNetworkChanged Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
OLDNEW
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/rand_util.h" 9 #include "base/rand_util.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 21 matching lines...) Expand all
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 kStartFetchDelaySeconds = 7; 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 base::TimeDelta::FromSeconds(kStartFetchDelaySeconds)); 40 base::TimeDelta::FromSeconds(kStartFetchDelaySeconds));
41 41
42 net::NetworkChangeNotifier::AddIPAddressObserver(this); 42 net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
43 } 43 }
44 44
45 IntranetRedirectDetector::~IntranetRedirectDetector() { 45 IntranetRedirectDetector::~IntranetRedirectDetector() {
46 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); 46 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
47 STLDeleteElements(&fetchers_); 47 STLDeleteElements(&fetchers_);
48 } 48 }
49 49
50 // static 50 // static
51 GURL IntranetRedirectDetector::RedirectOrigin() { 51 GURL IntranetRedirectDetector::RedirectOrigin() {
52 const IntranetRedirectDetector* const detector = 52 const IntranetRedirectDetector* const detector =
53 g_browser_process->intranet_redirect_detector(); 53 g_browser_process->intranet_redirect_detector();
54 return detector ? detector->redirect_origin_ : GURL(); 54 return detector ? detector->redirect_origin_ : GURL();
55 } 55 }
56 56
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 DCHECK(resulting_origins_.size() == 2); 136 DCHECK(resulting_origins_.size() == 2);
137 redirect_origin_ = net::RegistryControlledDomainService::SameDomainOrHost( 137 redirect_origin_ = net::RegistryControlledDomainService::SameDomainOrHost(
138 resulting_origins_.back(), origin) ? origin : GURL(); 138 resulting_origins_.back(), origin) ? origin : GURL();
139 } 139 }
140 140
141 g_browser_process->local_state()->SetString( 141 g_browser_process->local_state()->SetString(
142 prefs::kLastKnownIntranetRedirectOrigin, redirect_origin_.is_valid() ? 142 prefs::kLastKnownIntranetRedirectOrigin, redirect_origin_.is_valid() ?
143 redirect_origin_.spec() : std::string()); 143 redirect_origin_.spec() : std::string());
144 } 144 }
145 145
146 void IntranetRedirectDetector::OnIPAddressChanged() { 146 void IntranetRedirectDetector::OnNetworkChanged(
147 net::NetworkChangeNotifier::ConnectionType type) {
148 // Wait until network is up.
149 if (type == net::NetworkChangeNotifier::CONNECTION_NONE)
150 return;
147 // If a request is already scheduled, do not scheduled yet another one. 151 // If a request is already scheduled, do not scheduled yet another one.
148 if (in_sleep_) 152 if (in_sleep_)
149 return; 153 return;
150 154
151 // Since presumably many programs open connections after network changes, 155 // Since presumably many programs open connections after network changes,
152 // delay this a little bit. 156 // delay this a little bit.
153 in_sleep_ = true; 157 in_sleep_ = true;
154 static const int kNetworkSwitchDelayMS = 1000; 158 static const int kNetworkSwitchDelayMS = 1000;
155 MessageLoop::current()->PostDelayedTask(FROM_HERE, 159 MessageLoop::current()->PostDelayedTask(FROM_HERE,
156 base::Bind(&IntranetRedirectDetector::FinishSleep, 160 base::Bind(&IntranetRedirectDetector::FinishSleep,
(...skipping 16 matching lines...) Expand all
173 // the same thread. So just use the heuristic that any all-lowercase a-z 177 // the same thread. So just use the heuristic that any all-lowercase a-z
174 // hostname with the right number of characters is likely from the detector 178 // hostname with the right number of characters is likely from the detector
175 // (and thus should be blocked). 179 // (and thus should be blocked).
176 return ((host.length() == IntranetRedirectDetector::kNumCharsInHostnames) && 180 return ((host.length() == IntranetRedirectDetector::kNumCharsInHostnames) &&
177 (host.find_first_not_of("abcdefghijklmnopqrstuvwxyz") == 181 (host.find_first_not_of("abcdefghijklmnopqrstuvwxyz") ==
178 std::string::npos)) ? 182 std::string::npos)) ?
179 net::ERR_NAME_NOT_RESOLVED : 183 net::ERR_NAME_NOT_RESOLVED :
180 ResolveUsingPrevious(host, address_family, host_resolver_flags, addrlist, 184 ResolveUsingPrevious(host, address_family, host_resolver_flags, addrlist,
181 os_error); 185 os_error);
182 } 186 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698