Chromium Code Reviews| 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/predictors/autocomplete_action_predictor.h" | 5 #include "chrome/browser/predictors/autocomplete_action_predictor.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 | 90 |
| 91 // Observe all main frame loads so we can wait for the first to complete | 91 // Observe all main frame loads so we can wait for the first to complete |
| 92 // before accessing DB and IO threads to build the local cache. | 92 // before accessing DB and IO threads to build the local cache. |
| 93 notification_registrar_.Add(this, | 93 notification_registrar_.Add(this, |
| 94 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 94 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 95 content::NotificationService::AllSources()); | 95 content::NotificationService::AllSources()); |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 | 98 |
| 99 AutocompleteActionPredictor::~AutocompleteActionPredictor() { | 99 AutocompleteActionPredictor::~AutocompleteActionPredictor() { |
| 100 HistoryService* history_service = | |
|
sdefresne
2014/09/23 08:45:09
AutocompleteActionPredictor is a KeyedService. Sho
sdefresne
2014/10/20 13:15:42
Please move the unregistration into AutocompleteAc
nshaik
2014/10/29 08:43:39
Done.
| |
| 101 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | |
| 102 if (history_service) | |
|
sdefresne
2014/10/20 13:15:42
Use ScopedObserver<>.
| |
| 103 history_service->RemoveHistoryServiceObserver(this); | |
| 100 if (main_profile_predictor_) | 104 if (main_profile_predictor_) |
| 101 main_profile_predictor_->incognito_predictor_ = NULL; | 105 main_profile_predictor_->incognito_predictor_ = NULL; |
| 102 else if (incognito_predictor_) | 106 else if (incognito_predictor_) |
| 103 incognito_predictor_->main_profile_predictor_ = NULL; | 107 incognito_predictor_->main_profile_predictor_ = NULL; |
| 104 if (prerender_handle_.get()) | 108 if (prerender_handle_.get()) |
| 105 prerender_handle_->OnCancel(); | 109 prerender_handle_->OnCancel(); |
| 106 } | 110 } |
| 107 | 111 |
| 108 void AutocompleteActionPredictor::RegisterTransitionalMatches( | 112 void AutocompleteActionPredictor::RegisterTransitionalMatches( |
| 109 const base::string16& user_text, | 113 const base::string16& user_text, |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 | 254 |
| 251 case chrome::NOTIFICATION_OMNIBOX_OPENED_URL: { | 255 case chrome::NOTIFICATION_OMNIBOX_OPENED_URL: { |
| 252 DCHECK(initialized_); | 256 DCHECK(initialized_); |
| 253 | 257 |
| 254 // TODO(dominich): This doesn't need to be synchronous. Investigate | 258 // TODO(dominich): This doesn't need to be synchronous. Investigate |
| 255 // posting it as a task to be run later. | 259 // posting it as a task to be run later. |
| 256 OnOmniboxOpenedUrl(*content::Details<OmniboxLog>(details).ptr()); | 260 OnOmniboxOpenedUrl(*content::Details<OmniboxLog>(details).ptr()); |
| 257 break; | 261 break; |
| 258 } | 262 } |
| 259 | 263 |
| 260 case chrome::NOTIFICATION_HISTORY_LOADED: { | |
| 261 TryDeleteOldEntries(content::Details<HistoryService>(details).ptr()); | |
| 262 | |
| 263 notification_registrar_.Remove(this, | |
| 264 chrome::NOTIFICATION_HISTORY_LOADED, | |
| 265 content::Source<Profile>(profile_)); | |
| 266 break; | |
| 267 } | |
| 268 | |
| 269 default: | 264 default: |
| 270 NOTREACHED() << "Unexpected notification observed."; | 265 NOTREACHED() << "Unexpected notification observed."; |
| 271 break; | 266 break; |
| 272 } | 267 } |
| 273 } | 268 } |
| 274 | 269 |
| 275 void AutocompleteActionPredictor::CreateLocalCachesFromDatabase() { | 270 void AutocompleteActionPredictor::CreateLocalCachesFromDatabase() { |
| 276 // Create local caches using the database as loaded. We will garbage collect | 271 // Create local caches using the database as loaded. We will garbage collect |
| 277 // rows from the caches and the database once the history service is | 272 // rows from the caches and the database once the history service is |
| 278 // available. | 273 // available. |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 474 db_cache_[key] = value; | 469 db_cache_[key] = value; |
| 475 db_id_cache_[key] = it->id; | 470 db_id_cache_[key] = it->id; |
| 476 } | 471 } |
| 477 | 472 |
| 478 // If the history service is ready, delete any old or invalid entries. | 473 // If the history service is ready, delete any old or invalid entries. |
| 479 HistoryService* history_service = | 474 HistoryService* history_service = |
| 480 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 475 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 481 if (!TryDeleteOldEntries(history_service)) { | 476 if (!TryDeleteOldEntries(history_service)) { |
| 482 // Wait for the notification that the history service is ready and the URL | 477 // Wait for the notification that the history service is ready and the URL |
| 483 // DB is loaded. | 478 // DB is loaded. |
| 484 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_LOADED, | 479 history_service->AddHistoryServiceObserver(this); |
| 485 content::Source<Profile>(profile_)); | |
| 486 } | 480 } |
| 487 } | 481 } |
| 488 | 482 |
| 489 bool AutocompleteActionPredictor::TryDeleteOldEntries(HistoryService* service) { | 483 bool AutocompleteActionPredictor::TryDeleteOldEntries(HistoryService* service) { |
| 490 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 484 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 491 DCHECK(!profile_->IsOffTheRecord()); | 485 DCHECK(!profile_->IsOffTheRecord()); |
| 492 DCHECK(!initialized_); | 486 DCHECK(!initialized_); |
| 493 | 487 |
| 494 if (!service) | 488 if (!service) |
| 495 return false; | 489 return false; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 602 const double number_of_hits = static_cast<double>(value.number_of_hits); | 596 const double number_of_hits = static_cast<double>(value.number_of_hits); |
| 603 return number_of_hits / (number_of_hits + value.number_of_misses); | 597 return number_of_hits / (number_of_hits + value.number_of_misses); |
| 604 } | 598 } |
| 605 | 599 |
| 606 AutocompleteActionPredictor::TransitionalMatch::TransitionalMatch() { | 600 AutocompleteActionPredictor::TransitionalMatch::TransitionalMatch() { |
| 607 } | 601 } |
| 608 | 602 |
| 609 AutocompleteActionPredictor::TransitionalMatch::~TransitionalMatch() { | 603 AutocompleteActionPredictor::TransitionalMatch::~TransitionalMatch() { |
| 610 } | 604 } |
| 611 | 605 |
| 606 void AutocompleteActionPredictor::HistoryServiceLoaded( | |
| 607 HistoryService* history_service) { | |
| 608 TryDeleteOldEntries(history_service); | |
| 609 history_service->RemoveHistoryServiceObserver(this); | |
| 610 } | |
| 611 | |
| 612 } // namespace predictors | 612 } // namespace predictors |
| OLD | NEW |