| 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 // 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 base::Bind(&HistoryService::NotifyURLVisited, | 176 base::Bind(&HistoryService::NotifyURLVisited, |
| 177 history_service_, | 177 history_service_, |
| 178 transition, | 178 transition, |
| 179 row, | 179 row, |
| 180 redirects, | 180 redirects, |
| 181 visit_time)); | 181 visit_time)); |
| 182 } | 182 } |
| 183 | 183 |
| 184 void NotifyURLsModified(const history::URLRows& changed_urls) override { | 184 void NotifyURLsModified(const history::URLRows& changed_urls) override { |
| 185 service_task_runner_->PostTask( | 185 service_task_runner_->PostTask( |
| 186 FROM_HERE, | 186 FROM_HERE, base::Bind(&HistoryService::NotifyURLsModified, |
| 187 base::Bind(&HistoryService::NotifyURLsModified, | 187 history_service_, changed_urls)); |
| 188 history_service_, | 188 } |
| 189 changed_urls)); | 189 |
| 190 void NotifyURLsDeleted( |
| 191 const history::URLsDeletedDetails& deleted_details) override { |
| 192 service_task_runner_->PostTask( |
| 193 FROM_HERE, base::Bind(&HistoryService::NotifyURLsDeleted, |
| 194 history_service_, deleted_details)); |
| 190 } | 195 } |
| 191 | 196 |
| 192 void BroadcastNotifications( | 197 void BroadcastNotifications( |
| 193 int type, | 198 int type, |
| 194 scoped_ptr<history::HistoryDetails> details) override { | 199 scoped_ptr<history::HistoryDetails> details) override { |
| 195 // Send the notification on the history thread. | 200 // Send the notification on the history thread. |
| 196 if (content::NotificationService::current()) { | 201 if (content::NotificationService::current()) { |
| 197 content::Details<history::HistoryDetails> det(details.get()); | 202 content::Details<history::HistoryDetails> det(details.get()); |
| 198 content::NotificationService::current()->Notify( | 203 content::NotificationService::current()->Notify( |
| 199 type, content::Source<Profile>(profile_), det); | 204 type, content::Source<Profile>(profile_), det); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 HistoryService::HistoryService(history::HistoryClient* client, Profile* profile) | 237 HistoryService::HistoryService(history::HistoryClient* client, Profile* profile) |
| 233 : thread_(new base::Thread(kHistoryThreadName)), | 238 : thread_(new base::Thread(kHistoryThreadName)), |
| 234 history_client_(client), | 239 history_client_(client), |
| 235 profile_(profile), | 240 profile_(profile), |
| 236 visitedlink_master_(new visitedlink::VisitedLinkMaster( | 241 visitedlink_master_(new visitedlink::VisitedLinkMaster( |
| 237 profile, this, true)), | 242 profile, this, true)), |
| 238 backend_loaded_(false), | 243 backend_loaded_(false), |
| 239 no_db_(false), | 244 no_db_(false), |
| 240 weak_ptr_factory_(this) { | 245 weak_ptr_factory_(this) { |
| 241 DCHECK(profile_); | 246 DCHECK(profile_); |
| 242 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, | |
| 243 content::Source<Profile>(profile_)); | |
| 244 } | 247 } |
| 245 | 248 |
| 246 HistoryService::~HistoryService() { | 249 HistoryService::~HistoryService() { |
| 247 DCHECK(thread_checker_.CalledOnValidThread()); | 250 DCHECK(thread_checker_.CalledOnValidThread()); |
| 248 // Shutdown the backend. This does nothing if Cleanup was already invoked. | 251 // Shutdown the backend. This does nothing if Cleanup was already invoked. |
| 249 Cleanup(); | 252 Cleanup(); |
| 250 } | 253 } |
| 251 | 254 |
| 252 bool HistoryService::BackendLoaded() { | 255 bool HistoryService::BackendLoaded() { |
| 253 DCHECK(thread_checker_.CalledOnValidThread()); | 256 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 933 } | 936 } |
| 934 | 937 |
| 935 // Delete the thread, which joins with the background thread. We defensively | 938 // Delete the thread, which joins with the background thread. We defensively |
| 936 // NULL the pointer before deleting it in case somebody tries to use it | 939 // NULL the pointer before deleting it in case somebody tries to use it |
| 937 // during shutdown, but this shouldn't happen. | 940 // during shutdown, but this shouldn't happen. |
| 938 base::Thread* thread = thread_; | 941 base::Thread* thread = thread_; |
| 939 thread_ = NULL; | 942 thread_ = NULL; |
| 940 delete thread; | 943 delete thread; |
| 941 } | 944 } |
| 942 | 945 |
| 943 void HistoryService::Observe(int type, | |
| 944 const content::NotificationSource& source, | |
| 945 const content::NotificationDetails& details) { | |
| 946 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 947 if (!thread_) | |
| 948 return; | |
| 949 | |
| 950 switch (type) { | |
| 951 case chrome::NOTIFICATION_HISTORY_URLS_DELETED: { | |
| 952 // Update the visited link system for deleted URLs. We will update the | |
| 953 // visited link system for added URLs as soon as we get the add | |
| 954 // notification (we don't have to wait for the backend, which allows us to | |
| 955 // be faster to update the state). | |
| 956 // | |
| 957 // For deleted URLs, we don't typically know what will be deleted since | |
| 958 // delete notifications are by time. We would also like to be more | |
| 959 // respectful of privacy and never tell the user something is gone when it | |
| 960 // isn't. Therefore, we update the delete URLs after the fact. | |
| 961 if (visitedlink_master_) { | |
| 962 content::Details<history::URLsDeletedDetails> deleted_details(details); | |
| 963 | |
| 964 if (deleted_details->all_history) { | |
| 965 visitedlink_master_->DeleteAllURLs(); | |
| 966 } else { | |
| 967 URLIteratorFromURLRows iterator(deleted_details->rows); | |
| 968 visitedlink_master_->DeleteURLs(&iterator); | |
| 969 } | |
| 970 } | |
| 971 break; | |
| 972 } | |
| 973 | |
| 974 default: | |
| 975 NOTREACHED(); | |
| 976 } | |
| 977 } | |
| 978 | |
| 979 void HistoryService::RebuildTable( | 946 void HistoryService::RebuildTable( |
| 980 const scoped_refptr<URLEnumerator>& enumerator) { | 947 const scoped_refptr<URLEnumerator>& enumerator) { |
| 981 DCHECK(thread_) << "History service being called after cleanup"; | 948 DCHECK(thread_) << "History service being called after cleanup"; |
| 982 DCHECK(thread_checker_.CalledOnValidThread()); | 949 DCHECK(thread_checker_.CalledOnValidThread()); |
| 983 ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::IterateURLs, enumerator); | 950 ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::IterateURLs, enumerator); |
| 984 } | 951 } |
| 985 | 952 |
| 986 bool HistoryService::Init(const base::FilePath& history_dir, bool no_db) { | 953 bool HistoryService::Init(const base::FilePath& history_dir, bool no_db) { |
| 987 DCHECK(thread_) << "History service being called after cleanup"; | 954 DCHECK(thread_) << "History service being called after cleanup"; |
| 988 DCHECK(thread_checker_.CalledOnValidThread()); | 955 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1261 OnURLVisited(this, transition, row, redirects, visit_time)); | 1228 OnURLVisited(this, transition, row, redirects, visit_time)); |
| 1262 } | 1229 } |
| 1263 | 1230 |
| 1264 void HistoryService::NotifyURLsModified(const history::URLRows& changed_urls) { | 1231 void HistoryService::NotifyURLsModified(const history::URLRows& changed_urls) { |
| 1265 DCHECK(thread_checker_.CalledOnValidThread()); | 1232 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1266 FOR_EACH_OBSERVER(history::HistoryServiceObserver, | 1233 FOR_EACH_OBSERVER(history::HistoryServiceObserver, |
| 1267 observers_, | 1234 observers_, |
| 1268 OnURLsModified(this, changed_urls)); | 1235 OnURLsModified(this, changed_urls)); |
| 1269 } | 1236 } |
| 1270 | 1237 |
| 1238 void HistoryService::NotifyURLsDeleted( |
| 1239 const history::URLsDeletedDetails& deleted_details) { |
| 1240 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1241 // Update the visited link system for deleted URLs. We will update the |
| 1242 // visited link system for added URLs as soon as we get the add |
| 1243 // notification (we don't have to wait for the backend, which allows us to |
| 1244 // be faster to update the state). |
| 1245 // |
| 1246 // For deleted URLs, we don't typically know what will be deleted since |
| 1247 // delete notifications are by time. We would also like to be more |
| 1248 // respectful of privacy and never tell the user something is gone when it |
| 1249 // isn't. Therefore, we update the delete URLs after the fact. |
| 1250 if (visitedlink_master_) { |
| 1251 if (deleted_details.all_history) { |
| 1252 visitedlink_master_->DeleteAllURLs(); |
| 1253 } else { |
| 1254 URLIteratorFromURLRows iterator(deleted_details.rows); |
| 1255 visitedlink_master_->DeleteURLs(&iterator); |
| 1256 } |
| 1257 } |
| 1258 |
| 1259 FOR_EACH_OBSERVER(history::HistoryServiceObserver, observers_, |
| 1260 OnURLsDeleted(this, deleted_details)); |
| 1261 } |
| 1262 |
| 1271 void HistoryService::NotifyHistoryServiceLoaded() { | 1263 void HistoryService::NotifyHistoryServiceLoaded() { |
| 1272 DCHECK(thread_checker_.CalledOnValidThread()); | 1264 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1273 FOR_EACH_OBSERVER(history::HistoryServiceObserver, observers_, | 1265 FOR_EACH_OBSERVER(history::HistoryServiceObserver, observers_, |
| 1274 OnHistoryServiceLoaded(this)); | 1266 OnHistoryServiceLoaded(this)); |
| 1275 } | 1267 } |
| 1276 | 1268 |
| 1277 void HistoryService::NotifyHistoryServiceBeingDeleted() { | 1269 void HistoryService::NotifyHistoryServiceBeingDeleted() { |
| 1278 DCHECK(thread_checker_.CalledOnValidThread()); | 1270 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1279 FOR_EACH_OBSERVER(history::HistoryServiceObserver, observers_, | 1271 FOR_EACH_OBSERVER(history::HistoryServiceObserver, observers_, |
| 1280 HistoryServiceBeingDeleted(this)); | 1272 HistoryServiceBeingDeleted(this)); |
| 1281 } | 1273 } |
| 1282 | 1274 |
| 1283 scoped_ptr<base::CallbackList<void(const std::set<GURL>&)>::Subscription> | 1275 scoped_ptr<base::CallbackList<void(const std::set<GURL>&)>::Subscription> |
| 1284 HistoryService::AddFaviconChangedCallback( | 1276 HistoryService::AddFaviconChangedCallback( |
| 1285 const HistoryService::OnFaviconChangedCallback& callback) { | 1277 const HistoryService::OnFaviconChangedCallback& callback) { |
| 1286 DCHECK(thread_checker_.CalledOnValidThread()); | 1278 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1287 return favicon_changed_callback_list_.Add(callback); | 1279 return favicon_changed_callback_list_.Add(callback); |
| 1288 } | 1280 } |
| 1289 | 1281 |
| 1290 void HistoryService::NotifyFaviconChanged( | 1282 void HistoryService::NotifyFaviconChanged( |
| 1291 const std::set<GURL>& changed_favicons) { | 1283 const std::set<GURL>& changed_favicons) { |
| 1292 DCHECK(thread_checker_.CalledOnValidThread()); | 1284 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1293 favicon_changed_callback_list_.Notify(changed_favicons); | 1285 favicon_changed_callback_list_.Notify(changed_favicons); |
| 1294 } | 1286 } |
| OLD | NEW |