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 1125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1136 } else { | 1136 } else { |
1137 DeleteUrls(deleted_rows); | 1137 DeleteUrls(deleted_rows); |
1138 UMA_HISTOGRAM_ENUMERATION("ResourcePrefetchPredictor.ReportingEvent", | 1138 UMA_HISTOGRAM_ENUMERATION("ResourcePrefetchPredictor.ReportingEvent", |
1139 REPORTING_EVENT_PARTIAL_HISTORY_CLEARED, | 1139 REPORTING_EVENT_PARTIAL_HISTORY_CLEARED, |
1140 REPORTING_EVENT_COUNT); | 1140 REPORTING_EVENT_COUNT); |
1141 } | 1141 } |
1142 } | 1142 } |
1143 | 1143 |
1144 void ResourcePrefetchPredictor::OnHistoryServiceLoaded( | 1144 void ResourcePrefetchPredictor::OnHistoryServiceLoaded( |
1145 history::HistoryService* history_service) { | 1145 history::HistoryService* history_service) { |
1146 OnHistoryAndCacheLoaded(); | 1146 if (initialization_state_ == INITIALIZING) { |
1147 history_service_observer_.Remove(history_service); | 1147 OnHistoryAndCacheLoaded(); |
pasko
2016/11/29 18:01:00
Would it be possible for HistoryServiceFactory::Ge
dullweber
2016/11/30 11:49:21
I added this check for the same rare reason as for
| |
1148 } | |
1148 } | 1149 } |
1149 | 1150 |
1150 void ResourcePrefetchPredictor::ConnectToHistoryService() { | 1151 void ResourcePrefetchPredictor::ConnectToHistoryService() { |
1151 // Register for HistoryServiceLoading if it is not ready. | 1152 // Register for HistoryServiceLoading if it is not ready. |
1152 history::HistoryService* history_service = | 1153 history::HistoryService* history_service = |
1153 HistoryServiceFactory::GetForProfile(profile_, | 1154 HistoryServiceFactory::GetForProfile(profile_, |
1154 ServiceAccessType::EXPLICIT_ACCESS); | 1155 ServiceAccessType::EXPLICIT_ACCESS); |
1155 if (!history_service) | 1156 if (!history_service) |
1156 return; | 1157 return; |
1158 DCHECK(!history_service_observer_.IsObserving(history_service)); | |
1159 history_service_observer_.Add(history_service); | |
1157 if (history_service->BackendLoaded()) { | 1160 if (history_service->BackendLoaded()) { |
1158 // HistoryService is already loaded. Continue with Initialization. | 1161 // HistoryService is already loaded. Continue with Initialization. |
1159 OnHistoryAndCacheLoaded(); | 1162 OnHistoryAndCacheLoaded(); |
1160 return; | |
1161 } | 1163 } |
1162 DCHECK(!history_service_observer_.IsObserving(history_service)); | |
1163 history_service_observer_.Add(history_service); | |
1164 return; | |
1165 } | 1164 } |
1166 | 1165 |
1167 //////////////////////////////////////////////////////////////////////////////// | 1166 //////////////////////////////////////////////////////////////////////////////// |
1168 // TestObserver. | 1167 // TestObserver. |
1169 | 1168 |
1170 TestObserver::~TestObserver() { | 1169 TestObserver::~TestObserver() { |
1171 predictor_->SetObserverForTesting(nullptr); | 1170 predictor_->SetObserverForTesting(nullptr); |
1172 } | 1171 } |
1173 | 1172 |
1174 TestObserver::TestObserver(ResourcePrefetchPredictor* predictor) | 1173 TestObserver::TestObserver(ResourcePrefetchPredictor* predictor) |
1175 : predictor_(predictor) { | 1174 : predictor_(predictor) { |
1176 predictor_->SetObserverForTesting(this); | 1175 predictor_->SetObserverForTesting(this); |
1177 } | 1176 } |
1178 | 1177 |
1179 } // namespace predictors | 1178 } // namespace predictors |
OLD | NEW |