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/net/predictor.h" | 5 #include "chrome/browser/net/predictor.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <set> | 9 #include <set> |
10 #include <sstream> | 10 #include <sstream> |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 // Perform at least DNS pre-resolution. | 268 // Perform at least DNS pre-resolution. |
269 BrowserThread::PostTask( | 269 BrowserThread::PostTask( |
270 BrowserThread::IO, | 270 BrowserThread::IO, |
271 FROM_HERE, | 271 FROM_HERE, |
272 base::Bind(&Predictor::Resolve, base::Unretained(this), | 272 base::Bind(&Predictor::Resolve, base::Unretained(this), |
273 CanonicalizeUrl(url), motivation)); | 273 CanonicalizeUrl(url), motivation)); |
274 } | 274 } |
275 | 275 |
276 void Predictor::PreconnectUrlAndSubresources(const GURL& url, | 276 void Predictor::PreconnectUrlAndSubresources(const GURL& url, |
277 const GURL& first_party_for_cookies) { | 277 const GURL& first_party_for_cookies) { |
278 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 278 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
279 if (!predictor_enabled_) | 279 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 280 if (!predictor_enabled_ || !preconnect_enabled() || |
| 281 !url.is_valid() || !url.has_host()) |
280 return; | 282 return; |
281 if (!url.is_valid() || !url.has_host()) | 283 |
282 return; | 284 std::string host = url.HostNoBrackets(); |
283 if (preconnect_enabled()) { | 285 UrlInfo::ResolutionMotivation motivation(UrlInfo::EARLY_LOAD_MOTIVATED); |
284 std::string host = url.HostNoBrackets(); | 286 const int kConnectionsNeeded = 1; |
285 UrlInfo::ResolutionMotivation motivation(UrlInfo::EARLY_LOAD_MOTIVATED); | 287 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
286 const int kConnectionsNeeded = 1; | |
287 PreconnectOnUIThread(CanonicalizeUrl(url), first_party_for_cookies, | 288 PreconnectOnUIThread(CanonicalizeUrl(url), first_party_for_cookies, |
288 motivation, kConnectionsNeeded, | 289 motivation, kConnectionsNeeded, |
289 url_request_context_getter_); | 290 url_request_context_getter_); |
290 PredictFrameSubresources(url.GetWithEmptyPath(), first_party_for_cookies); | 291 } else { |
| 292 PreconnectOnIOThread(CanonicalizeUrl(url), first_party_for_cookies, |
| 293 motivation, kConnectionsNeeded, |
| 294 url_request_context_getter_); |
291 } | 295 } |
| 296 PredictFrameSubresources(url.GetWithEmptyPath(), first_party_for_cookies); |
292 } | 297 } |
293 | 298 |
294 UrlList Predictor::GetPredictedUrlListAtStartup( | 299 UrlList Predictor::GetPredictedUrlListAtStartup( |
295 PrefService* user_prefs, | 300 PrefService* user_prefs, |
296 PrefService* local_state) { | 301 PrefService* local_state) { |
297 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
298 UrlList urls; | 303 UrlList urls; |
299 // Recall list of URLs we learned about during last session. | 304 // Recall list of URLs we learned about during last session. |
300 // This may catch secondary hostnames, pulled in by the homepages. It will | 305 // This may catch secondary hostnames, pulled in by the homepages. It will |
301 // also catch more of the "primary" home pages, since that was (presumably) | 306 // also catch more of the "primary" home pages, since that was (presumably) |
(...skipping 888 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1190 IOThread* io_thread, | 1195 IOThread* io_thread, |
1191 net::URLRequestContextGetter* getter) { | 1196 net::URLRequestContextGetter* getter) { |
1192 // Empty function for unittests. | 1197 // Empty function for unittests. |
1193 } | 1198 } |
1194 | 1199 |
1195 void SimplePredictor::ShutdownOnUIThread(PrefService* user_prefs) { | 1200 void SimplePredictor::ShutdownOnUIThread(PrefService* user_prefs) { |
1196 SetShutdown(true); | 1201 SetShutdown(true); |
1197 } | 1202 } |
1198 | 1203 |
1199 } // namespace chrome_browser_net | 1204 } // namespace chrome_browser_net |
OLD | NEW |