OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <list> | 7 #include <list> |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.h" |
17 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
20 #include "base/time.h" | 20 #include "base/time.h" |
21 #include "chrome/browser/autocomplete/history_url_provider.h" | 21 #include "chrome/browser/autocomplete/history_url_provider.h" |
22 #include "chrome/browser/bookmarks/bookmark_service.h" | 22 #include "chrome/browser/bookmarks/bookmark_service.h" |
23 #include "chrome/browser/history/download_history_info.h" | 23 #include "chrome/browser/history/download_history_info.h" |
24 #include "chrome/browser/history/history_notifications.h" | 24 #include "chrome/browser/history/history_notifications.h" |
25 #include "chrome/browser/history/history_publisher.h" | 25 #include "chrome/browser/history/history_publisher.h" |
26 #include "chrome/browser/history/in_memory_history_backend.h" | 26 #include "chrome/browser/history/in_memory_history_backend.h" |
27 #include "chrome/browser/history/page_usage_data.h" | 27 #include "chrome/browser/history/page_usage_data.h" |
28 #include "chrome/browser/history/top_sites.h" | 28 #include "chrome/browser/history/top_sites.h" |
29 #include "chrome/common/chrome_constants.h" | 29 #include "chrome/common/chrome_constants.h" |
| 30 #include "chrome/common/chrome_notification_types.h" |
30 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
31 #include "content/common/notification_type.h" | |
32 #include "googleurl/src/gurl.h" | 32 #include "googleurl/src/gurl.h" |
33 #include "grit/chromium_strings.h" | 33 #include "grit/chromium_strings.h" |
34 #include "grit/generated_resources.h" | 34 #include "grit/generated_resources.h" |
35 #include "net/base/registry_controlled_domain.h" | 35 #include "net/base/registry_controlled_domain.h" |
36 | 36 |
37 using base::Time; | 37 using base::Time; |
38 using base::TimeDelta; | 38 using base::TimeDelta; |
39 using base::TimeTicks; | 39 using base::TimeTicks; |
40 | 40 |
41 /* The HistoryBackend consists of a number of components: | 41 /* The HistoryBackend consists of a number of components: |
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 first_recorded_time_ = visit_info.visit_time; | 711 first_recorded_time_ = visit_info.visit_time; |
712 | 712 |
713 // Broadcast a notification of the visit. | 713 // Broadcast a notification of the visit. |
714 if (visit_id) { | 714 if (visit_id) { |
715 URLVisitedDetails* details = new URLVisitedDetails; | 715 URLVisitedDetails* details = new URLVisitedDetails; |
716 details->transition = transition; | 716 details->transition = transition; |
717 details->row = url_info; | 717 details->row = url_info; |
718 // TODO(meelapshah) Disabled due to potential PageCycler regression. | 718 // TODO(meelapshah) Disabled due to potential PageCycler regression. |
719 // Re-enable this. | 719 // Re-enable this. |
720 // GetMostRecentRedirectsTo(url, &details->redirects); | 720 // GetMostRecentRedirectsTo(url, &details->redirects); |
721 BroadcastNotifications(NotificationType::HISTORY_URL_VISITED, details); | 721 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URL_VISITED, details); |
722 } else { | 722 } else { |
723 VLOG(0) << "Failed to build visit insert statement: " | 723 VLOG(0) << "Failed to build visit insert statement: " |
724 << "url_id = " << url_id; | 724 << "url_id = " << url_id; |
725 } | 725 } |
726 | 726 |
727 return std::make_pair(url_id, visit_id); | 727 return std::make_pair(url_id, visit_id); |
728 } | 728 } |
729 | 729 |
730 void HistoryBackend::AddPagesWithDetails(const std::vector<URLRow>& urls, | 730 void HistoryBackend::AddPagesWithDetails(const std::vector<URLRow>& urls, |
731 VisitSource visit_source) { | 731 VisitSource visit_source) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 if (visit_info.visit_time < first_recorded_time_) | 800 if (visit_info.visit_time < first_recorded_time_) |
801 first_recorded_time_ = visit_info.visit_time; | 801 first_recorded_time_ = visit_info.visit_time; |
802 } | 802 } |
803 } | 803 } |
804 | 804 |
805 // Broadcast a notification for typed URLs that have been modified. This | 805 // Broadcast a notification for typed URLs that have been modified. This |
806 // will be picked up by the in-memory URL database on the main thread. | 806 // will be picked up by the in-memory URL database on the main thread. |
807 // | 807 // |
808 // TODO(brettw) bug 1140015: Add an "add page" notification so the history | 808 // TODO(brettw) bug 1140015: Add an "add page" notification so the history |
809 // views can keep in sync. | 809 // views can keep in sync. |
810 BroadcastNotifications(NotificationType::HISTORY_TYPED_URLS_MODIFIED, | 810 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_TYPED_URLS_MODIFIED, |
811 modified.release()); | 811 modified.release()); |
812 | 812 |
813 ScheduleCommit(); | 813 ScheduleCommit(); |
814 } | 814 } |
815 | 815 |
816 void HistoryBackend::SetPageTitle(const GURL& url, | 816 void HistoryBackend::SetPageTitle(const GURL& url, |
817 const string16& title) { | 817 const string16& title) { |
818 if (!db_.get()) | 818 if (!db_.get()) |
819 return; | 819 return; |
820 | 820 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 // | 856 // |
857 // TODO(brettw) bug 1140020: Broadcast for all changes (not just typed), | 857 // TODO(brettw) bug 1140020: Broadcast for all changes (not just typed), |
858 // in which case some logic can be removed. | 858 // in which case some logic can be removed. |
859 if (typed_url_changed) { | 859 if (typed_url_changed) { |
860 URLsModifiedDetails* modified = | 860 URLsModifiedDetails* modified = |
861 new URLsModifiedDetails; | 861 new URLsModifiedDetails; |
862 for (size_t i = 0; i < changed_urls.size(); i++) { | 862 for (size_t i = 0; i < changed_urls.size(); i++) { |
863 if (changed_urls[i].typed_count() > 0) | 863 if (changed_urls[i].typed_count() > 0) |
864 modified->changed_urls.push_back(changed_urls[i]); | 864 modified->changed_urls.push_back(changed_urls[i]); |
865 } | 865 } |
866 BroadcastNotifications(NotificationType::HISTORY_TYPED_URLS_MODIFIED, | 866 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_TYPED_URLS_MODIFIED, |
867 modified); | 867 modified); |
868 } | 868 } |
869 | 869 |
870 // Update the full text index. | 870 // Update the full text index. |
871 if (text_database_.get()) | 871 if (text_database_.get()) |
872 text_database_->AddPageTitle(url, title); | 872 text_database_->AddPageTitle(url, title); |
873 | 873 |
874 // Only bother committing if things changed. | 874 // Only bother committing if things changed. |
875 if (!changed_urls.empty()) | 875 if (!changed_urls.empty()) |
876 ScheduleCommit(); | 876 ScheduleCommit(); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 return; | 1035 return; |
1036 } | 1036 } |
1037 | 1037 |
1038 db_->SetKeywordSearchTermsForURL(url_row.id(), keyword_id, term); | 1038 db_->SetKeywordSearchTermsForURL(url_row.id(), keyword_id, term); |
1039 | 1039 |
1040 // details is deleted by BroadcastNotifications. | 1040 // details is deleted by BroadcastNotifications. |
1041 KeywordSearchTermDetails* details = new KeywordSearchTermDetails; | 1041 KeywordSearchTermDetails* details = new KeywordSearchTermDetails; |
1042 details->url = url; | 1042 details->url = url; |
1043 details->keyword_id = keyword_id; | 1043 details->keyword_id = keyword_id; |
1044 details->term = term; | 1044 details->term = term; |
1045 BroadcastNotifications(NotificationType::HISTORY_KEYWORD_SEARCH_TERM_UPDATED, | 1045 BroadcastNotifications( |
1046 details); | 1046 chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED, details); |
1047 ScheduleCommit(); | 1047 ScheduleCommit(); |
1048 } | 1048 } |
1049 | 1049 |
1050 void HistoryBackend::DeleteAllSearchTermsForKeyword( | 1050 void HistoryBackend::DeleteAllSearchTermsForKeyword( |
1051 TemplateURLID keyword_id) { | 1051 TemplateURLID keyword_id) { |
1052 if (!db_.get()) | 1052 if (!db_.get()) |
1053 return; | 1053 return; |
1054 | 1054 |
1055 db_->DeleteAllSearchTermsForKeyword(keyword_id); | 1055 db_->DeleteAllSearchTermsForKeyword(keyword_id); |
1056 // TODO(sky): bug 1168470. Need to move from archive dbs too. | 1056 // TODO(sky): bug 1168470. Need to move from archive dbs too. |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1659 favicons_changed.insert(*url); | 1659 favicons_changed.insert(*url); |
1660 } | 1660 } |
1661 } | 1661 } |
1662 } | 1662 } |
1663 } | 1663 } |
1664 | 1664 |
1665 if (!favicons_changed.empty()) { | 1665 if (!favicons_changed.empty()) { |
1666 // Send the notification about the changed favicon URLs. | 1666 // Send the notification about the changed favicon URLs. |
1667 FaviconChangeDetails* changed_details = new FaviconChangeDetails; | 1667 FaviconChangeDetails* changed_details = new FaviconChangeDetails; |
1668 changed_details->urls.swap(favicons_changed); | 1668 changed_details->urls.swap(favicons_changed); |
1669 BroadcastNotifications(NotificationType::FAVICON_CHANGED, changed_details); | 1669 BroadcastNotifications(chrome::NOTIFICATION_FAVICON_CHANGED, |
| 1670 changed_details); |
1670 } | 1671 } |
1671 } | 1672 } |
1672 | 1673 |
1673 void HistoryBackend::UpdateFaviconMappingAndFetchImpl( | 1674 void HistoryBackend::UpdateFaviconMappingAndFetchImpl( |
1674 const GURL* page_url, | 1675 const GURL* page_url, |
1675 const GURL& icon_url, | 1676 const GURL& icon_url, |
1676 scoped_refptr<GetFaviconRequest> request, | 1677 scoped_refptr<GetFaviconRequest> request, |
1677 int icon_types) { | 1678 int icon_types) { |
1678 // Check only a single type was given when the page_url was specified. | 1679 // Check only a single type was given when the page_url was specified. |
1679 DCHECK(!page_url || (page_url && (icon_types == FAVICON || | 1680 DCHECK(!page_url || (page_url && (icon_types == FAVICON || |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1803 if (replaced_id && !thumbnail_db_->HasMappingFor(replaced_id)) | 1804 if (replaced_id && !thumbnail_db_->HasMappingFor(replaced_id)) |
1804 thumbnail_db_->DeleteFavicon(replaced_id); | 1805 thumbnail_db_->DeleteFavicon(replaced_id); |
1805 | 1806 |
1806 favicons_changed.insert(*i); | 1807 favicons_changed.insert(*i); |
1807 } | 1808 } |
1808 } | 1809 } |
1809 | 1810 |
1810 // Send the notification about the changed favicons. | 1811 // Send the notification about the changed favicons. |
1811 FaviconChangeDetails* changed_details = new FaviconChangeDetails; | 1812 FaviconChangeDetails* changed_details = new FaviconChangeDetails; |
1812 changed_details->urls.swap(favicons_changed); | 1813 changed_details->urls.swap(favicons_changed); |
1813 BroadcastNotifications(NotificationType::FAVICON_CHANGED, changed_details); | 1814 BroadcastNotifications(chrome::NOTIFICATION_FAVICON_CHANGED, |
| 1815 changed_details); |
1814 | 1816 |
1815 ScheduleCommit(); | 1817 ScheduleCommit(); |
1816 } | 1818 } |
1817 | 1819 |
1818 bool HistoryBackend::AddOrUpdateIconMapping(const GURL& page_url, | 1820 bool HistoryBackend::AddOrUpdateIconMapping(const GURL& page_url, |
1819 FaviconID id, | 1821 FaviconID id, |
1820 IconType icon_type, | 1822 IconType icon_type, |
1821 FaviconID* replaced_icon) { | 1823 FaviconID* replaced_icon) { |
1822 *replaced_icon = 0; | 1824 *replaced_icon = 0; |
1823 std::vector<IconMapping> icon_mappings; | 1825 std::vector<IconMapping> icon_mappings; |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2030 // release when done with the task. | 2032 // release when done with the task. |
2031 request->AddRef(); | 2033 request->AddRef(); |
2032 db_task_requests_.push_back(request.get()); | 2034 db_task_requests_.push_back(request.get()); |
2033 if (!task_scheduled) { | 2035 if (!task_scheduled) { |
2034 // No other tasks are scheduled. Process request now. | 2036 // No other tasks are scheduled. Process request now. |
2035 ProcessDBTaskImpl(); | 2037 ProcessDBTaskImpl(); |
2036 } | 2038 } |
2037 } | 2039 } |
2038 | 2040 |
2039 void HistoryBackend::BroadcastNotifications( | 2041 void HistoryBackend::BroadcastNotifications( |
2040 NotificationType type, | 2042 int type, |
2041 HistoryDetails* details_deleted) { | 2043 HistoryDetails* details_deleted) { |
2042 DCHECK(delegate_.get()); | 2044 DCHECK(delegate_.get()); |
2043 delegate_->BroadcastNotifications(type, details_deleted); | 2045 delegate_->BroadcastNotifications(type, details_deleted); |
2044 } | 2046 } |
2045 | 2047 |
2046 // Deleting -------------------------------------------------------------------- | 2048 // Deleting -------------------------------------------------------------------- |
2047 | 2049 |
2048 void HistoryBackend::DeleteAllHistory() { | 2050 void HistoryBackend::DeleteAllHistory() { |
2049 // Our approach to deleting all history is: | 2051 // Our approach to deleting all history is: |
2050 // 1. Copy the bookmarks and their dependencies to new tables with temporary | 2052 // 1. Copy the bookmarks and their dependencies to new tables with temporary |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2116 archived_db_->BeginTransaction(); | 2118 archived_db_->BeginTransaction(); |
2117 } | 2119 } |
2118 } | 2120 } |
2119 | 2121 |
2120 db_->GetStartDate(&first_recorded_time_); | 2122 db_->GetStartDate(&first_recorded_time_); |
2121 | 2123 |
2122 // Send out the notfication that history is cleared. The in-memory datdabase | 2124 // Send out the notfication that history is cleared. The in-memory datdabase |
2123 // will pick this up and clear itself. | 2125 // will pick this up and clear itself. |
2124 URLsDeletedDetails* details = new URLsDeletedDetails; | 2126 URLsDeletedDetails* details = new URLsDeletedDetails; |
2125 details->all_history = true; | 2127 details->all_history = true; |
2126 BroadcastNotifications(NotificationType::HISTORY_URLS_DELETED, details); | 2128 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_DELETED, details); |
2127 } | 2129 } |
2128 | 2130 |
2129 bool HistoryBackend::ClearAllThumbnailHistory( | 2131 bool HistoryBackend::ClearAllThumbnailHistory( |
2130 std::vector<URLRow>* kept_urls) { | 2132 std::vector<URLRow>* kept_urls) { |
2131 if (!thumbnail_db_.get()) { | 2133 if (!thumbnail_db_.get()) { |
2132 // When we have no reference to the thumbnail database, maybe there was an | 2134 // When we have no reference to the thumbnail database, maybe there was an |
2133 // error opening it. In this case, we just try to blow it away to try to | 2135 // error opening it. In this case, we just try to blow it away to try to |
2134 // fix the error if it exists. This may fail, in which case either the | 2136 // fix the error if it exists. This may fail, in which case either the |
2135 // file doesn't exist or there's no more we can do. | 2137 // file doesn't exist or there's no more we can do. |
2136 file_util::Delete(GetThumbnailFileName(), false); | 2138 file_util::Delete(GetThumbnailFileName(), false); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2227 return true; | 2229 return true; |
2228 } | 2230 } |
2229 | 2231 |
2230 BookmarkService* HistoryBackend::GetBookmarkService() { | 2232 BookmarkService* HistoryBackend::GetBookmarkService() { |
2231 if (bookmark_service_) | 2233 if (bookmark_service_) |
2232 bookmark_service_->BlockTillLoaded(); | 2234 bookmark_service_->BlockTillLoaded(); |
2233 return bookmark_service_; | 2235 return bookmark_service_; |
2234 } | 2236 } |
2235 | 2237 |
2236 } // namespace history | 2238 } // namespace history |
OLD | NEW |