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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 } // namespace | 62 } // namespace |
63 | 63 |
64 namespace predictors { | 64 namespace predictors { |
65 | 65 |
66 const int AutocompleteActionPredictor::kMaximumDaysToKeepEntry = 14; | 66 const int AutocompleteActionPredictor::kMaximumDaysToKeepEntry = 14; |
67 | 67 |
68 AutocompleteActionPredictor::AutocompleteActionPredictor(Profile* profile) | 68 AutocompleteActionPredictor::AutocompleteActionPredictor(Profile* profile) |
69 : profile_(profile), | 69 : profile_(profile), |
70 main_profile_predictor_(NULL), | 70 main_profile_predictor_(NULL), |
71 incognito_predictor_(NULL), | 71 incognito_predictor_(NULL), |
72 initialized_(false) { | 72 initialized_(false), |
73 history_service_observer_(this) { | |
73 if (profile_->IsOffTheRecord()) { | 74 if (profile_->IsOffTheRecord()) { |
74 main_profile_predictor_ = AutocompleteActionPredictorFactory::GetForProfile( | 75 main_profile_predictor_ = AutocompleteActionPredictorFactory::GetForProfile( |
75 profile_->GetOriginalProfile()); | 76 profile_->GetOriginalProfile()); |
76 DCHECK(main_profile_predictor_); | 77 DCHECK(main_profile_predictor_); |
77 main_profile_predictor_->incognito_predictor_ = this; | 78 main_profile_predictor_->incognito_predictor_ = this; |
78 if (main_profile_predictor_->initialized_) | 79 if (main_profile_predictor_->initialized_) |
79 CopyFromMainProfile(); | 80 CopyFromMainProfile(); |
80 } else { | 81 } else { |
81 // Request the in-memory database from the history to force it to load so | 82 // Request the in-memory database from the history to force it to load so |
82 // it's available as soon as possible. | 83 // it's available as soon as possible. |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 | 251 |
251 case chrome::NOTIFICATION_OMNIBOX_OPENED_URL: { | 252 case chrome::NOTIFICATION_OMNIBOX_OPENED_URL: { |
252 DCHECK(initialized_); | 253 DCHECK(initialized_); |
253 | 254 |
254 // TODO(dominich): This doesn't need to be synchronous. Investigate | 255 // TODO(dominich): This doesn't need to be synchronous. Investigate |
255 // posting it as a task to be run later. | 256 // posting it as a task to be run later. |
256 OnOmniboxOpenedUrl(*content::Details<OmniboxLog>(details).ptr()); | 257 OnOmniboxOpenedUrl(*content::Details<OmniboxLog>(details).ptr()); |
257 break; | 258 break; |
258 } | 259 } |
259 | 260 |
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: | 261 default: |
270 NOTREACHED() << "Unexpected notification observed."; | 262 NOTREACHED() << "Unexpected notification observed."; |
271 break; | 263 break; |
272 } | 264 } |
273 } | 265 } |
274 | 266 |
275 void AutocompleteActionPredictor::CreateLocalCachesFromDatabase() { | 267 void AutocompleteActionPredictor::CreateLocalCachesFromDatabase() { |
276 // Create local caches using the database as loaded. We will garbage collect | 268 // 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 | 269 // rows from the caches and the database once the history service is |
278 // available. | 270 // available. |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
474 db_cache_[key] = value; | 466 db_cache_[key] = value; |
475 db_id_cache_[key] = it->id; | 467 db_id_cache_[key] = it->id; |
476 } | 468 } |
477 | 469 |
478 // If the history service is ready, delete any old or invalid entries. | 470 // If the history service is ready, delete any old or invalid entries. |
479 HistoryService* history_service = | 471 HistoryService* history_service = |
480 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 472 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
481 if (!TryDeleteOldEntries(history_service)) { | 473 if (!TryDeleteOldEntries(history_service)) { |
482 // Wait for the notification that the history service is ready and the URL | 474 // Wait for the notification that the history service is ready and the URL |
483 // DB is loaded. | 475 // DB is loaded. |
484 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_LOADED, | 476 if (history_service) |
485 content::Source<Profile>(profile_)); | 477 history_service_observer_.Add(history_service); |
486 } | 478 } |
487 } | 479 } |
488 | 480 |
489 bool AutocompleteActionPredictor::TryDeleteOldEntries(HistoryService* service) { | 481 bool AutocompleteActionPredictor::TryDeleteOldEntries(HistoryService* service) { |
490 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 482 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
491 DCHECK(!profile_->IsOffTheRecord()); | 483 DCHECK(!profile_->IsOffTheRecord()); |
492 DCHECK(!initialized_); | 484 DCHECK(!initialized_); |
493 | 485 |
494 if (!service) | 486 if (!service) |
495 return false; | 487 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); | 594 const double number_of_hits = static_cast<double>(value.number_of_hits); |
603 return number_of_hits / (number_of_hits + value.number_of_misses); | 595 return number_of_hits / (number_of_hits + value.number_of_misses); |
604 } | 596 } |
605 | 597 |
606 AutocompleteActionPredictor::TransitionalMatch::TransitionalMatch() { | 598 AutocompleteActionPredictor::TransitionalMatch::TransitionalMatch() { |
607 } | 599 } |
608 | 600 |
609 AutocompleteActionPredictor::TransitionalMatch::~TransitionalMatch() { | 601 AutocompleteActionPredictor::TransitionalMatch::~TransitionalMatch() { |
610 } | 602 } |
611 | 603 |
604 void AutocompleteActionPredictor::Shutdown() { | |
brettw
2014/11/14 21:13:06
The order doesn't match the header file.
nshaik
2014/11/15 07:04:15
Done.
| |
605 history_service_observer_.RemoveAll(); | |
606 } | |
607 | |
608 void AutocompleteActionPredictor::OnHistoryServiceLoaded( | |
609 HistoryService* history_service) { | |
610 TryDeleteOldEntries(history_service); | |
611 history_service_observer_.Remove(history_service); | |
612 } | |
613 | |
612 } // namespace predictors | 614 } // namespace predictors |
OLD | NEW |