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 6292017: Extended: Add "system" URLRequestContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Continued Created 9 years, 10 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) 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-inl.h" 9 #include "base/stl_util-inl.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/prefs/pref_service.h" 12 #include "chrome/browser/prefs/pref_service.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/common/chrome_switches.h" 14 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/notification_service.h" 15 #include "chrome/common/notification_service.h"
16 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
17 #include "net/base/load_flags.h" 17 #include "net/base/load_flags.h"
18 #include "net/base/net_errors.h" 18 #include "net/base/net_errors.h"
19 #include "net/base/registry_controlled_domain.h" 19 #include "net/base/registry_controlled_domain.h"
20 #include "net/url_request/url_request_status.h" 20 #include "net/url_request/url_request_status.h"
21 21
22 const size_t IntranetRedirectDetector::kNumCharsInHostnames = 10; 22 const size_t IntranetRedirectDetector::kNumCharsInHostnames = 10;
23 23
24 IntranetRedirectDetector::IntranetRedirectDetector() 24 IntranetRedirectDetector::IntranetRedirectDetector()
25 : redirect_origin_(g_browser_process->local_state()->GetString( 25 : redirect_origin_(g_browser_process->local_state()->GetString(
26 prefs::kLastKnownIntranetRedirectOrigin)), 26 prefs::kLastKnownIntranetRedirectOrigin)),
27 ALLOW_THIS_IN_INITIALIZER_LIST(fetcher_factory_(this)), 27 ALLOW_THIS_IN_INITIALIZER_LIST(fetcher_factory_(this)),
28 in_sleep_(true), 28 in_sleep_(true),
29 request_context_available_(Profile::GetDefaultRequestContext() != NULL) { 29 request_context_available_(
30 g_browser_process->system_request_context() != NULL) {
30 registrar_.Add(this, NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, 31 registrar_.Add(this, NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
31 NotificationService::AllSources()); 32 NotificationService::AllSources());
32 33
33 // Because this function can be called during startup, when kicking off a URL 34 // Because this function can be called during startup, when kicking off a URL
34 // fetch can eat up 20 ms of time, we delay seven seconds, which is hopefully 35 // fetch can eat up 20 ms of time, we delay seven seconds, which is hopefully
35 // long enough to be after startup, but still get results back quickly. 36 // long enough to be after startup, but still get results back quickly.
36 // Ideally, instead of this timer, we'd do something like "check if the 37 // Ideally, instead of this timer, we'd do something like "check if the
37 // browser is starting up, and if so, come back later", but there is currently 38 // browser is starting up, and if so, come back later", but there is currently
38 // no function to do this. 39 // no function to do this.
39 static const int kStartFetchDelayMS = 7000; 40 static const int kStartFetchDelayMS = 7000;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 // Start three fetchers on random hostnames. 92 // Start three fetchers on random hostnames.
92 for (size_t i = 0; i < 3; ++i) { 93 for (size_t i = 0; i < 3; ++i) {
93 std::string url_string("http://"); 94 std::string url_string("http://");
94 for (size_t j = 0; j < kNumCharsInHostnames; ++j) 95 for (size_t j = 0; j < kNumCharsInHostnames; ++j)
95 url_string += ('a' + base::RandInt(0, 'z' - 'a')); 96 url_string += ('a' + base::RandInt(0, 'z' - 'a'));
96 GURL random_url(url_string + '/'); 97 GURL random_url(url_string + '/');
97 URLFetcher* fetcher = new URLFetcher(random_url, URLFetcher::HEAD, this); 98 URLFetcher* fetcher = new URLFetcher(random_url, URLFetcher::HEAD, this);
98 // We don't want these fetches to affect existing state in the profile. 99 // We don't want these fetches to affect existing state in the profile.
99 fetcher->set_load_flags(net::LOAD_DISABLE_CACHE | 100 fetcher->set_load_flags(net::LOAD_DISABLE_CACHE |
100 net::LOAD_DO_NOT_SAVE_COOKIES); 101 net::LOAD_DO_NOT_SAVE_COOKIES);
101 fetcher->set_request_context(Profile::GetDefaultRequestContext()); 102 fetcher->set_request_context(g_browser_process->system_request_context());
102 fetcher->Start(); 103 fetcher->Start();
103 fetchers_.insert(fetcher); 104 fetchers_.insert(fetcher);
104 } 105 }
105 } 106 }
106 107
107 void IntranetRedirectDetector::OnURLFetchComplete( 108 void IntranetRedirectDetector::OnURLFetchComplete(
108 const URLFetcher* source, 109 const URLFetcher* source,
109 const GURL& url, 110 const GURL& url,
110 const net::URLRequestStatus& status, 111 const net::URLRequestStatus& status,
111 int response_code, 112 int response_code,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 // the same thread. So just use the heuristic that any all-lowercase a-z 197 // the same thread. So just use the heuristic that any all-lowercase a-z
197 // hostname with the right number of characters is likely from the detector 198 // hostname with the right number of characters is likely from the detector
198 // (and thus should be blocked). 199 // (and thus should be blocked).
199 return ((host.length() == IntranetRedirectDetector::kNumCharsInHostnames) && 200 return ((host.length() == IntranetRedirectDetector::kNumCharsInHostnames) &&
200 (host.find_first_not_of("abcdefghijklmnopqrstuvwxyz") == 201 (host.find_first_not_of("abcdefghijklmnopqrstuvwxyz") ==
201 std::string::npos)) ? 202 std::string::npos)) ?
202 net::ERR_NAME_NOT_RESOLVED : 203 net::ERR_NAME_NOT_RESOLVED :
203 ResolveUsingPrevious(host, address_family, host_resolver_flags, addrlist, 204 ResolveUsingPrevious(host, address_family, host_resolver_flags, addrlist,
204 os_error); 205 os_error);
205 } 206 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698