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

Side by Side Diff: chrome/browser/net/predictor.cc

Issue 14749005: Implement WebPrescientNetworking to trigger preconnect from Blink (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove UrlInfo decl Created 7 years, 7 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
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/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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 267
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 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 277 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
278 if (!predictor_enabled_) 278 BrowserThread::CurrentlyOn(BrowserThread::IO));
279 if (!predictor_enabled_ || !preconnect_enabled() ||
280 !url.is_valid() || !url.has_host())
279 return; 281 return;
280 if (!url.is_valid() || !url.has_host()) 282
281 return; 283 std::string host = url.HostNoBrackets();
282 if (preconnect_enabled()) { 284 UrlInfo::ResolutionMotivation motivation(UrlInfo::EARLY_LOAD_MOTIVATED);
283 std::string host = url.HostNoBrackets(); 285 const int kConnectionsNeeded = 1;
284 UrlInfo::ResolutionMotivation motivation(UrlInfo::EARLY_LOAD_MOTIVATED); 286 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
285 const int kConnectionsNeeded = 1;
286 PreconnectOnUIThread(CanonicalizeUrl(url), motivation, 287 PreconnectOnUIThread(CanonicalizeUrl(url), motivation,
287 kConnectionsNeeded, 288 kConnectionsNeeded,
288 url_request_context_getter_); 289 url_request_context_getter_);
289 PredictFrameSubresources(url.GetWithEmptyPath()); 290 } else {
291 PreconnectOnIOThread(CanonicalizeUrl(url), motivation,
292 kConnectionsNeeded,
293 url_request_context_getter_);
290 } 294 }
295 PredictFrameSubresources(url.GetWithEmptyPath());
291 } 296 }
292 297
293 UrlList Predictor::GetPredictedUrlListAtStartup( 298 UrlList Predictor::GetPredictedUrlListAtStartup(
294 PrefService* user_prefs, 299 PrefService* user_prefs,
295 PrefService* local_state) { 300 PrefService* local_state) {
296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
297 UrlList urls; 302 UrlList urls;
298 // Recall list of URLs we learned about during last session. 303 // Recall list of URLs we learned about during last session.
299 // This may catch secondary hostnames, pulled in by the homepages. It will 304 // This may catch secondary hostnames, pulled in by the homepages. It will
300 // also catch more of the "primary" home pages, since that was (presumably) 305 // also catch more of the "primary" home pages, since that was (presumably)
(...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 IOThread* io_thread, 1191 IOThread* io_thread,
1187 net::URLRequestContextGetter* getter) { 1192 net::URLRequestContextGetter* getter) {
1188 // Empty function for unittests. 1193 // Empty function for unittests.
1189 } 1194 }
1190 1195
1191 void SimplePredictor::ShutdownOnUIThread(PrefService* user_prefs) { 1196 void SimplePredictor::ShutdownOnUIThread(PrefService* user_prefs) {
1192 SetShutdown(true); 1197 SetShutdown(true);
1193 } 1198 }
1194 1199
1195 } // namespace chrome_browser_net 1200 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698