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

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

Issue 16296002: Update chrome/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 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 // The history system runs on a background thread so that potentially slow 5 // The history system runs on a background thread so that potentially slow
6 // database operations don't delay the browser. This backend processing is 6 // database operations don't delay the browser. This backend processing is
7 // represented by HistoryBackend. The HistoryService's job is to dispatch to 7 // represented by HistoryBackend. The HistoryService's job is to dispatch to
8 // that thread. 8 // that thread.
9 // 9 //
10 // Main thread History thread 10 // Main thread History thread
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 // soon, so they will either listen for notifications or just retry this call 251 // soon, so they will either listen for notifications or just retry this call
252 // later. If we've purged the backend, we haven't necessarily restarted it 252 // later. If we've purged the backend, we haven't necessarily restarted it
253 // loading by now, so we need to trigger the load in order to maintain that 253 // loading by now, so we need to trigger the load in order to maintain that
254 // expectation. 254 // expectation.
255 LoadBackendIfNecessary(); 255 LoadBackendIfNecessary();
256 return backend_loaded_; 256 return backend_loaded_;
257 } 257 }
258 258
259 void HistoryService::UnloadBackend() { 259 void HistoryService::UnloadBackend() {
260 DCHECK(thread_checker_.CalledOnValidThread()); 260 DCHECK(thread_checker_.CalledOnValidThread());
261 if (!history_backend_) 261 if (!history_backend_.get())
262 return; // Already unloaded. 262 return; // Already unloaded.
263 263
264 // Get rid of the in-memory backend. 264 // Get rid of the in-memory backend.
265 in_memory_backend_.reset(); 265 in_memory_backend_.reset();
266 266
267 // Give the InMemoryURLIndex a chance to shutdown. 267 // Give the InMemoryURLIndex a chance to shutdown.
268 if (in_memory_url_index_) 268 if (in_memory_url_index_)
269 in_memory_url_index_->ShutDown(); 269 in_memory_url_index_->ShutDown();
270 270
271 // The backend's destructor must run on the history thread since it is not 271 // The backend's destructor must run on the history thread since it is not
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 syncer::SyncError HistoryService::ProcessLocalDeleteDirective( 1056 syncer::SyncError HistoryService::ProcessLocalDeleteDirective(
1057 const sync_pb::HistoryDeleteDirectiveSpecifics& delete_directive) { 1057 const sync_pb::HistoryDeleteDirectiveSpecifics& delete_directive) {
1058 DCHECK(thread_checker_.CalledOnValidThread()); 1058 DCHECK(thread_checker_.CalledOnValidThread());
1059 return delete_directive_handler_.ProcessLocalDeleteDirective( 1059 return delete_directive_handler_.ProcessLocalDeleteDirective(
1060 delete_directive); 1060 delete_directive);
1061 } 1061 }
1062 1062
1063 void HistoryService::SetInMemoryBackend(int backend_id, 1063 void HistoryService::SetInMemoryBackend(int backend_id,
1064 history::InMemoryHistoryBackend* mem_backend) { 1064 history::InMemoryHistoryBackend* mem_backend) {
1065 DCHECK(thread_checker_.CalledOnValidThread()); 1065 DCHECK(thread_checker_.CalledOnValidThread());
1066 if (!history_backend_ || current_backend_id_ != backend_id) { 1066 if (!history_backend_.get() || current_backend_id_ != backend_id) {
1067 DVLOG(1) << "Message from obsolete backend"; 1067 DVLOG(1) << "Message from obsolete backend";
1068 // Cleaning up the memory backend. 1068 // Cleaning up the memory backend.
1069 delete mem_backend; 1069 delete mem_backend;
1070 return; 1070 return;
1071 } 1071 }
1072 DCHECK(!in_memory_backend_) << "Setting mem DB twice"; 1072 DCHECK(!in_memory_backend_) << "Setting mem DB twice";
1073 in_memory_backend_.reset(mem_backend); 1073 in_memory_backend_.reset(mem_backend);
1074 1074
1075 // The database requires additional initialization once we own it. 1075 // The database requires additional initialization once we own it.
1076 in_memory_backend_->AttachToHistoryService(profile_); 1076 in_memory_backend_->AttachToHistoryService(profile_);
1077 } 1077 }
1078 1078
1079 void HistoryService::NotifyProfileError(int backend_id, 1079 void HistoryService::NotifyProfileError(int backend_id,
1080 sql::InitStatus init_status) { 1080 sql::InitStatus init_status) {
1081 DCHECK(thread_checker_.CalledOnValidThread()); 1081 DCHECK(thread_checker_.CalledOnValidThread());
1082 if (!history_backend_ || current_backend_id_ != backend_id) { 1082 if (!history_backend_.get() || current_backend_id_ != backend_id) {
1083 DVLOG(1) << "Message from obsolete backend"; 1083 DVLOG(1) << "Message from obsolete backend";
1084 return; 1084 return;
1085 } 1085 }
1086 ShowProfileErrorDialog( 1086 ShowProfileErrorDialog(
1087 (init_status == sql::INIT_FAILURE) ? 1087 (init_status == sql::INIT_FAILURE) ?
1088 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR); 1088 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR);
1089 } 1089 }
1090 1090
1091 void HistoryService::DeleteURL(const GURL& url) { 1091 void HistoryService::DeleteURL(const GURL& url) {
1092 DCHECK(thread_checker_.CalledOnValidThread()); 1092 DCHECK(thread_checker_.CalledOnValidThread());
1093 // We will update the visited links when we observe the delete notifications. 1093 // We will update the visited links when we observe the delete notifications.
1094 ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::DeleteURL, url); 1094 ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::DeleteURL, url);
1095 } 1095 }
1096 1096
1097 void HistoryService::DeleteURLsForTest(const std::vector<GURL>& urls) { 1097 void HistoryService::DeleteURLsForTest(const std::vector<GURL>& urls) {
1098 DCHECK(thread_checker_.CalledOnValidThread()); 1098 DCHECK(thread_checker_.CalledOnValidThread());
1099 // We will update the visited links when we observe the delete 1099 // We will update the visited links when we observe the delete
1100 // notifications. 1100 // notifications.
1101 ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::DeleteURLs, urls); 1101 ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::DeleteURLs, urls);
1102 } 1102 }
1103 1103
1104 void HistoryService::ExpireHistoryBetween( 1104 void HistoryService::ExpireHistoryBetween(
1105 const std::set<GURL>& restrict_urls, 1105 const std::set<GURL>& restrict_urls,
1106 Time begin_time, 1106 Time begin_time,
1107 Time end_time, 1107 Time end_time,
1108 const base::Closure& callback, 1108 const base::Closure& callback,
1109 CancelableTaskTracker* tracker) { 1109 CancelableTaskTracker* tracker) {
1110 DCHECK(thread_); 1110 DCHECK(thread_);
1111 DCHECK(thread_checker_.CalledOnValidThread()); 1111 DCHECK(thread_checker_.CalledOnValidThread());
1112 DCHECK(history_backend_); 1112 DCHECK(history_backend_.get());
1113 tracker->PostTaskAndReply( 1113 tracker->PostTaskAndReply(thread_->message_loop_proxy(),
1114 thread_->message_loop_proxy(), 1114 FROM_HERE,
1115 FROM_HERE, 1115 base::Bind(&HistoryBackend::ExpireHistoryBetween,
1116 base::Bind(&HistoryBackend::ExpireHistoryBetween, 1116 history_backend_,
1117 history_backend_, restrict_urls, begin_time, end_time), 1117 restrict_urls,
1118 callback); 1118 begin_time,
1119 end_time),
1120 callback);
1119 } 1121 }
1120 1122
1121 void HistoryService::ExpireHistory( 1123 void HistoryService::ExpireHistory(
1122 const std::vector<history::ExpireHistoryArgs>& expire_list, 1124 const std::vector<history::ExpireHistoryArgs>& expire_list,
1123 const base::Closure& callback, 1125 const base::Closure& callback,
1124 CancelableTaskTracker* tracker) { 1126 CancelableTaskTracker* tracker) {
1125 DCHECK(thread_); 1127 DCHECK(thread_);
1126 DCHECK(thread_checker_.CalledOnValidThread()); 1128 DCHECK(thread_checker_.CalledOnValidThread());
1127 DCHECK(history_backend_); 1129 DCHECK(history_backend_.get());
1128 tracker->PostTaskAndReply( 1130 tracker->PostTaskAndReply(
1129 thread_->message_loop_proxy(), 1131 thread_->message_loop_proxy(),
1130 FROM_HERE, 1132 FROM_HERE,
1131 base::Bind(&HistoryBackend::ExpireHistory, history_backend_, expire_list), 1133 base::Bind(&HistoryBackend::ExpireHistory, history_backend_, expire_list),
1132 callback); 1134 callback);
1133 } 1135 }
1134 1136
1135 void HistoryService::ExpireLocalAndRemoteHistoryBetween( 1137 void HistoryService::ExpireLocalAndRemoteHistoryBetween(
1136 const std::set<GURL>& restrict_urls, 1138 const std::set<GURL>& restrict_urls,
1137 Time begin_time, 1139 Time begin_time,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1184 // The details object just contains the pointer to the object that the 1186 // The details object just contains the pointer to the object that the
1185 // backend has allocated for us. The receiver of the notification will cast 1187 // backend has allocated for us. The receiver of the notification will cast
1186 // this to the proper type. 1188 // this to the proper type.
1187 content::Details<history::HistoryDetails> det(details); 1189 content::Details<history::HistoryDetails> det(details);
1188 1190
1189 content::NotificationService::current()->Notify(type, source, det); 1191 content::NotificationService::current()->Notify(type, source, det);
1190 } 1192 }
1191 1193
1192 void HistoryService::LoadBackendIfNecessary() { 1194 void HistoryService::LoadBackendIfNecessary() {
1193 DCHECK(thread_checker_.CalledOnValidThread()); 1195 DCHECK(thread_checker_.CalledOnValidThread());
1194 if (!thread_ || history_backend_) 1196 if (!thread_ || history_backend_.get())
1195 return; // Failed to init, or already started loading. 1197 return; // Failed to init, or already started loading.
1196 1198
1197 ++current_backend_id_; 1199 ++current_backend_id_;
1198 scoped_refptr<HistoryBackend> backend( 1200 scoped_refptr<HistoryBackend> backend(
1199 new HistoryBackend(history_dir_, 1201 new HistoryBackend(history_dir_,
1200 current_backend_id_, 1202 current_backend_id_,
1201 new BackendDelegate( 1203 new BackendDelegate(
1202 weak_ptr_factory_.GetWeakPtr(), 1204 weak_ptr_factory_.GetWeakPtr(),
1203 base::ThreadTaskRunnerHandle::Get(), 1205 base::ThreadTaskRunnerHandle::Get(),
1204 profile_), 1206 profile_),
1205 bookmark_service_)); 1207 bookmark_service_));
1206 history_backend_.swap(backend); 1208 history_backend_.swap(backend);
1207 1209
1208 // There may not be a profile when unit testing. 1210 // There may not be a profile when unit testing.
1209 std::string languages; 1211 std::string languages;
1210 if (profile_) { 1212 if (profile_) {
1211 PrefService* prefs = profile_->GetPrefs(); 1213 PrefService* prefs = profile_->GetPrefs();
1212 languages = prefs->GetString(prefs::kAcceptLanguages); 1214 languages = prefs->GetString(prefs::kAcceptLanguages);
1213 } 1215 }
1214 ScheduleAndForget(PRIORITY_UI, &HistoryBackend::Init, languages, no_db_); 1216 ScheduleAndForget(PRIORITY_UI, &HistoryBackend::Init, languages, no_db_);
1215 } 1217 }
1216 1218
1217 void HistoryService::OnDBLoaded(int backend_id) { 1219 void HistoryService::OnDBLoaded(int backend_id) {
1218 DCHECK(thread_checker_.CalledOnValidThread()); 1220 DCHECK(thread_checker_.CalledOnValidThread());
1219 if (!history_backend_ || current_backend_id_ != backend_id) { 1221 if (!history_backend_.get() || current_backend_id_ != backend_id) {
1220 DVLOG(1) << "Message from obsolete backend"; 1222 DVLOG(1) << "Message from obsolete backend";
1221 return; 1223 return;
1222 } 1224 }
1223 backend_loaded_ = true; 1225 backend_loaded_ = true;
1224 content::NotificationService::current()->Notify( 1226 content::NotificationService::current()->Notify(
1225 chrome::NOTIFICATION_HISTORY_LOADED, 1227 chrome::NOTIFICATION_HISTORY_LOADED,
1226 content::Source<Profile>(profile_), 1228 content::Source<Profile>(profile_),
1227 content::Details<HistoryService>(this)); 1229 content::Details<HistoryService>(this));
1228 if (thread_ && profile_) { 1230 if (thread_ && profile_) {
1229 // We don't want to force creation of TopSites. 1231 // We don't want to force creation of TopSites.
1230 history::TopSites* ts = profile_->GetTopSitesWithoutCreating(); 1232 history::TopSites* ts = profile_->GetTopSitesWithoutCreating();
1231 if (ts) 1233 if (ts)
1232 ts->HistoryLoaded(); 1234 ts->HistoryLoaded();
1233 } 1235 }
1234 } 1236 }
1235 1237
1236 bool HistoryService::GetRowForURL(const GURL& url, history::URLRow* url_row) { 1238 bool HistoryService::GetRowForURL(const GURL& url, history::URLRow* url_row) {
1237 DCHECK(thread_checker_.CalledOnValidThread()); 1239 DCHECK(thread_checker_.CalledOnValidThread());
1238 history::URLDatabase* db = InMemoryDatabase(); 1240 history::URLDatabase* db = InMemoryDatabase();
1239 return db && (db->GetRowForURL(url, url_row) != 0); 1241 return db && (db->GetRowForURL(url, url_row) != 0);
1240 } 1242 }
1241 1243
1242 void HistoryService::StartTopSitesMigration(int backend_id) { 1244 void HistoryService::StartTopSitesMigration(int backend_id) {
1243 DCHECK(thread_checker_.CalledOnValidThread()); 1245 DCHECK(thread_checker_.CalledOnValidThread());
1244 if (!history_backend_ || current_backend_id_ != backend_id) { 1246 if (!history_backend_.get() || current_backend_id_ != backend_id) {
1245 DVLOG(1) << "Message from obsolete backend"; 1247 DVLOG(1) << "Message from obsolete backend";
1246 return; 1248 return;
1247 } 1249 }
1248 needs_top_sites_migration_ = true; 1250 needs_top_sites_migration_ = true;
1249 if (thread_ && profile_) { 1251 if (thread_ && profile_) {
1250 // We don't want to force creation of TopSites. 1252 // We don't want to force creation of TopSites.
1251 history::TopSites* ts = profile_->GetTopSitesWithoutCreating(); 1253 history::TopSites* ts = profile_->GetTopSitesWithoutCreating();
1252 if (ts) 1254 if (ts)
1253 ts->MigrateFromHistory(); 1255 ts->MigrateFromHistory();
1254 } 1256 }
(...skipping 16 matching lines...) Expand all
1271 DCHECK(thread_checker_.CalledOnValidThread()); 1273 DCHECK(thread_checker_.CalledOnValidThread());
1272 visit_database_observers_.RemoveObserver(observer); 1274 visit_database_observers_.RemoveObserver(observer);
1273 } 1275 }
1274 1276
1275 void HistoryService::NotifyVisitDBObserversOnAddVisit( 1277 void HistoryService::NotifyVisitDBObserversOnAddVisit(
1276 const history::BriefVisitInfo& info) { 1278 const history::BriefVisitInfo& info) {
1277 DCHECK(thread_checker_.CalledOnValidThread()); 1279 DCHECK(thread_checker_.CalledOnValidThread());
1278 FOR_EACH_OBSERVER(history::VisitDatabaseObserver, visit_database_observers_, 1280 FOR_EACH_OBSERVER(history::VisitDatabaseObserver, visit_database_observers_,
1279 OnAddVisit(info)); 1281 OnAddVisit(info));
1280 } 1282 }
OLDNEW
« no previous file with comments | « chrome/browser/history/history_browsertest.cc ('k') | chrome/browser/history/history_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698