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 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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) { |
| 889 URLVisitedDetails* details = new URLVisitedDetails; | 891 URLVisitedDetails* details = new URLVisitedDetails; |
| 890 details->transition = transition; | 892 details->transition = transition; |
| 891 details->row = url_info; | 893 details->row = url_info; |
| 894 | |
| 895 // Notify typed url sync | |
|
Andrew T Wilson (Slow)
2013/04/09 12:48:30
nit: use sentence punctuation.
| |
| 896 if (typed_url_syncable_service_.get()) { | |
|
Andrew T Wilson (Slow)
2013/04/09 12:48:30
nit: omit braces on single-line if statements, bec
| |
| 897 typed_url_syncable_service_->OnUrlVisited(details); | |
| 898 } | |
| 892 // TODO(meelapshah) Disabled due to potential PageCycler regression. | 899 // TODO(meelapshah) Disabled due to potential PageCycler regression. |
| 893 // Re-enable this. | 900 // Re-enable this. |
| 894 // GetMostRecentRedirectsTo(url, &details->redirects); | 901 // GetMostRecentRedirectsTo(url, &details->redirects); |
| 895 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URL_VISITED, details); | 902 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URL_VISITED, details); |
| 896 } else { | 903 } else { |
| 897 VLOG(0) << "Failed to build visit insert statement: " | 904 VLOG(0) << "Failed to build visit insert statement: " |
| 898 << "url_id = " << url_id; | 905 << "url_id = " << url_id; |
| 899 } | 906 } |
| 900 | 907 |
| 901 return std::make_pair(url_id, visit_id); | 908 return std::make_pair(url_id, visit_id); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 973 NOTREACHED() << "Adding visit failed."; | 980 NOTREACHED() << "Adding visit failed."; |
| 974 return; | 981 return; |
| 975 } | 982 } |
| 976 NotifyVisitObservers(visit_info); | 983 NotifyVisitObservers(visit_info); |
| 977 | 984 |
| 978 if (visit_info.visit_time < first_recorded_time_) | 985 if (visit_info.visit_time < first_recorded_time_) |
| 979 first_recorded_time_ = visit_info.visit_time; | 986 first_recorded_time_ = visit_info.visit_time; |
| 980 } | 987 } |
| 981 } | 988 } |
| 982 | 989 |
| 990 // Notify typed url sync | |
|
Andrew T Wilson (Slow)
2013/04/09 12:48:30
Nit: use sentence punctuation (here and below).
| |
| 991 if (typed_url_syncable_service_.get()) { | |
| 992 typed_url_syncable_service_->OnUrlsModified(modified.get()); | |
| 993 } | |
| 994 | |
| 983 // Broadcast a notification for typed URLs that have been modified. This | 995 // 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. | 996 // will be picked up by the in-memory URL database on the main thread. |
| 985 // | 997 // |
| 986 // TODO(brettw) bug 1140015: Add an "add page" notification so the history | 998 // TODO(brettw) bug 1140015: Add an "add page" notification so the history |
| 987 // views can keep in sync. | 999 // views can keep in sync. |
| 988 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, | 1000 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, |
| 989 modified.release()); | 1001 modified.release()); |
| 990 | 1002 |
| 991 ScheduleCommit(); | 1003 ScheduleCommit(); |
| 992 } | 1004 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1027 for (size_t i = 0; i < redirects->size(); i++) { | 1039 for (size_t i = 0; i < redirects->size(); i++) { |
| 1028 URLRow row; | 1040 URLRow row; |
| 1029 URLID row_id = db_->GetRowForURL(redirects->at(i), &row); | 1041 URLID row_id = db_->GetRowForURL(redirects->at(i), &row); |
| 1030 if (row_id && row.title() != title) { | 1042 if (row_id && row.title() != title) { |
| 1031 row.set_title(title); | 1043 row.set_title(title); |
| 1032 db_->UpdateURLRow(row_id, row); | 1044 db_->UpdateURLRow(row_id, row); |
| 1033 details->changed_urls.push_back(row); | 1045 details->changed_urls.push_back(row); |
| 1034 } | 1046 } |
| 1035 } | 1047 } |
| 1036 | 1048 |
| 1049 // Notify typed url sync | |
| 1050 if (typed_url_syncable_service_.get()) { | |
| 1051 typed_url_syncable_service_->OnUrlsModified(details.get()); | |
| 1052 } | |
| 1053 | |
| 1037 // Broadcast notifications for any URLs that have changed. This will | 1054 // Broadcast notifications for any URLs that have changed. This will |
| 1038 // update the in-memory database and the InMemoryURLIndex. | 1055 // update the in-memory database and the InMemoryURLIndex. |
| 1039 if (!details->changed_urls.empty()) { | 1056 if (!details->changed_urls.empty()) { |
| 1040 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, | 1057 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, |
| 1041 details.release()); | 1058 details.release()); |
| 1042 ScheduleCommit(); | 1059 ScheduleCommit(); |
| 1043 } | 1060 } |
| 1044 } | 1061 } |
| 1045 | 1062 |
| 1046 void HistoryBackend::AddPageNoVisitForBookmark(const GURL& url, | 1063 void HistoryBackend::AddPageNoVisitForBookmark(const GURL& url, |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1167 success = true; | 1184 success = true; |
| 1168 | 1185 |
| 1169 // Optionally query the visits. | 1186 // Optionally query the visits. |
| 1170 if (want_visits) | 1187 if (want_visits) |
| 1171 db_->GetVisitsForURL(row->id(), visits); | 1188 db_->GetVisitsForURL(row->id(), visits); |
| 1172 } | 1189 } |
| 1173 } | 1190 } |
| 1174 request->ForwardResult(request->handle(), success, row, visits); | 1191 request->ForwardResult(request->handle(), success, row, visits); |
| 1175 } | 1192 } |
| 1176 | 1193 |
| 1194 TypedUrlSyncableService* HistoryBackend::GetTypedUrlSyncableService() const { | |
| 1195 return typed_url_syncable_service_.get(); | |
| 1196 } | |
| 1197 | |
| 1177 // Segment usage --------------------------------------------------------------- | 1198 // Segment usage --------------------------------------------------------------- |
| 1178 | 1199 |
| 1179 void HistoryBackend::DeleteOldSegmentData() { | 1200 void HistoryBackend::DeleteOldSegmentData() { |
| 1180 if (db_.get()) | 1201 if (db_.get()) |
| 1181 db_->DeleteSegmentData(Time::Now() - | 1202 db_->DeleteSegmentData(Time::Now() - |
| 1182 TimeDelta::FromDays(kSegmentDataRetention)); | 1203 TimeDelta::FromDays(kSegmentDataRetention)); |
| 1183 } | 1204 } |
| 1184 | 1205 |
| 1185 void HistoryBackend::QuerySegmentUsage( | 1206 void HistoryBackend::QuerySegmentUsage( |
| 1186 scoped_refptr<QuerySegmentUsageRequest> request, | 1207 scoped_refptr<QuerySegmentUsageRequest> request, |
| (...skipping 1666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2853 if (!task_scheduled) { | 2874 if (!task_scheduled) { |
| 2854 // No other tasks are scheduled. Process request now. | 2875 // No other tasks are scheduled. Process request now. |
| 2855 ProcessDBTaskImpl(); | 2876 ProcessDBTaskImpl(); |
| 2856 } | 2877 } |
| 2857 } | 2878 } |
| 2858 | 2879 |
| 2859 void HistoryBackend::BroadcastNotifications( | 2880 void HistoryBackend::BroadcastNotifications( |
| 2860 int type, | 2881 int type, |
| 2861 HistoryDetails* details_deleted) { | 2882 HistoryDetails* details_deleted) { |
| 2862 // |delegate_| may be NULL if |this| is in the process of closing (closed by | 2883 // |delegate_| may be NULL if |this| is in the process of closing (closed by |
| 2863 // HistoryService -> HistroyBackend::Closing(). | 2884 // HistoryService -> HistoryBackend::Closing(). |
| 2864 if (delegate_.get()) | 2885 if (delegate_.get()) { |
| 2886 // Typed urls sync service is called here to handle deleted urls, including | |
| 2887 // expirations from ExpireHistoryBackend. New and visited url handling is | |
| 2888 // called separately. | |
| 2889 if (type == chrome::NOTIFICATION_HISTORY_URLS_DELETED && | |
|
Andrew T Wilson (Slow)
2013/04/09 12:48:30
It seems weird that we're doing deletions via Broa
| |
| 2890 typed_url_syncable_service_.get()) { | |
| 2891 typed_url_syncable_service_->OnUrlsDeleted( | |
| 2892 static_cast<history::URLsDeletedDetails*>(details_deleted)); | |
| 2893 } | |
| 2865 delegate_->BroadcastNotifications(type, details_deleted); | 2894 delegate_->BroadcastNotifications(type, details_deleted); |
| 2866 else | 2895 } else { |
| 2867 delete details_deleted; | 2896 delete details_deleted; |
| 2897 } | |
| 2868 } | 2898 } |
| 2869 | 2899 |
| 2870 // Deleting -------------------------------------------------------------------- | 2900 // Deleting -------------------------------------------------------------------- |
| 2871 | 2901 |
| 2872 void HistoryBackend::DeleteAllHistory() { | 2902 void HistoryBackend::DeleteAllHistory() { |
| 2873 // Our approach to deleting all history is: | 2903 // Our approach to deleting all history is: |
| 2874 // 1. Copy the bookmarks and their dependencies to new tables with temporary | 2904 // 1. Copy the bookmarks and their dependencies to new tables with temporary |
| 2875 // names. | 2905 // names. |
| 2876 // 2. Delete the original tables. Since tables can not share pages, we know | 2906 // 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. | 2907 // that any data we don't want to keep is now in an unused page. |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3061 info.url_id = visit.url_id; | 3091 info.url_id = visit.url_id; |
| 3062 info.time = visit.visit_time; | 3092 info.time = visit.visit_time; |
| 3063 info.transition = visit.transition; | 3093 info.transition = visit.transition; |
| 3064 // If we don't have a delegate yet during setup or shutdown, we will drop | 3094 // If we don't have a delegate yet during setup or shutdown, we will drop |
| 3065 // these notifications. | 3095 // these notifications. |
| 3066 if (delegate_.get()) | 3096 if (delegate_.get()) |
| 3067 delegate_->NotifyVisitDBObserversOnAddVisit(info); | 3097 delegate_->NotifyVisitDBObserversOnAddVisit(info); |
| 3068 } | 3098 } |
| 3069 | 3099 |
| 3070 } // namespace history | 3100 } // namespace history |
| OLD | NEW |