Chromium Code Reviews| 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 15 matching lines...) Expand all Loading... | |
| 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/history/download_row.h" | 28 #include "chrome/browser/history/download_row.h" |
| 29 #include "chrome/browser/history/history_db_task.h" | 29 #include "chrome/browser/history/history_db_task.h" |
| 30 #include "chrome/browser/history/history_notifications.h" | 30 #include "chrome/browser/history/history_notifications.h" |
| 31 #include "chrome/browser/history/history_publisher.h" | 31 #include "chrome/browser/history/history_publisher.h" |
| 32 #include "chrome/browser/history/in_memory_history_backend.h" | 32 #include "chrome/browser/history/in_memory_history_backend.h" |
| 33 #include "chrome/browser/history/page_usage_data.h" | 33 #include "chrome/browser/history/page_usage_data.h" |
| 34 #include "chrome/browser/history/select_favicon_frames.h" | 34 #include "chrome/browser/history/select_favicon_frames.h" |
| 35 #include "chrome/browser/history/top_sites.h" | 35 #include "chrome/browser/history/top_sites.h" |
| 36 #include "chrome/browser/history/typed_url_syncable_service.h" | |
| 36 #include "chrome/browser/history/visit_filter.h" | 37 #include "chrome/browser/history/visit_filter.h" |
| 37 #include "chrome/common/chrome_constants.h" | 38 #include "chrome/common/chrome_constants.h" |
| 38 #include "chrome/common/chrome_notification_types.h" | 39 #include "chrome/common/chrome_notification_types.h" |
| 39 #include "chrome/common/url_constants.h" | 40 #include "chrome/common/url_constants.h" |
| 40 #include "googleurl/src/gurl.h" | 41 #include "googleurl/src/gurl.h" |
| 41 #include "grit/chromium_strings.h" | 42 #include "grit/chromium_strings.h" |
| 42 #include "grit/generated_resources.h" | 43 #include "grit/generated_resources.h" |
| 43 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 44 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 44 #include "sql/error_delegate_util.h" | 45 #include "sql/error_delegate_util.h" |
| 45 | 46 |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 | 290 |
| 290 #if defined(OS_ANDROID) | 291 #if defined(OS_ANDROID) |
| 291 file_util::Delete(GetAndroidCacheFileName(), false); | 292 file_util::Delete(GetAndroidCacheFileName(), false); |
| 292 #endif | 293 #endif |
| 293 } | 294 } |
| 294 | 295 |
| 295 void HistoryBackend::Init(const std::string& languages, bool force_fail) { | 296 void HistoryBackend::Init(const std::string& languages, bool force_fail) { |
| 296 if (!force_fail) | 297 if (!force_fail) |
| 297 InitImpl(languages); | 298 InitImpl(languages); |
| 298 delegate_->DBLoaded(id_); | 299 delegate_->DBLoaded(id_); |
| 300 typed_url_syncable_service_.reset(new TypedUrlSyncableService(this)); | |
| 299 } | 301 } |
| 300 | 302 |
| 301 void HistoryBackend::SetOnBackendDestroyTask(MessageLoop* message_loop, | 303 void HistoryBackend::SetOnBackendDestroyTask(MessageLoop* message_loop, |
| 302 const base::Closure& task) { | 304 const base::Closure& task) { |
| 303 if (!backend_destroy_task_.is_null()) | 305 if (!backend_destroy_task_.is_null()) |
| 304 DLOG(WARNING) << "Setting more than one destroy task, overriding"; | 306 DLOG(WARNING) << "Setting more than one destroy task, overriding"; |
| 305 backend_destroy_message_loop_ = message_loop; | 307 backend_destroy_message_loop_ = message_loop; |
| 306 backend_destroy_task_ = task; | 308 backend_destroy_task_ = task; |
| 307 } | 309 } |
| 308 | 310 |
| (...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 879 // Add the visit with the time to the database. | 881 // Add the visit with the time to the database. |
| 880 VisitRow visit_info(url_id, time, referring_visit, transition, 0); | 882 VisitRow visit_info(url_id, time, referring_visit, transition, 0); |
| 881 VisitID visit_id = db_->AddVisit(&visit_info, visit_source); | 883 VisitID visit_id = db_->AddVisit(&visit_info, visit_source); |
| 882 NotifyVisitObservers(visit_info); | 884 NotifyVisitObservers(visit_info); |
| 883 | 885 |
| 884 if (visit_info.visit_time < first_recorded_time_) | 886 if (visit_info.visit_time < first_recorded_time_) |
| 885 first_recorded_time_ = visit_info.visit_time; | 887 first_recorded_time_ = visit_info.visit_time; |
| 886 | 888 |
| 887 // Broadcast a notification of the visit. | 889 // Broadcast a notification of the visit. |
| 888 if (visit_id) { | 890 if (visit_id) { |
| 891 if (typed_url_syncable_service_.get()) { | |
|
brettw
2013/04/30 22:15:34
No {} for single-line conditionals (match surround
Nicolas Zea
2013/05/06 19:22:43
Done.
| |
| 892 typed_url_syncable_service_->OnUrlVisited(transition, &url_info); | |
| 893 } | |
| 894 | |
| 889 URLVisitedDetails* details = new URLVisitedDetails; | 895 URLVisitedDetails* details = new URLVisitedDetails; |
| 890 details->transition = transition; | 896 details->transition = transition; |
| 891 details->row = url_info; | 897 details->row = url_info; |
| 892 // TODO(meelapshah) Disabled due to potential PageCycler regression. | 898 // TODO(meelapshah) Disabled due to potential PageCycler regression. |
| 893 // Re-enable this. | 899 // Re-enable this. |
| 894 // GetMostRecentRedirectsTo(url, &details->redirects); | 900 // GetMostRecentRedirectsTo(url, &details->redirects); |
| 895 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URL_VISITED, details); | 901 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URL_VISITED, details); |
| 896 } else { | 902 } else { |
| 897 VLOG(0) << "Failed to build visit insert statement: " | 903 VLOG(0) << "Failed to build visit insert statement: " |
| 898 << "url_id = " << url_id; | 904 << "url_id = " << url_id; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 973 NOTREACHED() << "Adding visit failed."; | 979 NOTREACHED() << "Adding visit failed."; |
| 974 return; | 980 return; |
| 975 } | 981 } |
| 976 NotifyVisitObservers(visit_info); | 982 NotifyVisitObservers(visit_info); |
| 977 | 983 |
| 978 if (visit_info.visit_time < first_recorded_time_) | 984 if (visit_info.visit_time < first_recorded_time_) |
| 979 first_recorded_time_ = visit_info.visit_time; | 985 first_recorded_time_ = visit_info.visit_time; |
| 980 } | 986 } |
| 981 } | 987 } |
| 982 | 988 |
| 989 if (typed_url_syncable_service_.get()) { | |
| 990 typed_url_syncable_service_->OnUrlsModified(&modified->changed_urls); | |
| 991 } | |
| 992 | |
| 983 // Broadcast a notification for typed URLs that have been modified. This | 993 // Broadcast a notification for typed URLs that have been modified. This |
| 984 // will be picked up by the in-memory URL database on the main thread. | 994 // will be picked up by the in-memory URL database on the main thread. |
| 985 // | 995 // |
| 986 // TODO(brettw) bug 1140015: Add an "add page" notification so the history | 996 // TODO(brettw) bug 1140015: Add an "add page" notification so the history |
| 987 // views can keep in sync. | 997 // views can keep in sync. |
| 988 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, | 998 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, |
| 989 modified.release()); | 999 modified.release()); |
| 990 | 1000 |
| 991 ScheduleCommit(); | 1001 ScheduleCommit(); |
| 992 } | 1002 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1030 if (row_id && row.title() != title) { | 1040 if (row_id && row.title() != title) { |
| 1031 row.set_title(title); | 1041 row.set_title(title); |
| 1032 db_->UpdateURLRow(row_id, row); | 1042 db_->UpdateURLRow(row_id, row); |
| 1033 details->changed_urls.push_back(row); | 1043 details->changed_urls.push_back(row); |
| 1034 } | 1044 } |
| 1035 } | 1045 } |
| 1036 | 1046 |
| 1037 // Broadcast notifications for any URLs that have changed. This will | 1047 // Broadcast notifications for any URLs that have changed. This will |
| 1038 // update the in-memory database and the InMemoryURLIndex. | 1048 // update the in-memory database and the InMemoryURLIndex. |
| 1039 if (!details->changed_urls.empty()) { | 1049 if (!details->changed_urls.empty()) { |
| 1050 if (typed_url_syncable_service_.get()) { | |
| 1051 typed_url_syncable_service_->OnUrlsModified(&details->changed_urls); | |
| 1052 } | |
| 1040 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, | 1053 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, |
| 1041 details.release()); | 1054 details.release()); |
| 1042 ScheduleCommit(); | 1055 ScheduleCommit(); |
| 1043 } | 1056 } |
| 1044 } | 1057 } |
| 1045 | 1058 |
| 1046 void HistoryBackend::AddPageNoVisitForBookmark(const GURL& url, | 1059 void HistoryBackend::AddPageNoVisitForBookmark(const GURL& url, |
| 1047 const string16& title) { | 1060 const string16& title) { |
| 1048 if (!db_.get()) | 1061 if (!db_.get()) |
| 1049 return; | 1062 return; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1167 success = true; | 1180 success = true; |
| 1168 | 1181 |
| 1169 // Optionally query the visits. | 1182 // Optionally query the visits. |
| 1170 if (want_visits) | 1183 if (want_visits) |
| 1171 db_->GetVisitsForURL(row->id(), visits); | 1184 db_->GetVisitsForURL(row->id(), visits); |
| 1172 } | 1185 } |
| 1173 } | 1186 } |
| 1174 request->ForwardResult(request->handle(), success, row, visits); | 1187 request->ForwardResult(request->handle(), success, row, visits); |
| 1175 } | 1188 } |
| 1176 | 1189 |
| 1190 TypedUrlSyncableService* HistoryBackend::GetTypedUrlSyncableService() const { | |
| 1191 return typed_url_syncable_service_.get(); | |
| 1192 } | |
| 1193 | |
| 1177 // Segment usage --------------------------------------------------------------- | 1194 // Segment usage --------------------------------------------------------------- |
| 1178 | 1195 |
| 1179 void HistoryBackend::DeleteOldSegmentData() { | 1196 void HistoryBackend::DeleteOldSegmentData() { |
| 1180 if (db_.get()) | 1197 if (db_.get()) |
| 1181 db_->DeleteSegmentData(Time::Now() - | 1198 db_->DeleteSegmentData(Time::Now() - |
| 1182 TimeDelta::FromDays(kSegmentDataRetention)); | 1199 TimeDelta::FromDays(kSegmentDataRetention)); |
| 1183 } | 1200 } |
| 1184 | 1201 |
| 1185 void HistoryBackend::QuerySegmentUsage( | 1202 void HistoryBackend::QuerySegmentUsage( |
| 1186 scoped_refptr<QuerySegmentUsageRequest> request, | 1203 scoped_refptr<QuerySegmentUsageRequest> request, |
| (...skipping 1666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2853 if (!task_scheduled) { | 2870 if (!task_scheduled) { |
| 2854 // No other tasks are scheduled. Process request now. | 2871 // No other tasks are scheduled. Process request now. |
| 2855 ProcessDBTaskImpl(); | 2872 ProcessDBTaskImpl(); |
| 2856 } | 2873 } |
| 2857 } | 2874 } |
| 2858 | 2875 |
| 2859 void HistoryBackend::BroadcastNotifications( | 2876 void HistoryBackend::BroadcastNotifications( |
| 2860 int type, | 2877 int type, |
| 2861 HistoryDetails* details_deleted) { | 2878 HistoryDetails* details_deleted) { |
| 2862 // |delegate_| may be NULL if |this| is in the process of closing (closed by | 2879 // |delegate_| may be NULL if |this| is in the process of closing (closed by |
| 2863 // HistoryService -> HistroyBackend::Closing(). | 2880 // HistoryService -> HistoryBackend::Closing(). |
| 2864 if (delegate_.get()) | 2881 if (delegate_.get()) |
| 2865 delegate_->BroadcastNotifications(type, details_deleted); | 2882 delegate_->BroadcastNotifications(type, details_deleted); |
| 2866 else | 2883 else |
| 2867 delete details_deleted; | 2884 delete details_deleted; |
| 2868 } | 2885 } |
| 2869 | 2886 |
| 2887 void HistoryBackend::NotifySyncURLsDeleted(bool all_history, | |
| 2888 bool archived, | |
| 2889 URLRows* rows) { | |
| 2890 if (typed_url_syncable_service_.get()) { | |
| 2891 typed_url_syncable_service_->OnUrlsDeleted(all_history, | |
|
brettw
2013/04/30 22:15:34
Doesn't this fit on one line?
Nicolas Zea
2013/05/06 19:22:43
Done.
| |
| 2892 archived, | |
| 2893 rows); | |
| 2894 } | |
| 2895 } | |
| 2896 | |
| 2870 // Deleting -------------------------------------------------------------------- | 2897 // Deleting -------------------------------------------------------------------- |
| 2871 | 2898 |
| 2872 void HistoryBackend::DeleteAllHistory() { | 2899 void HistoryBackend::DeleteAllHistory() { |
| 2873 // Our approach to deleting all history is: | 2900 // Our approach to deleting all history is: |
| 2874 // 1. Copy the bookmarks and their dependencies to new tables with temporary | 2901 // 1. Copy the bookmarks and their dependencies to new tables with temporary |
| 2875 // names. | 2902 // names. |
| 2876 // 2. Delete the original tables. Since tables can not share pages, we know | 2903 // 2. Delete the original tables. Since tables can not share pages, we know |
| 2877 // that any data we don't want to keep is now in an unused page. | 2904 // that any data we don't want to keep is now in an unused page. |
| 2878 // 3. Renaming the temporary tables to match the original. | 2905 // 3. Renaming the temporary tables to match the original. |
| 2879 // 4. Vacuuming the database to delete the unused pages. | 2906 // 4. Vacuuming the database to delete the unused pages. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2940 archived_db_->BeginTransaction(); | 2967 archived_db_->BeginTransaction(); |
| 2941 } | 2968 } |
| 2942 } | 2969 } |
| 2943 | 2970 |
| 2944 db_->GetStartDate(&first_recorded_time_); | 2971 db_->GetStartDate(&first_recorded_time_); |
| 2945 | 2972 |
| 2946 // Send out the notfication that history is cleared. The in-memory datdabase | 2973 // Send out the notfication that history is cleared. The in-memory datdabase |
| 2947 // will pick this up and clear itself. | 2974 // will pick this up and clear itself. |
| 2948 URLsDeletedDetails* details = new URLsDeletedDetails; | 2975 URLsDeletedDetails* details = new URLsDeletedDetails; |
| 2949 details->all_history = true; | 2976 details->all_history = true; |
| 2977 NotifySyncURLsDeleted(true, false, NULL); | |
| 2950 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_DELETED, details); | 2978 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_DELETED, details); |
| 2951 } | 2979 } |
| 2952 | 2980 |
| 2953 bool HistoryBackend::ClearAllThumbnailHistory(URLRows* kept_urls) { | 2981 bool HistoryBackend::ClearAllThumbnailHistory(URLRows* kept_urls) { |
| 2954 if (!thumbnail_db_.get()) { | 2982 if (!thumbnail_db_.get()) { |
| 2955 // When we have no reference to the thumbnail database, maybe there was an | 2983 // When we have no reference to the thumbnail database, maybe there was an |
| 2956 // error opening it. In this case, we just try to blow it away to try to | 2984 // error opening it. In this case, we just try to blow it away to try to |
| 2957 // fix the error if it exists. This may fail, in which case either the | 2985 // fix the error if it exists. This may fail, in which case either the |
| 2958 // file doesn't exist or there's no more we can do. | 2986 // file doesn't exist or there's no more we can do. |
| 2959 file_util::Delete(GetThumbnailFileName(), false); | 2987 file_util::Delete(GetThumbnailFileName(), false); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3061 info.url_id = visit.url_id; | 3089 info.url_id = visit.url_id; |
| 3062 info.time = visit.visit_time; | 3090 info.time = visit.visit_time; |
| 3063 info.transition = visit.transition; | 3091 info.transition = visit.transition; |
| 3064 // If we don't have a delegate yet during setup or shutdown, we will drop | 3092 // If we don't have a delegate yet during setup or shutdown, we will drop |
| 3065 // these notifications. | 3093 // these notifications. |
| 3066 if (delegate_.get()) | 3094 if (delegate_.get()) |
| 3067 delegate_->NotifyVisitDBObserversOnAddVisit(info); | 3095 delegate_->NotifyVisitDBObserversOnAddVisit(info); |
| 3068 } | 3096 } |
| 3069 | 3097 |
| 3070 } // namespace history | 3098 } // namespace history |
| OLD | NEW |