Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Side by Side Diff: chrome/browser/predictors/autocomplete_action_predictor.cc

Issue 773103004: Remove NOTIFICATION_HISTORY_URLS_DELETED (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change Runloop::QuitClosure to Quit Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 const content::NotificationSource& source, 227 const content::NotificationSource& source,
230 const content::NotificationDetails& details) { 228 const content::NotificationDetails& details) {
231 switch (type) { 229 switch (type) {
232 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: 230 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME:
233 CreateLocalCachesFromDatabase(); 231 CreateLocalCachesFromDatabase();
234 notification_registrar_.Remove( 232 notification_registrar_.Remove(
235 this, 233 this,
236 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, 234 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
237 content::NotificationService::AllSources()); 235 content::NotificationService::AllSources());
238 break; 236 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: { 237 case chrome::NOTIFICATION_OMNIBOX_OPENED_URL: {
253 DCHECK(initialized_); 238 DCHECK(initialized_);
254 239
255 // TODO(dominich): This doesn't need to be synchronous. Investigate 240 // TODO(dominich): This doesn't need to be synchronous. Investigate
256 // posting it as a task to be run later. 241 // posting it as a task to be run later.
257 OnOmniboxOpenedUrl(*content::Details<OmniboxLog>(details).ptr()); 242 OnOmniboxOpenedUrl(*content::Details<OmniboxLog>(details).ptr());
258 break; 243 break;
259 } 244 }
260 245
261 default: 246 default:
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 void AutocompleteActionPredictor::FinishInitialization() { 540 void AutocompleteActionPredictor::FinishInitialization() {
556 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 541 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
557 DCHECK(!initialized_); 542 DCHECK(!initialized_);
558 543
559 // Incognito and normal profiles should listen only to omnibox notifications 544 // Incognito and normal profiles should listen only to omnibox notifications
560 // from their own profile, but both should listen to history deletions from 545 // 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 546 // the main profile, since opening the history page in either case actually
562 // opens the non-incognito history (and lets users delete from there). 547 // opens the non-incognito history (and lets users delete from there).
563 notification_registrar_.Add(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL, 548 notification_registrar_.Add(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL,
564 content::Source<Profile>(profile_)); 549 content::Source<Profile>(profile_));
565 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED,
566 content::Source<Profile>(profile_->GetOriginalProfile()));
567 initialized_ = true; 550 initialized_ = true;
568 } 551 }
569 552
570 double AutocompleteActionPredictor::CalculateConfidence( 553 double AutocompleteActionPredictor::CalculateConfidence(
571 const base::string16& user_text, 554 const base::string16& user_text,
572 const AutocompleteMatch& match, 555 const AutocompleteMatch& match,
573 bool* is_in_db) const { 556 bool* is_in_db) const {
574 const DBCacheKey key = { user_text, match.destination_url }; 557 const DBCacheKey key = { user_text, match.destination_url };
575 558
576 *is_in_db = false; 559 *is_in_db = false;
(...skipping 15 matching lines...) Expand all
592 return 0.0; 575 return 0.0;
593 576
594 const double number_of_hits = static_cast<double>(value.number_of_hits); 577 const double number_of_hits = static_cast<double>(value.number_of_hits);
595 return number_of_hits / (number_of_hits + value.number_of_misses); 578 return number_of_hits / (number_of_hits + value.number_of_misses);
596 } 579 }
597 580
598 void AutocompleteActionPredictor::Shutdown() { 581 void AutocompleteActionPredictor::Shutdown() {
599 history_service_observer_.RemoveAll(); 582 history_service_observer_.RemoveAll();
600 } 583 }
601 584
585 void AutocompleteActionPredictor::OnURLsDeleted(
586 HistoryService* history_service,
587 bool all_history,
588 bool expired,
589 const history::URLRows& deleted_rows,
590 const std::set<GURL>& favicon_urls) {
591 DCHECK(initialized_);
sky 2014/12/13 00:29:18 It looks as though the observer is added in the co
nshaik 2014/12/13 01:49:21 I wanted to replicate the exact behavior, but I ag
sky 2014/12/15 23:05:43 I'm not entirely sure that's true. Can you get a m
592 if (all_history)
593 DeleteAllRows();
594 else
595 DeleteRowsWithURLs(deleted_rows);
596 }
597
602 void AutocompleteActionPredictor::OnHistoryServiceLoaded( 598 void AutocompleteActionPredictor::OnHistoryServiceLoaded(
603 HistoryService* history_service) { 599 HistoryService* history_service) {
604 TryDeleteOldEntries(history_service); 600 TryDeleteOldEntries(history_service);
605 history_service_observer_.Remove(history_service); 601 history_service_observer_.Remove(history_service);
606 } 602 }
607 603
608 AutocompleteActionPredictor::TransitionalMatch::TransitionalMatch() { 604 AutocompleteActionPredictor::TransitionalMatch::TransitionalMatch() {
609 } 605 }
610 606
611 AutocompleteActionPredictor::TransitionalMatch::~TransitionalMatch() { 607 AutocompleteActionPredictor::TransitionalMatch::~TransitionalMatch() {
612 } 608 }
613 609
614 } // namespace predictors 610 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698