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 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1025 it != referrers_.end(); ++it) | 1025 it != referrers_.end(); ++it) |
1026 urls_being_trimmed_.push_back(it->first); | 1026 urls_being_trimmed_.push_back(it->first); |
1027 UMA_HISTOGRAM_COUNTS("Net.PredictionTrimSize", urls_being_trimmed_.size()); | 1027 UMA_HISTOGRAM_COUNTS("Net.PredictionTrimSize", urls_being_trimmed_.size()); |
1028 } | 1028 } |
1029 | 1029 |
1030 void Predictor::PostIncrementalTrimTask() { | 1030 void Predictor::PostIncrementalTrimTask() { |
1031 if (urls_being_trimmed_.empty()) | 1031 if (urls_being_trimmed_.empty()) |
1032 return; | 1032 return; |
1033 const TimeDelta kDurationBetweenTrimmingIncrements = | 1033 const TimeDelta kDurationBetweenTrimmingIncrements = |
1034 TimeDelta::FromSeconds(kDurationBetweenTrimmingIncrementsSeconds); | 1034 TimeDelta::FromSeconds(kDurationBetweenTrimmingIncrementsSeconds); |
1035 MessageLoop::current()->PostDelayedTask( | 1035 base::MessageLoop::current()->PostDelayedTask( |
1036 FROM_HERE, | 1036 FROM_HERE, |
1037 base::Bind(&Predictor::IncrementalTrimReferrers, | 1037 base::Bind(&Predictor::IncrementalTrimReferrers, |
1038 weak_factory_->GetWeakPtr(), false), | 1038 weak_factory_->GetWeakPtr(), |
| 1039 false), |
1039 kDurationBetweenTrimmingIncrements); | 1040 kDurationBetweenTrimmingIncrements); |
1040 } | 1041 } |
1041 | 1042 |
1042 void Predictor::IncrementalTrimReferrers(bool trim_all_now) { | 1043 void Predictor::IncrementalTrimReferrers(bool trim_all_now) { |
1043 size_t trim_count = urls_being_trimmed_.size(); | 1044 size_t trim_count = urls_being_trimmed_.size(); |
1044 if (!trim_all_now) | 1045 if (!trim_all_now) |
1045 trim_count = std::min(trim_count, kUrlsTrimmedPerIncrement); | 1046 trim_count = std::min(trim_count, kUrlsTrimmedPerIncrement); |
1046 while (trim_count-- != 0) { | 1047 while (trim_count-- != 0) { |
1047 Referrers::iterator it = referrers_.find(urls_being_trimmed_.back()); | 1048 Referrers::iterator it = referrers_.find(urls_being_trimmed_.back()); |
1048 urls_being_trimmed_.pop_back(); | 1049 urls_being_trimmed_.pop_back(); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1186 IOThread* io_thread, | 1187 IOThread* io_thread, |
1187 net::URLRequestContextGetter* getter) { | 1188 net::URLRequestContextGetter* getter) { |
1188 // Empty function for unittests. | 1189 // Empty function for unittests. |
1189 } | 1190 } |
1190 | 1191 |
1191 void SimplePredictor::ShutdownOnUIThread(PrefService* user_prefs) { | 1192 void SimplePredictor::ShutdownOnUIThread(PrefService* user_prefs) { |
1192 SetShutdown(true); | 1193 SetShutdown(true); |
1193 } | 1194 } |
1194 | 1195 |
1195 } // namespace chrome_browser_net | 1196 } // namespace chrome_browser_net |
OLD | NEW |