| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 main_profile_predictor_ = AutocompleteActionPredictorFactory::GetForProfile( | 75 main_profile_predictor_ = AutocompleteActionPredictorFactory::GetForProfile( |
| 76 profile_->GetOriginalProfile()); | 76 profile_->GetOriginalProfile()); |
| 77 DCHECK(main_profile_predictor_); | 77 DCHECK(main_profile_predictor_); |
| 78 main_profile_predictor_->incognito_predictor_ = this; | 78 main_profile_predictor_->incognito_predictor_ = this; |
| 79 if (main_profile_predictor_->initialized_) | 79 if (main_profile_predictor_->initialized_) |
| 80 CopyFromMainProfile(); | 80 CopyFromMainProfile(); |
| 81 } else { | 81 } else { |
| 82 // 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 |
| 83 // it's available as soon as possible. | 83 // it's available as soon as possible. |
| 84 HistoryService* history_service = HistoryServiceFactory::GetForProfile( | 84 HistoryService* history_service = HistoryServiceFactory::GetForProfile( |
| 85 profile_, Profile::EXPLICIT_ACCESS); | 85 profile_, ServiceAccessType::EXPLICIT_ACCESS); |
| 86 if (history_service) | 86 if (history_service) |
| 87 history_service->InMemoryDatabase(); | 87 history_service->InMemoryDatabase(); |
| 88 | 88 |
| 89 table_ = | 89 table_ = |
| 90 PredictorDatabaseFactory::GetForProfile(profile_)->autocomplete_table(); | 90 PredictorDatabaseFactory::GetForProfile(profile_)->autocomplete_table(); |
| 91 | 91 |
| 92 // Observe all main frame loads so we can wait for the first to complete | 92 // Observe all main frame loads so we can wait for the first to complete |
| 93 // before accessing DB and IO threads to build the local cache. | 93 // before accessing DB and IO threads to build the local cache. |
| 94 notification_registrar_.Add(this, | 94 notification_registrar_.Add(this, |
| 95 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 95 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 | 456 |
| 457 for (std::vector<AutocompleteActionPredictorTable::Row>::const_iterator it = | 457 for (std::vector<AutocompleteActionPredictorTable::Row>::const_iterator it = |
| 458 rows->begin(); it != rows->end(); ++it) { | 458 rows->begin(); it != rows->end(); ++it) { |
| 459 const DBCacheKey key = { it->user_text, it->url }; | 459 const DBCacheKey key = { it->user_text, it->url }; |
| 460 const DBCacheValue value = { it->number_of_hits, it->number_of_misses }; | 460 const DBCacheValue value = { it->number_of_hits, it->number_of_misses }; |
| 461 db_cache_[key] = value; | 461 db_cache_[key] = value; |
| 462 db_id_cache_[key] = it->id; | 462 db_id_cache_[key] = it->id; |
| 463 } | 463 } |
| 464 | 464 |
| 465 // If the history service is ready, delete any old or invalid entries. | 465 // If the history service is ready, delete any old or invalid entries. |
| 466 HistoryService* history_service = | 466 HistoryService* history_service = HistoryServiceFactory::GetForProfile( |
| 467 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 467 profile_, ServiceAccessType::EXPLICIT_ACCESS); |
| 468 if (!TryDeleteOldEntries(history_service)) { | 468 if (!TryDeleteOldEntries(history_service)) { |
| 469 // Wait for the notification that the history service is ready and the URL | 469 // Wait for the notification that the history service is ready and the URL |
| 470 // DB is loaded. | 470 // DB is loaded. |
| 471 if (history_service) | 471 if (history_service) |
| 472 history_service_observer_.Add(history_service); | 472 history_service_observer_.Add(history_service); |
| 473 } | 473 } |
| 474 } | 474 } |
| 475 | 475 |
| 476 bool AutocompleteActionPredictor::TryDeleteOldEntries(HistoryService* service) { | 476 bool AutocompleteActionPredictor::TryDeleteOldEntries(HistoryService* service) { |
| 477 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 477 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 history_service_observer_.Remove(history_service); | 600 history_service_observer_.Remove(history_service); |
| 601 } | 601 } |
| 602 | 602 |
| 603 AutocompleteActionPredictor::TransitionalMatch::TransitionalMatch() { | 603 AutocompleteActionPredictor::TransitionalMatch::TransitionalMatch() { |
| 604 } | 604 } |
| 605 | 605 |
| 606 AutocompleteActionPredictor::TransitionalMatch::~TransitionalMatch() { | 606 AutocompleteActionPredictor::TransitionalMatch::~TransitionalMatch() { |
| 607 } | 607 } |
| 608 | 608 |
| 609 } // namespace predictors | 609 } // namespace predictors |
| OLD | NEW |