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

Side by Side Diff: components/history/core/browser/history_backend.cc

Issue 1152933003: Preserve bookmark favicons when clearing all browsing data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
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 "components/history/core/browser/history_backend.h" 5 #include "components/history/core/browser/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 2512 matching lines...) Expand 10 before | Expand all | Expand 10 after
2523 // 2. Delete the original tables. Since tables can not share pages, we know 2523 // 2. Delete the original tables. Since tables can not share pages, we know
2524 // that any data we don't want to keep is now in an unused page. 2524 // that any data we don't want to keep is now in an unused page.
2525 // 3. Renaming the temporary tables to match the original. 2525 // 3. Renaming the temporary tables to match the original.
2526 // 4. Vacuuming the database to delete the unused pages. 2526 // 4. Vacuuming the database to delete the unused pages.
2527 // 2527 //
2528 // Since we are likely to have very few bookmarks and their dependencies 2528 // Since we are likely to have very few bookmarks and their dependencies
2529 // compared to all history, this is also much faster than just deleting from 2529 // compared to all history, this is also much faster than just deleting from
2530 // the original tables directly. 2530 // the original tables directly.
2531 2531
2532 // Get the bookmarked URLs. 2532 // Get the bookmarked URLs.
2533 std::vector<URLAndTitle> starred_urls; 2533 std::vector<URLAndTitle> starred_url_and_titles;
2534 HistoryClient* history_client = GetHistoryClient(); 2534 HistoryClient* history_client = GetHistoryClient();
2535 if (history_client) 2535 if (history_client)
2536 history_client->GetBookmarks(&starred_urls); 2536 history_client->GetBookmarks(&starred_url_and_titles);
2537 2537
2538 URLRows kept_urls; 2538 URLRows kept_url_rows;
2539 for (size_t i = 0; i < starred_urls.size(); i++) { 2539 std::vector<GURL> starred_urls;
2540 for (const URLAndTitle& url_and_title : starred_url_and_titles) {
2541 const GURL& url = url_and_title.url;
2542 starred_urls.push_back(url);
2543
2540 URLRow row; 2544 URLRow row;
2541 if (!db_->GetRowForURL(starred_urls[i].url, &row)) 2545 if (db_->GetRowForURL(url, &row)) {
2542 continue; 2546 // Clear the last visit time so when we write these rows they are "clean."
2543 2547 row.set_last_visit(Time());
2544 // Clear the last visit time so when we write these rows they are "clean." 2548 row.set_visit_count(0);
2545 row.set_last_visit(Time()); 2549 row.set_typed_count(0);
2546 row.set_visit_count(0); 2550 kept_url_rows.push_back(row);
2547 row.set_typed_count(0); 2551 }
2548 kept_urls.push_back(row);
2549 } 2552 }
2550 2553
2551 // Clear thumbnail and favicon history. The favicons for the given URLs will 2554 // Delete all cached favicons which are not used by bookmarks.
2552 // be kept. 2555 if (!ClearAllThumbnailHistory(starred_urls)) {
2553 if (!ClearAllThumbnailHistory(kept_urls)) {
2554 LOG(ERROR) << "Thumbnail history could not be cleared"; 2556 LOG(ERROR) << "Thumbnail history could not be cleared";
2555 // We continue in this error case. If the user wants to delete their 2557 // We continue in this error case. If the user wants to delete their
2556 // history, we should delete as much as we can. 2558 // history, we should delete as much as we can.
2557 } 2559 }
2558 2560
2559 // ClearAllMainHistory will change the IDs of the URLs in kept_urls. 2561 // ClearAllMainHistory will change the IDs of the URLs in kept_urls.
2560 // Therefore, we clear the list afterwards to make sure nobody uses this 2562 // Therefore, we clear the list afterwards to make sure nobody uses this
2561 // invalid data. 2563 // invalid data.
2562 if (!ClearAllMainHistory(kept_urls)) 2564 if (!ClearAllMainHistory(kept_url_rows))
2563 LOG(ERROR) << "Main history could not be cleared"; 2565 LOG(ERROR) << "Main history could not be cleared";
2564 kept_urls.clear(); 2566 kept_url_rows.clear();
2565 2567
2566 db_->GetStartDate(&first_recorded_time_); 2568 db_->GetStartDate(&first_recorded_time_);
2567 2569
2568 // Send out the notification that history is cleared. The in-memory database 2570 // Send out the notification that history is cleared. The in-memory database
2569 // will pick this up and clear itself. 2571 // will pick this up and clear itself.
2570 NotifyURLsDeleted(true, false, URLRows(), std::set<GURL>()); 2572 NotifyURLsDeleted(true, false, URLRows(), std::set<GURL>());
2571 } 2573 }
2572 2574
2573 bool HistoryBackend::ClearAllThumbnailHistory(const URLRows& kept_urls) { 2575 bool HistoryBackend::ClearAllThumbnailHistory(
2576 const std::vector<GURL>& kept_urls) {
2574 if (!thumbnail_db_) { 2577 if (!thumbnail_db_) {
2575 // When we have no reference to the thumbnail database, maybe there was an 2578 // When we have no reference to the thumbnail database, maybe there was an
2576 // error opening it. In this case, we just try to blow it away to try to 2579 // error opening it. In this case, we just try to blow it away to try to
2577 // fix the error if it exists. This may fail, in which case either the 2580 // fix the error if it exists. This may fail, in which case either the
2578 // file doesn't exist or there's no more we can do. 2581 // file doesn't exist or there's no more we can do.
2579 sql::Connection::Delete(GetFaviconsFileName()); 2582 sql::Connection::Delete(GetFaviconsFileName());
2580 2583
2581 // Older version of the database. 2584 // Older version of the database.
2582 sql::Connection::Delete(GetThumbnailFileName()); 2585 sql::Connection::Delete(GetThumbnailFileName());
2583 return true; 2586 return true;
2584 } 2587 }
2585 2588
2586 // Urls to retain mappings for.
2587 std::vector<GURL> urls_to_keep;
2588 for (URLRows::const_iterator i = kept_urls.begin(); i != kept_urls.end();
2589 ++i) {
2590 urls_to_keep.push_back(i->url());
2591 }
2592
2593 // Isolate from any long-running transaction. 2589 // Isolate from any long-running transaction.
2594 thumbnail_db_->CommitTransaction(); 2590 thumbnail_db_->CommitTransaction();
2595 thumbnail_db_->BeginTransaction(); 2591 thumbnail_db_->BeginTransaction();
2596 2592
2597 // TODO(shess): If this fails, perhaps the database should be razed 2593 // TODO(shess): If this fails, perhaps the database should be razed
2598 // or deleted. 2594 // or deleted.
2599 if (!thumbnail_db_->RetainDataForPageUrls(urls_to_keep)) { 2595 if (!thumbnail_db_->RetainDataForPageUrls(kept_urls)) {
2600 thumbnail_db_->RollbackTransaction(); 2596 thumbnail_db_->RollbackTransaction();
2601 thumbnail_db_->BeginTransaction(); 2597 thumbnail_db_->BeginTransaction();
2602 return false; 2598 return false;
2603 } 2599 }
2604 2600
2605 #if defined(OS_ANDROID) 2601 #if defined(OS_ANDROID)
2606 // TODO (michaelbai): Add the unit test once AndroidProviderBackend is 2602 // TODO (michaelbai): Add the unit test once AndroidProviderBackend is
2607 // available in HistoryBackend. 2603 // available in HistoryBackend.
2608 db_->ClearAndroidURLRows(); 2604 db_->ClearAndroidURLRows();
2609 #endif 2605 #endif
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2647 return true; 2643 return true;
2648 } 2644 }
2649 2645
2650 HistoryClient* HistoryBackend::GetHistoryClient() { 2646 HistoryClient* HistoryBackend::GetHistoryClient() {
2651 if (history_client_) 2647 if (history_client_)
2652 history_client_->BlockUntilBookmarksLoaded(); 2648 history_client_->BlockUntilBookmarksLoaded();
2653 return history_client_; 2649 return history_client_;
2654 } 2650 }
2655 2651
2656 } // namespace history 2652 } // namespace history
OLDNEW
« no previous file with comments | « components/history/core/browser/history_backend.h ('k') | components/history/core/browser/history_backend_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698