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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/guid.h" | 12 #include "base/guid.h" |
13 #include "base/i18n/case_conversion.h" | 13 #include "base/i18n/case_conversion.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "chrome/browser/chrome_notification_types.h" | 18 #include "chrome/browser/chrome_notification_types.h" |
19 #include "chrome/browser/history/history_notifications.h" | |
20 #include "chrome/browser/history/history_service.h" | 19 #include "chrome/browser/history/history_service.h" |
21 #include "chrome/browser/history/history_service_factory.h" | 20 #include "chrome/browser/history/history_service_factory.h" |
22 #include "chrome/browser/omnibox/omnibox_log.h" | 21 #include "chrome/browser/omnibox/omnibox_log.h" |
23 #include "chrome/browser/predictors/autocomplete_action_predictor_factory.h" | 22 #include "chrome/browser/predictors/autocomplete_action_predictor_factory.h" |
24 #include "chrome/browser/predictors/predictor_database.h" | 23 #include "chrome/browser/predictors/predictor_database.h" |
25 #include "chrome/browser/predictors/predictor_database_factory.h" | 24 #include "chrome/browser/predictors/predictor_database_factory.h" |
26 #include "chrome/browser/prerender/prerender_field_trial.h" | 25 #include "chrome/browser/prerender/prerender_field_trial.h" |
27 #include "chrome/browser/prerender/prerender_handle.h" | 26 #include "chrome/browser/prerender/prerender_handle.h" |
28 #include "chrome/browser/prerender/prerender_manager.h" | 27 #include "chrome/browser/prerender/prerender_manager.h" |
29 #include "chrome/browser/prerender/prerender_manager_factory.h" | 28 #include "chrome/browser/prerender/prerender_manager_factory.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 std::find(transitional_matches_.begin(), transitional_matches_.end(), | 117 std::find(transitional_matches_.begin(), transitional_matches_.end(), |
119 lower_user_text); | 118 lower_user_text); |
120 | 119 |
121 if (match_it == transitional_matches_.end()) { | 120 if (match_it == transitional_matches_.end()) { |
122 TransitionalMatch transitional_match; | 121 TransitionalMatch transitional_match; |
123 transitional_match.user_text = lower_user_text; | 122 transitional_match.user_text = lower_user_text; |
124 match_it = transitional_matches_.insert(transitional_matches_.end(), | 123 match_it = transitional_matches_.insert(transitional_matches_.end(), |
125 transitional_match); | 124 transitional_match); |
126 } | 125 } |
127 | 126 |
128 for (AutocompleteResult::const_iterator i(result.begin()); i != result.end(); | 127 for (const auto& i : result) { |
129 ++i) { | |
130 if (std::find(match_it->urls.begin(), match_it->urls.end(), | 128 if (std::find(match_it->urls.begin(), match_it->urls.end(), |
131 i->destination_url) == match_it->urls.end()) { | 129 i.destination_url) == match_it->urls.end()) { |
132 match_it->urls.push_back(i->destination_url); | 130 match_it->urls.push_back(i.destination_url); |
133 } | 131 } |
134 } | 132 } |
135 } | 133 } |
136 | 134 |
137 void AutocompleteActionPredictor::ClearTransitionalMatches() { | 135 void AutocompleteActionPredictor::ClearTransitionalMatches() { |
138 transitional_matches_.clear(); | 136 transitional_matches_.clear(); |
139 } | 137 } |
140 | 138 |
141 void AutocompleteActionPredictor::CancelPrerender() { | 139 void AutocompleteActionPredictor::CancelPrerender() { |
142 // If the prerender has already been abandoned, leave it to its own timeout; | 140 // If the prerender has already been abandoned, leave it to its own timeout; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 const content::NotificationSource& source, | 222 const content::NotificationSource& source, |
225 const content::NotificationDetails& details) { | 223 const content::NotificationDetails& details) { |
226 switch (type) { | 224 switch (type) { |
227 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: | 225 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: |
228 CreateLocalCachesFromDatabase(); | 226 CreateLocalCachesFromDatabase(); |
229 notification_registrar_.Remove( | 227 notification_registrar_.Remove( |
230 this, | 228 this, |
231 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 229 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
232 content::NotificationService::AllSources()); | 230 content::NotificationService::AllSources()); |
233 break; | 231 break; |
234 | |
235 case chrome::NOTIFICATION_HISTORY_URLS_DELETED: { | |
236 DCHECK(initialized_); | |
237 const content::Details<const history::URLsDeletedDetails> | |
238 urls_deleted_details = | |
239 content::Details<const history::URLsDeletedDetails>(details); | |
240 if (urls_deleted_details->all_history) | |
241 DeleteAllRows(); | |
242 else | |
243 DeleteRowsWithURLs(urls_deleted_details->rows); | |
244 break; | |
245 } | |
246 | |
247 case chrome::NOTIFICATION_OMNIBOX_OPENED_URL: { | 232 case chrome::NOTIFICATION_OMNIBOX_OPENED_URL: { |
248 DCHECK(initialized_); | 233 DCHECK(initialized_); |
249 | 234 |
250 // TODO(dominich): This doesn't need to be synchronous. Investigate | 235 // TODO(dominich): This doesn't need to be synchronous. Investigate |
251 // posting it as a task to be run later. | 236 // posting it as a task to be run later. |
252 OnOmniboxOpenedUrl(*content::Details<OmniboxLog>(details).ptr()); | 237 OnOmniboxOpenedUrl(*content::Details<OmniboxLog>(details).ptr()); |
253 break; | 238 break; |
254 } | 239 } |
255 | 240 |
256 default: | 241 default: |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 void AutocompleteActionPredictor::FinishInitialization() { | 535 void AutocompleteActionPredictor::FinishInitialization() { |
551 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 536 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
552 DCHECK(!initialized_); | 537 DCHECK(!initialized_); |
553 | 538 |
554 // Incognito and normal profiles should listen only to omnibox notifications | 539 // Incognito and normal profiles should listen only to omnibox notifications |
555 // from their own profile, but both should listen to history deletions from | 540 // from their own profile, but both should listen to history deletions from |
556 // the main profile, since opening the history page in either case actually | 541 // the main profile, since opening the history page in either case actually |
557 // opens the non-incognito history (and lets users delete from there). | 542 // opens the non-incognito history (and lets users delete from there). |
558 notification_registrar_.Add(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL, | 543 notification_registrar_.Add(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL, |
559 content::Source<Profile>(profile_)); | 544 content::Source<Profile>(profile_)); |
560 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, | |
561 content::Source<Profile>(profile_->GetOriginalProfile())); | |
562 initialized_ = true; | 545 initialized_ = true; |
563 } | 546 } |
564 | 547 |
565 double AutocompleteActionPredictor::CalculateConfidence( | 548 double AutocompleteActionPredictor::CalculateConfidence( |
566 const base::string16& user_text, | 549 const base::string16& user_text, |
567 const AutocompleteMatch& match, | 550 const AutocompleteMatch& match, |
568 bool* is_in_db) const { | 551 bool* is_in_db) const { |
569 const DBCacheKey key = { user_text, match.destination_url }; | 552 const DBCacheKey key = { user_text, match.destination_url }; |
570 | 553 |
571 *is_in_db = false; | 554 *is_in_db = false; |
(...skipping 15 matching lines...) Expand all Loading... |
587 return 0.0; | 570 return 0.0; |
588 | 571 |
589 const double number_of_hits = static_cast<double>(value.number_of_hits); | 572 const double number_of_hits = static_cast<double>(value.number_of_hits); |
590 return number_of_hits / (number_of_hits + value.number_of_misses); | 573 return number_of_hits / (number_of_hits + value.number_of_misses); |
591 } | 574 } |
592 | 575 |
593 void AutocompleteActionPredictor::Shutdown() { | 576 void AutocompleteActionPredictor::Shutdown() { |
594 history_service_observer_.RemoveAll(); | 577 history_service_observer_.RemoveAll(); |
595 } | 578 } |
596 | 579 |
| 580 void AutocompleteActionPredictor::OnURLsDeleted( |
| 581 HistoryService* history_service, |
| 582 bool all_history, |
| 583 bool expired, |
| 584 const history::URLRows& deleted_rows, |
| 585 const std::set<GURL>& favicon_urls) { |
| 586 if (!initialized_) |
| 587 return; |
| 588 |
| 589 if (all_history) |
| 590 DeleteAllRows(); |
| 591 else |
| 592 DeleteRowsWithURLs(deleted_rows); |
| 593 } |
| 594 |
597 void AutocompleteActionPredictor::OnHistoryServiceLoaded( | 595 void AutocompleteActionPredictor::OnHistoryServiceLoaded( |
598 HistoryService* history_service) { | 596 HistoryService* history_service) { |
599 TryDeleteOldEntries(history_service); | 597 TryDeleteOldEntries(history_service); |
600 history_service_observer_.Remove(history_service); | 598 history_service_observer_.Remove(history_service); |
601 } | 599 } |
602 | 600 |
603 AutocompleteActionPredictor::TransitionalMatch::TransitionalMatch() { | 601 AutocompleteActionPredictor::TransitionalMatch::TransitionalMatch() { |
604 } | 602 } |
605 | 603 |
606 AutocompleteActionPredictor::TransitionalMatch::~TransitionalMatch() { | 604 AutocompleteActionPredictor::TransitionalMatch::~TransitionalMatch() { |
607 } | 605 } |
608 | 606 |
609 } // namespace predictors | 607 } // namespace predictors |
OLD | NEW |