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

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

Issue 12703036: [Sync] Add interface and backend impl for typed URL syncable service (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix style and move logic into BroadcastNotifications Created 7 years, 8 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
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 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
Andrew T Wilson (Slow) 2013/04/10 08:43:22 nit: remove extraneous blank line
892 // TODO(meelapshah) Disabled due to potential PageCycler regression. 895 // TODO(meelapshah) Disabled due to potential PageCycler regression.
893 // Re-enable this. 896 // Re-enable this.
894 // GetMostRecentRedirectsTo(url, &details->redirects); 897 // GetMostRecentRedirectsTo(url, &details->redirects);
895 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URL_VISITED, details); 898 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URL_VISITED, details);
896 } else { 899 } else {
897 VLOG(0) << "Failed to build visit insert statement: " 900 VLOG(0) << "Failed to build visit insert statement: "
898 << "url_id = " << url_id; 901 << "url_id = " << url_id;
899 } 902 }
900 903
901 return std::make_pair(url_id, visit_id); 904 return std::make_pair(url_id, visit_id);
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 success = true; 1170 success = true;
1168 1171
1169 // Optionally query the visits. 1172 // Optionally query the visits.
1170 if (want_visits) 1173 if (want_visits)
1171 db_->GetVisitsForURL(row->id(), visits); 1174 db_->GetVisitsForURL(row->id(), visits);
1172 } 1175 }
1173 } 1176 }
1174 request->ForwardResult(request->handle(), success, row, visits); 1177 request->ForwardResult(request->handle(), success, row, visits);
1175 } 1178 }
1176 1179
1180 TypedUrlSyncableService* HistoryBackend::GetTypedUrlSyncableService() const {
1181 return typed_url_syncable_service_.get();
1182 }
1183
1177 // Segment usage --------------------------------------------------------------- 1184 // Segment usage ---------------------------------------------------------------
1178 1185
1179 void HistoryBackend::DeleteOldSegmentData() { 1186 void HistoryBackend::DeleteOldSegmentData() {
1180 if (db_.get()) 1187 if (db_.get())
1181 db_->DeleteSegmentData(Time::Now() - 1188 db_->DeleteSegmentData(Time::Now() -
1182 TimeDelta::FromDays(kSegmentDataRetention)); 1189 TimeDelta::FromDays(kSegmentDataRetention));
1183 } 1190 }
1184 1191
1185 void HistoryBackend::QuerySegmentUsage( 1192 void HistoryBackend::QuerySegmentUsage(
1186 scoped_refptr<QuerySegmentUsageRequest> request, 1193 scoped_refptr<QuerySegmentUsageRequest> request,
(...skipping 1666 matching lines...) Expand 10 before | Expand all | Expand 10 after
2853 if (!task_scheduled) { 2860 if (!task_scheduled) {
2854 // No other tasks are scheduled. Process request now. 2861 // No other tasks are scheduled. Process request now.
2855 ProcessDBTaskImpl(); 2862 ProcessDBTaskImpl();
2856 } 2863 }
2857 } 2864 }
2858 2865
2859 void HistoryBackend::BroadcastNotifications( 2866 void HistoryBackend::BroadcastNotifications(
2860 int type, 2867 int type,
2861 HistoryDetails* details_deleted) { 2868 HistoryDetails* details_deleted) {
2862 // |delegate_| may be NULL if |this| is in the process of closing (closed by 2869 // |delegate_| may be NULL if |this| is in the process of closing (closed by
2863 // HistoryService -> HistroyBackend::Closing(). 2870 // HistoryService -> HistoryBackend::Closing().
2864 if (delegate_.get()) 2871 if (delegate_.get()) {
2872 // Typed urls sync service is called here to handle deleted urls, including
2873 // expirations from ExpireHistoryBackend, new, modified, and visited urls
2874 if (typed_url_syncable_service_.get()) {
2875 switch (type) {
2876 case chrome::NOTIFICATION_HISTORY_URLS_DELETED: {
2877 typed_url_syncable_service_->OnUrlsDeleted(
2878 static_cast<history::URLsDeletedDetails*>(details_deleted));
2879 break;
2880 }
2881 case chrome::NOTIFICATION_HISTORY_URLS_MODIFIED: {
2882 typed_url_syncable_service_->OnUrlsModified(
2883 static_cast<history::URLsModifiedDetails*>(details_deleted));
2884 break;
2885 }
2886 case chrome::NOTIFICATION_HISTORY_URL_VISITED: {
2887 typed_url_syncable_service_->OnUrlVisited(
2888 static_cast<history::URLVisitedDetails*>(details_deleted));
2889 break;
2890 }
2891 default:
2892 break;
2893 }
2894 }
2865 delegate_->BroadcastNotifications(type, details_deleted); 2895 delegate_->BroadcastNotifications(type, details_deleted);
2866 else 2896 } else {
2867 delete details_deleted; 2897 delete details_deleted;
2898 }
2868 } 2899 }
2869 2900
2870 // Deleting -------------------------------------------------------------------- 2901 // Deleting --------------------------------------------------------------------
2871 2902
2872 void HistoryBackend::DeleteAllHistory() { 2903 void HistoryBackend::DeleteAllHistory() {
2873 // Our approach to deleting all history is: 2904 // Our approach to deleting all history is:
2874 // 1. Copy the bookmarks and their dependencies to new tables with temporary 2905 // 1. Copy the bookmarks and their dependencies to new tables with temporary
2875 // names. 2906 // names.
2876 // 2. Delete the original tables. Since tables can not share pages, we know 2907 // 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. 2908 // 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
3061 info.url_id = visit.url_id; 3092 info.url_id = visit.url_id;
3062 info.time = visit.visit_time; 3093 info.time = visit.visit_time;
3063 info.transition = visit.transition; 3094 info.transition = visit.transition;
3064 // If we don't have a delegate yet during setup or shutdown, we will drop 3095 // If we don't have a delegate yet during setup or shutdown, we will drop
3065 // these notifications. 3096 // these notifications.
3066 if (delegate_.get()) 3097 if (delegate_.get())
3067 delegate_->NotifyVisitDBObserversOnAddVisit(info); 3098 delegate_->NotifyVisitDBObserversOnAddVisit(info);
3068 } 3099 }
3069 3100
3070 } // namespace history 3101 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698