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/history_backend.h" | 5 #include "chrome/browser/history/history_backend.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <list> | 9 #include <list> |
10 #include <map> | 10 #include <map> |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "base/strings/string_util.h" | 23 #include "base/strings/string_util.h" |
24 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
25 #include "base/time/time.h" | 25 #include "base/time/time.h" |
26 #include "chrome/browser/autocomplete/history_url_provider.h" | 26 #include "chrome/browser/autocomplete/history_url_provider.h" |
27 #include "chrome/browser/bookmarks/bookmark_service.h" | 27 #include "chrome/browser/bookmarks/bookmark_service.h" |
28 #include "chrome/browser/chrome_notification_types.h" | 28 #include "chrome/browser/chrome_notification_types.h" |
29 #include "chrome/browser/favicon/favicon_changed_details.h" | 29 #include "chrome/browser/favicon/favicon_changed_details.h" |
30 #include "chrome/browser/history/download_row.h" | 30 #include "chrome/browser/history/download_row.h" |
31 #include "chrome/browser/history/history_db_task.h" | 31 #include "chrome/browser/history/history_db_task.h" |
32 #include "chrome/browser/history/history_notifications.h" | 32 #include "chrome/browser/history/history_notifications.h" |
33 #include "chrome/browser/history/history_publisher.h" | |
34 #include "chrome/browser/history/in_memory_history_backend.h" | 33 #include "chrome/browser/history/in_memory_history_backend.h" |
35 #include "chrome/browser/history/page_collector.h" | |
36 #include "chrome/browser/history/page_usage_data.h" | 34 #include "chrome/browser/history/page_usage_data.h" |
37 #include "chrome/browser/history/select_favicon_frames.h" | 35 #include "chrome/browser/history/select_favicon_frames.h" |
38 #include "chrome/browser/history/top_sites.h" | 36 #include "chrome/browser/history/top_sites.h" |
39 #include "chrome/browser/history/typed_url_syncable_service.h" | 37 #include "chrome/browser/history/typed_url_syncable_service.h" |
40 #include "chrome/browser/history/visit_filter.h" | 38 #include "chrome/browser/history/visit_filter.h" |
41 #include "chrome/common/chrome_constants.h" | 39 #include "chrome/common/chrome_constants.h" |
42 #include "chrome/common/importer/imported_favicon_usage.h" | 40 #include "chrome/common/importer/imported_favicon_usage.h" |
43 #include "chrome/common/url_constants.h" | 41 #include "chrome/common/url_constants.h" |
44 #include "grit/chromium_strings.h" | 42 #include "grit/chromium_strings.h" |
45 #include "grit/generated_resources.h" | 43 #include "grit/generated_resources.h" |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 // TODO(evanm): Due to http://b/1194536 we lose the referrers of a subframe | 538 // TODO(evanm): Due to http://b/1194536 we lose the referrers of a subframe |
541 // navigation anyway, so last_visit_id is always zero for them. But adding | 539 // navigation anyway, so last_visit_id is always zero for them. But adding |
542 // them here confuses main frame history, so we skip them for now. | 540 // them here confuses main frame history, so we skip them for now. |
543 if (stripped_transition != content::PAGE_TRANSITION_AUTO_SUBFRAME && | 541 if (stripped_transition != content::PAGE_TRANSITION_AUTO_SUBFRAME && |
544 stripped_transition != content::PAGE_TRANSITION_MANUAL_SUBFRAME && | 542 stripped_transition != content::PAGE_TRANSITION_MANUAL_SUBFRAME && |
545 !is_keyword_generated) { | 543 !is_keyword_generated) { |
546 tracker_.AddVisit(request.id_scope, request.page_id, request.url, | 544 tracker_.AddVisit(request.id_scope, request.page_id, request.url, |
547 last_ids.second); | 545 last_ids.second); |
548 } | 546 } |
549 | 547 |
550 if (page_collector_) | |
551 page_collector_->AddPageURL(request.url, request.time); | |
552 | |
553 ScheduleCommit(); | 548 ScheduleCommit(); |
554 } | 549 } |
555 | 550 |
556 void HistoryBackend::InitImpl(const std::string& languages) { | 551 void HistoryBackend::InitImpl(const std::string& languages) { |
557 DCHECK(!db_) << "Initializing HistoryBackend twice"; | 552 DCHECK(!db_) << "Initializing HistoryBackend twice"; |
558 // In the rare case where the db fails to initialize a dialog may get shown | 553 // In the rare case where the db fails to initialize a dialog may get shown |
559 // the blocks the caller, yet allows other messages through. For this reason | 554 // the blocks the caller, yet allows other messages through. For this reason |
560 // we only set db_ to the created database if creation is successful. That | 555 // we only set db_ to the created database if creation is successful. That |
561 // way other methods won't do anything as db_ is still NULL. | 556 // way other methods won't do anything as db_ is still NULL. |
562 | 557 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 // Fill the in-memory database and send it back to the history service on the | 597 // Fill the in-memory database and send it back to the history service on the |
603 // main thread. | 598 // main thread. |
604 InMemoryHistoryBackend* mem_backend = new InMemoryHistoryBackend; | 599 InMemoryHistoryBackend* mem_backend = new InMemoryHistoryBackend; |
605 if (mem_backend->Init(history_name, db_.get())) | 600 if (mem_backend->Init(history_name, db_.get())) |
606 delegate_->SetInMemoryBackend(id_, mem_backend); // Takes ownership of | 601 delegate_->SetInMemoryBackend(id_, mem_backend); // Takes ownership of |
607 // pointer. | 602 // pointer. |
608 else | 603 else |
609 delete mem_backend; // Error case, run without the in-memory DB. | 604 delete mem_backend; // Error case, run without the in-memory DB. |
610 db_->BeginExclusiveMode(); // Must be after the mem backend read the data. | 605 db_->BeginExclusiveMode(); // Must be after the mem backend read the data. |
611 | 606 |
612 // Create the history publisher which needs to be passed on to the thumbnail | |
613 // database for publishing history. | |
614 // TODO(shess): HistoryPublisher is being deprecated. I am still | |
615 // trying to track down who depends on it, meanwhile talk to me | |
616 // before removing interactions with it. http://crbug.com/294306 | |
617 history_publisher_.reset(new HistoryPublisher()); | |
618 if (!history_publisher_->Init()) { | |
619 // The init may fail when there are no indexers wanting our history. | |
620 // Hence no need to log the failure. | |
621 history_publisher_.reset(); | |
622 } | |
623 | |
624 // Collects page data for history_publisher_. | |
625 if (history_publisher_.get()) { | |
626 page_collector_.reset(new PageCollector()); | |
627 page_collector_->Init(history_publisher_.get()); | |
628 } | |
629 | |
630 // Thumbnail database. | 607 // Thumbnail database. |
631 // TODO(shess): "thumbnail database" these days only stores | 608 // TODO(shess): "thumbnail database" these days only stores |
632 // favicons. Thumbnails are stored in "top sites". Consider | 609 // favicons. Thumbnails are stored in "top sites". Consider |
633 // renaming "thumbnail" references to "favicons" or something of the | 610 // renaming "thumbnail" references to "favicons" or something of the |
634 // sort. | 611 // sort. |
635 thumbnail_db_.reset(new ThumbnailDatabase()); | 612 thumbnail_db_.reset(new ThumbnailDatabase()); |
636 if (thumbnail_db_->Init(thumbnail_name) != sql::INIT_OK) { | 613 if (thumbnail_db_->Init(thumbnail_name) != sql::INIT_OK) { |
637 // Unlike the main database, we don't error out when the database is too | 614 // Unlike the main database, we don't error out when the database is too |
638 // new because this error is much less severe. Generally, this shouldn't | 615 // new because this error is much less severe. Generally, this shouldn't |
639 // happen since the thumbnail and main database versions should be in sync. | 616 // happen since the thumbnail and main database versions should be in sync. |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 NOTREACHED() << "Could not add row to DB"; | 829 NOTREACHED() << "Could not add row to DB"; |
853 return; | 830 return; |
854 } | 831 } |
855 | 832 |
856 if (i->typed_count() > 0) { | 833 if (i->typed_count() > 0) { |
857 modified->changed_urls.push_back(*i); | 834 modified->changed_urls.push_back(*i); |
858 modified->changed_urls.back().set_id(url_id); // *i likely has |id_| 0. | 835 modified->changed_urls.back().set_id(url_id); // *i likely has |id_| 0. |
859 } | 836 } |
860 } | 837 } |
861 | 838 |
862 // TODO(shess): I'm not sure this case needs to exist anymore. | |
863 if (page_collector_) { | |
864 page_collector_->AddPageData(i->url(), i->last_visit(), | |
865 i->title(), string16()); | |
866 } | |
867 | |
868 // Sync code manages the visits itself. | 839 // Sync code manages the visits itself. |
869 if (visit_source != SOURCE_SYNCED) { | 840 if (visit_source != SOURCE_SYNCED) { |
870 // Make up a visit to correspond to the last visit to the page. | 841 // Make up a visit to correspond to the last visit to the page. |
871 VisitRow visit_info(url_id, i->last_visit(), 0, | 842 VisitRow visit_info(url_id, i->last_visit(), 0, |
872 content::PageTransitionFromInt( | 843 content::PageTransitionFromInt( |
873 content::PAGE_TRANSITION_LINK | | 844 content::PAGE_TRANSITION_LINK | |
874 content::PAGE_TRANSITION_CHAIN_START | | 845 content::PAGE_TRANSITION_CHAIN_START | |
875 content::PAGE_TRANSITION_CHAIN_END), 0); | 846 content::PAGE_TRANSITION_CHAIN_END), 0); |
876 if (!visit_database->AddVisit(&visit_info, visit_source)) { | 847 if (!visit_database->AddVisit(&visit_info, visit_source)) { |
877 NOTREACHED() << "Adding visit failed."; | 848 NOTREACHED() << "Adding visit failed."; |
(...skipping 21 matching lines...) Expand all Loading... |
899 } | 870 } |
900 | 871 |
901 bool HistoryBackend::IsExpiredVisitTime(const base::Time& time) { | 872 bool HistoryBackend::IsExpiredVisitTime(const base::Time& time) { |
902 return time < expirer_.GetCurrentArchiveTime(); | 873 return time < expirer_.GetCurrentArchiveTime(); |
903 } | 874 } |
904 | 875 |
905 void HistoryBackend::SetPageTitle(const GURL& url, const string16& title) { | 876 void HistoryBackend::SetPageTitle(const GURL& url, const string16& title) { |
906 if (!db_) | 877 if (!db_) |
907 return; | 878 return; |
908 | 879 |
909 if (page_collector_) | |
910 page_collector_->AddPageTitle(url, title); | |
911 | |
912 // Search for recent redirects which should get the same title. We make a | 880 // Search for recent redirects which should get the same title. We make a |
913 // dummy list containing the exact URL visited if there are no redirects so | 881 // dummy list containing the exact URL visited if there are no redirects so |
914 // the processing below can be the same. | 882 // the processing below can be the same. |
915 history::RedirectList dummy_list; | 883 history::RedirectList dummy_list; |
916 history::RedirectList* redirects; | 884 history::RedirectList* redirects; |
917 RedirectCache::iterator iter = recent_redirects_.Get(url); | 885 RedirectCache::iterator iter = recent_redirects_.Get(url); |
918 if (iter != recent_redirects_.end()) { | 886 if (iter != recent_redirects_.end()) { |
919 redirects = &iter->second; | 887 redirects = &iter->second; |
920 | 888 |
921 // This redirect chain should have the destination URL as the last item. | 889 // This redirect chain should have the destination URL as the last item. |
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1683 int num_databases_deleted = 0; | 1651 int num_databases_deleted = 0; |
1684 base::FilePath current_file; | 1652 base::FilePath current_file; |
1685 while (!(current_file = enumerator.Next()).empty()) { | 1653 while (!(current_file = enumerator.Next()).empty()) { |
1686 if (sql::Connection::Delete(current_file)) | 1654 if (sql::Connection::Delete(current_file)) |
1687 num_databases_deleted++; | 1655 num_databases_deleted++; |
1688 } | 1656 } |
1689 UMA_HISTOGRAM_COUNTS("History.DeleteFTSIndexDatabases", | 1657 UMA_HISTOGRAM_COUNTS("History.DeleteFTSIndexDatabases", |
1690 num_databases_deleted); | 1658 num_databases_deleted); |
1691 } | 1659 } |
1692 | 1660 |
1693 void HistoryBackend::SetPageContents(const GURL& url, | |
1694 const string16& contents) { | |
1695 if (page_collector_) | |
1696 page_collector_->AddPageContents(url, contents); | |
1697 } | |
1698 | |
1699 void HistoryBackend::GetFavicons( | 1661 void HistoryBackend::GetFavicons( |
1700 const std::vector<GURL>& icon_urls, | 1662 const std::vector<GURL>& icon_urls, |
1701 int icon_types, | 1663 int icon_types, |
1702 int desired_size_in_dip, | 1664 int desired_size_in_dip, |
1703 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 1665 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
1704 std::vector<chrome::FaviconBitmapResult>* bitmap_results) { | 1666 std::vector<chrome::FaviconBitmapResult>* bitmap_results) { |
1705 UpdateFaviconMappingsAndFetchImpl(NULL, icon_urls, icon_types, | 1667 UpdateFaviconMappingsAndFetchImpl(NULL, icon_urls, icon_types, |
1706 desired_size_in_dip, desired_scale_factors, | 1668 desired_size_in_dip, desired_scale_factors, |
1707 bitmap_results); | 1669 bitmap_results); |
1708 } | 1670 } |
(...skipping 1278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2987 int rank = kPageVisitStatsMaxTopSites; | 2949 int rank = kPageVisitStatsMaxTopSites; |
2988 std::map<GURL, int>::const_iterator it = most_visited_urls_map_.find(url); | 2950 std::map<GURL, int>::const_iterator it = most_visited_urls_map_.find(url); |
2989 if (it != most_visited_urls_map_.end()) | 2951 if (it != most_visited_urls_map_.end()) |
2990 rank = (*it).second; | 2952 rank = (*it).second; |
2991 UMA_HISTOGRAM_ENUMERATION("History.TopSitesVisitsByRank", | 2953 UMA_HISTOGRAM_ENUMERATION("History.TopSitesVisitsByRank", |
2992 rank, kPageVisitStatsMaxTopSites + 1); | 2954 rank, kPageVisitStatsMaxTopSites + 1); |
2993 } | 2955 } |
2994 #endif | 2956 #endif |
2995 | 2957 |
2996 } // namespace history | 2958 } // namespace history |
OLD | NEW |