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

Side by Side Diff: chrome/browser/history/url_index_private_data.cc

Issue 352913002: Port HistoryService::ScheduleDBTask to CancelableTaskTracker (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months 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 | Annotate | Revision Log
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/history/url_index_private_data.h" 5 #include "chrome/browser/history/url_index_private_data.h"
6 6
7 #include <functional> 7 #include <functional>
8 #include <iterator> 8 #include <iterator>
9 #include <limits> 9 #include <limits>
10 #include <numeric> 10 #include <numeric>
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 } 273 }
274 } 274 }
275 275
276 return scored_items; 276 return scored_items;
277 } 277 }
278 278
279 bool URLIndexPrivateData::UpdateURL( 279 bool URLIndexPrivateData::UpdateURL(
280 HistoryService* history_service, 280 HistoryService* history_service,
281 const URLRow& row, 281 const URLRow& row,
282 const std::string& languages, 282 const std::string& languages,
283 const std::set<std::string>& scheme_whitelist) { 283 const std::set<std::string>& scheme_whitelist,
284 base::CancelableTaskTracker* tracker) {
284 // The row may or may not already be in our index. If it is not already 285 // The row may or may not already be in our index. If it is not already
285 // indexed and it qualifies then it gets indexed. If it is already 286 // indexed and it qualifies then it gets indexed. If it is already
286 // indexed and still qualifies then it gets updated, otherwise it 287 // indexed and still qualifies then it gets updated, otherwise it
287 // is deleted from the index. 288 // is deleted from the index.
288 bool row_was_updated = false; 289 bool row_was_updated = false;
289 URLID row_id = row.id(); 290 URLID row_id = row.id();
290 HistoryInfoMap::iterator row_pos = history_info_map_.find(row_id); 291 HistoryInfoMap::iterator row_pos = history_info_map_.find(row_id);
291 if (row_pos == history_info_map_.end()) { 292 if (row_pos == history_info_map_.end()) {
292 // This new row should be indexed if it qualifies. 293 // This new row should be indexed if it qualifies.
293 URLRow new_row(row); 294 URLRow new_row(row);
294 new_row.set_id(row_id); 295 new_row.set_id(row_id);
295 row_was_updated = RowQualifiesAsSignificant(new_row, base::Time()) && 296 row_was_updated = RowQualifiesAsSignificant(new_row, base::Time()) &&
296 IndexRow(NULL, history_service, new_row, languages, scheme_whitelist); 297 IndexRow(NULL, history_service, new_row, languages, scheme_whitelist, tr acker);
blundell 2014/06/26 09:55:39 nit: 80 chars?
sdefresne 2014/06/28 08:14:26 Done.
297 } else if (RowQualifiesAsSignificant(row, base::Time())) { 298 } else if (RowQualifiesAsSignificant(row, base::Time())) {
298 // This indexed row still qualifies and will be re-indexed. 299 // This indexed row still qualifies and will be re-indexed.
299 // The url won't have changed but the title, visit count, etc. 300 // The url won't have changed but the title, visit count, etc.
300 // might have changed. 301 // might have changed.
301 URLRow& row_to_update = row_pos->second.url_row; 302 URLRow& row_to_update = row_pos->second.url_row;
302 bool title_updated = row_to_update.title() != row.title(); 303 bool title_updated = row_to_update.title() != row.title();
303 if (row_to_update.visit_count() != row.visit_count() || 304 if (row_to_update.visit_count() != row.visit_count() ||
304 row_to_update.typed_count() != row.typed_count() || 305 row_to_update.typed_count() != row.typed_count() ||
305 row_to_update.last_visit() != row.last_visit() || title_updated) { 306 row_to_update.last_visit() != row.last_visit() || title_updated) {
306 row_to_update.set_visit_count(row.visit_count()); 307 row_to_update.set_visit_count(row.visit_count());
307 row_to_update.set_typed_count(row.typed_count()); 308 row_to_update.set_typed_count(row.typed_count());
308 row_to_update.set_last_visit(row.last_visit()); 309 row_to_update.set_last_visit(row.last_visit());
309 // If something appears to have changed, update the recent visits 310 // If something appears to have changed, update the recent visits
310 // information. 311 // information.
311 ScheduleUpdateRecentVisits(history_service, row_id); 312 ScheduleUpdateRecentVisits(history_service, row_id, tracker);
312 // While the URL is guaranteed to remain stable, the title may have 313 // While the URL is guaranteed to remain stable, the title may have
313 // changed. If so, then update the index with the changed words. 314 // changed. If so, then update the index with the changed words.
314 if (title_updated) { 315 if (title_updated) {
315 // Clear all words associated with this row and re-index both the 316 // Clear all words associated with this row and re-index both the
316 // URL and title. 317 // URL and title.
317 RemoveRowWordsFromIndex(row_to_update); 318 RemoveRowWordsFromIndex(row_to_update);
318 row_to_update.set_title(row.title()); 319 row_to_update.set_title(row.title());
319 RowWordStarts word_starts; 320 RowWordStarts word_starts;
320 AddRowWordsToIndex(row_to_update, &word_starts, languages); 321 AddRowWordsToIndex(row_to_update, &word_starts, languages);
321 word_starts_map_[row_id] = word_starts; 322 word_starts_map_[row_id] = word_starts;
(...skipping 28 matching lines...) Expand all
350 } 351 }
351 } 352 }
352 // Else: Oddly, the URL doesn't seem to exist in the private index. 353 // Else: Oddly, the URL doesn't seem to exist in the private index.
353 // Ignore this update. This can happen if, for instance, the user 354 // Ignore this update. This can happen if, for instance, the user
354 // removes the URL from URLIndexPrivateData before the historyDB call 355 // removes the URL from URLIndexPrivateData before the historyDB call
355 // returns. 356 // returns.
356 } 357 }
357 358
358 void URLIndexPrivateData::ScheduleUpdateRecentVisits( 359 void URLIndexPrivateData::ScheduleUpdateRecentVisits(
359 HistoryService* history_service, 360 HistoryService* history_service,
360 URLID url_id) { 361 URLID url_id,
362 base::CancelableTaskTracker* tracker) {
361 history_service->ScheduleDBTask( 363 history_service->ScheduleDBTask(
362 new UpdateRecentVisitsFromHistoryDBTask(this, url_id), 364 new UpdateRecentVisitsFromHistoryDBTask(this, url_id), tracker);
363 &recent_visits_consumer_);
364 } 365 }
365 366
366 // Helper functor for DeleteURL. 367 // Helper functor for DeleteURL.
367 class HistoryInfoMapItemHasURL { 368 class HistoryInfoMapItemHasURL {
368 public: 369 public:
369 explicit HistoryInfoMapItemHasURL(const GURL& url): url_(url) {} 370 explicit HistoryInfoMapItemHasURL(const GURL& url): url_(url) {}
370 371
371 bool operator()(const std::pair<const HistoryID, HistoryInfoMapValue>& item) { 372 bool operator()(const std::pair<const HistoryID, HistoryInfoMapValue>& item) {
372 return item.second.url_row.url() == url_; 373 return item.second.url_row.url() == url_;
373 } 374 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 base::TimeTicks beginning_time = base::TimeTicks::Now(); 439 base::TimeTicks beginning_time = base::TimeTicks::Now();
439 440
440 scoped_refptr<URLIndexPrivateData> 441 scoped_refptr<URLIndexPrivateData>
441 rebuilt_data(new URLIndexPrivateData); 442 rebuilt_data(new URLIndexPrivateData);
442 URLDatabase::URLEnumerator history_enum; 443 URLDatabase::URLEnumerator history_enum;
443 if (!history_db->InitURLEnumeratorForSignificant(&history_enum)) 444 if (!history_db->InitURLEnumeratorForSignificant(&history_enum))
444 return NULL; 445 return NULL;
445 rebuilt_data->last_time_rebuilt_from_history_ = base::Time::Now(); 446 rebuilt_data->last_time_rebuilt_from_history_ = base::Time::Now();
446 for (URLRow row; history_enum.GetNextURL(&row); ) { 447 for (URLRow row; history_enum.GetNextURL(&row); ) {
447 rebuilt_data->IndexRow(history_db, NULL, row, languages, 448 rebuilt_data->IndexRow(history_db, NULL, row, languages,
448 scheme_whitelist); 449 scheme_whitelist, NULL);
449 } 450 }
450 451
451 UMA_HISTOGRAM_TIMES("History.InMemoryURLIndexingTime", 452 UMA_HISTOGRAM_TIMES("History.InMemoryURLIndexingTime",
452 base::TimeTicks::Now() - beginning_time); 453 base::TimeTicks::Now() - beginning_time);
453 UMA_HISTOGRAM_COUNTS("History.InMemoryURLHistoryItems", 454 UMA_HISTOGRAM_COUNTS("History.InMemoryURLHistoryItems",
454 rebuilt_data->history_id_word_map_.size()); 455 rebuilt_data->history_id_word_map_.size());
455 UMA_HISTOGRAM_COUNTS_10000("History.InMemoryURLWords", 456 UMA_HISTOGRAM_COUNTS_10000("History.InMemoryURLWords",
456 rebuilt_data->word_map_.size()); 457 rebuilt_data->word_map_.size());
457 UMA_HISTOGRAM_COUNTS_10000("History.InMemoryURLChars", 458 UMA_HISTOGRAM_COUNTS_10000("History.InMemoryURLChars",
458 rebuilt_data->char_word_map_.size()); 459 rebuilt_data->char_word_map_.size());
459 return rebuilt_data; 460 return rebuilt_data;
460 } 461 }
461 462
462 // static 463 // static
463 bool URLIndexPrivateData::WritePrivateDataToCacheFileTask( 464 bool URLIndexPrivateData::WritePrivateDataToCacheFileTask(
464 scoped_refptr<URLIndexPrivateData> private_data, 465 scoped_refptr<URLIndexPrivateData> private_data,
465 const base::FilePath& file_path) { 466 const base::FilePath& file_path) {
466 DCHECK(private_data.get()); 467 DCHECK(private_data.get());
467 DCHECK(!file_path.empty()); 468 DCHECK(!file_path.empty());
468 return private_data->SaveToFile(file_path); 469 return private_data->SaveToFile(file_path);
469 } 470 }
470 471
471 void URLIndexPrivateData::CancelPendingUpdates() {
472 recent_visits_consumer_.CancelAllRequests();
473 }
474
475 scoped_refptr<URLIndexPrivateData> URLIndexPrivateData::Duplicate() const { 472 scoped_refptr<URLIndexPrivateData> URLIndexPrivateData::Duplicate() const {
476 scoped_refptr<URLIndexPrivateData> data_copy = new URLIndexPrivateData; 473 scoped_refptr<URLIndexPrivateData> data_copy = new URLIndexPrivateData;
477 data_copy->last_time_rebuilt_from_history_ = last_time_rebuilt_from_history_; 474 data_copy->last_time_rebuilt_from_history_ = last_time_rebuilt_from_history_;
478 data_copy->word_list_ = word_list_; 475 data_copy->word_list_ = word_list_;
479 data_copy->available_words_ = available_words_; 476 data_copy->available_words_ = available_words_;
480 data_copy->word_map_ = word_map_; 477 data_copy->word_map_ = word_map_;
481 data_copy->char_word_map_ = char_word_map_; 478 data_copy->char_word_map_ = char_word_map_;
482 data_copy->word_id_history_map_ = word_id_history_map_; 479 data_copy->word_id_history_map_ = word_id_history_map_;
483 data_copy->history_id_word_map_ = history_id_word_map_; 480 data_copy->history_id_word_map_ = history_id_word_map_;
484 data_copy->history_info_map_ = history_info_map_; 481 data_copy->history_info_map_ = history_info_map_;
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 } 675 }
679 } 676 }
680 return word_id_set; 677 return word_id_set;
681 } 678 }
682 679
683 bool URLIndexPrivateData::IndexRow( 680 bool URLIndexPrivateData::IndexRow(
684 HistoryDatabase* history_db, 681 HistoryDatabase* history_db,
685 HistoryService* history_service, 682 HistoryService* history_service,
686 const URLRow& row, 683 const URLRow& row,
687 const std::string& languages, 684 const std::string& languages,
688 const std::set<std::string>& scheme_whitelist) { 685 const std::set<std::string>& scheme_whitelist,
686 base::CancelableTaskTracker* tracker) {
689 const GURL& gurl(row.url()); 687 const GURL& gurl(row.url());
690 688
691 // Index only URLs with a whitelisted scheme. 689 // Index only URLs with a whitelisted scheme.
692 if (!URLSchemeIsWhitelisted(gurl, scheme_whitelist)) 690 if (!URLSchemeIsWhitelisted(gurl, scheme_whitelist))
693 return false; 691 return false;
694 692
695 URLID row_id = row.id(); 693 URLID row_id = row.id();
696 // Strip out username and password before saving and indexing. 694 // Strip out username and password before saving and indexing.
697 base::string16 url(net::FormatUrl(gurl, languages, 695 base::string16 url(net::FormatUrl(gurl, languages,
698 net::kFormatUrlOmitUsernamePassword, 696 net::kFormatUrlOmitUsernamePassword,
(...skipping 24 matching lines...) Expand all
723 // So we don't do any thread checks. 721 // So we don't do any thread checks.
724 VisitVector recent_visits; 722 VisitVector recent_visits;
725 // Make sure the private data is going to get as many recent visits as 723 // Make sure the private data is going to get as many recent visits as
726 // ScoredHistoryMatch::GetFrequency() hopes to use. 724 // ScoredHistoryMatch::GetFrequency() hopes to use.
727 DCHECK_GE(kMaxVisitsToStoreInCache, ScoredHistoryMatch::kMaxVisitsToScore); 725 DCHECK_GE(kMaxVisitsToStoreInCache, ScoredHistoryMatch::kMaxVisitsToScore);
728 if (history_db->GetMostRecentVisitsForURL(row_id, 726 if (history_db->GetMostRecentVisitsForURL(row_id,
729 kMaxVisitsToStoreInCache, 727 kMaxVisitsToStoreInCache,
730 &recent_visits)) 728 &recent_visits))
731 UpdateRecentVisits(row_id, recent_visits); 729 UpdateRecentVisits(row_id, recent_visits);
732 } else { 730 } else {
731 DCHECK(tracker);
733 DCHECK(history_service); 732 DCHECK(history_service);
734 ScheduleUpdateRecentVisits(history_service, row_id); 733 ScheduleUpdateRecentVisits(history_service, row_id, tracker);
735 } 734 }
736 735
737 return true; 736 return true;
738 } 737 }
739 738
740 void URLIndexPrivateData::AddRowWordsToIndex(const URLRow& row, 739 void URLIndexPrivateData::AddRowWordsToIndex(const URLRow& row,
741 RowWordStarts* word_starts, 740 RowWordStarts* word_starts,
742 const std::string& languages) { 741 const std::string& languages) {
743 HistoryID history_id = static_cast<HistoryID>(row.id()); 742 HistoryID history_id = static_cast<HistoryID>(row.id());
744 // Split URL into individual, unique words then add in the title words. 743 // Split URL into individual, unique words then add in the title words.
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 // recently visited (within the last 12/24 hours) as highly important. Get 1336 // recently visited (within the last 12/24 hours) as highly important. Get
1338 // input from mpearson. 1337 // input from mpearson.
1339 if (r1.typed_count() != r2.typed_count()) 1338 if (r1.typed_count() != r2.typed_count())
1340 return (r1.typed_count() > r2.typed_count()); 1339 return (r1.typed_count() > r2.typed_count());
1341 if (r1.visit_count() != r2.visit_count()) 1340 if (r1.visit_count() != r2.visit_count())
1342 return (r1.visit_count() > r2.visit_count()); 1341 return (r1.visit_count() > r2.visit_count());
1343 return (r1.last_visit() > r2.last_visit()); 1342 return (r1.last_visit() > r2.last_visit());
1344 } 1343 }
1345 1344
1346 } // namespace history 1345 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698