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

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

Issue 1117613003: [chrome/browser/net] favor DCHECK_CURRENTLY_ON for better logs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« no previous file with comments | « chrome/browser/net/prediction_options.cc ('k') | chrome/browser/net/predictor_browsertest.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) 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 TimeDelta::FromMilliseconds(g_max_queueing_delay_ms)), 149 TimeDelta::FromMilliseconds(g_max_queueing_delay_ms)),
150 host_resolver_(NULL), 150 host_resolver_(NULL),
151 transport_security_state_(NULL), 151 transport_security_state_(NULL),
152 ssl_config_service_(NULL), 152 ssl_config_service_(NULL),
153 proxy_service_(NULL), 153 proxy_service_(NULL),
154 preconnect_enabled_(preconnect_enabled), 154 preconnect_enabled_(preconnect_enabled),
155 consecutive_omnibox_preconnect_count_(0), 155 consecutive_omnibox_preconnect_count_(0),
156 next_trim_time_(base::TimeTicks::Now() + 156 next_trim_time_(base::TimeTicks::Now() +
157 TimeDelta::FromHours(kDurationBetweenTrimmingsHours)), 157 TimeDelta::FromHours(kDurationBetweenTrimmingsHours)),
158 observer_(NULL) { 158 observer_(NULL) {
159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 159 DCHECK_CURRENTLY_ON(BrowserThread::UI);
160 } 160 }
161 161
162 Predictor::~Predictor() { 162 Predictor::~Predictor() {
163 // TODO(rlp): Add DCHECK for CurrentlyOn(BrowserThread::IO) when the 163 // TODO(rlp): Add DCHECK for CurrentlyOn(BrowserThread::IO) when the
164 // ProfileManagerTest has been updated with a mock profile. 164 // ProfileManagerTest has been updated with a mock profile.
165 DCHECK(shutdown_); 165 DCHECK(shutdown_);
166 } 166 }
167 167
168 // static 168 // static
169 Predictor* Predictor::CreatePredictor(bool preconnect_enabled, 169 Predictor* Predictor::CreatePredictor(bool preconnect_enabled,
(...skipping 10 matching lines...) Expand all
180 registry->RegisterListPref(prefs::kDnsPrefetchingHostReferralList); 180 registry->RegisterListPref(prefs::kDnsPrefetchingHostReferralList);
181 } 181 }
182 182
183 // --------------------- Start UI methods. ------------------------------------ 183 // --------------------- Start UI methods. ------------------------------------
184 184
185 void Predictor::InitNetworkPredictor(PrefService* user_prefs, 185 void Predictor::InitNetworkPredictor(PrefService* user_prefs,
186 PrefService* local_state, 186 PrefService* local_state,
187 IOThread* io_thread, 187 IOThread* io_thread,
188 net::URLRequestContextGetter* getter, 188 net::URLRequestContextGetter* getter,
189 ProfileIOData* profile_io_data) { 189 ProfileIOData* profile_io_data) {
190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 190 DCHECK_CURRENTLY_ON(BrowserThread::UI);
191 191
192 user_prefs_ = user_prefs; 192 user_prefs_ = user_prefs;
193 url_request_context_getter_ = getter; 193 url_request_context_getter_ = getter;
194 194
195 // Gather the list of hostnames to prefetch on startup. 195 // Gather the list of hostnames to prefetch on startup.
196 UrlList urls = GetPredictedUrlListAtStartup(user_prefs, local_state); 196 UrlList urls = GetPredictedUrlListAtStartup(user_prefs, local_state);
197 197
198 base::ListValue* referral_list = 198 base::ListValue* referral_list =
199 static_cast<base::ListValue*>(user_prefs->GetList( 199 static_cast<base::ListValue*>(user_prefs->GetList(
200 prefs::kDnsPrefetchingHostReferralList)->DeepCopy()); 200 prefs::kDnsPrefetchingHostReferralList)->DeepCopy());
201 201
202 // Now that we have the statistics in memory, wipe them from the Preferences 202 // Now that we have the statistics in memory, wipe them from the Preferences
203 // file. They will be serialized back on a clean shutdown. This way we only 203 // file. They will be serialized back on a clean shutdown. This way we only
204 // have to worry about clearing our in-memory state when Clearing Browsing 204 // have to worry about clearing our in-memory state when Clearing Browsing
205 // Data. 205 // Data.
206 user_prefs->ClearPref(prefs::kDnsPrefetchingStartupList); 206 user_prefs->ClearPref(prefs::kDnsPrefetchingStartupList);
207 user_prefs->ClearPref(prefs::kDnsPrefetchingHostReferralList); 207 user_prefs->ClearPref(prefs::kDnsPrefetchingHostReferralList);
208 208
209 BrowserThread::PostTask( 209 BrowserThread::PostTask(
210 BrowserThread::IO, 210 BrowserThread::IO,
211 FROM_HERE, 211 FROM_HERE,
212 base::Bind( 212 base::Bind(
213 &Predictor::FinalizeInitializationOnIOThread, 213 &Predictor::FinalizeInitializationOnIOThread,
214 base::Unretained(this), 214 base::Unretained(this),
215 urls, referral_list, 215 urls, referral_list,
216 io_thread, profile_io_data)); 216 io_thread, profile_io_data));
217 } 217 }
218 218
219 void Predictor::AnticipateOmniboxUrl(const GURL& url, bool preconnectable) { 219 void Predictor::AnticipateOmniboxUrl(const GURL& url, bool preconnectable) {
220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 220 DCHECK_CURRENTLY_ON(BrowserThread::UI);
221 if (!predictor_enabled_) 221 if (!predictor_enabled_)
222 return; 222 return;
223 if (!url.is_valid() || !url.has_host()) 223 if (!url.is_valid() || !url.has_host())
224 return; 224 return;
225 if (!CanPreresolveAndPreconnect()) 225 if (!CanPreresolveAndPreconnect())
226 return; 226 return;
227 227
228 std::string host = url.HostNoBrackets(); 228 std::string host = url.HostNoBrackets();
229 bool is_new_host_request = (host != last_omnibox_host_); 229 bool is_new_host_request = (host != last_omnibox_host_);
230 last_omnibox_host_ = host; 230 last_omnibox_host_ = host;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 UrlInfo::ResolutionMotivation motivation(UrlInfo::EARLY_LOAD_MOTIVATED); 304 UrlInfo::ResolutionMotivation motivation(UrlInfo::EARLY_LOAD_MOTIVATED);
305 const int kConnectionsNeeded = 1; 305 const int kConnectionsNeeded = 1;
306 PreconnectUrl(CanonicalizeUrl(url), first_party_for_cookies, 306 PreconnectUrl(CanonicalizeUrl(url), first_party_for_cookies,
307 motivation, kConnectionsNeeded); 307 motivation, kConnectionsNeeded);
308 PredictFrameSubresources(url.GetWithEmptyPath(), first_party_for_cookies); 308 PredictFrameSubresources(url.GetWithEmptyPath(), first_party_for_cookies);
309 } 309 }
310 310
311 UrlList Predictor::GetPredictedUrlListAtStartup( 311 UrlList Predictor::GetPredictedUrlListAtStartup(
312 PrefService* user_prefs, 312 PrefService* user_prefs,
313 PrefService* local_state) { 313 PrefService* local_state) {
314 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 314 DCHECK_CURRENTLY_ON(BrowserThread::UI);
315 UrlList urls; 315 UrlList urls;
316 // Recall list of URLs we learned about during last session. 316 // Recall list of URLs we learned about during last session.
317 // This may catch secondary hostnames, pulled in by the homepages. It will 317 // This may catch secondary hostnames, pulled in by the homepages. It will
318 // also catch more of the "primary" home pages, since that was (presumably) 318 // also catch more of the "primary" home pages, since that was (presumably)
319 // rendered first (and will be rendered first this time too). 319 // rendered first (and will be rendered first this time too).
320 const base::ListValue* startup_list = 320 const base::ListValue* startup_list =
321 user_prefs->GetList(prefs::kDnsPrefetchingStartupList); 321 user_prefs->GetList(prefs::kDnsPrefetchingStartupList);
322 322
323 if (startup_list) { 323 if (startup_list) {
324 base::ListValue::const_iterator it = startup_list->begin(); 324 base::ListValue::const_iterator it = startup_list->begin();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 } 358 }
359 } 359 }
360 360
361 if (urls.empty()) 361 if (urls.empty())
362 urls.push_back(GURL("http://www.google.com:80")); 362 urls.push_back(GURL("http://www.google.com:80"));
363 363
364 return urls; 364 return urls;
365 } 365 }
366 366
367 void Predictor::set_max_queueing_delay(int max_queueing_delay_ms) { 367 void Predictor::set_max_queueing_delay(int max_queueing_delay_ms) {
368 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 368 DCHECK_CURRENTLY_ON(BrowserThread::UI);
369 g_max_queueing_delay_ms = max_queueing_delay_ms; 369 g_max_queueing_delay_ms = max_queueing_delay_ms;
370 } 370 }
371 371
372 void Predictor::set_max_parallel_resolves(size_t max_parallel_resolves) { 372 void Predictor::set_max_parallel_resolves(size_t max_parallel_resolves) {
373 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 373 DCHECK_CURRENTLY_ON(BrowserThread::UI);
374 g_max_parallel_resolves = max_parallel_resolves; 374 g_max_parallel_resolves = max_parallel_resolves;
375 } 375 }
376 376
377 void Predictor::ShutdownOnUIThread() { 377 void Predictor::ShutdownOnUIThread() {
378 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 378 DCHECK_CURRENTLY_ON(BrowserThread::UI);
379 BrowserThread::PostTask( 379 BrowserThread::PostTask(
380 BrowserThread::IO, 380 BrowserThread::IO,
381 FROM_HERE, 381 FROM_HERE,
382 base::Bind(&Predictor::Shutdown, base::Unretained(this))); 382 base::Bind(&Predictor::Shutdown, base::Unretained(this)));
383 } 383 }
384 384
385 // ---------------------- End UI methods. ------------------------------------- 385 // ---------------------- End UI methods. -------------------------------------
386 386
387 // --------------------- Start IO methods. ------------------------------------ 387 // --------------------- Start IO methods. ------------------------------------
388 388
389 void Predictor::Shutdown() { 389 void Predictor::Shutdown() {
390 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 390 DCHECK_CURRENTLY_ON(BrowserThread::IO);
391 DCHECK(!shutdown_); 391 DCHECK(!shutdown_);
392 shutdown_ = true; 392 shutdown_ = true;
393 393
394 STLDeleteElements(&pending_lookups_); 394 STLDeleteElements(&pending_lookups_);
395 } 395 }
396 396
397 void Predictor::DiscardAllResults() { 397 void Predictor::DiscardAllResults() {
398 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 398 DCHECK_CURRENTLY_ON(BrowserThread::IO);
399 // Delete anything listed so far in this session that shows in about:dns. 399 // Delete anything listed so far in this session that shows in about:dns.
400 referrers_.clear(); 400 referrers_.clear();
401 401
402 402
403 // Try to delete anything in our work queue. 403 // Try to delete anything in our work queue.
404 while (!work_queue_.IsEmpty()) { 404 while (!work_queue_.IsEmpty()) {
405 // Emulate processing cycle as though host was not found. 405 // Emulate processing cycle as though host was not found.
406 GURL url = work_queue_.Pop(); 406 GURL url = work_queue_.Pop();
407 UrlInfo* info = &results_[url]; 407 UrlInfo* info = &results_[url];
408 DCHECK(info->HasUrl(url)); 408 DCHECK(info->HasUrl(url));
(...skipping 20 matching lines...) Expand all
429 // Put back in the names being worked on. 429 // Put back in the names being worked on.
430 for (Results::iterator it = assignees.begin(); assignees.end() != it; ++it) { 430 for (Results::iterator it = assignees.begin(); assignees.end() != it; ++it) {
431 DCHECK(it->second.is_marked_to_delete()); 431 DCHECK(it->second.is_marked_to_delete());
432 results_[it->first] = it->second; 432 results_[it->first] = it->second;
433 } 433 }
434 } 434 }
435 435
436 // Overloaded Resolve() to take a vector of names. 436 // Overloaded Resolve() to take a vector of names.
437 void Predictor::ResolveList(const UrlList& urls, 437 void Predictor::ResolveList(const UrlList& urls,
438 UrlInfo::ResolutionMotivation motivation) { 438 UrlInfo::ResolutionMotivation motivation) {
439 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 439 DCHECK_CURRENTLY_ON(BrowserThread::IO);
440 440
441 for (UrlList::const_iterator it = urls.begin(); it < urls.end(); ++it) { 441 for (UrlList::const_iterator it = urls.begin(); it < urls.end(); ++it) {
442 AppendToResolutionQueue(*it, motivation); 442 AppendToResolutionQueue(*it, motivation);
443 } 443 }
444 } 444 }
445 445
446 // Basic Resolve() takes an invidual name, and adds it 446 // Basic Resolve() takes an invidual name, and adds it
447 // to the queue. 447 // to the queue.
448 void Predictor::Resolve(const GURL& url, 448 void Predictor::Resolve(const GURL& url,
449 UrlInfo::ResolutionMotivation motivation) { 449 UrlInfo::ResolutionMotivation motivation) {
450 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 450 DCHECK_CURRENTLY_ON(BrowserThread::IO);
451 if (!url.has_host()) 451 if (!url.has_host())
452 return; 452 return;
453 AppendToResolutionQueue(url, motivation); 453 AppendToResolutionQueue(url, motivation);
454 } 454 }
455 455
456 void Predictor::LearnFromNavigation(const GURL& referring_url, 456 void Predictor::LearnFromNavigation(const GURL& referring_url,
457 const GURL& target_url) { 457 const GURL& target_url) {
458 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 458 DCHECK_CURRENTLY_ON(BrowserThread::IO);
459 if (!predictor_enabled_ || !CanPreresolveAndPreconnect()) 459 if (!predictor_enabled_ || !CanPreresolveAndPreconnect())
460 return; 460 return;
461 DCHECK_EQ(referring_url, Predictor::CanonicalizeUrl(referring_url)); 461 DCHECK_EQ(referring_url, Predictor::CanonicalizeUrl(referring_url));
462 DCHECK_NE(referring_url, GURL::EmptyGURL()); 462 DCHECK_NE(referring_url, GURL::EmptyGURL());
463 DCHECK_EQ(target_url, Predictor::CanonicalizeUrl(target_url)); 463 DCHECK_EQ(target_url, Predictor::CanonicalizeUrl(target_url));
464 DCHECK_NE(target_url, GURL::EmptyGURL()); 464 DCHECK_NE(target_url, GURL::EmptyGURL());
465 465
466 referrers_[referring_url].SuggestHost(target_url); 466 referrers_[referring_url].SuggestHost(target_url);
467 // Possibly do some referrer trimming. 467 // Possibly do some referrer trimming.
468 TrimReferrers(); 468 TrimReferrers();
469 } 469 }
470 470
471 //----------------------------------------------------------------------------- 471 //-----------------------------------------------------------------------------
472 // This section supports the about:dns page. 472 // This section supports the about:dns page.
473 473
474 void Predictor::PredictorGetHtmlInfo(Predictor* predictor, 474 void Predictor::PredictorGetHtmlInfo(Predictor* predictor,
475 std::string* output) { 475 std::string* output) {
476 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 476 DCHECK_CURRENTLY_ON(BrowserThread::IO);
477 477
478 output->append("<html><head><title>About DNS</title>" 478 output->append("<html><head><title>About DNS</title>"
479 // We'd like the following no-cache... but it doesn't work. 479 // We'd like the following no-cache... but it doesn't work.
480 // "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">" 480 // "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">"
481 "</head><body>"); 481 "</head><body>");
482 if (predictor && predictor->predictor_enabled() && 482 if (predictor && predictor->predictor_enabled() &&
483 predictor->CanPreresolveAndPreconnect()) { 483 predictor->CanPreresolveAndPreconnect()) {
484 predictor->GetHtmlInfo(output); 484 predictor->GetHtmlInfo(output);
485 } else { 485 } else {
486 output->append("DNS pre-resolution and TCP pre-connection is disabled."); 486 output->append("DNS pre-resolution and TCP pre-connection is disabled.");
(...skipping 18 matching lines...) Expand all
505 std::string reversed_host = JoinString(parts, '.'); 505 std::string reversed_host = JoinString(parts, '.');
506 506
507 // Return the new URL. 507 // Return the new URL.
508 GURL::Replacements url_components; 508 GURL::Replacements url_components;
509 url_components.SetHostStr(reversed_host); 509 url_components.SetHostStr(reversed_host);
510 return url.ReplaceComponents(url_components).spec(); 510 return url.ReplaceComponents(url_components).spec();
511 } 511 }
512 }; 512 };
513 513
514 void Predictor::GetHtmlReferrerLists(std::string* output) { 514 void Predictor::GetHtmlReferrerLists(std::string* output) {
515 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 515 DCHECK_CURRENTLY_ON(BrowserThread::IO);
516 if (referrers_.empty()) 516 if (referrers_.empty())
517 return; 517 return;
518 518
519 // TODO(jar): Remove any plausible JavaScript from names before displaying. 519 // TODO(jar): Remove any plausible JavaScript from names before displaying.
520 520
521 typedef std::set<GURL, struct RightToLeftStringSorter> 521 typedef std::set<GURL, struct RightToLeftStringSorter>
522 SortedNames; 522 SortedNames;
523 SortedNames sorted_names; 523 SortedNames sorted_names;
524 524
525 for (Referrers::iterator it = referrers_.begin(); 525 for (Referrers::iterator it = referrers_.begin();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 static_cast<int>(future_url->second.preconnection_count()), 558 static_cast<int>(future_url->second.preconnection_count()),
559 static_cast<int>(future_url->second.preresolution_count()), 559 static_cast<int>(future_url->second.preresolution_count()),
560 static_cast<double>(future_url->second.subresource_use_rate()), 560 static_cast<double>(future_url->second.subresource_use_rate()),
561 future_url->first.spec().c_str()); 561 future_url->first.spec().c_str());
562 } 562 }
563 } 563 }
564 output->append("</table>"); 564 output->append("</table>");
565 } 565 }
566 566
567 void Predictor::GetHtmlInfo(std::string* output) { 567 void Predictor::GetHtmlInfo(std::string* output) {
568 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 568 DCHECK_CURRENTLY_ON(BrowserThread::IO);
569 if (initial_observer_.get()) 569 if (initial_observer_.get())
570 initial_observer_->GetFirstResolutionsHtml(output); 570 initial_observer_->GetFirstResolutionsHtml(output);
571 // Show list of subresource predictions and stats. 571 // Show list of subresource predictions and stats.
572 GetHtmlReferrerLists(output); 572 GetHtmlReferrerLists(output);
573 573
574 // Local lists for calling UrlInfo 574 // Local lists for calling UrlInfo
575 UrlInfo::UrlInfoTable name_not_found; 575 UrlInfo::UrlInfoTable name_not_found;
576 UrlInfo::UrlInfoTable name_preresolved; 576 UrlInfo::UrlInfoTable name_preresolved;
577 577
578 // Get copies of all useful data. 578 // Get copies of all useful data.
(...skipping 21 matching lines...) Expand all
600 #endif // NDEBUG 600 #endif // NDEBUG
601 601
602 // Call for display of each table, along with title. 602 // Call for display of each table, along with title.
603 UrlInfo::GetHtmlTable(name_preresolved, 603 UrlInfo::GetHtmlTable(name_preresolved,
604 "Preresolution DNS records performed for ", brief, output); 604 "Preresolution DNS records performed for ", brief, output);
605 UrlInfo::GetHtmlTable(name_not_found, 605 UrlInfo::GetHtmlTable(name_not_found,
606 "Preresolving DNS records revealed non-existence for ", brief, output); 606 "Preresolving DNS records revealed non-existence for ", brief, output);
607 } 607 }
608 608
609 void Predictor::TrimReferrersNow() { 609 void Predictor::TrimReferrersNow() {
610 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 610 DCHECK_CURRENTLY_ON(BrowserThread::IO);
611 // Just finish up work if an incremental trim is in progress. 611 // Just finish up work if an incremental trim is in progress.
612 if (urls_being_trimmed_.empty()) 612 if (urls_being_trimmed_.empty())
613 LoadUrlsForTrimming(); 613 LoadUrlsForTrimming();
614 IncrementalTrimReferrers(true); // Do everything now. 614 IncrementalTrimReferrers(true); // Do everything now.
615 } 615 }
616 616
617 void Predictor::SerializeReferrers(base::ListValue* referral_list) { 617 void Predictor::SerializeReferrers(base::ListValue* referral_list) {
618 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 618 DCHECK_CURRENTLY_ON(BrowserThread::IO);
619 referral_list->Clear(); 619 referral_list->Clear();
620 referral_list->Append(new base::FundamentalValue(kPredictorReferrerVersion)); 620 referral_list->Append(new base::FundamentalValue(kPredictorReferrerVersion));
621 for (Referrers::const_iterator it = referrers_.begin(); 621 for (Referrers::const_iterator it = referrers_.begin();
622 it != referrers_.end(); ++it) { 622 it != referrers_.end(); ++it) {
623 // Serialize the list of subresource names. 623 // Serialize the list of subresource names.
624 base::Value* subresource_list(it->second.Serialize()); 624 base::Value* subresource_list(it->second.Serialize());
625 625
626 // Create a list for each referer. 626 // Create a list for each referer.
627 base::ListValue* motivator(new base::ListValue); 627 base::ListValue* motivator(new base::ListValue);
628 motivator->Append(new base::StringValue(it->first.spec())); 628 motivator->Append(new base::StringValue(it->first.spec()));
629 motivator->Append(subresource_list); 629 motivator->Append(subresource_list);
630 630
631 referral_list->Append(motivator); 631 referral_list->Append(motivator);
632 } 632 }
633 } 633 }
634 634
635 void Predictor::DeserializeReferrers(const base::ListValue& referral_list) { 635 void Predictor::DeserializeReferrers(const base::ListValue& referral_list) {
636 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 636 DCHECK_CURRENTLY_ON(BrowserThread::IO);
637 int format_version = -1; 637 int format_version = -1;
638 if (referral_list.GetSize() > 0 && 638 if (referral_list.GetSize() > 0 &&
639 referral_list.GetInteger(0, &format_version) && 639 referral_list.GetInteger(0, &format_version) &&
640 format_version == kPredictorReferrerVersion) { 640 format_version == kPredictorReferrerVersion) {
641 for (size_t i = 1; i < referral_list.GetSize(); ++i) { 641 for (size_t i = 1; i < referral_list.GetSize(); ++i) {
642 const base::ListValue* motivator; 642 const base::ListValue* motivator;
643 if (!referral_list.GetList(i, &motivator)) { 643 if (!referral_list.GetList(i, &motivator)) {
644 NOTREACHED(); 644 NOTREACHED();
645 return; 645 return;
646 } 646 }
(...skipping 14 matching lines...) Expand all
661 } 661 }
662 } 662 }
663 663
664 void Predictor::DeserializeReferrersThenDelete( 664 void Predictor::DeserializeReferrersThenDelete(
665 base::ListValue* referral_list) { 665 base::ListValue* referral_list) {
666 DeserializeReferrers(*referral_list); 666 DeserializeReferrers(*referral_list);
667 delete referral_list; 667 delete referral_list;
668 } 668 }
669 669
670 void Predictor::DiscardInitialNavigationHistory() { 670 void Predictor::DiscardInitialNavigationHistory() {
671 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 671 DCHECK_CURRENTLY_ON(BrowserThread::IO);
672 if (initial_observer_.get()) 672 if (initial_observer_.get())
673 initial_observer_->DiscardInitialNavigationHistory(); 673 initial_observer_->DiscardInitialNavigationHistory();
674 } 674 }
675 675
676 void Predictor::FinalizeInitializationOnIOThread( 676 void Predictor::FinalizeInitializationOnIOThread(
677 const UrlList& startup_urls, 677 const UrlList& startup_urls,
678 base::ListValue* referral_list, 678 base::ListValue* referral_list,
679 IOThread* io_thread, 679 IOThread* io_thread,
680 ProfileIOData* profile_io_data) { 680 ProfileIOData* profile_io_data) {
681 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 681 DCHECK_CURRENTLY_ON(BrowserThread::IO);
682 682
683 profile_io_data_ = profile_io_data; 683 profile_io_data_ = profile_io_data;
684 initial_observer_.reset(new InitialObserver()); 684 initial_observer_.reset(new InitialObserver());
685 host_resolver_ = io_thread->globals()->host_resolver.get(); 685 host_resolver_ = io_thread->globals()->host_resolver.get();
686 686
687 net::URLRequestContext* context = 687 net::URLRequestContext* context =
688 url_request_context_getter_->GetURLRequestContext(); 688 url_request_context_getter_->GetURLRequestContext();
689 transport_security_state_ = context->transport_security_state(); 689 transport_security_state_ = context->transport_security_state();
690 ssl_config_service_ = context->ssl_config_service(); 690 ssl_config_service_ = context->ssl_config_service();
691 proxy_service_ = context->proxy_service(); 691 proxy_service_ = context->proxy_service();
(...skipping 12 matching lines...) Expand all
704 } 704 }
705 705
706 //----------------------------------------------------------------------------- 706 //-----------------------------------------------------------------------------
707 // This section intermingles prefetch results with actual browser HTTP 707 // This section intermingles prefetch results with actual browser HTTP
708 // network activity. It supports calculating of the benefit of a prefetch, as 708 // network activity. It supports calculating of the benefit of a prefetch, as
709 // well as recording what prefetched hostname resolutions might be potentially 709 // well as recording what prefetched hostname resolutions might be potentially
710 // helpful during the next chrome-startup. 710 // helpful during the next chrome-startup.
711 //----------------------------------------------------------------------------- 711 //-----------------------------------------------------------------------------
712 712
713 void Predictor::LearnAboutInitialNavigation(const GURL& url) { 713 void Predictor::LearnAboutInitialNavigation(const GURL& url) {
714 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 714 DCHECK_CURRENTLY_ON(BrowserThread::IO);
715 if (!predictor_enabled_ || NULL == initial_observer_.get() || 715 if (!predictor_enabled_ || NULL == initial_observer_.get() ||
716 !CanPreresolveAndPreconnect()) { 716 !CanPreresolveAndPreconnect()) {
717 return; 717 return;
718 } 718 }
719 initial_observer_->Append(url, this); 719 initial_observer_->Append(url, this);
720 } 720 }
721 721
722 // This API is only used in the browser process. 722 // This API is only used in the browser process.
723 // It is called from an IPC message originating in the renderer. It currently 723 // It is called from an IPC message originating in the renderer. It currently
724 // includes both Page-Scan, and Link-Hover prefetching. 724 // includes both Page-Scan, and Link-Hover prefetching.
725 // TODO(jar): Separate out link-hover prefetching, and page-scan results. 725 // TODO(jar): Separate out link-hover prefetching, and page-scan results.
726 void Predictor::DnsPrefetchList(const NameList& hostnames) { 726 void Predictor::DnsPrefetchList(const NameList& hostnames) {
727 // TODO(jar): Push GURL transport further back into renderer, but this will 727 // TODO(jar): Push GURL transport further back into renderer, but this will
728 // require a Webkit change in the observer :-/. 728 // require a Webkit change in the observer :-/.
729 UrlList urls; 729 UrlList urls;
730 for (NameList::const_iterator it = hostnames.begin(); 730 for (NameList::const_iterator it = hostnames.begin();
731 it < hostnames.end(); 731 it < hostnames.end();
732 ++it) { 732 ++it) {
733 urls.push_back(GURL("http://" + *it + ":80")); 733 urls.push_back(GURL("http://" + *it + ":80"));
734 } 734 }
735 735
736 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 736 DCHECK_CURRENTLY_ON(BrowserThread::IO);
737 DnsPrefetchMotivatedList(urls, UrlInfo::PAGE_SCAN_MOTIVATED); 737 DnsPrefetchMotivatedList(urls, UrlInfo::PAGE_SCAN_MOTIVATED);
738 } 738 }
739 739
740 void Predictor::DnsPrefetchMotivatedList( 740 void Predictor::DnsPrefetchMotivatedList(
741 const UrlList& urls, 741 const UrlList& urls,
742 UrlInfo::ResolutionMotivation motivation) { 742 UrlInfo::ResolutionMotivation motivation) {
743 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 743 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
744 BrowserThread::CurrentlyOn(BrowserThread::IO)); 744 BrowserThread::CurrentlyOn(BrowserThread::IO));
745 if (!predictor_enabled_) 745 if (!predictor_enabled_)
746 return; 746 return;
(...skipping 13 matching lines...) Expand all
760 760
761 //----------------------------------------------------------------------------- 761 //-----------------------------------------------------------------------------
762 // Functions to handle saving of hostnames from one session to the next, to 762 // Functions to handle saving of hostnames from one session to the next, to
763 // expedite startup times. 763 // expedite startup times.
764 764
765 static void SaveDnsPrefetchStateForNextStartupAndTrimOnIOThread( 765 static void SaveDnsPrefetchStateForNextStartupAndTrimOnIOThread(
766 base::ListValue* startup_list, 766 base::ListValue* startup_list,
767 base::ListValue* referral_list, 767 base::ListValue* referral_list,
768 base::WaitableEvent* completion, 768 base::WaitableEvent* completion,
769 Predictor* predictor) { 769 Predictor* predictor) {
770 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 770 DCHECK_CURRENTLY_ON(BrowserThread::IO);
771 771
772 if (NULL == predictor) { 772 if (NULL == predictor) {
773 completion->Signal(); 773 completion->Signal();
774 return; 774 return;
775 } 775 }
776 predictor->SaveDnsPrefetchStateForNextStartupAndTrim( 776 predictor->SaveDnsPrefetchStateForNextStartupAndTrim(
777 startup_list, referral_list, completion); 777 startup_list, referral_list, completion);
778 } 778 }
779 779
780 void Predictor::SaveStateForNextStartupAndTrim() { 780 void Predictor::SaveStateForNextStartupAndTrim() {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 base::ThreadRestrictions::ScopedAllowWait allow_wait; 814 base::ThreadRestrictions::ScopedAllowWait allow_wait;
815 completion.Wait(); 815 completion.Wait();
816 } 816 }
817 } 817 }
818 } 818 }
819 819
820 void Predictor::SaveDnsPrefetchStateForNextStartupAndTrim( 820 void Predictor::SaveDnsPrefetchStateForNextStartupAndTrim(
821 base::ListValue* startup_list, 821 base::ListValue* startup_list,
822 base::ListValue* referral_list, 822 base::ListValue* referral_list,
823 base::WaitableEvent* completion) { 823 base::WaitableEvent* completion) {
824 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 824 DCHECK_CURRENTLY_ON(BrowserThread::IO);
825 if (initial_observer_.get()) 825 if (initial_observer_.get())
826 initial_observer_->GetInitialDnsResolutionList(startup_list); 826 initial_observer_->GetInitialDnsResolutionList(startup_list);
827 827
828 // Do at least one trim at shutdown, in case the user wasn't running long 828 // Do at least one trim at shutdown, in case the user wasn't running long
829 // enough to do any regular trimming of referrers. 829 // enough to do any regular trimming of referrers.
830 // TODO(lizeb): Should trimming really be done at each shutdown? This could be 830 // TODO(lizeb): Should trimming really be done at each shutdown? This could be
831 // a frequent occurrence on Android. 831 // a frequent occurrence on Android.
832 TrimReferrersNow(); 832 TrimReferrersNow();
833 SerializeReferrers(referral_list); 833 SerializeReferrers(referral_list);
834 834
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 FROM_HERE, 893 FROM_HERE,
894 base::Bind(&Predictor::PrepareFrameSubresources, 894 base::Bind(&Predictor::PrepareFrameSubresources,
895 base::Unretained(this), url, first_party_for_cookies)); 895 base::Unretained(this), url, first_party_for_cookies));
896 } 896 }
897 } 897 }
898 898
899 bool Predictor::CanPrefetchAndPrerender() const { 899 bool Predictor::CanPrefetchAndPrerender() const {
900 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { 900 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
901 return chrome_browser_net::CanPrefetchAndPrerenderUI(user_prefs_); 901 return chrome_browser_net::CanPrefetchAndPrerenderUI(user_prefs_);
902 } else { 902 } else {
903 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 903 DCHECK_CURRENTLY_ON(BrowserThread::IO);
904 return chrome_browser_net::CanPrefetchAndPrerenderIO(profile_io_data_); 904 return chrome_browser_net::CanPrefetchAndPrerenderIO(profile_io_data_);
905 } 905 }
906 } 906 }
907 907
908 bool Predictor::CanPreresolveAndPreconnect() const { 908 bool Predictor::CanPreresolveAndPreconnect() const {
909 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { 909 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
910 return chrome_browser_net::CanPreresolveAndPreconnectUI(user_prefs_); 910 return chrome_browser_net::CanPreresolveAndPreconnectUI(user_prefs_);
911 } else { 911 } else {
912 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 912 DCHECK_CURRENTLY_ON(BrowserThread::IO);
913 return chrome_browser_net::CanPreresolveAndPreconnectIO(profile_io_data_); 913 return chrome_browser_net::CanPreresolveAndPreconnectIO(profile_io_data_);
914 } 914 }
915 } 915 }
916 916
917 enum SubresourceValue { 917 enum SubresourceValue {
918 PRECONNECTION, 918 PRECONNECTION,
919 PRERESOLUTION, 919 PRERESOLUTION,
920 TOO_NEW, 920 TOO_NEW,
921 SUBRESOURCE_VALUE_MAX 921 SUBRESOURCE_VALUE_MAX
922 }; 922 };
923 923
924 void Predictor::PrepareFrameSubresources(const GURL& original_url, 924 void Predictor::PrepareFrameSubresources(const GURL& original_url,
925 const GURL& first_party_for_cookies) { 925 const GURL& first_party_for_cookies) {
926 // Apply HSTS redirect early so it is taken into account when looking up 926 // Apply HSTS redirect early so it is taken into account when looking up
927 // subresources. 927 // subresources.
928 GURL url = GetHSTSRedirectOnIOThread(original_url); 928 GURL url = GetHSTSRedirectOnIOThread(original_url);
929 929
930 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 930 DCHECK_CURRENTLY_ON(BrowserThread::IO);
931 DCHECK_EQ(url.GetWithEmptyPath(), url); 931 DCHECK_EQ(url.GetWithEmptyPath(), url);
932 Referrers::iterator it = referrers_.find(url); 932 Referrers::iterator it = referrers_.find(url);
933 if (referrers_.end() == it) { 933 if (referrers_.end() == it) {
934 // Only when we don't know anything about this url, make 2 connections 934 // Only when we don't know anything about this url, make 2 connections
935 // available. We could do this completely via learning (by prepopulating 935 // available. We could do this completely via learning (by prepopulating
936 // the referrer_ list with this expected value), but it would swell the 936 // the referrer_ list with this expected value), but it would swell the
937 // size of the list with all the "Leaf" nodes in the tree (nodes that don't 937 // size of the list with all the "Leaf" nodes in the tree (nodes that don't
938 // load any subresources). If we learn about this resource, we will instead 938 // load any subresources). If we learn about this resource, we will instead
939 // provide a more carefully estimated preconnection count. 939 // provide a more carefully estimated preconnection count.
940 if (preconnect_enabled_) { 940 if (preconnect_enabled_) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 if (queued_info) 973 if (queued_info)
974 queued_info->SetReferringHostname(url); 974 queued_info->SetReferringHostname(url);
975 } 975 }
976 UMA_HISTOGRAM_ENUMERATION("Net.PreconnectSubresourceEval", evalution, 976 UMA_HISTOGRAM_ENUMERATION("Net.PreconnectSubresourceEval", evalution,
977 SUBRESOURCE_VALUE_MAX); 977 SUBRESOURCE_VALUE_MAX);
978 } 978 }
979 } 979 }
980 980
981 void Predictor::OnLookupFinished(LookupRequest* request, const GURL& url, 981 void Predictor::OnLookupFinished(LookupRequest* request, const GURL& url,
982 bool found) { 982 bool found) {
983 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 983 DCHECK_CURRENTLY_ON(BrowserThread::IO);
984 984
985 LookupFinished(request, url, found); 985 LookupFinished(request, url, found);
986 pending_lookups_.erase(request); 986 pending_lookups_.erase(request);
987 delete request; 987 delete request;
988 988
989 StartSomeQueuedResolutions(); 989 StartSomeQueuedResolutions();
990 } 990 }
991 991
992 void Predictor::LookupFinished(LookupRequest* request, const GURL& url, 992 void Predictor::LookupFinished(LookupRequest* request, const GURL& url,
993 bool found) { 993 bool found) {
994 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 994 DCHECK_CURRENTLY_ON(BrowserThread::IO);
995 UrlInfo* info = &results_[url]; 995 UrlInfo* info = &results_[url];
996 DCHECK(info->HasUrl(url)); 996 DCHECK(info->HasUrl(url));
997 if (info->is_marked_to_delete()) { 997 if (info->is_marked_to_delete()) {
998 results_.erase(url); 998 results_.erase(url);
999 } else { 999 } else {
1000 if (found) 1000 if (found)
1001 info->SetFoundState(); 1001 info->SetFoundState();
1002 else 1002 else
1003 info->SetNoSuchNameState(); 1003 info->SetNoSuchNameState();
1004 } 1004 }
1005 } 1005 }
1006 1006
1007 bool Predictor::WouldLikelyProxyURL(const GURL& url) { 1007 bool Predictor::WouldLikelyProxyURL(const GURL& url) {
1008 if (!proxy_service_) 1008 if (!proxy_service_)
1009 return false; 1009 return false;
1010 1010
1011 net::ProxyInfo info; 1011 net::ProxyInfo info;
1012 bool synchronous_success = proxy_service_->TryResolveProxySynchronously( 1012 bool synchronous_success = proxy_service_->TryResolveProxySynchronously(
1013 url, net::LOAD_NORMAL, &info, NULL, net::BoundNetLog()); 1013 url, net::LOAD_NORMAL, &info, NULL, net::BoundNetLog());
1014 1014
1015 return synchronous_success && !info.is_direct(); 1015 return synchronous_success && !info.is_direct();
1016 } 1016 }
1017 1017
1018 UrlInfo* Predictor::AppendToResolutionQueue( 1018 UrlInfo* Predictor::AppendToResolutionQueue(
1019 const GURL& url, 1019 const GURL& url,
1020 UrlInfo::ResolutionMotivation motivation) { 1020 UrlInfo::ResolutionMotivation motivation) {
1021 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1021 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1022 DCHECK(url.has_host()); 1022 DCHECK(url.has_host());
1023 1023
1024 if (shutdown_) 1024 if (shutdown_)
1025 return NULL; 1025 return NULL;
1026 1026
1027 UrlInfo* info = &results_[url]; 1027 UrlInfo* info = &results_[url];
1028 info->SetUrl(url); // Initialize or DCHECK. 1028 info->SetUrl(url); // Initialize or DCHECK.
1029 // TODO(jar): I need to discard names that have long since expired. 1029 // TODO(jar): I need to discard names that have long since expired.
1030 // Currently we only add to the domain map :-/ 1030 // Currently we only add to the domain map :-/
1031 1031
(...skipping 18 matching lines...) Expand all
1050 } 1050 }
1051 1051
1052 info->SetQueuedState(motivation); 1052 info->SetQueuedState(motivation);
1053 work_queue_.Push(url, motivation); 1053 work_queue_.Push(url, motivation);
1054 1054
1055 StartSomeQueuedResolutions(); 1055 StartSomeQueuedResolutions();
1056 return info; 1056 return info;
1057 } 1057 }
1058 1058
1059 bool Predictor::CongestionControlPerformed(UrlInfo* info) { 1059 bool Predictor::CongestionControlPerformed(UrlInfo* info) {
1060 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1060 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1061 // Note: queue_duration is ONLY valid after we go to assigned state. 1061 // Note: queue_duration is ONLY valid after we go to assigned state.
1062 if (info->queue_duration() < max_dns_queue_delay_) 1062 if (info->queue_duration() < max_dns_queue_delay_)
1063 return false; 1063 return false;
1064 // We need to discard all entries in our queue, as we're keeping them waiting 1064 // We need to discard all entries in our queue, as we're keeping them waiting
1065 // too long. By doing this, we'll have a chance to quickly service urgent 1065 // too long. By doing this, we'll have a chance to quickly service urgent
1066 // resolutions, and not have a bogged down system. 1066 // resolutions, and not have a bogged down system.
1067 while (true) { 1067 while (true) {
1068 info->RemoveFromQueue(); 1068 info->RemoveFromQueue();
1069 if (work_queue_.IsEmpty()) 1069 if (work_queue_.IsEmpty())
1070 break; 1070 break;
1071 info = &results_[work_queue_.Pop()]; 1071 info = &results_[work_queue_.Pop()];
1072 info->SetAssignedState(); 1072 info->SetAssignedState();
1073 } 1073 }
1074 return true; 1074 return true;
1075 } 1075 }
1076 1076
1077 void Predictor::StartSomeQueuedResolutions() { 1077 void Predictor::StartSomeQueuedResolutions() {
1078 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1078 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1079 1079
1080 while (!work_queue_.IsEmpty() && 1080 while (!work_queue_.IsEmpty() &&
1081 pending_lookups_.size() < max_concurrent_dns_lookups_) { 1081 pending_lookups_.size() < max_concurrent_dns_lookups_) {
1082 const GURL url(work_queue_.Pop()); 1082 const GURL url(work_queue_.Pop());
1083 UrlInfo* info = &results_[url]; 1083 UrlInfo* info = &results_[url];
1084 DCHECK(info->HasUrl(url)); 1084 DCHECK(info->HasUrl(url));
1085 info->SetAssignedState(); 1085 info->SetAssignedState();
1086 1086
1087 if (CongestionControlPerformed(info)) { 1087 if (CongestionControlPerformed(info)) {
1088 DCHECK(work_queue_.IsEmpty()); 1088 DCHECK(work_queue_.IsEmpty());
(...skipping 20 matching lines...) Expand all
1109 // Completed synchronously (was already cached by HostResolver), or else 1109 // Completed synchronously (was already cached by HostResolver), or else
1110 // there was (equivalently) some network error that prevents us from 1110 // there was (equivalently) some network error that prevents us from
1111 // finding the name. Status net::OK means it was "found." 1111 // finding the name. Status net::OK means it was "found."
1112 LookupFinished(request, url, status == net::OK); 1112 LookupFinished(request, url, status == net::OK);
1113 delete request; 1113 delete request;
1114 } 1114 }
1115 } 1115 }
1116 } 1116 }
1117 1117
1118 void Predictor::TrimReferrers() { 1118 void Predictor::TrimReferrers() {
1119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1119 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1120 if (!urls_being_trimmed_.empty()) 1120 if (!urls_being_trimmed_.empty())
1121 return; // There is incremental trimming in progress already. 1121 return; // There is incremental trimming in progress already.
1122 1122
1123 // Check to see if it is time to trim yet. 1123 // Check to see if it is time to trim yet.
1124 base::TimeTicks now = base::TimeTicks::Now(); 1124 base::TimeTicks now = base::TimeTicks::Now();
1125 if (now < next_trim_time_) 1125 if (now < next_trim_time_)
1126 return; 1126 return;
1127 next_trim_time_ = now + TimeDelta::FromHours(kDurationBetweenTrimmingsHours); 1127 next_trim_time_ = now + TimeDelta::FromHours(kDurationBetweenTrimmingsHours);
1128 1128
1129 LoadUrlsForTrimming(); 1129 LoadUrlsForTrimming();
(...skipping 29 matching lines...) Expand all
1159 urls_being_trimmed_.pop_back(); 1159 urls_being_trimmed_.pop_back();
1160 if (it == referrers_.end()) 1160 if (it == referrers_.end())
1161 continue; // Defensive code: It got trimmed away already. 1161 continue; // Defensive code: It got trimmed away already.
1162 if (!it->second.Trim(kReferrerTrimRatio, kDiscardableExpectedValue)) 1162 if (!it->second.Trim(kReferrerTrimRatio, kDiscardableExpectedValue))
1163 referrers_.erase(it); 1163 referrers_.erase(it);
1164 } 1164 }
1165 PostIncrementalTrimTask(); 1165 PostIncrementalTrimTask();
1166 } 1166 }
1167 1167
1168 GURL Predictor::GetHSTSRedirectOnIOThread(const GURL& url) { 1168 GURL Predictor::GetHSTSRedirectOnIOThread(const GURL& url) {
1169 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1169 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1170 1170
1171 if (!transport_security_state_) 1171 if (!transport_security_state_)
1172 return url; 1172 return url;
1173 if (!url.SchemeIs("http")) 1173 if (!url.SchemeIs("http"))
1174 return url; 1174 return url;
1175 if (!transport_security_state_->ShouldUpgradeToSSL(url.host())) 1175 if (!transport_security_state_->ShouldUpgradeToSSL(url.host()))
1176 return url; 1176 return url;
1177 1177
1178 url::Replacements<char> replacements; 1178 url::Replacements<char> replacements;
1179 const char kNewScheme[] = "https"; 1179 const char kNewScheme[] = "https";
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 // Member definitions for InitialObserver class. 1223 // Member definitions for InitialObserver class.
1224 1224
1225 Predictor::InitialObserver::InitialObserver() { 1225 Predictor::InitialObserver::InitialObserver() {
1226 } 1226 }
1227 1227
1228 Predictor::InitialObserver::~InitialObserver() { 1228 Predictor::InitialObserver::~InitialObserver() {
1229 } 1229 }
1230 1230
1231 void Predictor::InitialObserver::Append(const GURL& url, 1231 void Predictor::InitialObserver::Append(const GURL& url,
1232 Predictor* predictor) { 1232 Predictor* predictor) {
1233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1233 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1234 1234
1235 // TODO(rlp): Do we really need the predictor check here? 1235 // TODO(rlp): Do we really need the predictor check here?
1236 if (NULL == predictor) 1236 if (NULL == predictor)
1237 return; 1237 return;
1238 if (kStartupResolutionCount <= first_navigations_.size()) 1238 if (kStartupResolutionCount <= first_navigations_.size())
1239 return; 1239 return;
1240 1240
1241 DCHECK(url.SchemeIsHTTPOrHTTPS()); 1241 DCHECK(url.SchemeIsHTTPOrHTTPS());
1242 DCHECK_EQ(url, Predictor::CanonicalizeUrl(url)); 1242 DCHECK_EQ(url, Predictor::CanonicalizeUrl(url));
1243 if (first_navigations_.find(url) == first_navigations_.end()) 1243 if (first_navigations_.find(url) == first_navigations_.end())
1244 first_navigations_[url] = base::TimeTicks::Now(); 1244 first_navigations_[url] = base::TimeTicks::Now();
1245 } 1245 }
1246 1246
1247 void Predictor::InitialObserver::GetInitialDnsResolutionList( 1247 void Predictor::InitialObserver::GetInitialDnsResolutionList(
1248 base::ListValue* startup_list) { 1248 base::ListValue* startup_list) {
1249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1249 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1250 DCHECK(startup_list); 1250 DCHECK(startup_list);
1251 startup_list->Clear(); 1251 startup_list->Clear();
1252 DCHECK_EQ(0u, startup_list->GetSize()); 1252 DCHECK_EQ(0u, startup_list->GetSize());
1253 startup_list->Append( 1253 startup_list->Append(
1254 new base::FundamentalValue(kPredictorStartupFormatVersion)); 1254 new base::FundamentalValue(kPredictorStartupFormatVersion));
1255 for (FirstNavigations::iterator it = first_navigations_.begin(); 1255 for (FirstNavigations::iterator it = first_navigations_.begin();
1256 it != first_navigations_.end(); 1256 it != first_navigations_.end();
1257 ++it) { 1257 ++it) {
1258 DCHECK(it->first == Predictor::CanonicalizeUrl(it->first)); 1258 DCHECK(it->first == Predictor::CanonicalizeUrl(it->first));
1259 startup_list->Append(new base::StringValue(it->first.spec())); 1259 startup_list->Append(new base::StringValue(it->first.spec()));
1260 } 1260 }
1261 } 1261 }
1262 1262
1263 void Predictor::InitialObserver::GetFirstResolutionsHtml( 1263 void Predictor::InitialObserver::GetFirstResolutionsHtml(
1264 std::string* output) { 1264 std::string* output) {
1265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1265 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1266 1266
1267 UrlInfo::UrlInfoTable resolution_list; 1267 UrlInfo::UrlInfoTable resolution_list;
1268 { 1268 {
1269 for (FirstNavigations::iterator it(first_navigations_.begin()); 1269 for (FirstNavigations::iterator it(first_navigations_.begin());
1270 it != first_navigations_.end(); 1270 it != first_navigations_.end();
1271 it++) { 1271 it++) {
1272 UrlInfo info; 1272 UrlInfo info;
1273 info.SetUrl(it->first); 1273 info.SetUrl(it->first);
1274 info.set_time(it->second); 1274 info.set_time(it->second);
1275 resolution_list.push_back(info); 1275 resolution_list.push_back(info);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1317 } 1317 }
1318 1318
1319 void SimplePredictor::ShutdownOnUIThread() { 1319 void SimplePredictor::ShutdownOnUIThread() {
1320 SetShutdown(true); 1320 SetShutdown(true);
1321 } 1321 }
1322 1322
1323 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; } 1323 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; }
1324 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; } 1324 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; }
1325 1325
1326 } // namespace chrome_browser_net 1326 } // namespace chrome_browser_net
OLDNEW
« no previous file with comments | « chrome/browser/net/prediction_options.cc ('k') | chrome/browser/net/predictor_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698