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 <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 1088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1099 } | 1099 } |
1100 } | 1100 } |
1101 | 1101 |
1102 void ResourcePrefetchPredictor::OnURLsDeleted( | 1102 void ResourcePrefetchPredictor::OnURLsDeleted( |
1103 history::HistoryService* history_service, | 1103 history::HistoryService* history_service, |
1104 bool all_history, | 1104 bool all_history, |
1105 bool expired, | 1105 bool expired, |
1106 const history::URLRows& deleted_rows, | 1106 const history::URLRows& deleted_rows, |
1107 const std::set<GURL>& favicon_urls) { | 1107 const std::set<GURL>& favicon_urls) { |
1108 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1108 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1109 if (INITIALIZED != initialization_state_) | 1109 DCHECK(initialization_state_ == INITIALIZED); |
1110 return; | |
1111 | 1110 |
1112 if (all_history) { | 1111 if (all_history) { |
1113 DeleteAllUrls(); | 1112 DeleteAllUrls(); |
1114 UMA_HISTOGRAM_ENUMERATION("ResourcePrefetchPredictor.ReportingEvent", | 1113 UMA_HISTOGRAM_ENUMERATION("ResourcePrefetchPredictor.ReportingEvent", |
1115 REPORTING_EVENT_ALL_HISTORY_CLEARED, | 1114 REPORTING_EVENT_ALL_HISTORY_CLEARED, |
1116 REPORTING_EVENT_COUNT); | 1115 REPORTING_EVENT_COUNT); |
1117 } else { | 1116 } else { |
1118 DeleteUrls(deleted_rows); | 1117 DeleteUrls(deleted_rows); |
1119 UMA_HISTOGRAM_ENUMERATION("ResourcePrefetchPredictor.ReportingEvent", | 1118 UMA_HISTOGRAM_ENUMERATION("ResourcePrefetchPredictor.ReportingEvent", |
1120 REPORTING_EVENT_PARTIAL_HISTORY_CLEARED, | 1119 REPORTING_EVENT_PARTIAL_HISTORY_CLEARED, |
1121 REPORTING_EVENT_COUNT); | 1120 REPORTING_EVENT_COUNT); |
1122 } | 1121 } |
1123 } | 1122 } |
1124 | 1123 |
1125 void ResourcePrefetchPredictor::OnHistoryServiceLoaded( | 1124 void ResourcePrefetchPredictor::OnHistoryServiceLoaded( |
1126 history::HistoryService* history_service) { | 1125 history::HistoryService* history_service) { |
1127 OnHistoryAndCacheLoaded(); | 1126 if (initialization_state_ == INITIALIZING) { |
1128 history_service_observer_.Remove(history_service); | 1127 OnHistoryAndCacheLoaded(); |
| 1128 } |
1129 } | 1129 } |
1130 | 1130 |
1131 void ResourcePrefetchPredictor::ConnectToHistoryService() { | 1131 void ResourcePrefetchPredictor::ConnectToHistoryService() { |
1132 // Register for HistoryServiceLoading if it is not ready. | 1132 // Register for HistoryServiceLoading if it is not ready. |
1133 history::HistoryService* history_service = | 1133 history::HistoryService* history_service = |
1134 HistoryServiceFactory::GetForProfile(profile_, | 1134 HistoryServiceFactory::GetForProfile(profile_, |
1135 ServiceAccessType::EXPLICIT_ACCESS); | 1135 ServiceAccessType::EXPLICIT_ACCESS); |
1136 if (!history_service) | 1136 if (!history_service) |
1137 return; | 1137 return; |
| 1138 DCHECK(!history_service_observer_.IsObserving(history_service)); |
| 1139 history_service_observer_.Add(history_service); |
1138 if (history_service->BackendLoaded()) { | 1140 if (history_service->BackendLoaded()) { |
1139 // HistoryService is already loaded. Continue with Initialization. | 1141 // HistoryService is already loaded. Continue with Initialization. |
1140 OnHistoryAndCacheLoaded(); | 1142 OnHistoryAndCacheLoaded(); |
1141 return; | |
1142 } | 1143 } |
1143 DCHECK(!history_service_observer_.IsObserving(history_service)); | |
1144 history_service_observer_.Add(history_service); | |
1145 return; | |
1146 } | 1144 } |
1147 | 1145 |
1148 //////////////////////////////////////////////////////////////////////////////// | 1146 //////////////////////////////////////////////////////////////////////////////// |
1149 // TestObserver. | 1147 // TestObserver. |
1150 | 1148 |
1151 TestObserver::~TestObserver() { | 1149 TestObserver::~TestObserver() { |
1152 predictor_->SetObserverForTesting(nullptr); | 1150 predictor_->SetObserverForTesting(nullptr); |
1153 } | 1151 } |
1154 | 1152 |
1155 TestObserver::TestObserver(ResourcePrefetchPredictor* predictor) | 1153 TestObserver::TestObserver(ResourcePrefetchPredictor* predictor) |
1156 : predictor_(predictor) { | 1154 : predictor_(predictor) { |
1157 predictor_->SetObserverForTesting(this); | 1155 predictor_->SetObserverForTesting(this); |
1158 } | 1156 } |
1159 | 1157 |
1160 } // namespace predictors | 1158 } // namespace predictors |
OLD | NEW |