| 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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 | 435 |
| 436 UrlList Predictor::GetPredictedUrlListAtStartup( | 436 UrlList Predictor::GetPredictedUrlListAtStartup( |
| 437 PrefService* user_prefs, | 437 PrefService* user_prefs, |
| 438 PrefService* local_state) { | 438 PrefService* local_state) { |
| 439 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 439 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 440 UrlList urls; | 440 UrlList urls; |
| 441 // Recall list of URLs we learned about during last session. | 441 // Recall list of URLs we learned about during last session. |
| 442 // This may catch secondary hostnames, pulled in by the homepages. It will | 442 // This may catch secondary hostnames, pulled in by the homepages. It will |
| 443 // also catch more of the "primary" home pages, since that was (presumably) | 443 // also catch more of the "primary" home pages, since that was (presumably) |
| 444 // rendered first (and will be rendered first this time too). | 444 // rendered first (and will be rendered first this time too). |
| 445 const ListValue* startup_list = | 445 const base::ListValue* startup_list = |
| 446 user_prefs->GetList(prefs::kDnsPrefetchingStartupList); | 446 user_prefs->GetList(prefs::kDnsPrefetchingStartupList); |
| 447 | 447 |
| 448 if (startup_list) { | 448 if (startup_list) { |
| 449 base::ListValue::const_iterator it = startup_list->begin(); | 449 base::ListValue::const_iterator it = startup_list->begin(); |
| 450 int format_version = -1; | 450 int format_version = -1; |
| 451 if (it != startup_list->end() && | 451 if (it != startup_list->end() && |
| 452 (*it)->GetAsInteger(&format_version) && | 452 (*it)->GetAsInteger(&format_version) && |
| 453 format_version == kPredictorStartupFormatVersion) { | 453 format_version == kPredictorStartupFormatVersion) { |
| 454 ++it; | 454 ++it; |
| 455 for (; it != startup_list->end(); ++it) { | 455 for (; it != startup_list->end(); ++it) { |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 IncrementalTrimReferrers(true); // Do everything now. | 738 IncrementalTrimReferrers(true); // Do everything now. |
| 739 } | 739 } |
| 740 | 740 |
| 741 void Predictor::SerializeReferrers(base::ListValue* referral_list) { | 741 void Predictor::SerializeReferrers(base::ListValue* referral_list) { |
| 742 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 742 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 743 referral_list->Clear(); | 743 referral_list->Clear(); |
| 744 referral_list->Append(new base::FundamentalValue(kPredictorReferrerVersion)); | 744 referral_list->Append(new base::FundamentalValue(kPredictorReferrerVersion)); |
| 745 for (Referrers::const_iterator it = referrers_.begin(); | 745 for (Referrers::const_iterator it = referrers_.begin(); |
| 746 it != referrers_.end(); ++it) { | 746 it != referrers_.end(); ++it) { |
| 747 // Serialize the list of subresource names. | 747 // Serialize the list of subresource names. |
| 748 Value* subresource_list(it->second.Serialize()); | 748 base::Value* subresource_list(it->second.Serialize()); |
| 749 | 749 |
| 750 // Create a list for each referer. | 750 // Create a list for each referer. |
| 751 ListValue* motivator(new ListValue); | 751 base::ListValue* motivator(new base::ListValue); |
| 752 motivator->Append(new StringValue(it->first.spec())); | 752 motivator->Append(new base::StringValue(it->first.spec())); |
| 753 motivator->Append(subresource_list); | 753 motivator->Append(subresource_list); |
| 754 | 754 |
| 755 referral_list->Append(motivator); | 755 referral_list->Append(motivator); |
| 756 } | 756 } |
| 757 } | 757 } |
| 758 | 758 |
| 759 void Predictor::DeserializeReferrers(const base::ListValue& referral_list) { | 759 void Predictor::DeserializeReferrers(const base::ListValue& referral_list) { |
| 760 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 760 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 761 int format_version = -1; | 761 int format_version = -1; |
| 762 if (referral_list.GetSize() > 0 && | 762 if (referral_list.GetSize() > 0 && |
| 763 referral_list.GetInteger(0, &format_version) && | 763 referral_list.GetInteger(0, &format_version) && |
| 764 format_version == kPredictorReferrerVersion) { | 764 format_version == kPredictorReferrerVersion) { |
| 765 for (size_t i = 1; i < referral_list.GetSize(); ++i) { | 765 for (size_t i = 1; i < referral_list.GetSize(); ++i) { |
| 766 const base::ListValue* motivator; | 766 const base::ListValue* motivator; |
| 767 if (!referral_list.GetList(i, &motivator)) { | 767 if (!referral_list.GetList(i, &motivator)) { |
| 768 NOTREACHED(); | 768 NOTREACHED(); |
| 769 return; | 769 return; |
| 770 } | 770 } |
| 771 std::string motivating_url_spec; | 771 std::string motivating_url_spec; |
| 772 if (!motivator->GetString(0, &motivating_url_spec)) { | 772 if (!motivator->GetString(0, &motivating_url_spec)) { |
| 773 NOTREACHED(); | 773 NOTREACHED(); |
| 774 return; | 774 return; |
| 775 } | 775 } |
| 776 | 776 |
| 777 const Value* subresource_list; | 777 const base::Value* subresource_list; |
| 778 if (!motivator->Get(1, &subresource_list)) { | 778 if (!motivator->Get(1, &subresource_list)) { |
| 779 NOTREACHED(); | 779 NOTREACHED(); |
| 780 return; | 780 return; |
| 781 } | 781 } |
| 782 | 782 |
| 783 referrers_[GURL(motivating_url_spec)].Deserialize(*subresource_list); | 783 referrers_[GURL(motivating_url_spec)].Deserialize(*subresource_list); |
| 784 } | 784 } |
| 785 } | 785 } |
| 786 } | 786 } |
| 787 | 787 |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1357 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1357 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1358 DCHECK(startup_list); | 1358 DCHECK(startup_list); |
| 1359 startup_list->Clear(); | 1359 startup_list->Clear(); |
| 1360 DCHECK_EQ(0u, startup_list->GetSize()); | 1360 DCHECK_EQ(0u, startup_list->GetSize()); |
| 1361 startup_list->Append( | 1361 startup_list->Append( |
| 1362 new base::FundamentalValue(kPredictorStartupFormatVersion)); | 1362 new base::FundamentalValue(kPredictorStartupFormatVersion)); |
| 1363 for (FirstNavigations::iterator it = first_navigations_.begin(); | 1363 for (FirstNavigations::iterator it = first_navigations_.begin(); |
| 1364 it != first_navigations_.end(); | 1364 it != first_navigations_.end(); |
| 1365 ++it) { | 1365 ++it) { |
| 1366 DCHECK(it->first == Predictor::CanonicalizeUrl(it->first)); | 1366 DCHECK(it->first == Predictor::CanonicalizeUrl(it->first)); |
| 1367 startup_list->Append(new StringValue(it->first.spec())); | 1367 startup_list->Append(new base::StringValue(it->first.spec())); |
| 1368 } | 1368 } |
| 1369 } | 1369 } |
| 1370 | 1370 |
| 1371 void Predictor::InitialObserver::GetFirstResolutionsHtml( | 1371 void Predictor::InitialObserver::GetFirstResolutionsHtml( |
| 1372 std::string* output) { | 1372 std::string* output) { |
| 1373 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1373 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1374 | 1374 |
| 1375 UrlInfo::UrlInfoTable resolution_list; | 1375 UrlInfo::UrlInfoTable resolution_list; |
| 1376 { | 1376 { |
| 1377 for (FirstNavigations::iterator it(first_navigations_.begin()); | 1377 for (FirstNavigations::iterator it(first_navigations_.begin()); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1421 IOThread* io_thread, | 1421 IOThread* io_thread, |
| 1422 net::URLRequestContextGetter* getter) { | 1422 net::URLRequestContextGetter* getter) { |
| 1423 // Empty function for unittests. | 1423 // Empty function for unittests. |
| 1424 } | 1424 } |
| 1425 | 1425 |
| 1426 void SimplePredictor::ShutdownOnUIThread() { | 1426 void SimplePredictor::ShutdownOnUIThread() { |
| 1427 SetShutdown(true); | 1427 SetShutdown(true); |
| 1428 } | 1428 } |
| 1429 | 1429 |
| 1430 } // namespace chrome_browser_net | 1430 } // namespace chrome_browser_net |
| OLD | NEW |