diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-05 08:15:53 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-05 08:15:53 +0000 |
commit | 21f4d251210a4408da8a3279510ef7eb44cc1e1a (patch) | |
tree | a235ca4b807641d671b244fc78ed9bb64205b4ac /chrome/browser/history | |
parent | 0c86dbf56c6f3e82ee748f34dca48aedf962dec2 (diff) | |
download | chromium_src-21f4d251210a4408da8a3279510ef7eb44cc1e1a.zip chromium_src-21f4d251210a4408da8a3279510ef7eb44cc1e1a.tar.gz chromium_src-21f4d251210a4408da8a3279510ef7eb44cc1e1a.tar.bz2 |
Implement edit mode for history page.
BUG=35338
TEST=none
Review URL: http://codereview.chromium.org/660283
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40722 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/history')
-rw-r--r-- | chrome/browser/history/expire_history_backend.cc | 28 | ||||
-rw-r--r-- | chrome/browser/history/expire_history_backend.h | 8 | ||||
-rw-r--r-- | chrome/browser/history/expire_history_backend_unittest.cc | 65 | ||||
-rw-r--r-- | chrome/browser/history/history.cc | 7 | ||||
-rw-r--r-- | chrome/browser/history/history.h | 7 | ||||
-rw-r--r-- | chrome/browser/history/history_backend.cc | 9 | ||||
-rw-r--r-- | chrome/browser/history/history_backend.h | 3 | ||||
-rw-r--r-- | chrome/browser/history/history_backend_unittest.cc | 6 | ||||
-rw-r--r-- | chrome/browser/history/text_database_manager.cc | 25 | ||||
-rw-r--r-- | chrome/browser/history/text_database_manager.h | 12 |
10 files changed, 129 insertions, 41 deletions
diff --git a/chrome/browser/history/expire_history_backend.cc b/chrome/browser/history/expire_history_backend.cc index 882a53c..2a01212 100644 --- a/chrome/browser/history/expire_history_backend.cc +++ b/chrome/browser/history/expire_history_backend.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -212,19 +212,32 @@ void ExpireHistoryBackend::DeleteURL(const GURL& url) { BroadcastDeleteNotifications(&dependencies); } -void ExpireHistoryBackend::ExpireHistoryBetween(Time begin_time, - Time end_time) { +void ExpireHistoryBackend::ExpireHistoryBetween( + const std::set<GURL>& restrict_urls, Time begin_time, Time end_time) { if (!main_db_) return; // There may be stuff in the text database manager's temporary cache. if (text_db_) - text_db_->DeleteFromUncommitted(begin_time, end_time); + text_db_->DeleteFromUncommitted(restrict_urls, begin_time, end_time); // Find the affected visits and delete them. // TODO(brettw): bug 1171164: We should query the archived database here, too. VisitVector visits; main_db_->GetAllVisitsInRange(begin_time, end_time, 0, &visits); + if (!restrict_urls.empty()) { + std::set<URLID> url_ids; + for (std::set<GURL>::const_iterator url = restrict_urls.begin(); + url != restrict_urls.end(); ++url) + url_ids.insert(main_db_->GetRowForURL(*url, NULL)); + VisitVector all_visits; + all_visits.swap(visits); + for (VisitVector::iterator visit = all_visits.begin(); + visit != all_visits.end(); ++visit) { + if (url_ids.find(visit->url_id) != url_ids.end()) + visits.push_back(*visit); + } + } if (visits.empty()) return; @@ -375,8 +388,11 @@ void ExpireHistoryBackend::DeleteOneURL( main_db_->DeleteSegmentForURL(url_row.id()); // The URL may be in the text database manager's temporary cache. - if (text_db_) - text_db_->DeleteURLFromUncommitted(url_row.url()); + if (text_db_) { + std::set<GURL> restrict_urls; + restrict_urls.insert(url_row.url()); + text_db_->DeleteFromUncommitted(restrict_urls, base::Time(), base::Time()); + } if (!is_bookmarked) { dependencies->deleted_urls.push_back(url_row); diff --git a/chrome/browser/history/expire_history_backend.h b/chrome/browser/history/expire_history_backend.h index 5b7525c..11c0416 100644 --- a/chrome/browser/history/expire_history_backend.h +++ b/chrome/browser/history/expire_history_backend.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -82,8 +82,10 @@ class ExpireHistoryBackend { // Deletes everything associated with a URL. void DeleteURL(const GURL& url); - // Removes all visits in the given time range, updating the URLs accordingly. - void ExpireHistoryBetween(base::Time begin_time, base::Time end_time); + // Removes all visits to restrict_urls (or all URLs if empty) in the given + // time range, updating the URLs accordingly, + void ExpireHistoryBetween(const std::set<GURL>& restrict_urls, + base::Time begin_time, base::Time end_time); // Archives all visits before and including the given time, updating the URLs // accordingly. This function is intended for migrating old databases diff --git a/chrome/browser/history/expire_history_backend_unittest.cc b/chrome/browser/history/expire_history_backend_unittest.cc index 03c4eef..2cdce64 100644 --- a/chrome/browser/history/expire_history_backend_unittest.cc +++ b/chrome/browser/history/expire_history_backend_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -529,7 +529,8 @@ TEST_F(ExpireHistoryTest, FlushRecentURLsUnstarred) { visits[0].visit_time); // This should delete the last two visits. - expirer_.ExpireHistoryBetween(visit_times[2], Time()); + std::set<GURL> restrict_urls; + expirer_.ExpireHistoryBetween(restrict_urls, visit_times[2], Time()); // Run the text database expirer. This will flush any pending entries so we // can check that nothing was committed. We use a time far in the future so @@ -562,6 +563,63 @@ TEST_F(ExpireHistoryTest, FlushRecentURLsUnstarred) { EXPECT_FALSE(HasFavIcon(url_row2.favicon_id())); } +// Expires only a specific URLs more recent than a given time, with no starred +// items. Our time threshold is such that the URL should be updated (we delete +// one of the two visits). +TEST_F(ExpireHistoryTest, FlushRecentURLsUnstarredRestricted) { + URLID url_ids[3]; + Time visit_times[4]; + AddExampleData(url_ids, visit_times); + + URLRow url_row1, url_row2; + ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1)); + ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &url_row2)); + + // In this test we also make sure that any pending entries in the text + // database manager are removed. + VisitVector visits; + main_db_->GetVisitsForURL(url_ids[2], &visits); + ASSERT_EQ(1U, visits.size()); + text_db_->AddPageURL(url_row2.url(), url_row2.id(), visits[0].visit_id, + visits[0].visit_time); + + // This should delete the last two visits. + std::set<GURL> restrict_urls; + restrict_urls.insert(url_row1.url()); + expirer_.ExpireHistoryBetween(restrict_urls, visit_times[2], Time()); + + // Run the text database expirer. This will flush any pending entries so we + // can check that nothing was committed. We use a time far in the future so + // that anything added recently will get flushed. + TimeTicks expiration_time = TimeTicks::Now() + TimeDelta::FromDays(1); + text_db_->FlushOldChangesForTime(expiration_time); + + // Verify that the middle URL had its last visit deleted only. + visits.clear(); + main_db_->GetVisitsForURL(url_ids[1], &visits); + EXPECT_EQ(1U, visits.size()); + EXPECT_EQ(0, CountTextMatchesForURL(url_row1.url())); + + // Verify that the middle URL visit time and visit counts were updated. + URLRow temp_row; + ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row)); + EXPECT_TRUE(visit_times[2] == url_row1.last_visit()); // Previous value. + EXPECT_TRUE(visit_times[1] == temp_row.last_visit()); // New value. + EXPECT_EQ(2, url_row1.visit_count()); + EXPECT_EQ(1, temp_row.visit_count()); + EXPECT_EQ(1, url_row1.typed_count()); + EXPECT_EQ(0, temp_row.typed_count()); + + // Verify that the middle URL's favicon and thumbnail is still there. + EXPECT_TRUE(HasFavIcon(url_row1.favicon_id())); + EXPECT_TRUE(HasThumbnail(url_row1.id())); + + // Verify that the last URL was not touched. + EXPECT_TRUE(main_db_->GetURLRow(url_ids[2], &temp_row)); + EXPECT_TRUE(HasFavIcon(url_row2.favicon_id())); + EXPECT_TRUE(HasThumbnail(url_row2.id())); +} + // Expire a starred URL, it shouldn't get deleted TEST_F(ExpireHistoryTest, FlushRecentURLsStarred) { URLID url_ids[3]; @@ -577,7 +635,8 @@ TEST_F(ExpireHistoryTest, FlushRecentURLsStarred) { StarURL(url_row2.url()); // This should delete the last two visits. - expirer_.ExpireHistoryBetween(visit_times[2], Time()); + std::set<GURL> restrict_urls; + expirer_.ExpireHistoryBetween(restrict_urls, visit_times[2], Time()); // The URL rows should still exist. URLRow new_url_row1, new_url_row2; diff --git a/chrome/browser/history/history.cc b/chrome/browser/history/history.cc index 71d48f0..53ad780 100644 --- a/chrome/browser/history/history.cc +++ b/chrome/browser/history/history.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -664,14 +664,15 @@ void HistoryService::DeleteURL(const GURL& url) { } void HistoryService::ExpireHistoryBetween( + const std::set<GURL>& restrict_urls, Time begin_time, Time end_time, CancelableRequestConsumerBase* consumer, ExpireHistoryCallback* callback) { // We will update the visited links when we observe the delete notifications. Schedule(PRIORITY_UI, &HistoryBackend::ExpireHistoryBetween, consumer, - new history::ExpireHistoryRequest(callback), - begin_time, end_time); + new history::ExpireHistoryRequest(callback), + restrict_urls, begin_time, end_time); } void HistoryService::BroadcastNotifications( diff --git a/chrome/browser/history/history.h b/chrome/browser/history/history.h index 5d251c0..8f7c68c 100644 --- a/chrome/browser/history/history.h +++ b/chrome/browser/history/history.h @@ -359,7 +359,7 @@ class HistoryService : public CancelableRequestProvider, // Delete all the information related to a single url. void DeleteURL(const GURL& url); - // Implemented by the caller of 'ExpireHistory(Since|Between)' below, and + // Implemented by the caller of ExpireHistoryBetween, and // is called when the history service has deleted the history. typedef Callback0::Type ExpireHistoryCallback; @@ -369,7 +369,10 @@ class HistoryService : public CancelableRequestProvider, // if they are no longer referenced. |callback| runs when the expiration is // complete. You may use null Time values to do an unbounded delete in // either direction. - void ExpireHistoryBetween(base::Time begin_time, base::Time end_time, + // If |restrict_urls| is not empty, only visits to the URLs in this set are + // removed. + void ExpireHistoryBetween(const std::set<GURL>& restrict_urls, + base::Time begin_time, base::Time end_time, CancelableRequestConsumerBase* consumer, ExpireHistoryCallback* callback); diff --git a/chrome/browser/history/history_backend.cc b/chrome/browser/history/history_backend.cc index 4fdcef8..33c079a 100644 --- a/chrome/browser/history/history_backend.cc +++ b/chrome/browser/history/history_backend.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -1740,19 +1740,20 @@ void HistoryBackend::DeleteURL(const GURL& url) { void HistoryBackend::ExpireHistoryBetween( scoped_refptr<ExpireHistoryRequest> request, + const std::set<GURL>& restrict_urls, Time begin_time, Time end_time) { if (request->canceled()) return; if (db_.get()) { - if (begin_time.is_null() && end_time.is_null()) { + if (begin_time.is_null() && end_time.is_null() && restrict_urls.empty()) { // Special case deleting all history so it can be faster and to reduce the // possibility of an information leak. DeleteAllHistory(); } else { // Clearing parts of history, have the expirer do the depend - expirer_.ExpireHistoryBetween(begin_time, end_time); + expirer_.ExpireHistoryBetween(restrict_urls, begin_time, end_time); // Force a commit, if the user is deleting something for privacy reasons, // we want to get it on disk ASAP. @@ -1765,7 +1766,7 @@ void HistoryBackend::ExpireHistoryBetween( request->ForwardResult(ExpireHistoryRequest::TupleType()); - if (history_publisher_.get()) + if (history_publisher_.get() && restrict_urls.empty()) history_publisher_->DeleteUserHistoryBetween(begin_time, end_time); } diff --git a/chrome/browser/history/history_backend.h b/chrome/browser/history/history_backend.h index 49569f5..54d8d63 100644 --- a/chrome/browser/history/history_backend.h +++ b/chrome/browser/history/history_backend.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -245,6 +245,7 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>, // Calls ExpireHistoryBackend::ExpireHistoryBetween and commits the change. void ExpireHistoryBetween(scoped_refptr<ExpireHistoryRequest> request, + const std::set<GURL>& restrict_urls, base::Time begin_time, base::Time end_time); diff --git a/chrome/browser/history/history_backend_unittest.cc b/chrome/browser/history/history_backend_unittest.cc index 84f1d95..d3d28a4 100644 --- a/chrome/browser/history/history_backend_unittest.cc +++ b/chrome/browser/history/history_backend_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -465,7 +465,9 @@ TEST_F(HistoryBackendTest, KeywordGenerated) { EXPECT_TRUE(visits.empty()); // Expire the visits. - backend_->expire_backend()->ExpireHistoryBetween(visit_time, Time::Now()); + std::set<GURL> restrict_urls; + backend_->expire_backend()->ExpireHistoryBetween(restrict_urls, + visit_time, Time::Now()); // The visit should have been nuked. visits.clear(); diff --git a/chrome/browser/history/text_database_manager.cc b/chrome/browser/history/text_database_manager.cc index 149cd72..0b27203 100644 --- a/chrome/browser/history/text_database_manager.cc +++ b/chrome/browser/history/text_database_manager.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -337,7 +337,8 @@ void TextDatabaseManager::DeletePageData(Time time, const GURL& url, db->DeletePageData(time, URLDatabase::GURLToDatabaseURL(url)); } -void TextDatabaseManager::DeleteFromUncommitted(Time begin, Time end) { +void TextDatabaseManager::DeleteFromUncommitted( + const std::set<GURL>& restrict_urls, Time begin, Time end) { // First find the beginning of the range to delete. Recall that the list // has the most recent item at the beginning. There won't normally be very // many items, so a brute-force search is fine. @@ -352,15 +353,17 @@ void TextDatabaseManager::DeleteFromUncommitted(Time begin, Time end) { // Now delete all visits up to the oldest one we were supposed to delete. // Note that if begin is_null, it will be less than or equal to any other // time. - while (cur != recent_changes_.end() && cur->second.visit_time() >= begin) - cur = recent_changes_.Erase(cur); -} - -void TextDatabaseManager::DeleteURLFromUncommitted(const GURL& url) { - RecentChangeList::iterator found = recent_changes_.Peek(url); - if (found == recent_changes_.end()) - return; // We don't know about this page, give up. - recent_changes_.Erase(found); + if (restrict_urls.empty()) { + while (cur != recent_changes_.end() && cur->second.visit_time() >= begin) + cur = recent_changes_.Erase(cur); + } else { + while (cur != recent_changes_.end() && cur->second.visit_time() >= begin) { + if (restrict_urls.find(cur->first) != restrict_urls.end()) + cur = recent_changes_.Erase(cur); + else + ++cur; + } + } } void TextDatabaseManager::DeleteAll() { diff --git a/chrome/browser/history/text_database_manager.h b/chrome/browser/history/text_database_manager.h index b27b9db..cec9dea 100644 --- a/chrome/browser/history/text_database_manager.h +++ b/chrome/browser/history/text_database_manager.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -124,14 +124,13 @@ class TextDatabaseManager { // file AddPageURL/Title/Body that may not be committed to the database yet. // This function removes entires from this list happening between the given // time range. It is called when the user clears their history for a time - // range, and we don't want any of our data to "leak." + // range, and we don't want any of our data to "leak." If restrict_urls is + // not empty, only changes on those URLs are deleted. // // Either or both times my be is_null to be unbounded in that direction. When // non-null, the range is [begin, end). - void DeleteFromUncommitted(base::Time begin, base::Time end); - - // Same as DeleteFromUncommitted but for a single URL. - void DeleteURLFromUncommitted(const GURL& url); + void DeleteFromUncommitted(const std::set<GURL>& restrict_urls, + base::Time begin, base::Time end); // Deletes all full text search data by removing the files from the disk. // This must be called OUTSIDE of a transaction since it actually deletes the @@ -161,6 +160,7 @@ class TextDatabaseManager { FRIEND_TEST(TextDatabaseManagerTest, PartialComplete); FRIEND_TEST(ExpireHistoryTest, DISABLED_DeleteURLAndFavicon); FRIEND_TEST(ExpireHistoryTest, FlushRecentURLsUnstarred); + FRIEND_TEST(ExpireHistoryTest, FlushRecentURLsUnstarredRestricted); // Stores "recent stuff" that has happened with the page, since the page // visit, title, and body all come in at different times. |