| Index: chrome/browser/predictors/resource_prefetch_predictor.cc
|
| diff --git a/chrome/browser/predictors/resource_prefetch_predictor.cc b/chrome/browser/predictors/resource_prefetch_predictor.cc
|
| index 1058a91590d2c153fdf3b8c5ac564e43d9441521..68db96e451dc87701bf384d55a1ce8ad5ef62e43 100644
|
| --- a/chrome/browser/predictors/resource_prefetch_predictor.cc
|
| +++ b/chrome/browser/predictors/resource_prefetch_predictor.cc
|
| @@ -15,8 +15,6 @@
|
| #include "base/strings/string_number_conversions.h"
|
| #include "base/strings/stringprintf.h"
|
| #include "base/time/time.h"
|
| -#include "chrome/browser/chrome_notification_types.h"
|
| -#include "chrome/browser/history/history_notifications.h"
|
| #include "chrome/browser/history/history_service.h"
|
| #include "chrome/browser/history/history_service_factory.h"
|
| #include "chrome/browser/predictors/predictor_database.h"
|
| @@ -29,9 +27,6 @@
|
| #include "components/history/core/browser/history_db_task.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "content/public/browser/navigation_controller.h"
|
| -#include "content/public/browser/notification_service.h"
|
| -#include "content/public/browser/notification_source.h"
|
| -#include "content/public/browser/notification_types.h"
|
| #include "content/public/browser/resource_request_info.h"
|
| #include "content/public/browser/web_contents.h"
|
| #include "net/base/mime_util.h"
|
| @@ -437,43 +432,12 @@ void ResourcePrefetchPredictor::FinishedPrefetchForNavigation(
|
| }
|
| }
|
|
|
| -void ResourcePrefetchPredictor::Observe(
|
| - int type,
|
| - const content::NotificationSource& source,
|
| - const content::NotificationDetails& details) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| -
|
| - switch (type) {
|
| - case chrome::NOTIFICATION_HISTORY_URLS_DELETED: {
|
| - DCHECK_EQ(initialization_state_, INITIALIZED);
|
| - const content::Details<const history::URLsDeletedDetails>
|
| - urls_deleted_details =
|
| - content::Details<const history::URLsDeletedDetails>(details);
|
| - if (urls_deleted_details->all_history) {
|
| - DeleteAllUrls();
|
| - UMA_HISTOGRAM_ENUMERATION("ResourcePrefetchPredictor.ReportingEvent",
|
| - REPORTING_EVENT_ALL_HISTORY_CLEARED,
|
| - REPORTING_EVENT_COUNT);
|
| - } else {
|
| - DeleteUrls(urls_deleted_details->rows);
|
| - UMA_HISTOGRAM_ENUMERATION("ResourcePrefetchPredictor.ReportingEvent",
|
| - REPORTING_EVENT_PARTIAL_HISTORY_CLEARED,
|
| - REPORTING_EVENT_COUNT);
|
| - }
|
| - break;
|
| - }
|
| -
|
| - default:
|
| - NOTREACHED() << "Unexpected notification observed.";
|
| - break;
|
| - }
|
| -}
|
| -
|
| void ResourcePrefetchPredictor::Shutdown() {
|
| if (prefetch_manager_.get()) {
|
| prefetch_manager_->ShutdownOnUIThread();
|
| prefetch_manager_ = NULL;
|
| }
|
| + history_service_observer_.RemoveAll();
|
| }
|
|
|
| void ResourcePrefetchPredictor::OnMainFrameRequest(
|
| @@ -709,7 +673,7 @@ void ResourcePrefetchPredictor::StopPrefetching(
|
| void ResourcePrefetchPredictor::StartInitialization() {
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
|
|
| - DCHECK_EQ(initialization_state_, NOT_INITIALIZED);
|
| + DCHECK_EQ(NOT_INITIALIZED, initialization_state_);
|
| initialization_state_ = INITIALIZING;
|
|
|
| // Create local caches using the database as loaded.
|
| @@ -731,7 +695,7 @@ void ResourcePrefetchPredictor::CreateCaches(
|
| scoped_ptr<PrefetchDataMap> host_data_map) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
|
|
| - DCHECK_EQ(initialization_state_, INITIALIZING);
|
| + DCHECK_EQ(INITIALIZING, initialization_state_);
|
| DCHECK(!url_table_cache_);
|
| DCHECK(!host_table_cache_);
|
| DCHECK(inflight_navigations_.empty());
|
| @@ -749,19 +713,13 @@ void ResourcePrefetchPredictor::CreateCaches(
|
|
|
| void ResourcePrefetchPredictor::OnHistoryAndCacheLoaded() {
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| - DCHECK_EQ(initialization_state_, INITIALIZING);
|
| -
|
| - notification_registrar_.Add(this,
|
| - chrome::NOTIFICATION_HISTORY_URLS_DELETED,
|
| - content::Source<Profile>(profile_));
|
| + DCHECK_EQ(INITIALIZING, initialization_state_);
|
|
|
| // Initialize the prefetch manager only if prefetching is enabled.
|
| if (config_.IsPrefetchingEnabled(profile_)) {
|
| prefetch_manager_ = new ResourcePrefetcherManager(
|
| this, config_, profile_->GetRequestContext());
|
| }
|
| -
|
| - history_service_observer_.RemoveAll();
|
| initialization_state_ = INITIALIZED;
|
| }
|
|
|
| @@ -807,15 +765,14 @@ void ResourcePrefetchPredictor::DeleteUrls(const history::URLRows& urls) {
|
| // in the cache.
|
| std::vector<std::string> urls_to_delete, hosts_to_delete;
|
|
|
| - for (history::URLRows::const_iterator it = urls.begin(); it != urls.end();
|
| - ++it) {
|
| - const std::string url_spec = it->url().spec();
|
| + for (const auto& it : urls) {
|
| + const std::string& url_spec = it.url().spec();
|
| if (url_table_cache_->find(url_spec) != url_table_cache_->end()) {
|
| urls_to_delete.push_back(url_spec);
|
| url_table_cache_->erase(url_spec);
|
| }
|
|
|
| - const std::string host = it->url().host();
|
| + const std::string& host = it.url().host();
|
| if (host_table_cache_->find(host) != host_table_cache_->end()) {
|
| hosts_to_delete.push_back(host);
|
| host_table_cache_->erase(host);
|
| @@ -1339,6 +1296,29 @@ void ResourcePrefetchPredictor::ReportPredictedAccuracyStatsHelper(
|
| #undef RPP_PREDICTED_HISTOGRAM_COUNTS
|
| }
|
|
|
| +void ResourcePrefetchPredictor::OnURLsDeleted(
|
| + HistoryService* history_service,
|
| + bool all_history,
|
| + bool expired,
|
| + const history::URLRows& deleted_rows,
|
| + const std::set<GURL>& favicon_urls) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| + if (INITIALIZED != initialization_state_)
|
| + return;
|
| +
|
| + if (all_history) {
|
| + DeleteAllUrls();
|
| + UMA_HISTOGRAM_ENUMERATION("ResourcePrefetchPredictor.ReportingEvent",
|
| + REPORTING_EVENT_ALL_HISTORY_CLEARED,
|
| + REPORTING_EVENT_COUNT);
|
| + } else {
|
| + DeleteUrls(deleted_rows);
|
| + UMA_HISTOGRAM_ENUMERATION("ResourcePrefetchPredictor.ReportingEvent",
|
| + REPORTING_EVENT_PARTIAL_HISTORY_CLEARED,
|
| + REPORTING_EVENT_COUNT);
|
| + }
|
| +}
|
| +
|
| void ResourcePrefetchPredictor::OnHistoryServiceLoaded(
|
| HistoryService* history_service) {
|
| OnHistoryAndCacheLoaded();
|
|
|