| 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/history/url_index_private_data.h" | 5 #include "chrome/browser/history/url_index_private_data.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <iterator> | 9 #include <iterator> |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 if (!history_db) | 437 if (!history_db) |
| 438 return NULL; | 438 return NULL; |
| 439 | 439 |
| 440 base::TimeTicks beginning_time = base::TimeTicks::Now(); | 440 base::TimeTicks beginning_time = base::TimeTicks::Now(); |
| 441 | 441 |
| 442 scoped_refptr<URLIndexPrivateData> | 442 scoped_refptr<URLIndexPrivateData> |
| 443 rebuilt_data(new URLIndexPrivateData); | 443 rebuilt_data(new URLIndexPrivateData); |
| 444 URLDatabase::URLEnumerator history_enum; | 444 URLDatabase::URLEnumerator history_enum; |
| 445 if (!history_db->InitURLEnumeratorForSignificant(&history_enum)) | 445 if (!history_db->InitURLEnumeratorForSignificant(&history_enum)) |
| 446 return NULL; | 446 return NULL; |
| 447 rebuilt_data->last_time_rebuilt_from_history_ = base::Time::Now(); |
| 447 for (URLRow row; history_enum.GetNextURL(&row); ) { | 448 for (URLRow row; history_enum.GetNextURL(&row); ) { |
| 448 rebuilt_data->IndexRow(history_db, NULL, row, languages, | 449 rebuilt_data->IndexRow(history_db, NULL, row, languages, |
| 449 scheme_whitelist); | 450 scheme_whitelist); |
| 450 } | 451 } |
| 451 | 452 |
| 452 UMA_HISTOGRAM_TIMES("History.InMemoryURLIndexingTime", | 453 UMA_HISTOGRAM_TIMES("History.InMemoryURLIndexingTime", |
| 453 base::TimeTicks::Now() - beginning_time); | 454 base::TimeTicks::Now() - beginning_time); |
| 454 UMA_HISTOGRAM_COUNTS("History.InMemoryURLHistoryItems", | 455 UMA_HISTOGRAM_COUNTS("History.InMemoryURLHistoryItems", |
| 455 rebuilt_data->history_id_word_map_.size()); | 456 rebuilt_data->history_id_word_map_.size()); |
| 456 UMA_HISTOGRAM_COUNTS_10000("History.InMemoryURLWords", | 457 UMA_HISTOGRAM_COUNTS_10000("History.InMemoryURLWords", |
| (...skipping 11 matching lines...) Expand all Loading... |
| 468 DCHECK(!file_path.empty()); | 469 DCHECK(!file_path.empty()); |
| 469 return private_data->SaveToFile(file_path); | 470 return private_data->SaveToFile(file_path); |
| 470 } | 471 } |
| 471 | 472 |
| 472 void URLIndexPrivateData::CancelPendingUpdates() { | 473 void URLIndexPrivateData::CancelPendingUpdates() { |
| 473 recent_visits_consumer_.CancelAllRequests(); | 474 recent_visits_consumer_.CancelAllRequests(); |
| 474 } | 475 } |
| 475 | 476 |
| 476 scoped_refptr<URLIndexPrivateData> URLIndexPrivateData::Duplicate() const { | 477 scoped_refptr<URLIndexPrivateData> URLIndexPrivateData::Duplicate() const { |
| 477 scoped_refptr<URLIndexPrivateData> data_copy = new URLIndexPrivateData; | 478 scoped_refptr<URLIndexPrivateData> data_copy = new URLIndexPrivateData; |
| 479 data_copy->last_time_rebuilt_from_history_ = last_time_rebuilt_from_history_; |
| 478 data_copy->word_list_ = word_list_; | 480 data_copy->word_list_ = word_list_; |
| 479 data_copy->available_words_ = available_words_; | 481 data_copy->available_words_ = available_words_; |
| 480 data_copy->word_map_ = word_map_; | 482 data_copy->word_map_ = word_map_; |
| 481 data_copy->char_word_map_ = char_word_map_; | 483 data_copy->char_word_map_ = char_word_map_; |
| 482 data_copy->word_id_history_map_ = word_id_history_map_; | 484 data_copy->word_id_history_map_ = word_id_history_map_; |
| 483 data_copy->history_id_word_map_ = history_id_word_map_; | 485 data_copy->history_id_word_map_ = history_id_word_map_; |
| 484 data_copy->history_info_map_ = history_info_map_; | 486 data_copy->history_info_map_ = history_info_map_; |
| 485 data_copy->word_starts_map_ = word_starts_map_; | 487 data_copy->word_starts_map_ = word_starts_map_; |
| 486 return data_copy; | 488 return data_copy; |
| 487 // Not copied: | 489 // Not copied: |
| 488 // search_term_cache_ | 490 // search_term_cache_ |
| 489 // pre_filter_item_count_ | 491 // pre_filter_item_count_ |
| 490 // post_filter_item_count_ | 492 // post_filter_item_count_ |
| 491 // post_scoring_item_count_ | 493 // post_scoring_item_count_ |
| 492 }; | 494 }; |
| 493 | 495 |
| 494 bool URLIndexPrivateData::Empty() const { | 496 bool URLIndexPrivateData::Empty() const { |
| 495 return history_info_map_.empty(); | 497 return history_info_map_.empty(); |
| 496 } | 498 } |
| 497 | 499 |
| 498 void URLIndexPrivateData::Clear() { | 500 void URLIndexPrivateData::Clear() { |
| 501 last_time_rebuilt_from_history_ = base::Time(); |
| 499 word_list_.clear(); | 502 word_list_.clear(); |
| 500 available_words_.clear(); | 503 available_words_.clear(); |
| 501 word_map_.clear(); | 504 word_map_.clear(); |
| 502 char_word_map_.clear(); | 505 char_word_map_.clear(); |
| 503 word_id_history_map_.clear(); | 506 word_id_history_map_.clear(); |
| 504 history_id_word_map_.clear(); | 507 history_id_word_map_.clear(); |
| 505 history_info_map_.clear(); | 508 history_info_map_.clear(); |
| 506 word_starts_map_.clear(); | 509 word_starts_map_.clear(); |
| 507 } | 510 } |
| 508 | 511 |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 return false; | 904 return false; |
| 902 } | 905 } |
| 903 UMA_HISTOGRAM_TIMES("History.InMemoryURLIndexSaveCacheTime", | 906 UMA_HISTOGRAM_TIMES("History.InMemoryURLIndexSaveCacheTime", |
| 904 base::TimeTicks::Now() - beginning_time); | 907 base::TimeTicks::Now() - beginning_time); |
| 905 return true; | 908 return true; |
| 906 } | 909 } |
| 907 | 910 |
| 908 void URLIndexPrivateData::SavePrivateData( | 911 void URLIndexPrivateData::SavePrivateData( |
| 909 InMemoryURLIndexCacheItem* cache) const { | 912 InMemoryURLIndexCacheItem* cache) const { |
| 910 DCHECK(cache); | 913 DCHECK(cache); |
| 911 cache->set_timestamp(base::Time::Now().ToInternalValue()); | 914 cache->set_last_rebuild_timestamp( |
| 915 last_time_rebuilt_from_history_.ToInternalValue()); |
| 912 cache->set_version(saved_cache_version_); | 916 cache->set_version(saved_cache_version_); |
| 913 // history_item_count_ is no longer used but rather than change the protobuf | 917 // history_item_count_ is no longer used but rather than change the protobuf |
| 914 // definition use a placeholder. This will go away with the switch to SQLite. | 918 // definition use a placeholder. This will go away with the switch to SQLite. |
| 915 cache->set_history_item_count(0); | 919 cache->set_history_item_count(0); |
| 916 SaveWordList(cache); | 920 SaveWordList(cache); |
| 917 SaveWordMap(cache); | 921 SaveWordMap(cache); |
| 918 SaveCharWordMap(cache); | 922 SaveCharWordMap(cache); |
| 919 SaveWordIDHistoryMap(cache); | 923 SaveWordIDHistoryMap(cache); |
| 920 SaveHistoryInfoMap(cache); | 924 SaveHistoryInfoMap(cache); |
| 921 SaveWordStartsMap(cache); | 925 SaveWordStartsMap(cache); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1033 map_entry->add_url_word_starts(*i); | 1037 map_entry->add_url_word_starts(*i); |
| 1034 for (WordStarts::const_iterator i = word_starts.title_word_starts_.begin(); | 1038 for (WordStarts::const_iterator i = word_starts.title_word_starts_.begin(); |
| 1035 i != word_starts.title_word_starts_.end(); ++i) | 1039 i != word_starts.title_word_starts_.end(); ++i) |
| 1036 map_entry->add_title_word_starts(*i); | 1040 map_entry->add_title_word_starts(*i); |
| 1037 } | 1041 } |
| 1038 } | 1042 } |
| 1039 | 1043 |
| 1040 bool URLIndexPrivateData::RestorePrivateData( | 1044 bool URLIndexPrivateData::RestorePrivateData( |
| 1041 const InMemoryURLIndexCacheItem& cache, | 1045 const InMemoryURLIndexCacheItem& cache, |
| 1042 const std::string& languages) { | 1046 const std::string& languages) { |
| 1047 last_time_rebuilt_from_history_ = |
| 1048 base::Time::FromInternalValue(cache.last_rebuild_timestamp()); |
| 1049 const base::TimeDelta rebuilt_ago = |
| 1050 base::Time::Now() - last_time_rebuilt_from_history_; |
| 1051 if ((rebuilt_ago > base::TimeDelta::FromDays(7)) || |
| 1052 (rebuilt_ago < base::TimeDelta::FromDays(-1))) { |
| 1053 // Cache is more than a week old or, somehow, from some time in the future. |
| 1054 // It's probably a good time to rebuild the index from history to |
| 1055 // allow synced entries to now appear, expired entries to disappear, etc. |
| 1056 // Allow one day in the future to make the cache not rebuild on simple |
| 1057 // system clock changes such as time zone changes. |
| 1058 return false; |
| 1059 } |
| 1043 if (cache.has_version()) { | 1060 if (cache.has_version()) { |
| 1044 if (cache.version() < kCurrentCacheFileVersion) { | 1061 if (cache.version() < kCurrentCacheFileVersion) { |
| 1045 // Don't try to restore an old format cache file. (This will cause | 1062 // Don't try to restore an old format cache file. (This will cause |
| 1046 // the InMemoryURLIndex to schedule rebuilding the URLIndexPrivateData | 1063 // the InMemoryURLIndex to schedule rebuilding the URLIndexPrivateData |
| 1047 // from history.) | 1064 // from history.) |
| 1048 return false; | 1065 return false; |
| 1049 } | 1066 } |
| 1050 restored_cache_version_ = cache.version(); | 1067 restored_cache_version_ = cache.version(); |
| 1051 } | 1068 } |
| 1052 return RestoreWordList(cache) && RestoreWordMap(cache) && | 1069 return RestoreWordList(cache) && RestoreWordMap(cache) && |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1315 // recently visited (within the last 12/24 hours) as highly important. Get | 1332 // recently visited (within the last 12/24 hours) as highly important. Get |
| 1316 // input from mpearson. | 1333 // input from mpearson. |
| 1317 if (r1.typed_count() != r2.typed_count()) | 1334 if (r1.typed_count() != r2.typed_count()) |
| 1318 return (r1.typed_count() > r2.typed_count()); | 1335 return (r1.typed_count() > r2.typed_count()); |
| 1319 if (r1.visit_count() != r2.visit_count()) | 1336 if (r1.visit_count() != r2.visit_count()) |
| 1320 return (r1.visit_count() > r2.visit_count()); | 1337 return (r1.visit_count() > r2.visit_count()); |
| 1321 return (r1.last_visit() > r2.last_visit()); | 1338 return (r1.last_visit() > r2.last_visit()); |
| 1322 } | 1339 } |
| 1323 | 1340 |
| 1324 } // namespace history | 1341 } // namespace history |
| OLD | NEW |