| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/predictors/resource_prefetch_predictor.h" | 5 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
| 6 | 6 |
| 7 #include <algorithm> | |
| 8 #include <map> | 7 #include <map> |
| 9 #include <set> | 8 #include <set> |
| 10 #include <utility> | 9 #include <utility> |
| 11 | 10 |
| 12 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 13 #include "base/macros.h" | 12 #include "base/macros.h" |
| 14 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 15 #include "base/metrics/sparse_histogram.h" | 14 #include "base/metrics/sparse_histogram.h" |
| 16 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| (...skipping 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1054 // Trim and sort the resources after the update. | 1053 // Trim and sort the resources after the update. |
| 1055 ResourceRows& resources = cache_entry->second.resources; | 1054 ResourceRows& resources = cache_entry->second.resources; |
| 1056 for (ResourceRows::iterator it = resources.begin(); | 1055 for (ResourceRows::iterator it = resources.begin(); |
| 1057 it != resources.end();) { | 1056 it != resources.end();) { |
| 1058 it->UpdateScore(); | 1057 it->UpdateScore(); |
| 1059 if (it->consecutive_misses >= config_.max_consecutive_misses) | 1058 if (it->consecutive_misses >= config_.max_consecutive_misses) |
| 1060 it = resources.erase(it); | 1059 it = resources.erase(it); |
| 1061 else | 1060 else |
| 1062 ++it; | 1061 ++it; |
| 1063 } | 1062 } |
| 1064 std::sort(resources.begin(), resources.end(), | 1063 ResourcePrefetchPredictorTables::SortResourceRows(&resources); |
| 1065 ResourcePrefetchPredictorTables::ResourceRowSorter()); | |
| 1066 if (resources.size() > config_.max_resources_per_entry) | 1064 if (resources.size() > config_.max_resources_per_entry) |
| 1067 resources.resize(config_.max_resources_per_entry); | 1065 resources.resize(config_.max_resources_per_entry); |
| 1068 | 1066 |
| 1069 // If the row has no resources, remove it from the cache and delete the | 1067 // If the row has no resources, remove it from the cache and delete the |
| 1070 // entry in the database. Else update the database. | 1068 // entry in the database. Else update the database. |
| 1071 if (resources.empty()) { | 1069 if (resources.empty()) { |
| 1072 data_map->erase(key); | 1070 data_map->erase(key); |
| 1073 BrowserThread::PostTask( | 1071 BrowserThread::PostTask( |
| 1074 BrowserThread::DB, FROM_HERE, | 1072 BrowserThread::DB, FROM_HERE, |
| 1075 base::Bind(&ResourcePrefetchPredictorTables::DeleteSingleDataPoint, | 1073 base::Bind(&ResourcePrefetchPredictorTables::DeleteSingleDataPoint, |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1426 // HistoryService is already loaded. Continue with Initialization. | 1424 // HistoryService is already loaded. Continue with Initialization. |
| 1427 OnHistoryAndCacheLoaded(); | 1425 OnHistoryAndCacheLoaded(); |
| 1428 return; | 1426 return; |
| 1429 } | 1427 } |
| 1430 DCHECK(!history_service_observer_.IsObserving(history_service)); | 1428 DCHECK(!history_service_observer_.IsObserving(history_service)); |
| 1431 history_service_observer_.Add(history_service); | 1429 history_service_observer_.Add(history_service); |
| 1432 return; | 1430 return; |
| 1433 } | 1431 } |
| 1434 | 1432 |
| 1435 } // namespace predictors | 1433 } // namespace predictors |
| OLD | NEW |