| 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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 const content::NotificationSource& source, | 229 const content::NotificationSource& source, |
| 230 const content::NotificationDetails& details) { | 230 const content::NotificationDetails& details) { |
| 231 switch (type) { | 231 switch (type) { |
| 232 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: | 232 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: |
| 233 CreateLocalCachesFromDatabase(); | 233 CreateLocalCachesFromDatabase(); |
| 234 notification_registrar_.Remove( | 234 notification_registrar_.Remove( |
| 235 this, | 235 this, |
| 236 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 236 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 237 content::NotificationService::AllSources()); | 237 content::NotificationService::AllSources()); |
| 238 break; | 238 break; |
| 239 | |
| 240 case chrome::NOTIFICATION_HISTORY_URLS_DELETED: { | |
| 241 DCHECK(initialized_); | |
| 242 const content::Details<const history::URLsDeletedDetails> | |
| 243 urls_deleted_details = | |
| 244 content::Details<const history::URLsDeletedDetails>(details); | |
| 245 if (urls_deleted_details->all_history) | |
| 246 DeleteAllRows(); | |
| 247 else | |
| 248 DeleteRowsWithURLs(urls_deleted_details->rows); | |
| 249 break; | |
| 250 } | |
| 251 | |
| 252 case chrome::NOTIFICATION_OMNIBOX_OPENED_URL: { | 239 case chrome::NOTIFICATION_OMNIBOX_OPENED_URL: { |
| 253 DCHECK(initialized_); | 240 DCHECK(initialized_); |
| 254 | 241 |
| 255 // TODO(dominich): This doesn't need to be synchronous. Investigate | 242 // TODO(dominich): This doesn't need to be synchronous. Investigate |
| 256 // posting it as a task to be run later. | 243 // posting it as a task to be run later. |
| 257 OnOmniboxOpenedUrl(*content::Details<OmniboxLog>(details).ptr()); | 244 OnOmniboxOpenedUrl(*content::Details<OmniboxLog>(details).ptr()); |
| 258 break; | 245 break; |
| 259 } | 246 } |
| 260 | 247 |
| 261 default: | 248 default: |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 void AutocompleteActionPredictor::FinishInitialization() { | 542 void AutocompleteActionPredictor::FinishInitialization() { |
| 556 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 543 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 557 DCHECK(!initialized_); | 544 DCHECK(!initialized_); |
| 558 | 545 |
| 559 // Incognito and normal profiles should listen only to omnibox notifications | 546 // Incognito and normal profiles should listen only to omnibox notifications |
| 560 // from their own profile, but both should listen to history deletions from | 547 // from their own profile, but both should listen to history deletions from |
| 561 // the main profile, since opening the history page in either case actually | 548 // the main profile, since opening the history page in either case actually |
| 562 // opens the non-incognito history (and lets users delete from there). | 549 // opens the non-incognito history (and lets users delete from there). |
| 563 notification_registrar_.Add(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL, | 550 notification_registrar_.Add(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL, |
| 564 content::Source<Profile>(profile_)); | 551 content::Source<Profile>(profile_)); |
| 565 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, | |
| 566 content::Source<Profile>(profile_->GetOriginalProfile())); | |
| 567 initialized_ = true; | 552 initialized_ = true; |
| 568 } | 553 } |
| 569 | 554 |
| 570 double AutocompleteActionPredictor::CalculateConfidence( | 555 double AutocompleteActionPredictor::CalculateConfidence( |
| 571 const base::string16& user_text, | 556 const base::string16& user_text, |
| 572 const AutocompleteMatch& match, | 557 const AutocompleteMatch& match, |
| 573 bool* is_in_db) const { | 558 bool* is_in_db) const { |
| 574 const DBCacheKey key = { user_text, match.destination_url }; | 559 const DBCacheKey key = { user_text, match.destination_url }; |
| 575 | 560 |
| 576 *is_in_db = false; | 561 *is_in_db = false; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 592 return 0.0; | 577 return 0.0; |
| 593 | 578 |
| 594 const double number_of_hits = static_cast<double>(value.number_of_hits); | 579 const double number_of_hits = static_cast<double>(value.number_of_hits); |
| 595 return number_of_hits / (number_of_hits + value.number_of_misses); | 580 return number_of_hits / (number_of_hits + value.number_of_misses); |
| 596 } | 581 } |
| 597 | 582 |
| 598 void AutocompleteActionPredictor::Shutdown() { | 583 void AutocompleteActionPredictor::Shutdown() { |
| 599 history_service_observer_.RemoveAll(); | 584 history_service_observer_.RemoveAll(); |
| 600 } | 585 } |
| 601 | 586 |
| 587 void AutocompleteActionPredictor::OnURLsDeleted( |
| 588 HistoryService* history_service, |
| 589 const history::URLsDeletedDetails& deleted_details) { |
| 590 DCHECK(initialized_); |
| 591 if (deleted_details.all_history) |
| 592 DeleteAllRows(); |
| 593 else |
| 594 DeleteRowsWithURLs(deleted_details.rows); |
| 595 } |
| 596 |
| 602 void AutocompleteActionPredictor::OnHistoryServiceLoaded( | 597 void AutocompleteActionPredictor::OnHistoryServiceLoaded( |
| 603 HistoryService* history_service) { | 598 HistoryService* history_service) { |
| 604 TryDeleteOldEntries(history_service); | 599 TryDeleteOldEntries(history_service); |
| 605 history_service_observer_.Remove(history_service); | 600 history_service_observer_.Remove(history_service); |
| 606 } | 601 } |
| 607 | 602 |
| 608 AutocompleteActionPredictor::TransitionalMatch::TransitionalMatch() { | 603 AutocompleteActionPredictor::TransitionalMatch::TransitionalMatch() { |
| 609 } | 604 } |
| 610 | 605 |
| 611 AutocompleteActionPredictor::TransitionalMatch::~TransitionalMatch() { | 606 AutocompleteActionPredictor::TransitionalMatch::~TransitionalMatch() { |
| 612 } | 607 } |
| 613 | 608 |
| 614 } // namespace predictors | 609 } // namespace predictors |
| OLD | NEW |