summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-06 19:46:57 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-06 19:46:57 +0000
commitbbe192b6e32035bae275f798bd495d136a1a1d68 (patch)
tree4e094f9446b48dcf01d331b44e298fd807f61fd7
parent145db1f5370109e0abcd324c37424dded8a501df (diff)
downloadchromium_src-bbe192b6e32035bae275f798bd495d136a1a1d68.zip
chromium_src-bbe192b6e32035bae275f798bd495d136a1a1d68.tar.gz
chromium_src-bbe192b6e32035bae275f798bd495d136a1a1d68.tar.bz2
Revert "Replace --top-sites flag with --no-top-sites flag. TopSites becomes the default."
Introduced new crashes. TBR=nshkrob Review URL: http://codereview.chromium.org/3026059 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55268 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/dom_ui/dom_ui_thumbnail_source.cc4
-rw-r--r--chrome/browser/dom_ui/most_visited_handler.cc14
-rw-r--r--chrome/browser/history/expire_history_backend_unittest.cc20
-rw-r--r--chrome/browser/history/history_backend.cc4
-rw-r--r--chrome/browser/history/history_backend_unittest.cc8
-rw-r--r--chrome/browser/history/history_database.cc13
-rw-r--r--chrome/browser/history/history_types.h11
-rw-r--r--chrome/browser/history/history_unittest.cc5
-rw-r--r--chrome/browser/history/thumbnail_database.cc18
-rw-r--r--chrome/browser/history/thumbnail_database_unittest.cc20
-rw-r--r--chrome/browser/history/top_sites.cc180
-rw-r--r--chrome/browser/history/top_sites.h49
-rw-r--r--chrome/browser/history/top_sites_database.cc15
-rw-r--r--chrome/browser/history/top_sites_database.h21
-rw-r--r--chrome/browser/history/top_sites_unittest.cc64
-rw-r--r--chrome/browser/profile_impl.cc2
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc2
-rw-r--r--chrome/common/chrome_switches.cc7
-rw-r--r--chrome/common/chrome_switches.h2
-rw-r--r--chrome/test/data/profiles/typical_history/Default/Historybin13770752 -> 13770752 bytes
-rw-r--r--chrome/test/testing_profile.cc4
-rw-r--r--chrome/test/testing_profile.h15
22 files changed, 157 insertions, 321 deletions
diff --git a/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc b/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc
index ebff335..fd6eae7 100644
--- a/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc
+++ b/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc
@@ -28,8 +28,8 @@ DOMUIThumbnailSource::~DOMUIThumbnailSource() {
void DOMUIThumbnailSource::StartDataRequest(const std::string& path,
bool is_off_the_record,
int request_id) {
- if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTopSites)) {
- history::TopSites* top_sites = profile_->GetTopSites();
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTopSites)) {
+ scoped_refptr<history::TopSites> top_sites = profile_->GetTopSites();
RefCountedBytes* data = NULL;
if (top_sites->GetPageThumbnail(GURL(path), &data)) {
// We have the thumbnail.
diff --git a/chrome/browser/dom_ui/most_visited_handler.cc b/chrome/browser/dom_ui/most_visited_handler.cc
index 3528a9c..e6e8ac14 100644
--- a/chrome/browser/dom_ui/most_visited_handler.cc
+++ b/chrome/browser/dom_ui/most_visited_handler.cc
@@ -150,7 +150,7 @@ void MostVisitedHandler::SendPagesValue() {
}
void MostVisitedHandler::StartQueryForMostVisited() {
- if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTopSites)) {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTopSites)) {
// Use TopSites.
history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites();
ts->GetMostVisitedURLs(
@@ -212,7 +212,7 @@ void MostVisitedHandler::HandleRemoveURLsFromBlacklist(const Value* urls) {
}
UserMetrics::RecordAction(UserMetricsAction("MostVisited_UrlRemoved"),
dom_ui_->GetProfile());
- if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTopSites)) {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTopSites)) {
history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites();
ts->RemoveBlacklistedURL(GURL(WideToASCII(url)));
return;
@@ -227,7 +227,7 @@ void MostVisitedHandler::HandleClearBlacklist(const Value* value) {
UserMetrics::RecordAction(UserMetricsAction("MostVisited_BlacklistCleared"),
dom_ui_->GetProfile());
- if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTopSites)) {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTopSites)) {
history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites();
ts->ClearBlacklistedURLs();
return;
@@ -276,7 +276,7 @@ void MostVisitedHandler::HandleAddPinnedURL(const Value* value) {
}
void MostVisitedHandler::AddPinnedURL(const MostVisitedPage& page, int index) {
- if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTopSites)) {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTopSites)) {
history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites();
ts->AddPinnedURL(page.url, index);
return;
@@ -315,7 +315,7 @@ void MostVisitedHandler::HandleRemovePinnedURL(const Value* value) {
}
void MostVisitedHandler::RemovePinnedURL(const GURL& url) {
- if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTopSites)) {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTopSites)) {
history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites();
ts->RemovePinnedURL(url);
return;
@@ -485,7 +485,7 @@ void MostVisitedHandler::SetPagesValue(std::vector<PageUsageData*>* data) {
void MostVisitedHandler::SetPagesValueFromTopSites(
const history::MostVisitedURLList& data) {
- DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTopSites));
+ DCHECK(CommandLine::ForCurrentProcess()->HasSwitch(switches::kTopSites));
pages_value_.reset(new ListValue);
for (size_t i = 0; i < data.size(); i++) {
const history::MostVisitedURL& url = data[i];
@@ -607,7 +607,7 @@ void MostVisitedHandler::Observe(NotificationType type,
}
void MostVisitedHandler::BlacklistURL(const GURL& url) {
- if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTopSites)) {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTopSites)) {
history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites();
ts->AddBlacklistedURL(url);
return;
diff --git a/chrome/browser/history/expire_history_backend_unittest.cc b/chrome/browser/history/expire_history_backend_unittest.cc
index 95b391f..ca822bc 100644
--- a/chrome/browser/history/expire_history_backend_unittest.cc
+++ b/chrome/browser/history/expire_history_backend_unittest.cc
@@ -16,10 +16,8 @@
#include "chrome/browser/history/history_notifications.h"
#include "chrome/browser/history/text_database_manager.h"
#include "chrome/browser/history/thumbnail_database.h"
-#include "chrome/browser/history/top_sites.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/thumbnail_score.h"
-#include "chrome/test/testing_profile.h"
#include "chrome/tools/profiles/thumbnail-inl.h"
#include "gfx/codec/jpeg_codec.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -92,8 +90,6 @@ class ExpireHistoryTest : public testing::Test,
scoped_ptr<ArchivedDatabase> archived_db_;
scoped_ptr<ThumbnailDatabase> thumb_db_;
scoped_ptr<TextDatabaseManager> text_db_;
- TestingProfile profile_;
- scoped_refptr<TopSites> top_sites_;
// Time at the beginning of the test, so everybody agrees what "now" is.
const Time now_;
@@ -138,7 +134,6 @@ class ExpireHistoryTest : public testing::Test,
expirer_.SetDatabases(main_db_.get(), archived_db_.get(), thumb_db_.get(),
text_db_.get());
- top_sites_ = profile_.GetTopSites();
}
void TearDown() {
@@ -150,7 +145,6 @@ class ExpireHistoryTest : public testing::Test,
archived_db_.reset();
thumb_db_.reset();
text_db_.reset();
- TopSites::DeleteTopSites(top_sites_);
file_util::Delete(dir_, true);
}
@@ -217,9 +211,9 @@ void ExpireHistoryTest::AddExampleData(URLID url_ids[3], Time visit_times[4]) {
Time time;
GURL gurl;
- top_sites_->SetPageThumbnail(url_row1.url(), *thumbnail, score);
- top_sites_->SetPageThumbnail(url_row2.url(), *thumbnail, score);
- top_sites_->SetPageThumbnail(url_row3.url(), *thumbnail, score);
+ thumb_db_->SetPageThumbnail(gurl, url_ids[0], *thumbnail, score, time);
+ thumb_db_->SetPageThumbnail(gurl, url_ids[1], *thumbnail, score, time);
+ thumb_db_->SetPageThumbnail(gurl, url_ids[2], *thumbnail, score, time);
// Four visits.
VisitRow visit_row1;
@@ -277,12 +271,8 @@ bool ExpireHistoryTest::HasFavIcon(FavIconID favicon_id) {
}
bool ExpireHistoryTest::HasThumbnail(URLID url_id) {
- URLRow info;
- if (!main_db_->GetURLRow(url_id, &info))
- return false;
- GURL url = info.url();
- RefCountedBytes *data;
- return top_sites_->GetPageThumbnail(url, &data);
+ std::vector<unsigned char> temp_data;
+ return thumb_db_->GetPageThumbnail(url_id, &temp_data);
}
int ExpireHistoryTest::CountTextMatchesForURL(const GURL& url) {
diff --git a/chrome/browser/history/history_backend.cc b/chrome/browser/history/history_backend.cc
index 1c58f74..8e1c5fb 100644
--- a/chrome/browser/history/history_backend.cc
+++ b/chrome/browser/history/history_backend.cc
@@ -581,7 +581,7 @@ void HistoryBackend::InitImpl() {
// Thumbnail database.
thumbnail_db_.reset(new ThumbnailDatabase());
- if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTopSites)) {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTopSites)) {
if (!db_->needs_version_18_migration()) {
// No convertion needed - use new filename right away.
thumbnail_name = GetFaviconsFileName();
@@ -598,7 +598,7 @@ void HistoryBackend::InitImpl() {
thumbnail_db_.reset();
}
- if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTopSites)) {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTopSites)) {
if (db_->needs_version_18_migration()) {
LOG(INFO) << "Starting TopSites migration";
delegate_->StartTopSitesMigration();
diff --git a/chrome/browser/history/history_backend_unittest.cc b/chrome/browser/history/history_backend_unittest.cc
index 780038d..24cc1cd 100644
--- a/chrome/browser/history/history_backend_unittest.cc
+++ b/chrome/browser/history/history_backend_unittest.cc
@@ -4,7 +4,6 @@
#include "base/file_path.h"
#include "base/file_util.h"
-#include "base/command_line.h"
#include "base/path_service.h"
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
@@ -14,7 +13,6 @@
#include "chrome/browser/history/history_notifications.h"
#include "chrome/browser/history/in_memory_history_backend.h"
#include "chrome/browser/history/in_memory_database.h"
-#include "chrome/common/chrome_switches.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/thumbnail_score.h"
#include "chrome/tools/profiles/thumbnail-inl.h"
@@ -404,9 +402,6 @@ TEST_F(HistoryBackendTest, URLsNoLongerBookmarked) {
TEST_F(HistoryBackendTest, GetPageThumbnailAfterRedirects) {
ASSERT_TRUE(backend_.get());
- if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTopSites))
- return;
-
const char* base_url = "http://mail";
const char* thumbnail_url = "http://mail.google.com";
@@ -603,9 +598,6 @@ TEST_F(HistoryBackendTest, StripUsernamePasswordTest) {
}
TEST_F(HistoryBackendTest, DeleteThumbnailsDatabaseTest) {
- if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTopSites))
- return;
-
EXPECT_TRUE(backend_->thumbnail_db_->NeedsMigrationToTopSites());
backend_->delegate_->StartTopSitesMigration();
EXPECT_FALSE(backend_->thumbnail_db_->NeedsMigrationToTopSites());
diff --git a/chrome/browser/history/history_database.cc b/chrome/browser/history/history_database.cc
index 7869fcc..26bb81a 100644
--- a/chrome/browser/history/history_database.cc
+++ b/chrome/browser/history/history_database.cc
@@ -134,11 +134,14 @@ void HistoryDatabase::BeginExclusiveMode() {
// static
int HistoryDatabase::GetCurrentVersion() {
- // If we don't use TopSites, we are one version number behind.
- if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTopSites))
- return 17; // Last pre-TopSites version.
- else
+ // Temporary solution while TopSites is behind a flag. If there is
+ // no flag, we are still using the Thumbnails file, i.e. we are at
+ // version 17.
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTopSites)) {
return kCurrentVersionNumber;
+ } else {
+ return kCurrentVersionNumber - 1;
+ }
}
void HistoryDatabase::BeginTransaction() {
@@ -283,7 +286,7 @@ sql::InitStatus HistoryDatabase::EnsureCurrentVersion(
if (cur_version == 17)
needs_version_18_migration_ = true;
- if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTopSites) &&
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTopSites) &&
cur_version == 18) {
// Set DB version back to pre-top sites.
cur_version = 17;
diff --git a/chrome/browser/history/history_types.h b/chrome/browser/history/history_types.h
index 21e8067..0c283b1 100644
--- a/chrome/browser/history/history_types.h
+++ b/chrome/browser/history/history_types.h
@@ -13,14 +13,12 @@
#include <vector>
#include "base/basictypes.h"
-#include "base/ref_counted_memory.h"
#include "base/stack_container.h"
#include "base/string16.h"
#include "base/time.h"
#include "chrome/browser/history/snippet.h"
#include "chrome/common/page_transition_types.h"
#include "chrome/common/ref_counted_util.h"
-#include "chrome/common/thumbnail_score.h"
#include "googleurl/src/gurl.h"
namespace history {
@@ -529,15 +527,6 @@ struct MostVisitedURL {
}
};
-// Used by TopSites to store the thumbnails.
-struct Images {
- scoped_refptr<RefCountedBytes> thumbnail;
- ThumbnailScore thumbnail_score;
-
- // TODO(brettw): this will eventually store the favicon.
- // scoped_refptr<RefCountedBytes> favicon;
-};
-
typedef std::vector<MostVisitedURL> MostVisitedURLList;
// Used for intermediate history result operations.
diff --git a/chrome/browser/history/history_unittest.cc b/chrome/browser/history/history_unittest.cc
index 063414f..c8db05a 100644
--- a/chrome/browser/history/history_unittest.cc
+++ b/chrome/browser/history/history_unittest.cc
@@ -24,7 +24,6 @@
#include "app/sql/statement.h"
#include "base/basictypes.h"
#include "base/callback.h"
-#include "base/command_line.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/message_loop.h"
@@ -42,7 +41,6 @@
#include "chrome/browser/history/in_memory_history_backend.h"
#include "chrome/browser/history/page_usage_data.h"
#include "chrome/common/chrome_paths.h"
-#include "chrome/common/chrome_switches.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/thumbnail_score.h"
#include "chrome/tools/profiles/thumbnail-inl.h"
@@ -687,9 +685,6 @@ TEST_F(HistoryTest, Segments) {
// This just tests history system -> thumbnail database integration, the actual
// thumbnail tests are in its own file.
TEST_F(HistoryTest, Thumbnails) {
- if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTopSites))
- return; // TopSitesTest replaces this.
-
scoped_refptr<HistoryService> history(new HistoryService);
history_service_ = history;
ASSERT_TRUE(history->Init(history_dir_, NULL));
diff --git a/chrome/browser/history/thumbnail_database.cc b/chrome/browser/history/thumbnail_database.cc
index 979accf..8bf203d 100644
--- a/chrome/browser/history/thumbnail_database.cc
+++ b/chrome/browser/history/thumbnail_database.cc
@@ -130,7 +130,7 @@ sql::InitStatus ThumbnailDatabase::OpenDatabase(sql::Connection* db,
bool ThumbnailDatabase::InitThumbnailTable() {
if (!db_.DoesTableExist("thumbnails")) {
- if (!CommandLine::ForCurrentProcess()-> HasSwitch(switches::kNoTopSites)) {
+ if (CommandLine::ForCurrentProcess()-> HasSwitch(switches::kTopSites)) {
use_top_sites_ = true;
return true;
}
@@ -231,10 +231,8 @@ void ThumbnailDatabase::SetPageThumbnail(
const SkBitmap& thumbnail,
const ThumbnailScore& score,
base::Time time) {
- if (use_top_sites_) {
- LOG(WARNING) << "Use TopSites instead.";
+ if (use_top_sites_)
return; // Not possible after migration to TopSites.
- }
if (!thumbnail.isNull()) {
bool add_thumbnail = true;
@@ -288,10 +286,8 @@ void ThumbnailDatabase::SetPageThumbnail(
bool ThumbnailDatabase::GetPageThumbnail(URLID id,
std::vector<unsigned char>* data) {
- if (use_top_sites_) {
- LOG(WARNING) << "Use TopSites instead.";
+ if (use_top_sites_)
return false; // Not possible after migration to TopSites.
- }
sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
"SELECT data FROM thumbnails WHERE url_id=?"));
@@ -307,10 +303,8 @@ bool ThumbnailDatabase::GetPageThumbnail(URLID id,
}
bool ThumbnailDatabase::DeleteThumbnail(URLID id) {
- if (use_top_sites_) {
- LOG(WARNING) << "Use TopSites instead.";
+ 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 = ?"));
@@ -323,10 +317,8 @@ bool ThumbnailDatabase::DeleteThumbnail(URLID id) {
bool ThumbnailDatabase::ThumbnailScoreForId(URLID id,
ThumbnailScore* score) {
- if (use_top_sites_) {
- LOG(WARNING) << "Use TopSites instead.";
+ if (use_top_sites_)
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.
diff --git a/chrome/browser/history/thumbnail_database_unittest.cc b/chrome/browser/history/thumbnail_database_unittest.cc
index 24c990b..4d2c2bf 100644
--- a/chrome/browser/history/thumbnail_database_unittest.cc
+++ b/chrome/browser/history/thumbnail_database_unittest.cc
@@ -6,7 +6,6 @@
#include <vector>
#include "base/basictypes.h"
-#include "base/command_line.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/path_service.h"
@@ -14,7 +13,6 @@
#include "base/scoped_temp_dir.h"
#include "chrome/browser/history/thumbnail_database.h"
#include "chrome/common/chrome_paths.h"
-#include "chrome/common/chrome_switches.h"
#include "chrome/common/thumbnail_score.h"
#include "chrome/tools/profiles/thumbnail-inl.h"
#include "gfx/codec/jpeg_codec.h"
@@ -72,9 +70,6 @@ class ThumbnailDatabaseTest : public testing::Test {
};
TEST_F(ThumbnailDatabaseTest, AddDelete) {
- if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTopSites))
- return; // TopSitesTest replaces this.
-
ThumbnailDatabase db;
ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL));
@@ -117,9 +112,6 @@ TEST_F(ThumbnailDatabaseTest, AddDelete) {
}
TEST_F(ThumbnailDatabaseTest, UseLessBoringThumbnails) {
- if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTopSites))
- return; // TopSitesTest replaces this.
-
ThumbnailDatabase db;
Time now = Time::Now();
ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL));
@@ -154,9 +146,6 @@ TEST_F(ThumbnailDatabaseTest, UseLessBoringThumbnails) {
}
TEST_F(ThumbnailDatabaseTest, UseAtTopThumbnails) {
- if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTopSites))
- return; // TopSitesTest replaces this.
-
ThumbnailDatabase db;
Time now = Time::Now();
ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL));
@@ -228,9 +217,6 @@ TEST_F(ThumbnailDatabaseTest, UseAtTopThumbnails) {
}
TEST_F(ThumbnailDatabaseTest, ThumbnailTimeDegradation) {
- if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTopSites))
- return; // TopSitesTest replaces this.
-
ThumbnailDatabase db;
const Time kNow = Time::Now();
const Time kThreeHoursAgo = kNow - TimeDelta::FromHours(4);
@@ -275,9 +261,6 @@ TEST_F(ThumbnailDatabaseTest, NeverAcceptTotallyBoringThumbnail) {
// should replace a thumbnail with another because of reasons other
// than straight up boringness score, still reject because the
// thumbnail is totally boring.
- if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTopSites))
- return; // TopSitesTest replaces this.
-
ThumbnailDatabase db;
Time now = Time::Now();
ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL));
@@ -349,9 +332,6 @@ TEST_F(ThumbnailDatabaseTest, NeverAcceptTotallyBoringThumbnail) {
}
TEST_F(ThumbnailDatabaseTest, NeedsMigrationToTopSites) {
- if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTopSites))
- return; // TopSitesTest replaces this.
-
ThumbnailDatabase db;
ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL));
db.BeginTransaction();
diff --git a/chrome/browser/history/top_sites.cc b/chrome/browser/history/top_sites.cc
index eb0fb74..7d8c66a 100644
--- a/chrome/browser/history/top_sites.cc
+++ b/chrome/browser/history/top_sites.cc
@@ -54,15 +54,10 @@ TopSites::TopSites(Profile* profile) : profile_(profile),
waiting_for_results_(true),
blacklist_(NULL),
pinned_urls_(NULL) {
- if (!profile_)
- return;
-
- if (NotificationService::current()) {
- registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED,
- Source<Profile>(profile_));
- registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
- NotificationService::AllSources());
- }
+ registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED,
+ Source<Profile>(profile_));
+ registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
+ NotificationService::AllSources());
blacklist_ = profile_->GetPrefs()->
GetMutableDictionary(prefs::kNTPMostVisitedURLsBlacklist);
@@ -95,14 +90,16 @@ void TopSites::ReadDatabase() {
std::map<GURL, Images> thumbnails;
DCHECK(db_.get());
- MostVisitedURLList top_urls;
- db_->GetPageThumbnails(&top_urls, &thumbnails);
- MostVisitedURLList copy(top_urls); // StoreMostVisited destroys the list.
- StoreMostVisited(&top_urls);
- if (AddPrepopulatedPages(&copy))
- UpdateMostVisited(copy);
+ {
+ AutoLock lock(lock_);
+ MostVisitedURLList top_urls;
+ db_->GetPageThumbnails(&top_urls, &thumbnails);
+ MostVisitedURLList copy(top_urls); // StoreMostVisited destroys the list.
+ StoreMostVisited(&top_urls);
+ if (AddPrepopulatedPages(&copy))
+ UpdateMostVisited(copy);
+ } // Lock is released here.
- AutoLock lock(lock_);
for (size_t i = 0; i < top_sites_.size(); i++) {
GURL url = top_sites_[i].url;
Images thumbnail = thumbnails[url];
@@ -148,14 +145,12 @@ bool TopSites::SetPageThumbnail(const GURL& url,
return true;
}
- AutoLock lock(lock_);
- return SetPageThumbnailEncoded(url, thumbnail_data, score);
+ return SetPageThumbnail(url, thumbnail_data, score);
}
-bool TopSites::SetPageThumbnailEncoded(const GURL& url,
- const RefCountedBytes* thumbnail,
- const ThumbnailScore& score) {
- lock_.AssertAcquired();
+bool TopSites::SetPageThumbnail(const GURL& url,
+ const RefCountedBytes* thumbnail,
+ const ThumbnailScore& score) {
if (!SetPageThumbnailNoDB(url, thumbnail, score))
return false;
@@ -176,7 +171,7 @@ bool TopSites::SetPageThumbnailEncoded(const GURL& url,
void TopSites::WriteThumbnailToDB(const MostVisitedURL& url,
int url_rank,
- const Images& thumbnail) {
+ const TopSites::Images& thumbnail) {
DCHECK(db_.get());
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::DB));
db_->SetPageThumbnail(url, url_rank, thumbnail);
@@ -186,7 +181,7 @@ void TopSites::WriteThumbnailToDB(const MostVisitedURL& url,
bool TopSites::SetPageThumbnailNoDB(const GURL& url,
const RefCountedBytes* thumbnail_data,
const ThumbnailScore& score) {
- lock_.AssertAcquired();
+ AutoLock lock(lock_);
std::map<GURL, size_t>::iterator found = canonical_urls_.find(url);
if (found == canonical_urls_.end()) {
@@ -242,21 +237,15 @@ void TopSites::GetMostVisitedURLs(CancelableRequestConsumer* consumer,
return;
MostVisitedURLList filtered_urls;
- {
- AutoLock lock(lock_);
- ApplyBlacklistAndPinnedURLs(top_sites_, &filtered_urls);
- }
+ ApplyBlacklistAndPinnedURLs(top_sites_, &filtered_urls);
+
request->ForwardResult(GetTopSitesCallback::TupleType(filtered_urls));
}
bool TopSites::GetPageThumbnail(const GURL& url, RefCountedBytes** data) const {
- AutoLock lock(lock_);
std::map<GURL, Images>::const_iterator found = top_images_.find(url);
- if (found == top_images_.end()) {
- found = temp_thumbnails_map_.find(url);
- if (found == temp_thumbnails_map_.end())
- return false; // No thumbnail for this URL.
- }
+ if (found == top_images_.end())
+ return false; // No thumbnail for this URL.
Images image = found->second;
*data = image.thumbnail.get();
@@ -273,11 +262,8 @@ static int IndexOf(const MostVisitedURLList& urls, const GURL& url) {
int TopSites::GetIndexForChromeStore(const MostVisitedURLList& urls) {
GURL store_url = MostVisitedHandler::GetChromeStoreURLWithLocale();
- {
- AutoLock lock(lock_);
- if (IsBlacklisted(store_url))
- return -1;
- }
+ if (IsBlacklisted(store_url))
+ return -1;
if (IndexOf(urls, store_url) != -1)
return -1; // It's already there, no need to add.
@@ -304,9 +290,6 @@ bool TopSites::AddChromeStore(MostVisitedURLList* urls) {
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableApps))
return false;
- if (!profile_)
- return false;
-
ExtensionsService* service = profile_->GetExtensionsService();
if (!service || service->HasApps())
return false;
@@ -388,7 +371,6 @@ void TopSites::MigratePinnedURLs() {
void TopSites::ApplyBlacklistAndPinnedURLs(const MostVisitedURLList& urls,
MostVisitedURLList* out) {
MostVisitedURLList urls_copy;
- lock_.AssertAcquired();
for (size_t i = 0; i < urls.size(); i++) {
if (!IsBlacklisted(urls[i].url))
urls_copy.push_back(urls[i]);
@@ -435,12 +417,10 @@ void TopSites::ApplyBlacklistAndPinnedURLs(const MostVisitedURLList& urls,
}
std::wstring TopSites::GetURLString(const GURL& url) {
- lock_.AssertAcquired();
return ASCIIToWide(GetCanonicalURL(url).spec());
}
std::wstring TopSites::GetURLHash(const GURL& url) {
- lock_.AssertAcquired();
return ASCIIToWide(MD5String(GetCanonicalURL(url).spec()));
}
@@ -450,33 +430,27 @@ void TopSites::UpdateMostVisited(MostVisitedURLList most_visited) {
std::vector<size_t> added; // Indices into most_visited.
std::vector<size_t> deleted; // Indices into top_sites_.
std::vector<size_t> moved; // Indices into most_visited.
-
DiffMostVisited(top_sites_, most_visited, &added, &deleted, &moved);
// #added == #deleted; #added + #moved = total.
last_num_urls_changed_ = added.size() + moved.size();
- {
- AutoLock lock(lock_);
+ // Process the diff: delete from images and disk, add to disk.
+ // Delete all the thumbnails associated with URLs that were deleted.
+ for (size_t i = 0; i < deleted.size(); i++) {
+ const MostVisitedURL& deleted_url = top_sites_[deleted[i]];
+ std::map<GURL, Images>::iterator found =
+ top_images_.find(deleted_url.url);
+ if (found != top_images_.end())
+ top_images_.erase(found);
- // Process the diff: delete from images and disk, add to disk.
- // Delete all the thumbnails associated with URLs that were deleted.
- for (size_t i = 0; i < deleted.size(); i++) {
- const MostVisitedURL& deleted_url = top_sites_[deleted[i]];
- std::map<GURL, Images>::iterator found =
- top_images_.find(deleted_url.url);
- if (found != top_images_.end())
- top_images_.erase(found);
- }
+ // Delete from disk.
+ if (db_.get())
+ db_->RemoveURL(deleted_url);
}
- // Write the updates to the DB.
if (db_.get()) {
- for (size_t i = 0; i < deleted.size(); i++) {
- const MostVisitedURL& deleted_url = top_sites_[deleted[i]];
- if (db_.get())
- db_->RemoveURL(deleted_url);
- }
+ // Write both added and moved urls.
for (size_t i = 0; i < added.size(); i++) {
const MostVisitedURL& added_url = most_visited[added[i]];
db_->SetPageThumbnail(added_url, added[i], Images());
@@ -510,9 +484,6 @@ void TopSites::UpdateMostVisited(MostVisitedURLList most_visited) {
void TopSites::OnMigrationDone() {
migration_in_progress_ = false;
- if (!profile_)
- return;
-
HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
// |hs| may be null during unit tests.
if (!hs)
@@ -550,9 +521,6 @@ void TopSites::StartQueryForThumbnail(size_t index) {
return;
}
- if (!profile_)
- return;
-
HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
// |hs| may be null during unit tests.
if (!hs)
@@ -565,7 +533,6 @@ void TopSites::StartQueryForThumbnail(size_t index) {
}
void TopSites::GenerateCanonicalURLs() {
- lock_.AssertAcquired();
canonical_urls_.clear();
for (size_t i = 0; i < top_sites_.size(); i++) {
const MostVisitedURL& mv = top_sites_[i];
@@ -575,9 +542,8 @@ void TopSites::GenerateCanonicalURLs() {
void TopSites::StoreMostVisited(MostVisitedURLList* most_visited) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::DB));
- AutoLock lock(lock_);
- top_sites_.clear();
// Take ownership of the most visited data.
+ top_sites_.clear();
top_sites_.swap(*most_visited);
waiting_for_results_ = false;
@@ -594,8 +560,8 @@ void TopSites::StoreMostVisited(MostVisitedURLList* most_visited) {
// when we add a temp thumbnail, redirect chain is not known.
// This is slow, but temp_thumbnails_map_ should have very few URLs.
if (canonical_url == GetCanonicalURL(it->first)) {
- SetPageThumbnailEncoded(mv.url, it->second.thumbnail,
- it->second.thumbnail_score);
+ SetPageThumbnail(mv.url, it->second.thumbnail,
+ it->second.thumbnail_score);
temp_thumbnails_map_.erase(it);
break;
}
@@ -618,7 +584,6 @@ void TopSites::StoreRedirectChain(const RedirectList& redirects,
}
GURL TopSites::GetCanonicalURL(const GURL& url) const {
- lock_.AssertAcquired();
std::map<GURL, size_t>::const_iterator found = canonical_urls_.find(url);
if (found == canonical_urls_.end())
return url; // Unknown URL - return unchanged.
@@ -687,9 +652,6 @@ void TopSites::StartQueryForMostVisited() {
&cancelable_consumer_,
NewCallback(this, &TopSites::OnTopSitesAvailable));
} else {
- if (!profile_)
- return;
-
HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
// |hs| may be null during unit tests.
if (hs) {
@@ -711,20 +673,17 @@ void TopSites::StartMigration() {
}
void TopSites::AddBlacklistedURL(const GURL& url) {
- AutoLock lock(lock_);
- RemovePinnedURLLocked(url);
+ RemovePinnedURL(url);
Value* dummy = Value::CreateNullValue();
blacklist_->SetWithoutPathExpansion(GetURLHash(url), dummy);
}
bool TopSites::IsBlacklisted(const GURL& url) {
- lock_.AssertAcquired();
bool result = blacklist_->HasKey(GetURLHash(url));
return result;
}
void TopSites::RemoveBlacklistedURL(const GURL& url) {
- AutoLock lock(lock_);
blacklist_->RemoveWithoutPathExpansion(GetURLHash(url), NULL);
}
@@ -743,22 +702,22 @@ void TopSites::AddPinnedURL(const GURL& url, size_t pinned_index) {
}
Value* index = Value::CreateIntegerValue(pinned_index);
- AutoLock lock(lock_);
pinned_urls_->SetWithoutPathExpansion(GetURLString(url), index);
}
void TopSites::RemovePinnedURL(const GURL& url) {
- AutoLock lock(lock_);
- RemovePinnedURLLocked(url);
+ pinned_urls_->RemoveWithoutPathExpansion(GetURLString(url), NULL);
}
-void TopSites::RemovePinnedURLLocked(const GURL& url) {
- lock_.AssertAcquired();
- pinned_urls_->RemoveWithoutPathExpansion(GetURLString(url), NULL);
+bool TopSites::GetIndexOfPinnedURL(const GURL& url, size_t* index) {
+ int tmp;
+ bool result = pinned_urls_->GetIntegerWithoutPathExpansion(
+ GetURLString(url), &tmp);
+ *index = static_cast<size_t>(tmp);
+ return result;
}
bool TopSites::IsURLPinned(const GURL& url) {
- AutoLock lock(lock_);
int tmp;
bool result = pinned_urls_->GetIntegerWithoutPathExpansion(
GetURLString(url), &tmp);
@@ -779,24 +738,6 @@ bool TopSites::GetPinnedURLAtIndex(size_t index, GURL* url) {
return false;
}
-// static
-void TopSites::DeleteTopSites(scoped_refptr<TopSites>& ptr) {
- if (!ptr.get() || !MessageLoop::current())
- return;
- if (ChromeThread::IsWellKnownThread(ChromeThread::UI)) {
- ptr = NULL;
- } else {
- // Need to roll our own UI thread.
- ChromeThread ui_loop(ChromeThread::UI, MessageLoop::current());
- ptr = NULL;
- MessageLoop::current()->RunAllPending();
- }
-}
-
-void TopSites::ClearProfile() {
- profile_ = NULL;
-}
-
base::TimeDelta TopSites::GetUpdateDelay() {
if (top_sites_.size() == 0)
return base::TimeDelta::FromSeconds(30);
@@ -817,10 +758,7 @@ void TopSites::OnTopSitesAvailable(
if (!pending_callbacks_.empty()) {
MostVisitedURLList filtered_urls;
- {
- AutoLock lock(lock_);
- ApplyBlacklistAndPinnedURLs(pages, &filtered_urls);
- }
+ ApplyBlacklistAndPinnedURLs(pages, &filtered_urls);
PendingCallbackSet::iterator i;
for (i = pending_callbacks_.begin();
@@ -839,9 +777,6 @@ void TopSites::OnThumbnailAvailable(CancelableRequestProvider::Handle handle,
if (mock_history_service_) {
index = handle;
} else {
- if (!profile_)
- return;
-
HistoryService* hs = profile_ ->GetHistoryService(Profile::EXPLICIT_ACCESS);
index = cancelable_consumer_.GetClientData(hs, handle);
}
@@ -852,8 +787,7 @@ void TopSites::OnThumbnailAvailable(CancelableRequestProvider::Handle handle,
if (thumbnail.get() && thumbnail->size()) {
const MostVisitedURL& url = top_sites_[index];
- AutoLock lock(lock_);
- SetPageThumbnailEncoded(url.url, thumbnail, ThumbnailScore());
+ SetPageThumbnail(url.url, thumbnail, ThumbnailScore());
}
if (migration_in_progress_ && migration_pending_urls_.empty() &&
@@ -869,7 +803,6 @@ void TopSites::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
if (type == NotificationType::HISTORY_URLS_DELETED) {
- AutoLock lock(lock_);
Details<history::URLsDeletedDetails> deleted_details(details);
if (deleted_details->all_history) {
top_sites_.clear();
@@ -888,7 +821,7 @@ void TopSites::Observe(NotificationType type,
for (std::set<size_t>::reverse_iterator i = indices_to_delete.rbegin();
i != indices_to_delete.rend(); i++) {
size_t index = *i;
- RemovePinnedURLLocked(top_sites_[index].url);
+ RemovePinnedURL(top_sites_[index].url);
top_sites_.erase(top_sites_.begin() + index);
}
}
@@ -897,14 +830,11 @@ void TopSites::Observe(NotificationType type,
StartQueryForMostVisited();
} else if (type == NotificationType::NAV_ENTRY_COMMITTED) {
if (top_sites_.size() < kTopSitesNumber) {
- NavigationController::LoadCommittedDetails* load_details =
- Details<NavigationController::LoadCommittedDetails>(details).ptr();
- if (!load_details)
- return;
- GURL url = load_details->entry->url();
+ const NavigationController::LoadCommittedDetails& load_details =
+ *Details<NavigationController::LoadCommittedDetails>(details).ptr();
+ GURL url = load_details.entry->url();
if (canonical_urls_.find(url) == canonical_urls_.end() &&
- HistoryService::CanAddURL(url)) {
- AutoLock lock(lock_);
+ HistoryService::CanAddURL(url)) {
// Add this page to the known pages in case the thumbnail comes
// in before we get the results.
MostVisitedURL mv;
diff --git a/chrome/browser/history/top_sites.h b/chrome/browser/history/top_sites.h
index b460afb..09d0af0 100644
--- a/chrome/browser/history/top_sites.h
+++ b/chrome/browser/history/top_sites.h
@@ -18,7 +18,6 @@
#include "base/ref_counted.h"
#include "base/ref_counted_memory.h"
#include "chrome/browser/cancelable_request.h"
-#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/history/history_types.h"
#include "chrome/browser/history/history.h"
#include "chrome/browser/history/page_usage_data.h"
@@ -48,11 +47,9 @@ typedef std::vector<MostVisitedURL> MostVisitedURLList;
// new tab page requests on the I/O thread without proxying to the UI thread is
// a nontrivial performance win, especially when the browser is starting and
// the UI thread is busy.
-class TopSites :
- public base::RefCountedThreadSafe<TopSites,
- ChromeThread::DeleteOnUIThread>,
- public NotificationObserver,
- public CancelableRequestProvider {
+class TopSites : public NotificationObserver,
+ public base::RefCountedThreadSafe<TopSites>,
+ public CancelableRequestProvider {
public:
explicit TopSites(Profile* profile);
@@ -71,6 +68,14 @@ class TopSites :
size_t index) = 0;
};
+ struct Images {
+ scoped_refptr<RefCountedBytes> thumbnail;
+ ThumbnailScore thumbnail_score;
+
+ // TODO(brettw): this will eventually store the favicon.
+ // scoped_refptr<RefCountedBytes> favicon;
+ };
+
// Initializes TopSites.
void Init(const FilePath& db_name);
@@ -103,6 +108,9 @@ class TopSites :
// Add a URL to the blacklist.
void AddBlacklistedURL(const GURL& url);
+ // Returns true if the URL is blacklisted.
+ bool IsBlacklisted(const GURL& url);
+
// Removes a URL from the blacklist.
void RemoveBlacklistedURL(const GURL& url);
@@ -114,6 +122,9 @@ class TopSites :
// Pin a URL at |index|.
void AddPinnedURL(const GURL& url, size_t index);
+ // Get the index of a URL. Returns true if |url| is pinned.
+ bool GetIndexOfPinnedURL(const GURL& url, size_t* index);
+
// Returns true if a URL is pinned.
bool IsURLPinned(const GURL& url);
@@ -124,18 +135,8 @@ class TopSites :
// is a URL pinned at |index|.
bool GetPinnedURLAtIndex(size_t index, GURL* out);
- // TopSites must be deleted on a UI thread. This happens
- // automatically in a real browser, but in unit_tests we don't have
- // a real UI thread. Use this function to delete a TopSites object.
- static void DeleteTopSites(scoped_refptr<TopSites>& ptr);
-
- // Sets the profile pointer to NULL. This is for the case where
- // TopSites outlives the profile, since TopSites is refcounted.
- void ClearProfile();
-
private:
- friend struct ChromeThread::DeleteOnThread<ChromeThread::UI>;
- friend class DeleteTask<TopSites>;
+ friend class base::RefCountedThreadSafe<TopSites>;
friend class TopSitesTest;
FRIEND_TEST_ALL_PREFIXES(TopSitesTest, GetMostVisited);
FRIEND_TEST_ALL_PREFIXES(TopSitesTest, RealDatabase);
@@ -164,9 +165,9 @@ class TopSites :
// A version of SetPageThumbnail that takes RefCountedBytes as
// returned by HistoryService.
- bool SetPageThumbnailEncoded(const GURL& url,
- const RefCountedBytes* thumbnail,
- const ThumbnailScore& score);
+ bool SetPageThumbnail(const GURL& url,
+ const RefCountedBytes* thumbnail,
+ const ThumbnailScore& score);
// Query history service for the list of available thumbnails.
void StartQueryForMostVisited();
@@ -228,12 +229,6 @@ class TopSites :
const NotificationSource& source,
const NotificationDetails& details);
- // Returns true if the URL is blacklisted.
- bool IsBlacklisted(const GURL& url);
-
- // A variant of RemovePinnedURL that must be called within a lock.
- void RemovePinnedURLLocked(const GURL& url);
-
// Returns the delay until the next update of history is needed.
// Uses num_urls_changed
base::TimeDelta GetUpdateDelay();
@@ -248,7 +243,7 @@ class TopSites :
// Write a thumbnail to database.
void WriteThumbnailToDB(const MostVisitedURL& url,
int url_rank,
- const Images& thumbnail);
+ const TopSites::Images& thumbnail);
// Updates the top sites list and writes the difference to disk.
void UpdateMostVisited(MostVisitedURLList most_visited);
diff --git a/chrome/browser/history/top_sites_database.cc b/chrome/browser/history/top_sites_database.cc
index 96da3f9..99f0bb4 100644
--- a/chrome/browser/history/top_sites_database.cc
+++ b/chrome/browser/history/top_sites_database.cc
@@ -5,7 +5,6 @@
#include "app/sql/transaction.h"
#include "base/string_util.h"
#include "chrome/browser/diagnostics/sqlite_diagnostics.h"
-#include "chrome/browser/history/history_types.h"
#include "chrome/browser/history/top_sites.h"
#include "chrome/browser/history/top_sites_database.h"
@@ -49,7 +48,7 @@ bool TopSitesDatabaseImpl::InitThumbnailTable() {
void TopSitesDatabaseImpl::GetPageThumbnails(MostVisitedURLList* urls,
std::map<GURL,
- Images>* thumbnails) {
+ TopSites::Images>* thumbnails) {
sql::Statement statement(db_.GetCachedStatement(
SQL_FROM_HERE,
"SELECT url, url_rank, title, thumbnail, redirects, "
@@ -76,7 +75,7 @@ void TopSitesDatabaseImpl::GetPageThumbnails(MostVisitedURLList* urls,
std::vector<unsigned char> data;
statement.ColumnBlobAsVector(3, &data);
- Images thumbnail;
+ TopSites::Images thumbnail;
thumbnail.thumbnail = RefCountedBytes::TakeVector(&data);
thumbnail.thumbnail_score.boring_score = statement.ColumnDouble(5);
thumbnail.thumbnail_score.good_clipping = statement.ColumnBool(6);
@@ -107,7 +106,7 @@ void TopSitesDatabaseImpl::SetRedirects(const std::string& redirects,
void TopSitesDatabaseImpl::SetPageThumbnail(const MostVisitedURL& url,
int new_rank,
- const Images& thumbnail) {
+ const TopSites::Images& thumbnail) {
sql::Transaction transaction(&db_);
transaction.Begin();
@@ -123,7 +122,7 @@ void TopSitesDatabaseImpl::SetPageThumbnail(const MostVisitedURL& url,
}
void TopSitesDatabaseImpl::UpdatePageThumbnail(
- const MostVisitedURL& url, const Images& thumbnail) {
+ const MostVisitedURL& url, const TopSites::Images& thumbnail) {
sql::Statement statement(db_.GetCachedStatement(
SQL_FROM_HERE,
"UPDATE thumbnails SET "
@@ -151,7 +150,7 @@ void TopSitesDatabaseImpl::UpdatePageThumbnail(
void TopSitesDatabaseImpl::AddPageThumbnail(const MostVisitedURL& url,
int new_rank,
- const Images& thumbnail) {
+ const TopSites::Images& thumbnail) {
int count = GetRowCount();
sql::Statement statement(db_.GetCachedStatement(
@@ -195,7 +194,7 @@ void TopSitesDatabaseImpl::UpdatePageRankNoTransaction(
const MostVisitedURL& url, int new_rank) {
int prev_rank = GetURLRank(url);
if (prev_rank == -1) {
- LOG(WARNING) << "Updating rank of an unknown URL: " << url.url.spec();
+ NOTREACHED() << "Updating rank of an unknown URL: " << url.url.spec();
return;
}
@@ -237,7 +236,7 @@ void TopSitesDatabaseImpl::UpdatePageRankNoTransaction(
}
bool TopSitesDatabaseImpl::GetPageThumbnail(const GURL& url,
- Images* thumbnail) {
+ TopSites::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 11188a7..18ec201 100644
--- a/chrome/browser/history/top_sites_database.h
+++ b/chrome/browser/history/top_sites_database.h
@@ -12,12 +12,13 @@
#include "app/sql/connection.h"
#include "base/ref_counted.h"
+#include "chrome/browser/history/history_types.h"
#include "chrome/browser/history/url_database.h" // For DBCloseScoper.
class FilePath;
class RefCountedMemory;
class SkBitmap;
-class Images;
+class TopSites;
namespace base {
class Time;
@@ -37,7 +38,7 @@ class TopSitesDatabase {
// Returns a list of all URLs currently in the table.
virtual void GetPageThumbnails(MostVisitedURLList* urls,
std::map<GURL,
- Images>* thumbnails) = 0;
+ TopSites::Images>* thumbnails) = 0;
// Set a thumbnail for a URL. |url_rank| is the position of the URL
// in the list of TopURLs, zero-based.
@@ -45,20 +46,20 @@ class TopSitesDatabase {
// thumbnail.
virtual void SetPageThumbnail(const MostVisitedURL& url,
int url_rank,
- const Images& thumbnail) = 0;
+ const TopSites::Images& thumbnail) = 0;
// Update rank of a URL that's already in the database.
virtual void UpdatePageRank(const MostVisitedURL& url, int new_rank) = 0;
// Convenience wrapper.
bool GetPageThumbnail(const MostVisitedURL& url,
- Images* thumbnail) {
+ TopSites::Images* thumbnail) {
return GetPageThumbnail(url.url, thumbnail);
}
// Get a thumbnail for a given page. Returns true iff we have the thumbnail.
virtual bool GetPageThumbnail(const GURL& url,
- Images* thumbnail) = 0;
+ TopSites::Images* thumbnail) = 0;
// Remove the record for this URL. Returns true iff removed successfully.
virtual bool RemoveURL(const MostVisitedURL& url) = 0;
@@ -78,7 +79,7 @@ class TopSitesDatabaseImpl : public TopSitesDatabase {
// Returns a list of all URLs currently in the table.
// WARNING: clears both input arguments.
virtual void GetPageThumbnails(MostVisitedURLList* urls,
- std::map<GURL, Images>* thumbnails);
+ std::map<GURL, TopSites::Images>* thumbnails);
// Set a thumbnail for a URL. |url_rank| is the position of the URL
// in the list of TopURLs, zero-based.
@@ -86,7 +87,7 @@ class TopSitesDatabaseImpl : public TopSitesDatabase {
// thumbnail and rank. Shift the ranks of other URLs if necessary.
virtual void SetPageThumbnail(const MostVisitedURL& url,
int new_rank,
- const Images& thumbnail);
+ const TopSites::Images& thumbnail);
// Sets the rank for a given URL. The URL must be in the database.
// Use SetPageThumbnail if it's not.
@@ -94,7 +95,7 @@ class TopSitesDatabaseImpl : public TopSitesDatabase {
// Get a thumbnail for a given page. Returns true iff we have the thumbnail.
virtual bool GetPageThumbnail(const GURL& url,
- Images* thumbnail);
+ TopSites::Images* thumbnail);
// Remove the record for this URL. Returns true iff removed successfully.
virtual bool RemoveURL(const MostVisitedURL& url);
@@ -107,14 +108,14 @@ class TopSitesDatabaseImpl : public TopSitesDatabase {
// Adds a new URL to the database.
void AddPageThumbnail(const MostVisitedURL& url,
int new_rank,
- const Images& thumbnail);
+ const TopSites::Images& thumbnail);
// Sets the page rank. Should be called within an open transaction.
void UpdatePageRankNoTransaction(const MostVisitedURL& url, int new_rank);
// Updates thumbnail of a URL that's already in the database.
void UpdatePageThumbnail(const MostVisitedURL& url,
- const Images& thumbnail);
+ const TopSites::Images& thumbnail);
// Returns the URL's current rank or -1 if it is not present.
int GetURLRank(const MostVisitedURL& url);
diff --git a/chrome/browser/history/top_sites_unittest.cc b/chrome/browser/history/top_sites_unittest.cc
index f8ebf95..94db4f2 100644
--- a/chrome/browser/history/top_sites_unittest.cc
+++ b/chrome/browser/history/top_sites_unittest.cc
@@ -74,7 +74,7 @@ class TopSitesTest : public testing::Test {
virtual void TearDown() {
profile_.reset();
- TopSites::DeleteTopSites(top_sites_);
+ top_sites_ = NULL;
EXPECT_TRUE(file_util::Delete(file_name_, false));
}
@@ -92,6 +92,7 @@ class TopSitesTest : public testing::Test {
}
void StoreMostVisited(std::vector<MostVisitedURL>* urls) {
+ AutoLock lock(top_sites_->lock_); // The function asserts it's in the lock.
top_sites_->StoreMostVisited(urls);
}
@@ -104,10 +105,6 @@ class TopSitesTest : public testing::Test {
added_urls, deleted_urls, moved_urls);
}
- Lock& lock() {
- return top_sites_->lock_;
- }
-
private:
scoped_refptr<TopSites> top_sites_;
MostVisitedURLList urls_;
@@ -124,7 +121,6 @@ class TopSitesTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(TopSitesTest);
};
-
// A mockup of a HistoryService used for testing TopSites.
class MockHistoryServiceImpl : public TopSites::MockHistoryService {
public:
@@ -192,14 +188,14 @@ class MockHistoryServiceImpl : public TopSites::MockHistoryService {
class MockTopSitesDatabaseImpl : public TopSitesDatabase {
public:
virtual void GetPageThumbnails(MostVisitedURLList* urls,
- std::map<GURL, Images>* thumbnails) {
+ std::map<GURL, TopSites::Images>* thumbnails) {
// Return a copy of the vector.
*urls = top_sites_list_;
*thumbnails = thumbnails_map_;
}
virtual void SetPageThumbnail(const MostVisitedURL& url, int url_rank,
- const Images& thumbnail) {
+ const TopSites::Images& thumbnail) {
SetPageRank(url, url_rank);
// Update thubmnail
thumbnails_map_[url.url] = thumbnail;
@@ -233,8 +229,8 @@ class MockTopSitesDatabaseImpl : public TopSitesDatabase {
// Get a thumbnail for a given page. Returns true iff we have the thumbnail.
virtual bool GetPageThumbnail(const GURL& url,
- Images* thumbnail) {
- std::map<GURL, Images>::const_iterator found =
+ TopSites::Images* thumbnail) {
+ std::map<GURL, TopSites::Images>::const_iterator found =
thumbnails_map_.find(url);
if (found == thumbnails_map_.end())
return false; // No thumbnail for this URL.
@@ -259,7 +255,7 @@ class MockTopSitesDatabaseImpl : public TopSitesDatabase {
private:
MostVisitedURLList top_sites_list_; // Keeps the URLs sorted by score (rank).
- std::map<GURL, Images> thumbnails_map_;
+ std::map<GURL, TopSites::Images> thumbnails_map_;
};
@@ -452,7 +448,7 @@ TEST_F(TopSitesTest, MockDatabase) {
url.url = asdf_url;
url.title = asdf_title;
url.redirects.push_back(url.url);
- Images thumbnail;
+ TopSites::Images thumbnail;
db->SetPageThumbnail(url, 0, thumbnail);
top_sites().ReadDatabase();
@@ -499,7 +495,7 @@ TEST_F(TopSitesTest, MockDatabase) {
top_sites().StartQueryForMostVisited();
MessageLoop::current()->RunAllPending();
- std::map<GURL, Images> thumbnails;
+ std::map<GURL, TopSites::Images> thumbnails;
MostVisitedURLList result;
db->GetPageThumbnails(&result, &thumbnails);
ASSERT_EQ(4u, result.size());
@@ -524,18 +520,18 @@ TEST_F(TopSitesTest, TopSitesDB) {
url.url = asdf_url;
url.title = asdf_title;
url.redirects.push_back(url.url);
- Images thumbnail;
+ TopSites::Images thumbnail;
thumbnail.thumbnail = random_thumbnail();
// Add asdf at rank 0.
db.SetPageThumbnail(url, 0, thumbnail);
- Images result;
+ TopSites::Images result;
EXPECT_TRUE(db.GetPageThumbnail(url.url, &result));
EXPECT_EQ(thumbnail.thumbnail->data.size(), result.thumbnail->data.size());
EXPECT_TRUE(ThumbnailsAreEqual(thumbnail.thumbnail, result.thumbnail));
MostVisitedURLList urls;
- std::map<GURL, Images> thumbnails;
+ std::map<GURL, TopSites::Images> thumbnails;
db.GetPageThumbnails(&urls, &thumbnails);
ASSERT_EQ(1u, urls.size());
EXPECT_EQ(asdf_url, urls[0].url);
@@ -611,7 +607,7 @@ TEST_F(TopSitesTest, RealDatabase) {
url.url = asdf_url;
url.title = asdf_title;
url.redirects.push_back(url.url);
- Images thumbnail;
+ TopSites::Images thumbnail;
thumbnail.thumbnail = random_thumbnail();
db->SetPageThumbnail(url, 0, thumbnail);
@@ -627,7 +623,7 @@ TEST_F(TopSitesTest, RealDatabase) {
EXPECT_EQ(welcome_url(), urls()[1].url);
EXPECT_EQ(themes_url(), urls()[2].url);
- Images img_result;
+ TopSites::Images img_result;
db->GetPageThumbnail(asdf_url, &img_result);
EXPECT_TRUE(img_result.thumbnail != NULL);
EXPECT_TRUE(ThumbnailsAreEqual(random_thumbnail(), img_result.thumbnail));
@@ -645,7 +641,7 @@ TEST_F(TopSitesTest, RealDatabase) {
url2.redirects.push_back(google3_url);
// Add new thumbnail at rank 0 and shift the other result to 1.
- Images g_thumbnail;
+ TopSites::Images g_thumbnail;
g_thumbnail.thumbnail = google_thumbnail();
db->SetPageThumbnail(url2, 0, g_thumbnail);
@@ -680,7 +676,7 @@ TEST_F(TopSitesTest, RealDatabase) {
top_sites().StartQueryForMostVisited();
MessageLoop::current()->RunAllPending();
- std::map<GURL, Images> thumbnails;
+ std::map<GURL, TopSites::Images> thumbnails;
MostVisitedURLList results;
db->GetPageThumbnails(&results, &thumbnails);
ASSERT_EQ(4u, results.size());
@@ -701,7 +697,7 @@ TEST_F(TopSitesTest, RealDatabase) {
*weewar_bitmap,
medium_score));
RefCountedBytes* out_1;
- Images out_2;
+ TopSites::Images out_2;
EXPECT_TRUE(top_sites().GetPageThumbnail(google1_url, &out_1));
MessageLoop::current()->RunAllPending();
@@ -1078,11 +1074,7 @@ TEST_F(TopSitesTest, Blacklisting) {
&TopSitesTest::OnTopSitesAvailable));
top_sites().OnTopSitesAvailable(0, pages);
MessageLoop::current()->RunAllPending();
- {
- Lock& l = lock();
- AutoLock lock(l); // IsBlacklisted must be in a lock.
- EXPECT_FALSE(top_sites().IsBlacklisted(GURL("http://bbc.com/")));
- }
+ EXPECT_FALSE(top_sites().IsBlacklisted(GURL("http://bbc.com/")));
EXPECT_EQ(1u, number_of_callbacks());
@@ -1093,13 +1085,9 @@ TEST_F(TopSitesTest, Blacklisting) {
EXPECT_EQ(themes_url(), urls()[3].url);
top_sites().AddBlacklistedURL(GURL("http://google.com/"));
- {
- Lock& l = lock();
- AutoLock lock(l); // IsBlacklisted must be in a lock.
- EXPECT_TRUE(top_sites().IsBlacklisted(GURL("http://google.com/")));
- EXPECT_FALSE(top_sites().IsBlacklisted(GURL("http://bbc.com/")));
- EXPECT_FALSE(top_sites().IsBlacklisted(welcome_url()));
- }
+ EXPECT_TRUE(top_sites().IsBlacklisted(GURL("http://google.com/")));
+ EXPECT_FALSE(top_sites().IsBlacklisted(GURL("http://bbc.com/")));
+ EXPECT_FALSE(top_sites().IsBlacklisted(welcome_url()));
top_sites().GetMostVisitedURLs(
&c,
@@ -1122,11 +1110,7 @@ TEST_F(TopSitesTest, Blacklisting) {
EXPECT_EQ(themes_url(), urls()[1].url);
top_sites().RemoveBlacklistedURL(GURL("http://google.com/"));
- {
- Lock& l = lock();
- AutoLock lock(l); // IsBlacklisted must be in a lock.
- EXPECT_FALSE(top_sites().IsBlacklisted(GURL("http://google.com/")));
- }
+ EXPECT_FALSE(top_sites().IsBlacklisted(GURL("http://google.com/")));
top_sites().GetMostVisitedURLs(
&c,
@@ -1167,6 +1151,7 @@ TEST_F(TopSitesTest, PinnedURLs) {
&TopSitesTest::OnTopSitesAvailable));
top_sites().OnTopSitesAvailable(0, pages);
MessageLoop::current()->RunAllPending();
+ size_t index = 0;
EXPECT_FALSE(top_sites().IsURLPinned(GURL("http://bbc.com/")));
ASSERT_EQ(4u, urls().size());
@@ -1176,6 +1161,9 @@ TEST_F(TopSitesTest, PinnedURLs) {
EXPECT_EQ(themes_url(), urls()[3].url);
top_sites().AddPinnedURL(GURL("http://google.com/"), 3);
+ EXPECT_TRUE(top_sites().GetIndexOfPinnedURL(GURL("http://google.com/"),
+ &index));
+ EXPECT_EQ(3u, index);
EXPECT_FALSE(top_sites().IsURLPinned(GURL("http://bbc.com/")));
EXPECT_FALSE(top_sites().IsURLPinned(welcome_url()));
diff --git a/chrome/browser/profile_impl.cc b/chrome/browser/profile_impl.cc
index 62e50d5..bb335bf 100644
--- a/chrome/browser/profile_impl.cc
+++ b/chrome/browser/profile_impl.cc
@@ -498,8 +498,6 @@ ProfileImpl::~ProfileImpl() {
// This causes the Preferences file to be written to disk.
MarkAsCleanShutdown();
- if (top_sites_.get())
- top_sites_->ClearProfile();
}
ProfileId ProfileImpl::GetRuntimeId() {
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index 866da5a..2992612 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -2418,7 +2418,7 @@ void TabContents::UpdateThumbnail(const GURL& url,
const SkBitmap& bitmap,
const ThumbnailScore& score) {
// Tell History about this thumbnail
- if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTopSites)) {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTopSites)) {
if (!profile()->IsOffTheRecord())
profile()->GetTopSites()->SetPageThumbnail(url, bitmap, score);
} else {
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index 111dc88..454fffd 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -682,9 +682,6 @@ const char kNoProxyServer[] = "no-proxy-server";
// Runs the renderer outside the sandbox.
const char kNoSandbox[] = "no-sandbox";
-// Don't use TopSites; use old ThumbnailDatabase code instead.
-const char kNoTopSites[] = "no-top-sites";
-
// Specifies the maximum number of threads to use for running the Proxy
// Autoconfig (PAC) script.
const char kNumPacThreads[] = "num-pac-threads";
@@ -945,6 +942,10 @@ const char kTestType[] = "test-type";
// testing-related messages on IPC channel with the given ID.
const char kTestingChannelID[] = "testing-channel";
+// Enables using TopSites instead of ThumbnailDatabase (and
+// ThumbnailStore) for getting thumbnails for the new tab page.
+const char kTopSites[] = "top-sites";
+
// Excludes these plugins from the plugin sandbox.
// This is a comma-separated list of plugin library names.
const char kTrustedPlugins[] = "trusted-plugins";
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index 1e660dd..cc69770 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -201,7 +201,6 @@ extern const char kNoJsRandomness[];
extern const char kNoProxyServer[];
extern const char kNoReferrers[];
extern const char kNoSandbox[];
-extern const char kNoTopSites[];
extern const char kNumPacThreads[];
extern const char kOpenInNewWindow[];
extern const char kOrganicInstall[];
@@ -270,6 +269,7 @@ extern const char kTestName[];
extern const char kTestSandbox[];
extern const char kTestType[];
extern const char kTestingChannelID[];
+extern const char kTopSites[];
extern const char kTrustedPlugins[];
extern const char kTryChromeAgain[];
extern const char kUninstall[];
diff --git a/chrome/test/data/profiles/typical_history/Default/History b/chrome/test/data/profiles/typical_history/Default/History
index cf186c9..98481ce 100644
--- a/chrome/test/data/profiles/typical_history/Default/History
+++ b/chrome/test/data/profiles/typical_history/Default/History
Binary files differ
diff --git a/chrome/test/testing_profile.cc b/chrome/test/testing_profile.cc
index 48d2e51..547aff0 100644
--- a/chrome/test/testing_profile.cc
+++ b/chrome/test/testing_profile.cc
@@ -178,10 +178,6 @@ TestingProfile::~TestingProfile() {
// FaviconService depends on HistoryServce so destroying it later.
DestroyFaviconService();
DestroyWebDataService();
- history::TopSites::DeleteTopSites(top_sites_);
- if (top_sites_.get())
- top_sites_->ClearProfile();
-
file_util::Delete(path_, true);
}
diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h
index dd8976e..36f638f 100644
--- a/chrome/test/testing_profile.h
+++ b/chrome/test/testing_profile.h
@@ -9,7 +9,6 @@
#include "base/base_paths.h"
#include "base/file_util.h"
#include "base/path_service.h"
-#include "base/scoped_temp_dir.h"
#include "chrome/browser/autocomplete/autocomplete_classifier.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/browser_prefs.h"
@@ -21,7 +20,6 @@
#include "chrome/browser/geolocation/geolocation_permission_context.h"
#include "chrome/browser/host_content_settings_map.h"
#include "chrome/browser/history/history.h"
-#include "chrome/browser/history/top_sites.h"
#include "chrome/browser/in_process_webkit/webkit_context.h"
#include "chrome/browser/notifications/desktop_notification_service.h"
#include "chrome/browser/pref_service.h"
@@ -165,16 +163,7 @@ class TestingProfile : public Profile {
return template_url_model_.get();
}
virtual TemplateURLFetcher* GetTemplateURLFetcher() { return NULL; }
- virtual history::TopSites* GetTopSites() {
- if (!top_sites_.get()) {
- top_sites_ = new history::TopSites(this);
- if (!temp_dir_.CreateUniqueTempDir())
- return NULL;
- FilePath file_name = temp_dir_.path().AppendASCII("TopSites.db");
- top_sites_->Init(file_name);
- }
- return top_sites_;
- }
+ virtual history::TopSites* GetTopSites() { return NULL; }
virtual DownloadManager* GetDownloadManager() { return NULL; }
virtual PersonalDataManager* GetPersonalDataManager() { return NULL; }
virtual bool HasCreatedDownloadManager() const { return false; }
@@ -383,8 +372,6 @@ class TestingProfile : public Profile {
scoped_ptr<FindBarState> find_bar_state_;
FilePath last_selected_directory_;
- scoped_refptr<history::TopSites> top_sites_; // For history and thumbnails.
- ScopedTempDir temp_dir_;
};
// A profile that derives from another profile. This does not actually