Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: chrome/browser/history/history_backend.cc

Issue 14615010: [Sync] Add interface and backend impl for typed URL syncable service (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/history/history_backend.h ('k') | chrome/browser/history/history_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 // Add the visit with the time to the database. 882 // Add the visit with the time to the database.
881 VisitRow visit_info(url_id, time, referring_visit, transition, 0); 883 VisitRow visit_info(url_id, time, referring_visit, transition, 0);
882 VisitID visit_id = db_->AddVisit(&visit_info, visit_source); 884 VisitID visit_id = db_->AddVisit(&visit_info, visit_source);
883 NotifyVisitObservers(visit_info); 885 NotifyVisitObservers(visit_info);
884 886
885 if (visit_info.visit_time < first_recorded_time_) 887 if (visit_info.visit_time < first_recorded_time_)
886 first_recorded_time_ = visit_info.visit_time; 888 first_recorded_time_ = visit_info.visit_time;
887 889
888 // Broadcast a notification of the visit. 890 // Broadcast a notification of the visit.
889 if (visit_id) { 891 if (visit_id) {
892 if (typed_url_syncable_service_.get())
893 typed_url_syncable_service_->OnUrlVisited(transition, &url_info);
894
890 URLVisitedDetails* details = new URLVisitedDetails; 895 URLVisitedDetails* details = new URLVisitedDetails;
891 details->transition = transition; 896 details->transition = transition;
892 details->row = url_info; 897 details->row = url_info;
893 // TODO(meelapshah) Disabled due to potential PageCycler regression. 898 // TODO(meelapshah) Disabled due to potential PageCycler regression.
894 // Re-enable this. 899 // Re-enable this.
895 // GetMostRecentRedirectsTo(url, &details->redirects); 900 // GetMostRecentRedirectsTo(url, &details->redirects);
896 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URL_VISITED, details); 901 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URL_VISITED, details);
897 } else { 902 } else {
898 VLOG(0) << "Failed to build visit insert statement: " 903 VLOG(0) << "Failed to build visit insert statement: "
899 << "url_id = " << url_id; 904 << "url_id = " << url_id;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 NOTREACHED() << "Adding visit failed."; 979 NOTREACHED() << "Adding visit failed.";
975 return; 980 return;
976 } 981 }
977 NotifyVisitObservers(visit_info); 982 NotifyVisitObservers(visit_info);
978 983
979 if (visit_info.visit_time < first_recorded_time_) 984 if (visit_info.visit_time < first_recorded_time_)
980 first_recorded_time_ = visit_info.visit_time; 985 first_recorded_time_ = visit_info.visit_time;
981 } 986 }
982 } 987 }
983 988
989 if (typed_url_syncable_service_.get())
990 typed_url_syncable_service_->OnUrlsModified(&modified->changed_urls);
991
984 // Broadcast a notification for typed URLs that have been modified. This 992 // Broadcast a notification for typed URLs that have been modified. This
985 // will be picked up by the in-memory URL database on the main thread. 993 // will be picked up by the in-memory URL database on the main thread.
986 // 994 //
987 // TODO(brettw) bug 1140015: Add an "add page" notification so the history 995 // TODO(brettw) bug 1140015: Add an "add page" notification so the history
988 // views can keep in sync. 996 // views can keep in sync.
989 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, 997 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED,
990 modified.release()); 998 modified.release());
991 999
992 ScheduleCommit(); 1000 ScheduleCommit();
993 } 1001 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 if (row_id && row.title() != title) { 1039 if (row_id && row.title() != title) {
1032 row.set_title(title); 1040 row.set_title(title);
1033 db_->UpdateURLRow(row_id, row); 1041 db_->UpdateURLRow(row_id, row);
1034 details->changed_urls.push_back(row); 1042 details->changed_urls.push_back(row);
1035 } 1043 }
1036 } 1044 }
1037 1045
1038 // Broadcast notifications for any URLs that have changed. This will 1046 // Broadcast notifications for any URLs that have changed. This will
1039 // update the in-memory database and the InMemoryURLIndex. 1047 // update the in-memory database and the InMemoryURLIndex.
1040 if (!details->changed_urls.empty()) { 1048 if (!details->changed_urls.empty()) {
1049 if (typed_url_syncable_service_.get())
1050 typed_url_syncable_service_->OnUrlsModified(&details->changed_urls);
1041 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, 1051 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED,
1042 details.release()); 1052 details.release());
1043 ScheduleCommit(); 1053 ScheduleCommit();
1044 } 1054 }
1045 } 1055 }
1046 1056
1047 void HistoryBackend::AddPageNoVisitForBookmark(const GURL& url, 1057 void HistoryBackend::AddPageNoVisitForBookmark(const GURL& url,
1048 const string16& title) { 1058 const string16& title) {
1049 if (!db_.get()) 1059 if (!db_.get())
1050 return; 1060 return;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 success = true; 1178 success = true;
1169 1179
1170 // Optionally query the visits. 1180 // Optionally query the visits.
1171 if (want_visits) 1181 if (want_visits)
1172 db_->GetVisitsForURL(row->id(), visits); 1182 db_->GetVisitsForURL(row->id(), visits);
1173 } 1183 }
1174 } 1184 }
1175 request->ForwardResult(request->handle(), success, row, visits); 1185 request->ForwardResult(request->handle(), success, row, visits);
1176 } 1186 }
1177 1187
1188 TypedUrlSyncableService* HistoryBackend::GetTypedUrlSyncableService() const {
1189 return typed_url_syncable_service_.get();
1190 }
1191
1178 // Segment usage --------------------------------------------------------------- 1192 // Segment usage ---------------------------------------------------------------
1179 1193
1180 void HistoryBackend::DeleteOldSegmentData() { 1194 void HistoryBackend::DeleteOldSegmentData() {
1181 if (db_.get()) 1195 if (db_.get())
1182 db_->DeleteSegmentData(Time::Now() - 1196 db_->DeleteSegmentData(Time::Now() -
1183 TimeDelta::FromDays(kSegmentDataRetention)); 1197 TimeDelta::FromDays(kSegmentDataRetention));
1184 } 1198 }
1185 1199
1186 void HistoryBackend::QuerySegmentUsage( 1200 void HistoryBackend::QuerySegmentUsage(
1187 scoped_refptr<QuerySegmentUsageRequest> request, 1201 scoped_refptr<QuerySegmentUsageRequest> request,
(...skipping 1671 matching lines...) Expand 10 before | Expand all | Expand 10 after
2859 if (!task_scheduled) { 2873 if (!task_scheduled) {
2860 // No other tasks are scheduled. Process request now. 2874 // No other tasks are scheduled. Process request now.
2861 ProcessDBTaskImpl(); 2875 ProcessDBTaskImpl();
2862 } 2876 }
2863 } 2877 }
2864 2878
2865 void HistoryBackend::BroadcastNotifications( 2879 void HistoryBackend::BroadcastNotifications(
2866 int type, 2880 int type,
2867 HistoryDetails* details_deleted) { 2881 HistoryDetails* details_deleted) {
2868 // |delegate_| may be NULL if |this| is in the process of closing (closed by 2882 // |delegate_| may be NULL if |this| is in the process of closing (closed by
2869 // HistoryService -> HistroyBackend::Closing(). 2883 // HistoryService -> HistoryBackend::Closing().
2870 if (delegate_.get()) 2884 if (delegate_.get())
2871 delegate_->BroadcastNotifications(type, details_deleted); 2885 delegate_->BroadcastNotifications(type, details_deleted);
2872 else 2886 else
2873 delete details_deleted; 2887 delete details_deleted;
2874 } 2888 }
2875 2889
2890 void HistoryBackend::NotifySyncURLsDeleted(bool all_history,
2891 bool archived,
2892 URLRows* rows) {
2893 if (typed_url_syncable_service_.get())
2894 typed_url_syncable_service_->OnUrlsDeleted(all_history, archived, rows);
2895 }
2896
2876 // Deleting -------------------------------------------------------------------- 2897 // Deleting --------------------------------------------------------------------
2877 2898
2878 void HistoryBackend::DeleteAllHistory() { 2899 void HistoryBackend::DeleteAllHistory() {
2879 // Our approach to deleting all history is: 2900 // Our approach to deleting all history is:
2880 // 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
2881 // names. 2902 // names.
2882 // 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
2883 // 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.
2884 // 3. Renaming the temporary tables to match the original. 2905 // 3. Renaming the temporary tables to match the original.
2885 // 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
2946 archived_db_->BeginTransaction(); 2967 archived_db_->BeginTransaction();
2947 } 2968 }
2948 } 2969 }
2949 2970
2950 db_->GetStartDate(&first_recorded_time_); 2971 db_->GetStartDate(&first_recorded_time_);
2951 2972
2952 // 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
2953 // will pick this up and clear itself. 2974 // will pick this up and clear itself.
2954 URLsDeletedDetails* details = new URLsDeletedDetails; 2975 URLsDeletedDetails* details = new URLsDeletedDetails;
2955 details->all_history = true; 2976 details->all_history = true;
2977 NotifySyncURLsDeleted(true, false, NULL);
2956 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_DELETED, details); 2978 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_DELETED, details);
2957 } 2979 }
2958 2980
2959 bool HistoryBackend::ClearAllThumbnailHistory(URLRows* kept_urls) { 2981 bool HistoryBackend::ClearAllThumbnailHistory(URLRows* kept_urls) {
2960 if (!thumbnail_db_.get()) { 2982 if (!thumbnail_db_.get()) {
2961 // 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
2962 // 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
2963 // 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
2964 // 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.
2965 file_util::Delete(GetThumbnailFileName(), false); 2987 file_util::Delete(GetThumbnailFileName(), false);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
3067 info.url_id = visit.url_id; 3089 info.url_id = visit.url_id;
3068 info.time = visit.visit_time; 3090 info.time = visit.visit_time;
3069 info.transition = visit.transition; 3091 info.transition = visit.transition;
3070 // 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
3071 // these notifications. 3093 // these notifications.
3072 if (delegate_.get()) 3094 if (delegate_.get())
3073 delegate_->NotifyVisitDBObserversOnAddVisit(info); 3095 delegate_->NotifyVisitDBObserversOnAddVisit(info);
3074 } 3096 }
3075 3097
3076 } // namespace history 3098 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/history_backend.h ('k') | chrome/browser/history/history_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698