diff options
author | shess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-22 09:30:40 +0000 |
---|---|---|
committer | shess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-22 09:30:40 +0000 |
commit | 9132fe8464be21ca0738873db2abae5dd348922c (patch) | |
tree | accf365a16e1467e2918928c29d8b7d7543e5b61 | |
parent | 23d679081855a690891e6094277040a1e93bc8e3 (diff) | |
download | chromium_src-9132fe8464be21ca0738873db2abae5dd348922c.zip chromium_src-9132fe8464be21ca0738873db2abae5dd348922c.tar.gz chromium_src-9132fe8464be21ca0738873db2abae5dd348922c.tar.bz2 |
Remove thumbnail migration code from history.
Thumbnails were originally stored in a database with favicons, but
later were migrated to "Top Sites". I believe this happened in early
2011. Any profiles remaining to migrate will lose their old
thumbnails data, which by now should be expired in any case.
Also cleanup methods which were no longer in use.
BUG=240396
Review URL: https://chromiumcodereview.appspot.com/23288005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@218973 0039d316-1c4b-4281-b951-d872f2087c98
23 files changed, 44 insertions, 1121 deletions
diff --git a/chrome/browser/history/android/android_provider_backend_unittest.cc b/chrome/browser/history/android/android_provider_backend_unittest.cc index 830f74c..c828167 100644 --- a/chrome/browser/history/android/android_provider_backend_unittest.cc +++ b/chrome/browser/history/android/android_provider_backend_unittest.cc @@ -76,7 +76,6 @@ class AndroidProviderBackendDelegate : public HistoryBackend::Delegate { } } virtual void DBLoaded(int backend_id) OVERRIDE {} - virtual void StartTopSitesMigration(int backend_id) OVERRIDE {} virtual void NotifyVisitDBObserversOnAddVisit( const history::BriefVisitInfo& info) OVERRIDE {} diff --git a/chrome/browser/history/expire_history_backend.cc b/chrome/browser/history/expire_history_backend.cc index 370a62b..aa7ede3 100644 --- a/chrome/browser/history/expire_history_backend.cc +++ b/chrome/browser/history/expire_history_backend.cc @@ -421,8 +421,6 @@ void ExpireHistoryBackend::DeleteOneURL( // Delete stuff that references this URL. if (thumb_db_) { - thumb_db_->DeleteThumbnail(url_row.id()); - // Collect shared information. std::vector<IconMapping> icon_mappings; if (thumb_db_->GetIconMappingsForPageURL(url_row.url(), &icon_mappings)) { diff --git a/chrome/browser/history/history_backend.cc b/chrome/browser/history/history_backend.cc index 3ab8c16..7cdecc5 100644 --- a/chrome/browser/history/history_backend.cc +++ b/chrome/browser/history/history_backend.cc @@ -564,7 +564,7 @@ void HistoryBackend::InitImpl(const std::string& languages) { // Compute the file names. base::FilePath history_name = history_dir_.Append(chrome::kHistoryFilename); - base::FilePath thumbnail_name = GetThumbnailFileName(); + base::FilePath thumbnail_name = GetFaviconsFileName(); base::FilePath archived_name = GetArchivedFileName(); // Delete the old index database files which are no longer used. @@ -619,11 +619,11 @@ void HistoryBackend::InitImpl(const std::string& languages) { } // Thumbnail database. + // TODO(shess): "thumbnail database" these days only stores + // favicons. Thumbnails are stored in "top sites". Consider + // renaming "thumbnail" references to "favicons" or something of the + // sort. thumbnail_db_.reset(new ThumbnailDatabase()); - if (!db_->GetNeedsThumbnailMigration()) { - // No convertion needed - use new filename right away. - thumbnail_name = GetFaviconsFileName(); - } if (thumbnail_db_->Init(thumbnail_name, history_publisher_.get(), db_.get()) != sql::INIT_OK) { @@ -636,11 +636,6 @@ void HistoryBackend::InitImpl(const std::string& languages) { thumbnail_db_.reset(); } - if (db_->GetNeedsThumbnailMigration()) { - VLOG(1) << "Starting TopSites migration"; - delegate_->StartTopSitesMigration(id_); - } - // Archived database. if (db_->needs_version_17_migration()) { // See needs_version_17_migration() decl for more. In this case, we want @@ -1651,89 +1646,6 @@ void HistoryBackend::ScheduleAutocomplete(HistoryURLProvider* provider, provider->ExecuteWithDB(this, db_.get(), params); } -void HistoryBackend::SetPageThumbnail( - const GURL& url, - const gfx::Image* thumbnail, - const ThumbnailScore& score) { - if (!db_ || !thumbnail_db_) - return; - - URLRow url_row; - URLID url_id = db_->GetRowForURL(url, &url_row); - if (url_id) { - thumbnail_db_->SetPageThumbnail(url, url_id, thumbnail, score, - url_row.last_visit()); - } - - ScheduleCommit(); -} - -void HistoryBackend::GetPageThumbnail( - scoped_refptr<GetPageThumbnailRequest> request, - const GURL& page_url) { - if (request->canceled()) - return; - - scoped_refptr<base::RefCountedBytes> data; - GetPageThumbnailDirectly(page_url, &data); - - request->ForwardResult(request->handle(), data); -} - -void HistoryBackend::GetPageThumbnailDirectly( - const GURL& page_url, - scoped_refptr<base::RefCountedBytes>* data) { - if (thumbnail_db_) { - *data = new base::RefCountedBytes; - - // Time the result. - TimeTicks beginning_time = TimeTicks::Now(); - - history::RedirectList redirects; - URLID url_id; - bool success = false; - - // If there are some redirects, try to get a thumbnail from the last - // redirect destination. - if (GetMostRecentRedirectsFrom(page_url, &redirects) && - !redirects.empty()) { - if ((url_id = db_->GetRowForURL(redirects.back(), NULL))) - success = thumbnail_db_->GetPageThumbnail(url_id, &(*data)->data()); - } - - // If we don't have a thumbnail from redirects, try the URL directly. - if (!success) { - if ((url_id = db_->GetRowForURL(page_url, NULL))) - success = thumbnail_db_->GetPageThumbnail(url_id, &(*data)->data()); - } - - // In this rare case, we start to mine the older redirect sessions - // from the visit table to try to find a thumbnail. - if (!success) { - success = GetThumbnailFromOlderRedirect(page_url, &(*data)->data()); - } - - if (!success) - *data = NULL; // This will tell the callback there was an error. - - UMA_HISTOGRAM_TIMES("History.GetPageThumbnail", - TimeTicks::Now() - beginning_time); - } -} - -void HistoryBackend::MigrateThumbnailsDatabase() { - // If there is no History DB, we can't record that the migration was done. - // It will be recorded on the next run. - if (db_) { - // If there is no thumbnail DB, we can still record a successful migration. - if (thumbnail_db_) { - thumbnail_db_->RenameAndDropThumbnails(GetThumbnailFileName(), - GetFaviconsFileName()); - } - db_->ThumbnailMigrationDone(); - } -} - void HistoryBackend::DeleteFTSIndexDatabases() { // Find files on disk matching the text databases file pattern so we can // quickly test for and delete them. @@ -1751,37 +1663,6 @@ void HistoryBackend::DeleteFTSIndexDatabases() { num_databases_deleted); } -bool HistoryBackend::GetThumbnailFromOlderRedirect( - const GURL& page_url, - std::vector<unsigned char>* data) { - // Look at a few previous visit sessions. - VisitVector older_sessions; - URLID page_url_id = db_->GetRowForURL(page_url, NULL); - static const int kVisitsToSearchForThumbnail = 4; - db_->GetMostRecentVisitsForURL( - page_url_id, kVisitsToSearchForThumbnail, &older_sessions); - - // Iterate across all those previous visits, and see if any of the - // final destinations of those redirect chains have a good thumbnail - // for us. - bool success = false; - for (VisitVector::const_iterator it = older_sessions.begin(); - !success && it != older_sessions.end(); ++it) { - history::RedirectList redirects; - if (it->visit_id) { - GetRedirectsFromSpecificVisit(it->visit_id, &redirects); - - if (!redirects.empty()) { - URLID url_id; - if ((url_id = db_->GetRowForURL(redirects.back(), NULL))) - success = thumbnail_db_->GetPageThumbnail(url_id, data); - } - } - } - - return success; -} - void HistoryBackend::GetFavicons( const std::vector<GURL>& icon_urls, int icon_types, @@ -2871,6 +2752,9 @@ bool HistoryBackend::ClearAllThumbnailHistory(const URLRows& kept_urls) { // error opening it. In this case, we just try to blow it away to try to // fix the error if it exists. This may fail, in which case either the // file doesn't exist or there's no more we can do. + sql::Connection::Delete(GetFaviconsFileName()); + + // Older version of the database. sql::Connection::Delete(GetThumbnailFileName()); return true; } @@ -2900,8 +2784,6 @@ bool HistoryBackend::ClearAllThumbnailHistory(const URLRows& kept_urls) { db_->ClearAndroidURLRows(); #endif - thumbnail_db_->RecreateThumbnailTable(); - // Vacuum to remove all the pages associated with the dropped tables. There // must be no transaction open on the table when we do this. We assume that // our long-running transaction is open, so we complete it and start it again. diff --git a/chrome/browser/history/history_backend.h b/chrome/browser/history/history_backend.h index 4173ef8..de64e5c 100644 --- a/chrome/browser/history/history_backend.h +++ b/chrome/browser/history/history_backend.h @@ -99,9 +99,6 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>, // Invoked when the backend has finished loading the db. virtual void DBLoaded(int backend_id) = 0; - // Tell TopSites to start reading thumbnails from the ThumbnailsDB. - virtual void StartTopSitesMigration(int backend_id) = 0; - virtual void NotifyVisitDBObserversOnAddVisit( const history::BriefVisitInfo& info) = 0; }; @@ -231,28 +228,6 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>, bool GetMostRecentRedirectsTo(const GURL& url, history::RedirectList* redirects); - // Thumbnails ---------------------------------------------------------------- - - void SetPageThumbnail(const GURL& url, - const gfx::Image* thumbnail, - const ThumbnailScore& score); - - // Retrieves a thumbnail, passing it across thread boundaries - // via. the included callback. - void GetPageThumbnail(scoped_refptr<GetPageThumbnailRequest> request, - const GURL& page_url); - - // Backend implementation of GetPageThumbnail. Unlike - // GetPageThumbnail(), this method has way to transport data across - // thread boundaries. - // - // Exposed for testing reasons. - void GetPageThumbnailDirectly( - const GURL& page_url, - scoped_refptr<base::RefCountedBytes>* data); - - void MigrateThumbnailsDatabase(); - // Favicon ------------------------------------------------------------------- void GetFavicons(const std::vector<GURL>& icon_urls, @@ -563,13 +538,12 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>, friend class ::TestingProfile; // Computes the name of the specified database on disk. + base::FilePath GetArchivedFileName() const; base::FilePath GetThumbnailFileName() const; // Returns the name of the Favicons database. This is the new name // of the Thumbnails database. - // See ThumbnailDatabase::RenameAndDropThumbnails. base::FilePath GetFaviconsFileName() const; - base::FilePath GetArchivedFileName() const; #if defined(OS_ANDROID) // Returns the name of android cache database. @@ -629,16 +603,6 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>, // Update the visit_duration information in visits table. void UpdateVisitDuration(VisitID visit_id, const base::Time end_ts); - // Thumbnail Helpers --------------------------------------------------------- - - // When a simple GetMostRecentRedirectsFrom() fails, this method is - // called which searches the last N visit sessions instead of just - // the current one. Returns true and puts thumbnail data in |data| - // if a proper thumbnail was found. Returns false otherwise. Assumes - // that this HistoryBackend object has been Init()ed successfully. - bool GetThumbnailFromOlderRedirect( - const GURL& page_url, std::vector<unsigned char>* data); - // Querying ------------------------------------------------------------------ // Backends for QueryHistory. *Basic() handles queries that are not diff --git a/chrome/browser/history/history_backend_unittest.cc b/chrome/browser/history/history_backend_unittest.cc index 8bb0111..c450a8a 100644 --- a/chrome/browser/history/history_backend_unittest.cc +++ b/chrome/browser/history/history_backend_unittest.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "chrome/browser/history/history_backend.h" + #include <algorithm> #include <set> #include <vector> @@ -9,21 +11,18 @@ #include "base/basictypes.h" #include "base/bind.h" -#include "base/bind_helpers.h" #include "base/command_line.h" #include "base/file_util.h" #include "base/files/file_path.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/path_service.h" -#include "base/platform_file.h" #include "base/strings/string16.h" #include "base/strings/string_number_conversions.h" #include "base/strings/utf_string_conversions.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/bookmarks/bookmark_utils.h" -#include "chrome/browser/history/history_backend.h" #include "chrome/browser/history/history_notifications.h" #include "chrome/browser/history/history_service.h" #include "chrome/browser/history/history_service_factory.h" @@ -34,17 +33,12 @@ #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/importer/imported_favicon_usage.h" -#include "chrome/common/thumbnail_score.h" #include "chrome/test/base/testing_profile.h" #include "chrome/test/base/ui_test_utils.h" -#include "chrome/tools/profiles/thumbnail-inl.h" #include "content/public/browser/notification_details.h" #include "content/public/browser/notification_source.h" #include "content/public/test/test_browser_thread.h" #include "testing/gtest/include/gtest/gtest.h" -#include "third_party/skia/include/core/SkBitmap.h" -#include "ui/gfx/codec/jpeg_codec.h" -#include "ui/gfx/image/image.h" #include "url/gurl.h" using base::Time; @@ -57,10 +51,6 @@ using base::TimeDelta; namespace { -// data we'll put into the thumbnail database -static const unsigned char blob1[] = - "12346102356120394751634516591348710478123649165419234519234512349134"; - static const gfx::Size kTinySize = gfx::Size(10, 10); static const gfx::Size kSmallSize = gfx::Size(16, 16); static const gfx::Size kLargeSize = gfx::Size(32, 32); @@ -96,7 +86,6 @@ class HistoryBackendTestDelegate : public HistoryBackend::Delegate { virtual void BroadcastNotifications(int type, HistoryDetails* details) OVERRIDE; virtual void DBLoaded(int backend_id) OVERRIDE; - virtual void StartTopSitesMigration(int backend_id) OVERRIDE; virtual void NotifyVisitDBObserversOnAddVisit( const BriefVisitInfo& info) OVERRIDE {} @@ -438,10 +427,6 @@ void HistoryBackendTestDelegate::DBLoaded(int backend_id) { test_->loaded_ = true; } -void HistoryBackendTestDelegate::StartTopSitesMigration(int backend_id) { - test_->backend_->MigrateThumbnailsDatabase(); -} - // http://crbug.com/114287 #if defined(OS_WIN) #define MAYBE_Loaded DISABLED_Loaded @@ -517,24 +502,6 @@ TEST_F(HistoryBackendTest, DeleteAll) { URLRow outrow1; EXPECT_TRUE(mem_backend_->db_->GetRowForURL(row1.url(), NULL)); - // Add thumbnails for each page. The |Images| take ownership of SkBitmap - // created from decoding the images. - ThumbnailScore score(0.25, true, true); - scoped_ptr<SkBitmap> google_bitmap( - gfx::JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); - - gfx::Image google_image = gfx::Image::CreateFrom1xBitmap(*google_bitmap); - - Time time; - GURL gurl; - backend_->thumbnail_db_->SetPageThumbnail(gurl, row1_id, &google_image, - score, time); - scoped_ptr<SkBitmap> weewar_bitmap( - gfx::JPEGCodec::Decode(kWeewarThumbnail, sizeof(kWeewarThumbnail))); - gfx::Image weewar_image = gfx::Image::CreateFrom1xBitmap(*weewar_bitmap); - backend_->thumbnail_db_->SetPageThumbnail(gurl, row2_id, &weewar_image, - score, time); - // Star row1. bookmark_model_.AddURL( bookmark_model_.bookmark_bar_node(), 0, string16(), row1.url()); @@ -558,12 +525,6 @@ TEST_F(HistoryBackendTest, DeleteAll) { backend_->db_->GetAllVisitsInRange(Time(), Time(), 0, &all_visits); ASSERT_EQ(0U, all_visits.size()); - // All thumbnails should be deleted. - std::vector<unsigned char> out_data; - EXPECT_FALSE(backend_->thumbnail_db_->GetPageThumbnail(outrow1.id(), - &out_data)); - EXPECT_FALSE(backend_->thumbnail_db_->GetPageThumbnail(row2_id, &out_data)); - // We should have a favicon and favicon bitmaps for the first URL only. We // look them up by favicon URL since the IDs may have changed. chrome::FaviconID out_favicon1 = backend_->thumbnail_db_-> diff --git a/chrome/browser/history/history_database.cc b/chrome/browser/history/history_database.cc index ca2d4ab..1f26b7e 100644 --- a/chrome/browser/history/history_database.cc +++ b/chrome/browser/history/history_database.cc @@ -31,10 +31,6 @@ const int kCurrentVersionNumber = 28; const int kCompatibleVersionNumber = 16; const char kEarlyExpirationThresholdKey[] = "early_expiration_threshold"; -// Key in the meta table used to determine if we need to migrate thumbnails out -// of history. -const char kNeedsThumbnailMigrationKey[] = "needs_thumbnail_migration"; - } // namespace HistoryDatabase::HistoryDatabase() @@ -245,16 +241,6 @@ bool HistoryDatabase::Raze() { return db_.Raze(); } -void HistoryDatabase::ThumbnailMigrationDone() { - meta_table_.SetValue(kNeedsThumbnailMigrationKey, 0); -} - -bool HistoryDatabase::GetNeedsThumbnailMigration() { - int value = 0; - return (meta_table_.GetValue(kNeedsThumbnailMigrationKey, &value) && - value != 0); -} - bool HistoryDatabase::SetSegmentID(VisitID visit_id, SegmentID segment_id) { sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE, "UPDATE visits SET segment_id = ? WHERE id = ?")); @@ -365,9 +351,7 @@ sql::InitStatus HistoryDatabase::EnsureCurrentVersion() { if (cur_version == 19) { cur_version++; meta_table_.SetVersionNumber(cur_version); - // Set a key indicating we need to migrate thumbnails. When successfull the - // key is removed (ThumbnailMigrationDone). - meta_table_.SetValue(kNeedsThumbnailMigrationKey, 1); + // This was the thumbnail migration. Obsolete. } if (cur_version == 20) { diff --git a/chrome/browser/history/history_database.h b/chrome/browser/history/history_database.h index 5aac5ba..7c631cf 100644 --- a/chrome/browser/history/history_database.h +++ b/chrome/browser/history/history_database.h @@ -149,12 +149,6 @@ class HistoryDatabase : public DownloadDatabase, return needs_version_17_migration_; } - // Marks the database as no longer needing migration. - void ThumbnailMigrationDone(); - - // Returns true if thumbnails needs to be migrated. - bool GetNeedsThumbnailMigration(); - // Visit table functions ---------------------------------------------------- // Update the segment id of a visit. Return true on success. diff --git a/chrome/browser/history/history_marshaling.h b/chrome/browser/history/history_marshaling.h index 47703ee..a3204da 100644 --- a/chrome/browser/history/history_marshaling.h +++ b/chrome/browser/history/history_marshaling.h @@ -50,11 +50,6 @@ typedef CancelableRequest1<HistoryService::QueryFilteredURLsCallback, history::FilteredURLList> QueryFilteredURLsRequest; -// Thumbnails ----------------------------------------------------------------- - -typedef CancelableRequest<HistoryService::ThumbnailDataCallback> - GetPageThumbnailRequest; - // Segment usage -------------------------------------------------------------- typedef CancelableRequest1<HistoryService::SegmentQueryCallback, diff --git a/chrome/browser/history/history_service.cc b/chrome/browser/history/history_service.cc index a722409..0ad19e33 100644 --- a/chrome/browser/history/history_service.cc +++ b/chrome/browser/history/history_service.cc @@ -175,13 +175,6 @@ class HistoryService::BackendDelegate : public HistoryBackend::Delegate { backend_id)); } - virtual void StartTopSitesMigration(int backend_id) OVERRIDE { - service_task_runner_->PostTask( - FROM_HERE, - base::Bind(&HistoryService::StartTopSitesMigration, - history_service_, backend_id)); - } - virtual void NotifyVisitDBObserversOnAddVisit( const history::BriefVisitInfo& info) OVERRIDE { service_task_runner_->PostTask( @@ -206,8 +199,7 @@ HistoryService::HistoryService() backend_loaded_(false), current_backend_id_(-1), bookmark_service_(NULL), - no_db_(false), - needs_top_sites_migration_(false) { + no_db_(false) { } HistoryService::HistoryService(Profile* profile) @@ -219,8 +211,7 @@ HistoryService::HistoryService(Profile* profile) backend_loaded_(false), current_backend_id_(-1), bookmark_service_(NULL), - no_db_(false), - needs_top_sites_migration_(false) { + no_db_(false) { DCHECK(profile_); registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, content::Source<Profile>(profile_)); @@ -593,15 +584,6 @@ void HistoryService::AddPagesWithDetails(const history::URLRows& info, &HistoryBackend::AddPagesWithDetails, info, visit_source); } -HistoryService::Handle HistoryService::GetPageThumbnail( - const GURL& page_url, - CancelableRequestConsumerBase* consumer, - const ThumbnailDataCallback& callback) { - DCHECK(thread_checker_.CalledOnValidThread()); - return Schedule(PRIORITY_NORMAL, &HistoryBackend::GetPageThumbnail, consumer, - new history::GetPageThumbnailRequest(callback), page_url); -} - CancelableTaskTracker::TaskId HistoryService::GetFavicons( const std::vector<GURL>& icon_urls, int icon_types, @@ -1228,12 +1210,6 @@ void HistoryService::OnDBLoaded(int backend_id) { chrome::NOTIFICATION_HISTORY_LOADED, content::Source<Profile>(profile_), content::Details<HistoryService>(this)); - if (thread_ && profile_) { - // We don't want to force creation of TopSites. - history::TopSites* ts = profile_->GetTopSitesWithoutCreating(); - if (ts) - ts->HistoryLoaded(); - } } bool HistoryService::GetRowForURL(const GURL& url, history::URLRow* url_row) { @@ -1242,27 +1218,6 @@ bool HistoryService::GetRowForURL(const GURL& url, history::URLRow* url_row) { return db && (db->GetRowForURL(url, url_row) != 0); } -void HistoryService::StartTopSitesMigration(int backend_id) { - DCHECK(thread_checker_.CalledOnValidThread()); - if (!history_backend_.get() || current_backend_id_ != backend_id) { - DVLOG(1) << "Message from obsolete backend"; - return; - } - needs_top_sites_migration_ = true; - if (thread_ && profile_) { - // We don't want to force creation of TopSites. - history::TopSites* ts = profile_->GetTopSitesWithoutCreating(); - if (ts) - ts->MigrateFromHistory(); - } -} - -void HistoryService::OnTopSitesReady() { - DCHECK(thread_checker_.CalledOnValidThread()); - ScheduleAndForget(PRIORITY_NORMAL, - &HistoryBackend::MigrateThumbnailsDatabase); -} - void HistoryService::AddVisitDatabaseObserver( history::VisitDatabaseObserver* observer) { DCHECK(thread_checker_.CalledOnValidThread()); diff --git a/chrome/browser/history/history_service.h b/chrome/browser/history/history_service.h index 1662571..f8d383b 100644 --- a/chrome/browser/history/history_service.h +++ b/chrome/browser/history/history_service.h @@ -367,22 +367,6 @@ class HistoryService : public CancelableRequestProvider, CancelableRequestConsumerBase* consumer, const QueryFilteredURLsCallback& callback); - // Thumbnails ---------------------------------------------------------------- - - // Implemented by consumers to get thumbnail data. Called when a request for - // the thumbnail data is complete. Once this callback is made, the request - // will be completed and no other calls will be made for that handle. - // - // This function will be called even on error conditions or if there is no - // thumbnail for that page. In these cases, the data pointer will be NULL. - typedef base::Callback<void(Handle, scoped_refptr<base::RefCountedBytes>)> - ThumbnailDataCallback; - - // Requests a page thumbnail. See ThumbnailDataCallback definition above. - Handle GetPageThumbnail(const GURL& page_url, - CancelableRequestConsumerBase* consumer, - const ThumbnailDataCallback& callback); - // Database management operations -------------------------------------------- // Delete all the information related to a single url. @@ -541,10 +525,6 @@ class HistoryService : public CancelableRequestProvider, virtual void ScheduleDBTask(history::HistoryDBTask* task, CancelableRequestConsumerBase* consumer); - // Returns true if top sites needs to be migrated out of history into its own - // db. - bool needs_top_sites_migration() const { return needs_top_sites_migration_; } - // Adds or removes observers for the VisitDatabase. void AddVisitDatabaseObserver(history::VisitDatabaseObserver* observer); void RemoveVisitDatabaseObserver(history::VisitDatabaseObserver* observer); @@ -590,14 +570,6 @@ class HistoryService : public CancelableRequestProvider, void AddPagesWithDetails(const history::URLRows& info, history::VisitSource visit_source); - // Starts the TopSites migration in the HistoryThread. Called by the - // BackendDelegate. - void StartTopSitesMigration(int backend_id); - - // Called by TopSites after the thumbnails were read and it is safe - // to delete the thumbnails DB. - void OnTopSitesReady(); - // Returns true if this looks like the type of URL we want to add to the // history. We filter out some URLs such as JavaScript. static bool CanAddURL(const GURL& url); @@ -1078,9 +1050,6 @@ class HistoryService : public CancelableRequestProvider, BookmarkService* bookmark_service_; bool no_db_; - // True if needs top site migration. - bool needs_top_sites_migration_; - // The index used for quick history lookups. // TODO(mrossetti): Move in_memory_url_index out of history_service. // See http://crbug.com/138321 diff --git a/chrome/browser/history/history_unittest.cc b/chrome/browser/history/history_unittest.cc index 28db9ba..53ffcf5 100644 --- a/chrome/browser/history/history_unittest.cc +++ b/chrome/browser/history/history_unittest.cc @@ -95,7 +95,6 @@ class BackendDelegate : public HistoryBackend::Delegate { virtual void BroadcastNotifications(int type, HistoryDetails* details) OVERRIDE; virtual void DBLoaded(int backend_id) OVERRIDE {} - virtual void StartTopSitesMigration(int backend_id) OVERRIDE {} virtual void NotifyVisitDBObserversOnAddVisit( const BriefVisitInfo& info) OVERRIDE {} private: diff --git a/chrome/browser/history/thumbnail_database.cc b/chrome/browser/history/thumbnail_database.cc index bb85711..59d60a1 100644 --- a/chrome/browser/history/thumbnail_database.cc +++ b/chrome/browser/history/thumbnail_database.cc @@ -7,29 +7,23 @@ #include <algorithm> #include <string> -#include "base/command_line.h" +#include "base/bind.h" #include "base/debug/alias.h" #include "base/file_util.h" #include "base/format_macros.h" #include "base/memory/ref_counted_memory.h" #include "base/metrics/histogram.h" #include "base/rand_util.h" -#include "base/strings/string_number_conversions.h" -#include "base/strings/string_tokenizer.h" #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" -#include "base/strings/utf_string_conversions.h" #include "base/time/time.h" #include "chrome/browser/history/history_publisher.h" -#include "chrome/browser/history/top_sites.h" #include "chrome/browser/history/url_database.h" #include "chrome/common/chrome_version_info.h" #include "chrome/common/dump_without_crashing.h" -#include "chrome/common/thumbnail_score.h" #include "sql/statement.h" #include "sql/transaction.h" #include "third_party/sqlite/sqlite3.h" -#include "ui/gfx/image/image_util.h" #if defined(OS_MACOSX) #include "base/mac/mac_util.h" @@ -281,10 +275,6 @@ namespace history { static const int kCurrentVersionNumber = 7; static const int kCompatibleVersionNumber = 7; -// Use 90 quality (out of 100) which is pretty high, because we're very -// sensitive to artifacts for these small sized, highly detailed images. -static const int kImageQuality = 90; - ThumbnailDatabase::IconMappingEnumerator::IconMappingEnumerator() { } @@ -300,8 +290,7 @@ bool ThumbnailDatabase::IconMappingEnumerator::GetNextIconMapping( } ThumbnailDatabase::ThumbnailDatabase() - : history_publisher_(NULL), - use_top_sites_(false) { + : history_publisher_(NULL) { } sql::InitStatus ThumbnailDatabase::CantUpgradeToVersion(int cur_version) { @@ -333,10 +322,13 @@ sql::InitStatus ThumbnailDatabase::Init( base::mac::SetFileBackupExclusion(db_name); #endif + // thumbnails table has been obsolete for a long time, remove any + // detrious. + ignore_result(db_.Execute("DROP TABLE IF EXISTS thumbnails")); + // Create the tables. if (!meta_table_.Init(&db_, kCurrentVersionNumber, kCompatibleVersionNumber) || - !InitThumbnailTable() || !InitFaviconBitmapsTable(&db_) || !InitFaviconBitmapsIndex() || !InitFaviconsTable(&db_) || @@ -460,51 +452,13 @@ void ThumbnailDatabase::ComputeDatabaseMetrics() { favicon_count.Step() ? favicon_count.ColumnInt(0) : 0); } -bool ThumbnailDatabase::InitThumbnailTable() { - if (!db_.DoesTableExist("thumbnails")) { - use_top_sites_ = true; - } - return true; -} - bool ThumbnailDatabase::UpgradeToVersion3() { - if (use_top_sites_) { - meta_table_.SetVersionNumber(3); - meta_table_.SetCompatibleVersionNumber( - std::min(3, kCompatibleVersionNumber)); - return true; // Not needed after migration to TopSites. - } - - // sqlite doesn't like the "ALTER TABLE xxx ADD (column_one, two, - // three)" syntax, so list out the commands we need to execute: - const char* alterations[] = { - "ALTER TABLE thumbnails ADD boring_score DOUBLE DEFAULT 1.0", - "ALTER TABLE thumbnails ADD good_clipping INTEGER DEFAULT 0", - "ALTER TABLE thumbnails ADD at_top INTEGER DEFAULT 0", - "ALTER TABLE thumbnails ADD last_updated INTEGER DEFAULT 0", - NULL - }; - - for (int i = 0; alterations[i] != NULL; ++i) { - if (!db_.Execute(alterations[i])) { - return false; - } - } - + // Version 3 migrated table thumbnails, which is obsolete. meta_table_.SetVersionNumber(3); meta_table_.SetCompatibleVersionNumber(std::min(3, kCompatibleVersionNumber)); return true; } -bool ThumbnailDatabase::RecreateThumbnailTable() { - if (use_top_sites_) - return true; // Not needed after migration to TopSites. - - if (!db_.Execute("DROP TABLE thumbnails")) - return false; - return InitThumbnailTable(); -} - bool ThumbnailDatabase::InitFaviconsTable(sql::Connection* db) { const char kSql[] = "CREATE TABLE IF NOT EXISTS favicons" @@ -570,115 +524,6 @@ void ThumbnailDatabase::TrimMemory(bool aggressively) { db_.TrimMemory(aggressively); } -bool ThumbnailDatabase::SetPageThumbnail( - const GURL& url, - URLID id, - const gfx::Image* thumbnail, - const ThumbnailScore& score, - base::Time time) { - if (use_top_sites_) { - LOG(WARNING) << "Use TopSites instead."; - return false; // Not possible after migration to TopSites. - } - - if (!thumbnail) - return DeleteThumbnail(id); - - bool add_thumbnail = true; - ThumbnailScore current_score; - if (ThumbnailScoreForId(id, ¤t_score)) { - add_thumbnail = ShouldReplaceThumbnailWith(current_score, score); - } - - if (!add_thumbnail) - return true; - - std::vector<unsigned char> jpeg_data; - bool encoded = gfx::JPEG1xEncodedDataFromImage( - *thumbnail, kImageQuality, &jpeg_data); - if (encoded) { - sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, - "INSERT OR REPLACE INTO thumbnails " - "(url_id, boring_score, good_clipping, at_top, last_updated, data) " - "VALUES (?,?,?,?,?,?)")); - statement.BindInt64(0, id); - statement.BindDouble(1, score.boring_score); - statement.BindBool(2, score.good_clipping); - statement.BindBool(3, score.at_top); - statement.BindInt64(4, score.time_at_snapshot.ToInternalValue()); - statement.BindBlob(5, &jpeg_data[0], - static_cast<int>(jpeg_data.size())); - - if (!statement.Run()) - return false; - } - - // Publish the thumbnail to any indexers listening to us. - // The tests may send an invalid url. Hence avoid publishing those. - if (url.is_valid() && history_publisher_ != NULL) - history_publisher_->PublishPageThumbnail(jpeg_data, url, time); - - return true; -} - -bool ThumbnailDatabase::GetPageThumbnail(URLID id, - std::vector<unsigned char>* data) { - if (use_top_sites_) { - LOG(WARNING) << "Use TopSites instead."; - return false; // Not possible after migration to TopSites. - } - - sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, - "SELECT data FROM thumbnails WHERE url_id=?")); - statement.BindInt64(0, id); - - if (!statement.Step()) - return false; // don't have a thumbnail for this ID - - statement.ColumnBlobAsVector(0, data); - return true; -} - -bool ThumbnailDatabase::DeleteThumbnail(URLID id) { - if (use_top_sites_) { - return true; // Not possible after migration to TopSites. - } - - sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, - "DELETE FROM thumbnails WHERE url_id = ?")); - statement.BindInt64(0, id); - - return statement.Run(); -} - -bool ThumbnailDatabase::ThumbnailScoreForId(URLID id, - ThumbnailScore* score) { - DCHECK(score); - if (use_top_sites_) { - LOG(WARNING) << "Use TopSites instead."; - return false; // Not possible after migration to TopSites. - } - - // Fetch the current thumbnail's information to make sure we - // aren't replacing a good thumbnail with one that's worse. - sql::Statement select_statement(db_.GetCachedStatement(SQL_FROM_HERE, - "SELECT boring_score, good_clipping, at_top, last_updated " - "FROM thumbnails WHERE url_id=?")); - select_statement.BindInt64(0, id); - - if (!select_statement.Step()) - return false; - - double current_boring_score = select_statement.ColumnDouble(0); - bool current_clipping = select_statement.ColumnBool(1); - bool current_at_top = select_statement.ColumnBool(2); - base::Time last_updated = - base::Time::FromInternalValue(select_statement.ColumnInt64(3)); - *score = ThumbnailScore(current_boring_score, current_clipping, - current_at_top, last_updated); - return true; -} - bool ThumbnailDatabase::GetFaviconBitmapIDSizes( chrome::FaviconID icon_id, std::vector<FaviconBitmapIDSize>* bitmap_id_sizes) { @@ -819,14 +664,6 @@ bool ThumbnailDatabase::SetFaviconBitmapLastUpdateTime( return statement.Run(); } -bool ThumbnailDatabase::DeleteFaviconBitmapsForFavicon( - chrome::FaviconID icon_id) { - sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, - "DELETE FROM favicon_bitmaps WHERE icon_id=?")); - statement.BindInt64(0, icon_id); - return statement.Run(); -} - bool ThumbnailDatabase::DeleteFaviconBitmap(FaviconBitmapID bitmap_id) { sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, "DELETE FROM favicon_bitmaps WHERE id=?")); @@ -1166,92 +1003,6 @@ bool ThumbnailDatabase::RetainDataForPageUrls( return transaction.Commit(); } -bool ThumbnailDatabase::NeedsMigrationToTopSites() { - return !use_top_sites_; -} - -bool ThumbnailDatabase::RenameAndDropThumbnails( - const base::FilePath& old_db_file, - const base::FilePath& new_db_file) { - // Init favicons tables - same schema as the thumbnails. - sql::Connection favicons; - if (OpenDatabase(&favicons, new_db_file) != sql::INIT_OK) - return false; - - if (!InitFaviconBitmapsTable(&favicons) || - !InitFaviconsTable(&favicons) || - !InitIconMappingTable(&favicons)) { - favicons.Close(); - return false; - } - favicons.Close(); - - // Can't attach within a transaction. - if (transaction_nesting()) - CommitTransaction(); - - // Attach new DB. - { - // This block is needed because otherwise the attach statement is - // never cleared from cache and we can't close the DB :P - sql::Statement attach(db_.GetUniqueStatement("ATTACH ? AS new_favicons")); - if (!attach.is_valid()) { - // Keep the transaction open, even though we failed. - BeginTransaction(); - return false; - } - -#if defined(OS_POSIX) - attach.BindString(0, new_db_file.value()); -#else - attach.BindString(0, WideToUTF8(new_db_file.value())); -#endif - - if (!attach.Run()) { - BeginTransaction(); - return false; - } - } - - // Move favicons and favicon_bitmaps to new DB. - bool successfully_moved_data = - db_.Execute("INSERT OR REPLACE INTO new_favicons.favicon_bitmaps " - "SELECT * FROM favicon_bitmaps") && - db_.Execute("INSERT OR REPLACE INTO new_favicons.favicons " - "SELECT * FROM favicons"); - if (!successfully_moved_data) { - DLOG(FATAL) << "Unable to copy favicons and favicon_bitmaps."; - BeginTransaction(); - return false; - } - - if (!db_.Execute("DETACH new_favicons")) { - DLOG(FATAL) << "Unable to detach database."; - BeginTransaction(); - return false; - } - - db_.Close(); - - // Reset the DB to point to new file. - if (OpenDatabase(&db_, new_db_file) != sql::INIT_OK) - return false; - - sql::Connection::Delete(old_db_file); - - meta_table_.Reset(); - if (!meta_table_.Init(&db_, kCurrentVersionNumber, kCompatibleVersionNumber)) - return false; - - if (!InitFaviconBitmapsIndex() || !InitFaviconsIndex()) - return false; - - // Reopen the transaction. - BeginTransaction(); - use_top_sites_ = true; - return true; -} - bool ThumbnailDatabase::InitIconMappingTable(sql::Connection* db) { const char kSql[] = "CREATE TABLE IF NOT EXISTS icon_mapping" diff --git a/chrome/browser/history/thumbnail_database.h b/chrome/browser/history/thumbnail_database.h index eb9095e..d407897 100644 --- a/chrome/browser/history/thumbnail_database.h +++ b/chrome/browser/history/thumbnail_database.h @@ -78,33 +78,6 @@ class ThumbnailDatabase { // true try to trim all unused cache, otherwise trim by half. void TrimMemory(bool aggressively); - // Thumbnails ---------------------------------------------------------------- - - // Sets the given data to be the thumbnail for the given URL, - // overwriting any previous data. If the SkBitmap contains no pixel - // data, the thumbnail will be deleted. - bool SetPageThumbnail(const GURL& url, - URLID id, - const gfx::Image* thumbnail, - const ThumbnailScore& score, - base::Time time); - - // Retrieves thumbnail data for the given URL, returning true on success, - // false if there is no such thumbnail or there was some other error. - bool GetPageThumbnail(URLID id, std::vector<unsigned char>* data); - - // Delete the thumbnail with the provided id. Returns false on failure - bool DeleteThumbnail(URLID id); - - // If there is a thumbnail score for the id provided, retrieves the - // current thumbnail score and places it in |score| and returns - // true. Returns false otherwise. - bool ThumbnailScoreForId(URLID id, ThumbnailScore* score); - - // Called by the to delete all old thumbnails and make a clean table. - // Returns true on success. - bool RecreateThumbnailTable(); - // Favicon Bitmaps ----------------------------------------------------------- // Returns true if there are favicon bitmaps for |icon_id|. If @@ -155,10 +128,6 @@ class ThumbnailDatabase { bool SetFaviconBitmapLastUpdateTime(FaviconBitmapID bitmap_id, base::Time time); - // Deletes the favicon bitmaps for the favicon with with |icon_id|. - // Returns true if successful. - bool DeleteFaviconBitmapsForFavicon(chrome::FaviconID icon_id); - // Deletes the favicon bitmap with |bitmap_id|. // Returns true if successful. bool DeleteFaviconBitmap(FaviconBitmapID bitmap_id); @@ -279,14 +248,6 @@ class ThumbnailDatabase { // so failure causes any outer transaction to be rolled back. bool RetainDataForPageUrls(const std::vector<GURL>& urls_to_keep); - // Returns true iff the thumbnails table exists. - // Migrating to TopSites is dropping the thumbnails table. - bool NeedsMigrationToTopSites(); - - // Renames the database file and drops the Thumbnails table. - bool RenameAndDropThumbnails(const base::FilePath& old_db_file, - const base::FilePath& new_db_file); - private: friend class ExpireHistoryBackend; FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, @@ -373,10 +334,6 @@ class ThumbnailDatabase { // This can be NULL if there are no indexers registered to receive indexing // data from us. const HistoryPublisher* history_publisher_; - - // True if migration to TopSites has been done and the thumbnails - // table should not be used. - bool use_top_sites_; }; } // namespace history diff --git a/chrome/browser/history/thumbnail_database_unittest.cc b/chrome/browser/history/thumbnail_database_unittest.cc index 10b0574..75758e7 100644 --- a/chrome/browser/history/thumbnail_database_unittest.cc +++ b/chrome/browser/history/thumbnail_database_unittest.cc @@ -93,12 +93,11 @@ class IconMappingMigrationTest : public HistoryUnitTestBase { data_path = data_path.AppendASCII("History"); history_db_name_ = profile_->GetPath().Append(chrome::kHistoryFilename); - // Set up history and thumbnails as they would be before migration. ASSERT_NO_FATAL_FAILURE( ExecuteSQLScript(data_path.AppendASCII("history.20.sql"), history_db_name_)); thumbnail_db_name_ = - profile_->GetPath().Append(chrome::kThumbnailsFilename); + profile_->GetPath().Append(chrome::kFaviconsFilename); ASSERT_NO_FATAL_FAILURE( ExecuteSQLScript(data_path.AppendASCII("thumbnails.3.sql"), thumbnail_db_name_)); @@ -112,66 +111,6 @@ class IconMappingMigrationTest : public HistoryUnitTestBase { scoped_ptr<TestingProfile> profile_; }; -TEST_F(ThumbnailDatabaseTest, GetFaviconAfterMigrationToTopSites) { - ThumbnailDatabase db; - ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); - db.BeginTransaction(); - - std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); - scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); - - GURL url("http://google.com"); - chrome::FaviconID icon_id = db.AddFavicon(url, chrome::FAVICON); - base::Time time = base::Time::Now(); - FaviconBitmapID bitmap1_id = db.AddFaviconBitmap(icon_id, favicon, time, - kSmallSize); - FaviconBitmapID bitmap2_id = db.AddFaviconBitmap(icon_id, favicon, time, - kLargeSize); - EXPECT_TRUE(db.RenameAndDropThumbnails(file_name_, new_file_name_)); - EXPECT_TRUE(db.IsLatestVersion()); - - GURL url_out; - chrome::IconType icon_type_out; - EXPECT_TRUE(db.GetFaviconHeader(icon_id, &url_out, &icon_type_out)); - - EXPECT_EQ(url, url_out); - EXPECT_EQ(chrome::FAVICON, icon_type_out); - - std::vector<FaviconBitmap> favicon_bitmaps_out; - EXPECT_TRUE(db.GetFaviconBitmaps(icon_id, &favicon_bitmaps_out)); - EXPECT_EQ(2u, favicon_bitmaps_out.size()); - - FaviconBitmap favicon_bitmap1 = favicon_bitmaps_out[0]; - FaviconBitmap favicon_bitmap2 = favicon_bitmaps_out[1]; - - // Favicon bitmaps do not need to be in particular order. - if (favicon_bitmap1.bitmap_id == bitmap2_id) { - FaviconBitmap tmp_favicon_bitmap = favicon_bitmap1; - favicon_bitmap1 = favicon_bitmap2; - favicon_bitmap2 = tmp_favicon_bitmap; - } - - EXPECT_EQ(bitmap1_id, favicon_bitmap1.bitmap_id); - EXPECT_EQ(icon_id, favicon_bitmap1.icon_id); - EXPECT_EQ(time.ToInternalValue(), - favicon_bitmap1.last_updated.ToInternalValue()); - EXPECT_EQ(data.size(), favicon_bitmap1.bitmap_data->size()); - EXPECT_TRUE(std::equal(data.begin(), - data.end(), - favicon_bitmap1.bitmap_data->front())); - EXPECT_EQ(kSmallSize, favicon_bitmap1.pixel_size); - - EXPECT_EQ(bitmap2_id, favicon_bitmap2.bitmap_id); - EXPECT_EQ(icon_id, favicon_bitmap2.icon_id); - EXPECT_EQ(time.ToInternalValue(), - favicon_bitmap2.last_updated.ToInternalValue()); - EXPECT_EQ(data.size(), favicon_bitmap2.bitmap_data->size()); - EXPECT_TRUE(std::equal(data.begin(), - data.end(), - favicon_bitmap2.bitmap_data->front())); - EXPECT_EQ(kLargeSize, favicon_bitmap2.pixel_size); -} - TEST_F(ThumbnailDatabaseTest, AddIconMapping) { ThumbnailDatabase db; ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL)); diff --git a/chrome/browser/history/top_sites.h b/chrome/browser/history/top_sites.h index 5cfe8ba..6d57d12 100644 --- a/chrome/browser/history/top_sites.h +++ b/chrome/browser/history/top_sites.h @@ -90,19 +90,6 @@ class TopSites virtual bool GetTemporaryPageThumbnailScore(const GURL& url, ThumbnailScore* score) = 0; - // Invoked from History if migration is needed. If this is invoked it will - // be before HistoryLoaded is invoked. Should be called from the UI thread. - virtual void MigrateFromHistory() = 0; - - // Invoked with data from migrating thumbnails out of history. Should be - // called from the UI thread. - virtual void FinishHistoryMigration(const ThumbnailMigration& data) = 0; - - // Invoked from history when it finishes loading. If MigrateFromHistory was - // not invoked at this point then we load from the top sites service. Should - // be called from the UI thread. - virtual void HistoryLoaded() = 0; - // Asks TopSites to refresh what it thinks the top sites are. This may do // nothing. Should be called from the UI thread. virtual void SyncWithHistory() = 0; diff --git a/chrome/browser/history/top_sites_backend.cc b/chrome/browser/history/top_sites_backend.cc index 58bf38d2..a186675 100644 --- a/chrome/browser/history/top_sites_backend.cc +++ b/chrome/browser/history/top_sites_backend.cc @@ -37,16 +37,14 @@ void TopSitesBackend::GetMostVisitedThumbnails( const GetMostVisitedThumbnailsCallback& callback, CancelableTaskTracker* tracker) { scoped_refptr<MostVisitedThumbnails> thumbnails = new MostVisitedThumbnails(); - bool* need_history_migration = new bool(false); tracker->PostTaskAndReply( BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB).get(), FROM_HERE, base::Bind(&TopSitesBackend::GetMostVisitedThumbnailsOnDBThread, this, - thumbnails, - need_history_migration), - base::Bind(callback, thumbnails, base::Owned(need_history_migration))); + thumbnails), + base::Bind(callback, thumbnails)); } void TopSitesBackend::UpdateTopSites(const TopSitesDelta& delta) { @@ -98,15 +96,12 @@ void TopSitesBackend::ShutdownDBOnDBThread() { } void TopSitesBackend::GetMostVisitedThumbnailsOnDBThread( - scoped_refptr<MostVisitedThumbnails> thumbnails, - bool* need_history_migration) { + scoped_refptr<MostVisitedThumbnails> thumbnails) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); - *need_history_migration = false; if (db_) { db_->GetPageThumbnails(&(thumbnails->most_visited), &(thumbnails->url_to_images_map)); - *need_history_migration = db_->may_need_history_migration(); } } diff --git a/chrome/browser/history/top_sites_backend.h b/chrome/browser/history/top_sites_backend.h index e77705f..cad49e1 100644 --- a/chrome/browser/history/top_sites_backend.h +++ b/chrome/browser/history/top_sites_backend.h @@ -28,8 +28,7 @@ class TopSitesBackend : public base::RefCountedThreadSafe<TopSitesBackend> { public: // The boolean parameter indicates if the DB existed on disk or needs to be // migrated. - typedef base::Callback<void(const scoped_refptr<MostVisitedThumbnails>&, - const bool*)> + typedef base::Callback<void(const scoped_refptr<MostVisitedThumbnails>&)> GetMostVisitedThumbnailsCallback; TopSitesBackend(); @@ -74,8 +73,7 @@ class TopSitesBackend : public base::RefCountedThreadSafe<TopSitesBackend> { // Does the work of getting the most visted thumbnails. void GetMostVisitedThumbnailsOnDBThread( - scoped_refptr<MostVisitedThumbnails> thumbnails, - bool* need_history_migration); + scoped_refptr<MostVisitedThumbnails> thumbnails); // Updates top sites. void UpdateTopSitesOnDBThread(const TopSitesDelta& delta); diff --git a/chrome/browser/history/top_sites_database.cc b/chrome/browser/history/top_sites_database.cc index 6192a87..c87c108 100644 --- a/chrome/browser/history/top_sites_database.cc +++ b/chrome/browser/history/top_sites_database.cc @@ -18,7 +18,7 @@ namespace history { // should be able to read version 2 files just fine. static const int kVersionNumber = 2; -TopSitesDatabase::TopSitesDatabase() : may_need_history_migration_(false) { +TopSitesDatabase::TopSitesDatabase() { } TopSitesDatabase::~TopSitesDatabase() { @@ -27,17 +27,12 @@ TopSitesDatabase::~TopSitesDatabase() { bool TopSitesDatabase::Init(const base::FilePath& db_name) { bool file_existed = base::PathExists(db_name); - if (!file_existed) - may_need_history_migration_ = true; - db_.reset(CreateDB(db_name)); if (!db_) return false; bool does_meta_exist = sql::MetaTable::DoesTableExist(db_.get()); if (!does_meta_exist && file_existed) { - may_need_history_migration_ = true; - // If the meta file doesn't exist, this version is old. We could remove all // the entries as they are no longer applicable, but it's safest to just // remove the file and start over. @@ -255,6 +250,7 @@ void TopSitesDatabase::UpdatePageRank(const MostVisitedURL& url, // Caller should have a transaction open. void TopSitesDatabase::UpdatePageRankNoTransaction( const MostVisitedURL& url, int new_rank) { + DCHECK_GT(db_->transaction_nesting(), 0); int prev_rank = GetURLRank(url); if (prev_rank == -1) { LOG(WARNING) << "Updating rank of an unknown URL: " << url.url.spec(); @@ -296,7 +292,7 @@ void TopSitesDatabase::UpdatePageRankNoTransaction( } bool TopSitesDatabase::GetPageThumbnail(const GURL& url, - Images* thumbnail) { + Images* thumbnail) { sql::Statement statement(db_->GetCachedStatement( SQL_FROM_HERE, "SELECT thumbnail, boring_score, good_clipping, at_top, last_updated " diff --git a/chrome/browser/history/top_sites_database.h b/chrome/browser/history/top_sites_database.h index 42e04ed..5823938 100644 --- a/chrome/browser/history/top_sites_database.h +++ b/chrome/browser/history/top_sites_database.h @@ -32,13 +32,6 @@ class TopSitesDatabase { // Returns true on success. If false, no other functions should be called. bool Init(const base::FilePath& db_name); - // Returns true if migration of top sites from history may be needed. A value - // of true means either migration is definitely needed (the top sites file is - // old) or doesn't exist (as would happen for a new user). - bool may_need_history_migration() const { - return may_need_history_migration_; - } - // Thumbnails ---------------------------------------------------------------- // Returns a list of all URLs currently in the table. @@ -105,9 +98,6 @@ class TopSitesDatabase { scoped_ptr<sql::Connection> db_; sql::MetaTable meta_table_; - // See description above class. - bool may_need_history_migration_; - DISALLOW_COPY_AND_ASSIGN(TopSitesDatabase); }; diff --git a/chrome/browser/history/top_sites_impl.cc b/chrome/browser/history/top_sites_impl.cc index ed97392..3a1077a 100644 --- a/chrome/browser/history/top_sites_impl.cc +++ b/chrome/browser/history/top_sites_impl.cc @@ -82,80 +82,12 @@ static const int64 kMaxUpdateIntervalMinutes = 60; // artifacts for these small sized, highly detailed images. static const int kTopSitesImageQuality = 100; -namespace { - -// HistoryDBTask used during migration of thumbnails from history to top sites. -// When run on the history thread it collects the top sites and the -// corresponding thumbnails. When run back on the ui thread it calls into -// TopSitesImpl::FinishHistoryMigration. -class LoadThumbnailsFromHistoryTask : public HistoryDBTask { - public: - LoadThumbnailsFromHistoryTask(TopSites* top_sites, - int result_count) - : top_sites_(top_sites), - result_count_(result_count) { - // l10n_util isn't thread safe, so cache for use on the db thread. - ignore_urls_.insert(l10n_util::GetStringUTF8(IDS_CHROME_WELCOME_URL)); - ignore_urls_.insert(l10n_util::GetStringUTF8(IDS_WEBSTORE_URL)); -#if defined(OS_ANDROID) - ignore_urls_.insert(l10n_util::GetStringUTF8(IDS_MOBILE_WELCOME_URL)); -#endif - } - - virtual bool RunOnDBThread(history::HistoryBackend* backend, - history::HistoryDatabase* db) OVERRIDE { - // Get the most visited urls. - backend->QueryMostVisitedURLsImpl(result_count_, - kDaysOfHistory, - &data_.most_visited); - - // And fetch the thumbnails. - for (size_t i = 0; i < data_.most_visited.size(); ++i) { - const GURL& url = data_.most_visited[i].url; - if (ShouldFetchThumbnailFor(url)) { - scoped_refptr<base::RefCountedBytes> data; - backend->GetPageThumbnailDirectly(url, &data); - data_.url_to_thumbnail_map[url] = data; - } - } - return true; - } - - virtual void DoneRunOnMainThread() OVERRIDE { - top_sites_->FinishHistoryMigration(data_); - } - - private: - virtual ~LoadThumbnailsFromHistoryTask() {} - - bool ShouldFetchThumbnailFor(const GURL& url) { - return ignore_urls_.find(url.spec()) == ignore_urls_.end(); - } - - // Set of URLs we don't load thumbnails for. This is created on the UI thread - // and used on the history thread. - std::set<std::string> ignore_urls_; - - scoped_refptr<TopSites> top_sites_; - - // Number of results to request from history. - const int result_count_; - - ThumbnailMigration data_; - - DISALLOW_COPY_AND_ASSIGN(LoadThumbnailsFromHistoryTask); -}; - -} // namespace - TopSitesImpl::TopSitesImpl(Profile* profile) : backend_(NULL), cache_(new TopSitesCache()), thread_safe_cache_(new TopSitesCache()), profile_(profile), last_num_urls_changed_(0), - history_state_(HISTORY_LOADING), - top_sites_state_(TOP_SITES_LOADING), loaded_(false) { if (!profile_) return; @@ -184,16 +116,6 @@ void TopSitesImpl::Init(const base::FilePath& db_name) { base::Bind(&TopSitesImpl::OnGotMostVisitedThumbnails, base::Unretained(this)), &cancelable_task_tracker_); - - // History may have already finished loading by the time we're created. - HistoryService* history = - HistoryServiceFactory::GetForProfileWithoutCreating(profile_); - if (history && history->backend_loaded()) { - if (history->needs_top_sites_migration()) - MigrateFromHistory(); - else - history_state_ = HISTORY_LOADED; - } } bool TopSitesImpl::SetPageThumbnail(const GURL& url, @@ -341,71 +263,6 @@ static int IndexOf(const MostVisitedURLList& urls, const GURL& url) { return -1; } -void TopSitesImpl::MigrateFromHistory() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - if (history_state_ != HISTORY_LOADING) { - // This can happen if history was unloaded then loaded again. - return; - } - - history_state_ = HISTORY_MIGRATING; - HistoryServiceFactory::GetForProfile( - profile_, Profile::EXPLICIT_ACCESS)->ScheduleDBTask( - new LoadThumbnailsFromHistoryTask( - this, - num_results_to_request_from_history()), - &history_consumer_); -} - -void TopSitesImpl::FinishHistoryMigration(const ThumbnailMigration& data) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK_EQ(history_state_, HISTORY_MIGRATING); - - history_state_ = HISTORY_LOADED; - - SetTopSites(data.most_visited); - - for (size_t i = 0; i < data.most_visited.size(); ++i) { - URLToThumbnailMap::const_iterator image_i = - data.url_to_thumbnail_map.find(data.most_visited[i].url); - if (image_i != data.url_to_thumbnail_map.end()) { - SetPageThumbnailEncoded( - data.most_visited[i].url, image_i->second.get(), ThumbnailScore()); - } - } - - MoveStateToLoaded(); - - ResetThreadSafeImageCache(); - - // We've scheduled all the thumbnails and top sites to be written to the top - // sites db, but it hasn't happened yet. Schedule a request on the db thread - // that notifies us when done. When done we'll know everything was written and - // we can tell history to finish its part of migration. - backend_->DoEmptyRequest( - base::Bind(&TopSitesImpl::OnHistoryMigrationWrittenToDisk, - base::Unretained(this)), - &cancelable_task_tracker_); -} - -void TopSitesImpl::HistoryLoaded() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - if (history_state_ != HISTORY_MIGRATING) { - // No migration from history is needed. - history_state_ = HISTORY_LOADED; - if (top_sites_state_ == TOP_SITES_LOADED_WAITING_FOR_HISTORY) { - // TopSites thought it needed migration, but it really didn't. This - // typically happens the first time a profile is run with Top Sites - // enabled - SetTopSites(MostVisitedURLList()); - MoveStateToLoaded(); - } - } - // else case can happen if history is unloaded, then loaded again. -} - void TopSitesImpl::SyncWithHistory() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); if (loaded_ && temp_images_.size()) { @@ -888,54 +745,23 @@ void TopSitesImpl::RestartQueryForTopSitesTimer(base::TimeDelta delta) { timer_.Start(FROM_HERE, delta, this, &TopSitesImpl::TimerFired); } -void TopSitesImpl::OnHistoryMigrationWrittenToDisk() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - if (!profile_) - return; - - HistoryService* history = HistoryServiceFactory::GetForProfile( - profile_, Profile::EXPLICIT_ACCESS); - if (history) - history->OnTopSitesReady(); -} - void TopSitesImpl::OnGotMostVisitedThumbnails( - const scoped_refptr<MostVisitedThumbnails>& thumbnails, - const bool* need_history_migration) { + const scoped_refptr<MostVisitedThumbnails>& thumbnails) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK_EQ(top_sites_state_, TOP_SITES_LOADING); - - if (!*need_history_migration) { - top_sites_state_ = TOP_SITES_LOADED; - // Set the top sites directly in the cache so that SetTopSites diffs - // correctly. - cache_->SetTopSites(thumbnails->most_visited); - SetTopSites(thumbnails->most_visited); - cache_->SetThumbnails(thumbnails->url_to_images_map); + // Set the top sites directly in the cache so that SetTopSites diffs + // correctly. + cache_->SetTopSites(thumbnails->most_visited); + SetTopSites(thumbnails->most_visited); + cache_->SetThumbnails(thumbnails->url_to_images_map); - ResetThreadSafeImageCache(); + ResetThreadSafeImageCache(); - MoveStateToLoaded(); + MoveStateToLoaded(); - // Start a timer that refreshes top sites from history. - RestartQueryForTopSitesTimer( - base::TimeDelta::FromSeconds(kUpdateIntervalSecs)); - } else { - // The top sites file didn't exist or is the wrong version. We need to wait - // for history to finish loading to know if we really needed to migrate. - if (history_state_ == HISTORY_LOADED) { - top_sites_state_ = TOP_SITES_LOADED; - SetTopSites(MostVisitedURLList()); - MoveStateToLoaded(); - } else { - top_sites_state_ = TOP_SITES_LOADED_WAITING_FOR_HISTORY; - // Ask for history just in case it hasn't been loaded yet. When history - // finishes loading we'll do migration and/or move to loaded. - HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); - } - } + // Start a timer that refreshes top sites from history. + RestartQueryForTopSitesTimer( + base::TimeDelta::FromSeconds(kUpdateIntervalSecs)); } void TopSitesImpl::OnTopSitesAvailableFromHistory( diff --git a/chrome/browser/history/top_sites_impl.h b/chrome/browser/history/top_sites_impl.h index 025ac4d..678bf63 100644 --- a/chrome/browser/history/top_sites_impl.h +++ b/chrome/browser/history/top_sites_impl.h @@ -70,9 +70,6 @@ class TopSitesImpl : public TopSites { ThumbnailScore* score) OVERRIDE; virtual bool GetTemporaryPageThumbnailScore(const GURL& url, ThumbnailScore* score) OVERRIDE; - virtual void MigrateFromHistory() OVERRIDE; - virtual void FinishHistoryMigration(const ThumbnailMigration& data) OVERRIDE; - virtual void HistoryLoaded() OVERRIDE; virtual void SyncWithHistory() OVERRIDE; virtual bool HasBlacklistedItems() const OVERRIDE; virtual void AddBlacklistedURL(const GURL& url) OVERRIDE; @@ -110,34 +107,6 @@ class TopSitesImpl : public TopSites { const MostVisitedURLList& new_list, TopSitesDelta* delta); - // Enumeration of the possible states history can be in. These values do not - // necessarily reflect the loaded state of history. In particular if the - // history backend is unloaded |history_state_| may be HISTORY_LOADED. - enum HistoryLoadState { - // We're waiting for history to finish loading. - HISTORY_LOADING, - - // History finished loading and we need to migrate top sites out of history. - HISTORY_MIGRATING, - - // History is loaded. - HISTORY_LOADED - }; - - // Enumeration of possible states the top sites backend can be in. - enum TopSitesLoadState { - // We're waiting for the backend to finish loading. - TOP_SITES_LOADING, - - // The backend finished loading, but we may need to migrate. This is true if - // the top sites db didn't exist, or if the db existed but is from an old - // version. - TOP_SITES_LOADED_WAITING_FOR_HISTORY, - - // Top sites is loaded. - TOP_SITES_LOADED - }; - // Sets the thumbnail without writing to the database. Useful when // reading last known top sites from the DB. // Returns true if the thumbnail was set, false if the existing one is better. @@ -215,16 +184,10 @@ class TopSitesImpl : public TopSites { // Stops and starts timer with a delay of |delta|. void RestartQueryForTopSitesTimer(base::TimeDelta delta); - // Callback after TopSitesBackend has finished migration. This tells history - // to finish it's side of migration (nuking thumbnails on disk). Should be - // called from the UI thread. - void OnHistoryMigrationWrittenToDisk(); - // Callback from TopSites with the top sites/thumbnails. Should be called // from the UI thread. void OnGotMostVisitedThumbnails( - const scoped_refptr<MostVisitedThumbnails>& thumbnails, - const bool* need_history_migration); + const scoped_refptr<MostVisitedThumbnails>& thumbnails); // Called when history service returns a list of top URLs. void OnTopSitesAvailableFromHistory(CancelableRequestProvider::Handle handle, @@ -273,12 +236,6 @@ class TopSitesImpl : public TopSites { // SetTopSites call. TempImages temp_images_; - // See description above HistoryLoadState. - HistoryLoadState history_state_; - - // See description above TopSitesLoadState. - TopSitesLoadState top_sites_state_; - // URL List of prepopulated page. std::vector<GURL> prepopulated_page_urls_; diff --git a/chrome/browser/history/top_sites_impl_unittest.cc b/chrome/browser/history/top_sites_impl_unittest.cc index a0b9f22..734132f 100644 --- a/chrome/browser/history/top_sites_impl_unittest.cc +++ b/chrome/browser/history/top_sites_impl_unittest.cc @@ -3,42 +3,23 @@ // found in the LICENSE file. #include "base/bind.h" -#include "base/bind_helpers.h" -#include "base/file_util.h" -#include "base/files/scoped_temp_dir.h" -#include "base/format_macros.h" #include "base/memory/weak_ptr.h" +#include "base/message_loop/message_loop.h" #include "base/path_service.h" -#include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" -#include "base/values.h" -#include "chrome/browser/chrome_notification_types.h" -#include "chrome/browser/history/history_backend.h" -#include "chrome/browser/history/history_database.h" #include "chrome/browser/history/history_db_task.h" -#include "chrome/browser/history/history_marshaling.h" -#include "chrome/browser/history/history_notifications.h" #include "chrome/browser/history/history_service_factory.h" +#include "chrome/browser/history/history_types.h" #include "chrome/browser/history/history_unittest_base.h" -#include "chrome/browser/history/top_sites_backend.h" #include "chrome/browser/history/top_sites_cache.h" -#include "chrome/browser/history/top_sites_database.h" #include "chrome/browser/history/top_sites_impl.h" -#include "chrome/browser/ui/webui/ntp/most_visited_handler.h" #include "chrome/common/cancelable_task_tracker.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" -#include "chrome/common/chrome_switches.h" #include "chrome/test/base/testing_profile.h" -#include "chrome/tools/profiles/thumbnail-inl.h" #include "content/public/test/test_browser_thread.h" -#include "content/public/test/test_utils.h" -#include "grit/chromium_strings.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkBitmap.h" -#include "ui/base/l10n/l10n_util.h" #include "ui/gfx/codec/jpeg_codec.h" #include "url/gurl.h" @@ -341,64 +322,6 @@ class TopSitesImplTest : public HistoryUnitTestBase { DISALLOW_COPY_AND_ASSIGN(TopSitesImplTest); }; // Class TopSitesImplTest -class TopSitesMigrationTest : public TopSitesImplTest { - public: - TopSitesMigrationTest() {} - - virtual void SetUp() { - TopSitesImplTest::SetUp(); - - base::FilePath data_path; - ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); - data_path = data_path.AppendASCII("top_sites"); - - // Set up history and thumbnails as they would be before migration. - ASSERT_NO_FATAL_FAILURE(ExecuteSQLScript( - data_path.AppendASCII("history.19.sql"), - profile()->GetPath().Append(chrome::kHistoryFilename))); - ASSERT_NO_FATAL_FAILURE(ExecuteSQLScript( - data_path.AppendASCII("thumbnails.3.sql"), - profile()->GetPath().Append(chrome::kThumbnailsFilename))); - - ASSERT_TRUE(profile()->CreateHistoryService(false, false)); - profile()->CreateTopSites(); - profile()->BlockUntilTopSitesLoaded(); - } - - // Returns true if history and top sites should be created in SetUp. - virtual bool CreateHistoryAndTopSites() OVERRIDE { - return false; - } - - protected: - // Assertions for the migration test. This is extracted into a standalone - // method so that it can be invoked twice. - void MigrationAssertions() { - TopSitesQuerier querier; - querier.QueryTopSites(top_sites(), false); - - // We shouldn't have gotten a callback. - EXPECT_EQ(1, querier.number_of_callbacks()); - - // The data we loaded should contain google and yahoo. - ASSERT_EQ(2u + GetPrepopulatePages().size(), querier.urls().size()); - EXPECT_EQ(GURL("http://google.com/"), querier.urls()[0].url); - EXPECT_EQ(GURL("http://yahoo.com/"), querier.urls()[1].url); - ASSERT_NO_FATAL_FAILURE(ContainsPrepopulatePages(querier, 2)); - - SkBitmap goog_thumbnail = GetThumbnail(GURL("http://google.com/")); - EXPECT_EQ(1, goog_thumbnail.width()); - - SkBitmap yahoo_thumbnail = GetThumbnail(GURL("http://yahoo.com/")); - EXPECT_EQ(2, yahoo_thumbnail.width()); - - // Favicon assertions are handled in ThumbnailDatabase. - } - - private: - DISALLOW_COPY_AND_ASSIGN(TopSitesMigrationTest); -}; - // Helper function for appending a URL to a vector of "most visited" URLs, // using the default values for everything but the URL. static void AppendMostVisitedURL(std::vector<MostVisitedURL>* list, @@ -899,27 +822,6 @@ TEST_F(TopSitesImplTest, GetUpdateDelay) { EXPECT_EQ(1, GetUpdateDelay().InMinutes()); } -TEST_F(TopSitesMigrationTest, Migrate) { - EXPECT_TRUE(IsTopSitesLoaded()); - - // Make sure the data was migrated to top sites. - ASSERT_NO_FATAL_FAILURE(MigrationAssertions()); - - // We need to wait for top sites and history to finish processing requests. - WaitForTopSites(); - WaitForHistory(); - - // Make sure there is no longer a Thumbnails file on disk. - ASSERT_FALSE(base::PathExists( - profile()->GetPath().Append(chrome::kThumbnailsFilename))); - - // Recreate top sites and make sure everything is still there. - ASSERT_TRUE(profile()->CreateHistoryService(false, false)); - RecreateTopSitesAndBlock(); - - ASSERT_NO_FATAL_FAILURE(MigrationAssertions()); -} - // Verifies that callbacks are notified correctly if requested before top sites // has loaded. TEST_F(TopSitesImplTest, NotifyCallbacksWhenLoaded) { @@ -1191,77 +1093,4 @@ TEST_F(TopSitesImplTest, AddPrepopulatedPages) { ASSERT_NO_FATAL_FAILURE(ContainsPrepopulatePages(q, 0)); } -// Makes sure creating top sites before history is created works. -TEST_F(TopSitesImplTest, CreateTopSitesThenHistory) { - profile()->DestroyTopSites(); - profile()->DestroyHistoryService(); - - // Remove the TopSites file. This forces TopSites to wait until history loads - // before TopSites is considered loaded. - sql::Connection::Delete( - profile()->GetPath().Append(chrome::kTopSitesFilename)); - - // Create TopSites, but not History. - profile()->CreateTopSites(); - WaitForTopSites(); - EXPECT_FALSE(IsTopSitesLoaded()); - - // Load history, which should make TopSites finish loading too. - ASSERT_TRUE(profile()->CreateHistoryService(false, false)); - profile()->BlockUntilTopSitesLoaded(); - EXPECT_TRUE(IsTopSitesLoaded()); -} - -class TopSitesUnloadTest : public TopSitesImplTest { - public: - TopSitesUnloadTest() {} - - virtual bool CreateHistoryAndTopSites() OVERRIDE { - return false; - } - - private: - DISALLOW_COPY_AND_ASSIGN(TopSitesUnloadTest); -}; - -// Makes sure if history is unloaded after topsites is loaded we don't hit any -// assertions. -TEST_F(TopSitesUnloadTest, UnloadHistoryTest) { - ASSERT_TRUE(profile()->CreateHistoryService(false, false)); - profile()->CreateTopSites(); - profile()->BlockUntilTopSitesLoaded(); - HistoryServiceFactory::GetForProfile( - profile(), Profile::EXPLICIT_ACCESS)->UnloadBackend(); - profile()->BlockUntilHistoryProcessesPendingRequests(); -} - -// Makes sure if history (with migration code) is unloaded after topsites is -// loaded we don't hit any assertions. -TEST_F(TopSitesUnloadTest, UnloadWithMigration) { - // Set up history and thumbnails as they would be before migration. - base::FilePath data_path; - ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); - data_path = data_path.AppendASCII("top_sites"); - ASSERT_NO_FATAL_FAILURE(ExecuteSQLScript( - data_path.AppendASCII("history.19.sql"), - profile()->GetPath().Append(chrome::kHistoryFilename))); - ASSERT_NO_FATAL_FAILURE(ExecuteSQLScript( - data_path.AppendASCII("thumbnails.3.sql"), - profile()->GetPath().Append(chrome::kThumbnailsFilename))); - - // Create history and block until it's loaded. - ASSERT_TRUE(profile()->CreateHistoryService(false, false)); - profile()->BlockUntilHistoryProcessesPendingRequests(); - - // Create top sites and unload history. - content::WindowedNotificationObserver observer( - chrome::NOTIFICATION_TOP_SITES_LOADED, - content::Source<Profile>(profile())); - profile()->CreateTopSites(); - HistoryServiceFactory::GetForProfile( - profile(), Profile::EXPLICIT_ACCESS)->UnloadBackend(); - profile()->BlockUntilHistoryProcessesPendingRequests(); - observer.Wait(); -} - } // namespace history diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc index e37adf4..0a0833e 100644 --- a/chrome/test/base/testing_profile.cc +++ b/chrome/test/base/testing_profile.cc @@ -497,8 +497,6 @@ void TestingProfile::BlockUntilTopSitesLoaded() { content::WindowedNotificationObserver top_sites_loaded_observer( chrome::NOTIFICATION_TOP_SITES_LOADED, content::NotificationService::AllSources()); - if (!HistoryServiceFactory::GetForProfile(this, Profile::EXPLICIT_ACCESS)) - GetTopSites()->HistoryLoaded(); top_sites_loaded_observer.Wait(); } |