Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/expire_history_backend.h" | 5 #include "chrome/browser/history/expire_history_backend.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 ArchivedDatabase* archived_db, | 190 ArchivedDatabase* archived_db, |
| 191 ThumbnailDatabase* thumb_db, | 191 ThumbnailDatabase* thumb_db, |
| 192 TextDatabaseManager* text_db) { | 192 TextDatabaseManager* text_db) { |
| 193 main_db_ = main_db; | 193 main_db_ = main_db; |
| 194 archived_db_ = archived_db; | 194 archived_db_ = archived_db; |
| 195 thumb_db_ = thumb_db; | 195 thumb_db_ = thumb_db; |
| 196 text_db_ = text_db; | 196 text_db_ = text_db; |
| 197 } | 197 } |
| 198 | 198 |
| 199 void ExpireHistoryBackend::DeleteURL(const GURL& url) { | 199 void ExpireHistoryBackend::DeleteURL(const GURL& url) { |
| 200 if (!main_db_) | 200 if (!main_db_) |
|
sky
2011/12/14 23:16:49
Implement this in terms of DeleteURLs.
akalin
2011/12/14 23:43:08
Done.
| |
| 201 return; | 201 return; |
| 202 | 202 |
| 203 URLRow url_row; | |
| 204 if (!main_db_->GetRowForURL(url, &url_row)) | |
| 205 return; // Nothing to delete. | |
| 206 | |
| 207 // Collect all the visits and delete them. Note that we don't give up if | |
| 208 // there are no visits, since the URL could still have an entry that we should | |
| 209 // delete. | |
| 210 // TODO(brettw): bug 1171148: We should also delete from the archived DB. | |
| 211 VisitVector visits; | |
| 212 main_db_->GetVisitsForURL(url_row.id(), &visits); | |
| 213 | |
| 214 DeleteDependencies dependencies; | 203 DeleteDependencies dependencies; |
| 215 DeleteVisitRelatedInfo(visits, &dependencies); | 204 DeleteURLHelper(url, &dependencies); |
| 216 | |
| 217 // We skip ExpireURLsForVisits (since we are deleting from the URL, and not | |
| 218 // starting with visits in a given time range). We therefore need to call the | |
| 219 // deletion and favicon update functions manually. | |
| 220 | |
| 221 BookmarkService* bookmark_service = GetBookmarkService(); | |
| 222 bool is_bookmarked = | |
| 223 (bookmark_service && bookmark_service->IsBookmarked(url)); | |
| 224 | |
| 225 DeleteOneURL(url_row, is_bookmarked, &dependencies); | |
| 226 if (!is_bookmarked) | |
| 227 DeleteFaviconsIfPossible(dependencies.affected_favicons); | |
| 228 | |
| 229 if (text_db_) | |
| 230 text_db_->OptimizeChangedDatabases(dependencies.text_db_changes); | |
| 231 | 205 |
| 232 BroadcastDeleteNotifications(&dependencies); | 206 BroadcastDeleteNotifications(&dependencies); |
| 233 } | 207 } |
| 208 | |
| 209 void ExpireHistoryBackend::DeleteURLs(const std::vector<GURL>& urls) { | |
| 210 if (!main_db_) | |
| 211 return; | |
| 212 | |
| 213 DeleteDependencies dependencies; | |
| 214 for (std::vector<GURL>::const_iterator url = urls.begin(); url != urls.end(); | |
| 215 ++url) { | |
| 216 DeleteURLHelper(*url, &dependencies); | |
| 217 } | |
| 218 | |
| 219 BroadcastDeleteNotifications(&dependencies); | |
| 220 } | |
| 234 | 221 |
| 235 void ExpireHistoryBackend::ExpireHistoryBetween( | 222 void ExpireHistoryBackend::ExpireHistoryBetween( |
| 236 const std::set<GURL>& restrict_urls, Time begin_time, Time end_time) { | 223 const std::set<GURL>& restrict_urls, Time begin_time, Time end_time) { |
| 237 if (!main_db_) | 224 if (!main_db_) |
| 238 return; | 225 return; |
| 239 | 226 |
| 240 // There may be stuff in the text database manager's temporary cache. | 227 // There may be stuff in the text database manager's temporary cache. |
| 241 if (text_db_) | 228 if (text_db_) |
| 242 text_db_->DeleteFromUncommitted(restrict_urls, begin_time, end_time); | 229 text_db_->DeleteFromUncommitted(restrict_urls, begin_time, end_time); |
| 243 | 230 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 351 // determine if they care whether anything was deleted). | 338 // determine if they care whether anything was deleted). |
| 352 URLsDeletedDetails* deleted_details = new URLsDeletedDetails; | 339 URLsDeletedDetails* deleted_details = new URLsDeletedDetails; |
| 353 deleted_details->all_history = false; | 340 deleted_details->all_history = false; |
| 354 for (size_t i = 0; i < dependencies->deleted_urls.size(); i++) | 341 for (size_t i = 0; i < dependencies->deleted_urls.size(); i++) |
| 355 deleted_details->urls.insert(dependencies->deleted_urls[i].url()); | 342 deleted_details->urls.insert(dependencies->deleted_urls[i].url()); |
| 356 delegate_->BroadcastNotifications( | 343 delegate_->BroadcastNotifications( |
| 357 chrome::NOTIFICATION_HISTORY_URLS_DELETED, deleted_details); | 344 chrome::NOTIFICATION_HISTORY_URLS_DELETED, deleted_details); |
| 358 } | 345 } |
| 359 } | 346 } |
| 360 | 347 |
| 348 void ExpireHistoryBackend::DeleteURLHelper( | |
| 349 const GURL& url, DeleteDependencies* dependencies) { | |
| 350 URLRow url_row; | |
| 351 if (!main_db_->GetRowForURL(url, &url_row)) | |
| 352 return; // Nothing to delete. | |
| 353 | |
| 354 // Collect all the visits and delete them. Note that we don't give up if | |
| 355 // there are no visits, since the URL could still have an entry that we should | |
| 356 // delete. | |
| 357 // TODO(brettw): bug 1171148: We should also delete from the archived DB. | |
| 358 VisitVector visits; | |
| 359 main_db_->GetVisitsForURL(url_row.id(), &visits); | |
| 360 | |
| 361 DeleteVisitRelatedInfo(visits, dependencies); | |
| 362 | |
| 363 // We skip ExpireURLsForVisits (since we are deleting from the URL, and not | |
| 364 // starting with visits in a given time range). We therefore need to call the | |
| 365 // deletion and favicon update functions manually. | |
| 366 | |
| 367 BookmarkService* bookmark_service = GetBookmarkService(); | |
| 368 bool is_bookmarked = | |
| 369 (bookmark_service && bookmark_service->IsBookmarked(url)); | |
| 370 | |
| 371 DeleteOneURL(url_row, is_bookmarked, dependencies); | |
| 372 if (!is_bookmarked) | |
| 373 DeleteFaviconsIfPossible(dependencies->affected_favicons); | |
| 374 | |
| 375 if (text_db_) | |
| 376 text_db_->OptimizeChangedDatabases(dependencies->text_db_changes); | |
| 377 } | |
| 378 | |
| 361 void ExpireHistoryBackend::DeleteVisitRelatedInfo( | 379 void ExpireHistoryBackend::DeleteVisitRelatedInfo( |
| 362 const VisitVector& visits, | 380 const VisitVector& visits, |
| 363 DeleteDependencies* dependencies) { | 381 DeleteDependencies* dependencies) { |
| 364 for (size_t i = 0; i < visits.size(); i++) { | 382 for (size_t i = 0; i < visits.size(); i++) { |
| 365 // Delete the visit itself. | 383 // Delete the visit itself. |
| 366 main_db_->DeleteVisit(visits[i]); | 384 main_db_->DeleteVisit(visits[i]); |
| 367 | 385 |
| 368 // Add the URL row to the affected URL list. | 386 // Add the URL row to the affected URL list. |
| 369 std::map<URLID, URLRow>::const_iterator found = | 387 std::map<URLID, URLRow>::const_iterator found = |
| 370 dependencies->affected_urls.find(visits[i].url_id); | 388 dependencies->affected_urls.find(visits[i].url_id); |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 707 // We use the bookmark service to determine if a URL is bookmarked. The | 725 // We use the bookmark service to determine if a URL is bookmarked. The |
| 708 // bookmark service is loaded on a separate thread and may not be done by the | 726 // bookmark service is loaded on a separate thread and may not be done by the |
| 709 // time we get here. We therefor block until the bookmarks have finished | 727 // time we get here. We therefor block until the bookmarks have finished |
| 710 // loading. | 728 // loading. |
| 711 if (bookmark_service_) | 729 if (bookmark_service_) |
| 712 bookmark_service_->BlockTillLoaded(); | 730 bookmark_service_->BlockTillLoaded(); |
| 713 return bookmark_service_; | 731 return bookmark_service_; |
| 714 } | 732 } |
| 715 | 733 |
| 716 } // namespace history | 734 } // namespace history |
| OLD | NEW |