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 <iterator> | 9 #include <iterator> |
10 #include <set> | 10 #include <set> |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 } | 535 } |
536 | 536 |
537 // Iterating through a MRUCache goes through most recent first. Iterate | 537 // Iterating through a MRUCache goes through most recent first. Iterate |
538 // backwards here so that adding items in order "Just Works" when deserializing. | 538 // backwards here so that adding items in order "Just Works" when deserializing. |
539 void Predictor::SerializeReferrers(base::ListValue* referral_list) { | 539 void Predictor::SerializeReferrers(base::ListValue* referral_list) { |
540 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 540 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
541 DCHECK(referral_list->empty()); | 541 DCHECK(referral_list->empty()); |
542 referral_list->AppendInteger(kPredictorReferrerVersion); | 542 referral_list->AppendInteger(kPredictorReferrerVersion); |
543 for (Referrers::const_reverse_iterator it = referrers_.rbegin(); | 543 for (Referrers::const_reverse_iterator it = referrers_.rbegin(); |
544 it != referrers_.rend(); ++it) { | 544 it != referrers_.rend(); ++it) { |
545 // Serialize the list of subresource names. | |
546 base::Value* subresource_list(it->second.Serialize()); | |
547 | |
548 // Create a list for each referer. | 545 // Create a list for each referer. |
549 std::unique_ptr<base::ListValue> motivator(new base::ListValue); | 546 std::unique_ptr<base::ListValue> motivator(new base::ListValue); |
550 motivator->AppendString(it->first.spec()); | 547 motivator->AppendString(it->first.spec()); |
551 motivator->Append(subresource_list); | 548 motivator->Append(it->second.Serialize()); |
552 | 549 |
553 referral_list->Append(std::move(motivator)); | 550 referral_list->Append(std::move(motivator)); |
554 } | 551 } |
555 } | 552 } |
556 | 553 |
557 void Predictor::DeserializeReferrers(const base::ListValue& referral_list) { | 554 void Predictor::DeserializeReferrers(const base::ListValue& referral_list) { |
558 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 555 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
559 int format_version = -1; | 556 int format_version = -1; |
560 if (referral_list.GetSize() > 0 && | 557 if (referral_list.GetSize() > 0 && |
561 referral_list.GetInteger(0, &format_version) && | 558 referral_list.GetInteger(0, &format_version) && |
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1199 } | 1196 } |
1200 | 1197 |
1201 void SimplePredictor::ShutdownOnUIThread() { | 1198 void SimplePredictor::ShutdownOnUIThread() { |
1202 SetShutdown(true); | 1199 SetShutdown(true); |
1203 } | 1200 } |
1204 | 1201 |
1205 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; } | 1202 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; } |
1206 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; } | 1203 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; } |
1207 | 1204 |
1208 } // namespace chrome_browser_net | 1205 } // namespace chrome_browser_net |
OLD | NEW |