diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_thumbnail_source.cc | 44 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_thumbnail_source.h | 11 | ||||
-rw-r--r-- | chrome/browser/dom_ui/most_visited_handler.cc | 210 | ||||
-rw-r--r-- | chrome/browser/dom_ui/most_visited_handler.h | 12 | ||||
-rw-r--r-- | chrome/browser/history/history.cc | 4 | ||||
-rw-r--r-- | chrome/browser/history/history_backend.cc | 4 | ||||
-rw-r--r-- | chrome/browser/history/history_backend_unittest.cc | 49 | ||||
-rw-r--r-- | chrome/browser/history/history_unittest.cc | 81 | ||||
-rw-r--r-- | chrome/browser/history/thumbnail_database.cc | 13 | ||||
-rw-r--r-- | chrome/browser/history/thumbnail_database_unittest.cc | 292 | ||||
-rw-r--r-- | chrome/browser/history/top_sites.cc | 8 | ||||
-rw-r--r-- | chrome/browser/history/top_sites.h | 3 | ||||
-rw-r--r-- | chrome/browser/history/top_sites_unittest.cc | 1 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 13 | ||||
-rw-r--r-- | chrome/common/chrome_switches.cc | 3 | ||||
-rw-r--r-- | chrome/tools/profiles/generate_profile.cc | 3 |
16 files changed, 42 insertions, 709 deletions
diff --git a/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc b/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc index 8b15821..b43a9e9 100644 --- a/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc +++ b/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc @@ -15,10 +15,8 @@ DOMUIThumbnailSource::DOMUIThumbnailSource(Profile* profile) : DataSource(chrome::kChromeUIThumbnailPath, MessageLoop::current()), profile_(profile) { - if (history::TopSites::IsEnabled()) { - // Set TopSites now as Profile isn't thread safe. - top_sites_ = profile_->GetTopSites(); - } + // Set TopSites now as Profile isn't thread safe. + top_sites_ = profile_->GetTopSites(); } DOMUIThumbnailSource::~DOMUIThumbnailSource() { @@ -27,28 +25,12 @@ DOMUIThumbnailSource::~DOMUIThumbnailSource() { void DOMUIThumbnailSource::StartDataRequest(const std::string& path, bool is_off_the_record, int request_id) { - if (top_sites_.get()) { - scoped_refptr<RefCountedBytes> data; - if (top_sites_->GetPageThumbnail(GURL(path), &data)) { - // We have the thumbnail. - SendResponse(request_id, data.get()); - } else { - SendDefaultThumbnail(request_id); - } - return; - } - - HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); - if (hs) { - HistoryService::Handle handle = hs->GetPageThumbnail( - GURL(path), - &cancelable_consumer_, - NewCallback(this, &DOMUIThumbnailSource::OnThumbnailDataAvailable)); - // Attach the ChromeURLDataManager request ID to the history request. - cancelable_consumer_.SetClientData(hs, handle, request_id); + scoped_refptr<RefCountedBytes> data; + if (top_sites_->GetPageThumbnail(GURL(path), &data)) { + // We have the thumbnail. + SendResponse(request_id, data.get()); } else { - // Tell the caller that no thumbnail is available. - SendResponse(request_id, NULL); + SendDefaultThumbnail(request_id); } } @@ -73,15 +55,3 @@ void DOMUIThumbnailSource::SendDefaultThumbnail(int request_id) { } SendResponse(request_id, default_thumbnail_); } - -void DOMUIThumbnailSource::OnThumbnailDataAvailable( - HistoryService::Handle request_handle, - scoped_refptr<RefCountedBytes> data) { - int request_id = cancelable_consumer_.GetClientDataForCurrentRequest(); - // Forward the data along to the networking system. - if (data.get() && !data->data.empty()) { - SendResponse(request_id, data); - } else { - SendDefaultThumbnail(request_id); - } -} diff --git a/chrome/browser/dom_ui/dom_ui_thumbnail_source.h b/chrome/browser/dom_ui/dom_ui_thumbnail_source.h index 8dd3a2d..57a1187 100644 --- a/chrome/browser/dom_ui/dom_ui_thumbnail_source.h +++ b/chrome/browser/dom_ui/dom_ui_thumbnail_source.h @@ -10,9 +10,8 @@ #include "base/basictypes.h" #include "base/ref_counted.h" +#include "base/ref_counted_memory.h" #include "chrome/browser/dom_ui/chrome_url_data_manager.h" -#include "chrome/browser/history/history.h" -#include "chrome/common/notification_registrar.h" class Profile; @@ -36,10 +35,6 @@ class DOMUIThumbnailSource : public ChromeURLDataManager::DataSource { virtual MessageLoop* MessageLoopForRequestPath(const std::string& path) const; - // Called when thumbnail data is available from the history backend. - void OnThumbnailDataAvailable(HistoryService::Handle request_handle, - scoped_refptr<RefCountedBytes> data); - private: virtual ~DOMUIThumbnailSource(); @@ -48,13 +43,11 @@ class DOMUIThumbnailSource : public ChromeURLDataManager::DataSource { Profile* profile_; - CancelableRequestConsumerT<int, 0> cancelable_consumer_; - // Raw PNG representation of the thumbnail to show when the thumbnail // database doesn't have a thumbnail for a webpage. scoped_refptr<RefCountedMemory> default_thumbnail_; - // TopSites. If non-null we're using TopSites. + // TopSites. scoped_refptr<history::TopSites> top_sites_; DISALLOW_COPY_AND_ASSIGN(DOMUIThumbnailSource); diff --git a/chrome/browser/dom_ui/most_visited_handler.cc b/chrome/browser/dom_ui/most_visited_handler.cc index 86f3ddd..8f15379 100644 --- a/chrome/browser/dom_ui/most_visited_handler.cc +++ b/chrome/browser/dom_ui/most_visited_handler.cc @@ -23,7 +23,6 @@ #include "chrome/browser/dom_ui/dom_ui_thumbnail_source.h" #include "chrome/browser/dom_ui/new_tab_ui.h" #include "chrome/browser/history/page_usage_data.h" -#include "chrome/browser/history/history.h" #include "chrome/browser/history/top_sites.h" #include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/prefs/pref_service.h" @@ -132,11 +131,9 @@ void MostVisitedHandler::HandleGetMostVisited(const ListValue* args) { void MostVisitedHandler::SendPagesValue() { if (pages_value_.get()) { bool has_blacklisted_urls = !url_blacklist_->empty(); - if (history::TopSites::IsEnabled()) { - history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites(); - if (ts) - has_blacklisted_urls = ts->HasBlacklistedItems(); - } + history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites(); + if (ts) + has_blacklisted_urls = ts->HasBlacklistedItems(); FundamentalValue first_run(IsFirstRun()); FundamentalValue has_blacklisted_urls_value(has_blacklisted_urls); dom_ui_->CallJavascriptFunction(L"mostVisitedPages", @@ -148,32 +145,12 @@ void MostVisitedHandler::SendPagesValue() { } void MostVisitedHandler::StartQueryForMostVisited() { - if (history::TopSites::IsEnabled()) { - // Use TopSites. - history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites(); - if (ts) { - ts->GetMostVisitedURLs( - &topsites_consumer_, - NewCallback(this, &MostVisitedHandler::OnMostVisitedURLsAvailable)); - } - return; - } - - const int page_count = kMostVisitedPages; - // Let's query for the number of items we want plus the blacklist size as - // we'll be filtering-out the returned list with the blacklist URLs. - // We do not subtract the number of pinned URLs we have because the - // HistoryService does not know about those. - const int result_count = page_count + url_blacklist_->size(); - HistoryService* hs = - dom_ui_->GetProfile()->GetHistoryService(Profile::EXPLICIT_ACCESS); - // |hs| may be null during unit tests. - if (hs) { - hs->QuerySegmentUsageSince( - &cancelable_consumer_, - base::Time::Now() - base::TimeDelta::FromDays(kMostVisitedScope), - result_count, - NewCallback(this, &MostVisitedHandler::OnSegmentUsageAvailable)); + // Use TopSites. + history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites(); + if (ts) { + ts->GetMostVisitedURLs( + &topsites_consumer_, + NewCallback(this, &MostVisitedHandler::OnMostVisitedURLsAvailable)); } } @@ -195,15 +172,9 @@ void MostVisitedHandler::HandleRemoveURLsFromBlacklist(const ListValue* args) { } UserMetrics::RecordAction(UserMetricsAction("MostVisited_UrlRemoved"), dom_ui_->GetProfile()); - if (history::TopSites::IsEnabled()) { - history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites(); - if (ts) - ts->RemoveBlacklistedURL(GURL(url)); - return; - } - - r = url_blacklist_->Remove(GetDictionaryKeyForURL(url), NULL); - DCHECK(r) << "Unknown URL removed from the NTP Most Visited blacklist."; + history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites(); + if (ts) + ts->RemoveBlacklistedURL(GURL(url)); } } @@ -211,14 +182,9 @@ void MostVisitedHandler::HandleClearBlacklist(const ListValue* args) { UserMetrics::RecordAction(UserMetricsAction("MostVisited_BlacklistCleared"), dom_ui_->GetProfile()); - if (history::TopSites::IsEnabled()) { - history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites(); - if (ts) - ts->ClearBlacklistedURLs(); - return; - } - - url_blacklist_->Clear(); + history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites(); + if (ts) + ts->ClearBlacklistedURLs(); } void MostVisitedHandler::HandleAddPinnedURL(const ListValue* args) { @@ -256,28 +222,9 @@ void MostVisitedHandler::HandleAddPinnedURL(const ListValue* args) { } void MostVisitedHandler::AddPinnedURL(const MostVisitedPage& page, int index) { - if (history::TopSites::IsEnabled()) { - history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites(); - if (ts) - ts->AddPinnedURL(page.url, index); - return; - } - - // Remove any pinned URL at the given index. - MostVisitedPage old_page; - if (GetPinnedURLAtIndex(index, &old_page)) { - RemovePinnedURL(old_page.url); - } - - DictionaryValue* new_value = new DictionaryValue(); - SetMostVisistedPage(new_value, page); - - new_value->SetInteger("index", index); - pinned_urls_->Set(GetDictionaryKeyForURL(page.url.spec()), new_value); - - // TODO(arv): Notify observers? - - // Don't call HandleGetMostVisited. Let the client call this as needed. + history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites(); + if (ts) + ts->AddPinnedURL(page.url, index); } void MostVisitedHandler::HandleRemovePinnedURL(const ListValue* args) { @@ -286,20 +233,9 @@ void MostVisitedHandler::HandleRemovePinnedURL(const ListValue* args) { } void MostVisitedHandler::RemovePinnedURL(const GURL& url) { - if (history::TopSites::IsEnabled()) { - history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites(); - if (ts) - ts->RemovePinnedURL(url); - return; - } - - const std::string key = GetDictionaryKeyForURL(url.spec()); - if (pinned_urls_->HasKey(key)) - pinned_urls_->Remove(key, NULL); - - // TODO(arv): Notify observers? - - // Don't call HandleGetMostVisited. Let the client call this as needed. + history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites(); + if (ts) + ts->RemovePinnedURL(url); } bool MostVisitedHandler::GetPinnedURLAtIndex(int index, @@ -343,84 +279,8 @@ bool MostVisitedHandler::GetPinnedURLAtIndex(int index, return false; } -void MostVisitedHandler::OnSegmentUsageAvailable( - CancelableRequestProvider::Handle handle, - std::vector<PageUsageData*>* data) { - SetPagesValue(data); - if (got_first_most_visited_request_) { - SendPagesValue(); - } -} - -void MostVisitedHandler::SetPagesValue(std::vector<PageUsageData*>* data) { - most_visited_urls_.clear(); - pages_value_.reset(new ListValue); - std::set<GURL> seen_urls; - - size_t data_index = 0; - size_t output_index = 0; - size_t pre_populated_index = 0; - const std::vector<MostVisitedPage> pre_populated_pages = - MostVisitedHandler::GetPrePopulatedPages(); - - while (output_index < kMostVisitedPages) { - bool found = false; - bool pinned = false; - std::string pinned_url; - std::string pinned_title; - MostVisitedPage mvp; - - if (MostVisitedHandler::GetPinnedURLAtIndex(output_index, &mvp)) { - pinned = true; - found = true; - } - - while (!found && data_index < data->size()) { - const PageUsageData& page = *(*data)[data_index]; - data_index++; - mvp.url = page.GetURL(); - - // Don't include blacklisted or pinned URLs. - std::string key = GetDictionaryKeyForURL(mvp.url.spec()); - if (pinned_urls_->HasKey(key) || url_blacklist_->HasKey(key)) - continue; - - mvp.title = page.GetTitle(); - found = true; - } - - while (!found && pre_populated_index < pre_populated_pages.size()) { - mvp = pre_populated_pages[pre_populated_index++]; - std::string key = GetDictionaryKeyForURL(mvp.url.spec()); - if (pinned_urls_->HasKey(key) || url_blacklist_->HasKey(key) || - seen_urls.find(mvp.url) != seen_urls.end()) - continue; - - found = true; - } - - if (found) { - // Add fillers as needed. - while (pages_value_->GetSize() < output_index) { - DictionaryValue* filler_value = new DictionaryValue(); - filler_value->SetBoolean("filler", true); - pages_value_->Append(filler_value); - } - - DictionaryValue* page_value = new DictionaryValue(); - SetMostVisistedPage(page_value, mvp); - page_value->SetBoolean("pinned", pinned); - pages_value_->Append(page_value); - most_visited_urls_.push_back(mvp.url); - seen_urls.insert(mvp.url); - } - output_index++; - } -} - void MostVisitedHandler::SetPagesValueFromTopSites( const history::MostVisitedURLList& data) { - DCHECK(history::TopSites::IsEnabled()); pages_value_.reset(new ListValue); for (size_t i = 0; i < data.size(); i++) { const history::MostVisitedURL& url = data[i]; @@ -473,18 +333,6 @@ bool MostVisitedHandler::IsFirstRun() { } // static -void MostVisitedHandler::SetMostVisistedPage( - DictionaryValue* dict, - const MostVisitedHandler::MostVisitedPage& page) { - NewTabUI::SetURLTitleAndDirection(dict, page.title, page.url); - if (!page.favicon_url.is_empty()) - dict->SetString("faviconUrl", page.favicon_url.spec()); - if (!page.thumbnail_url.is_empty()) - dict->SetString("thumbnailUrl", page.thumbnail_url.spec()); -} - - -// static const std::vector<MostVisitedHandler::MostVisitedPage>& MostVisitedHandler::GetPrePopulatedPages() { // TODO(arv): This needs to get the data from some configurable place. @@ -522,19 +370,9 @@ void MostVisitedHandler::Observe(NotificationType type, } void MostVisitedHandler::BlacklistURL(const GURL& url) { - if (history::TopSites::IsEnabled()) { - history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites(); - if (ts) - ts->AddBlacklistedURL(url); - return; - } - - RemovePinnedURL(url); - - std::string key = GetDictionaryKeyForURL(url.spec()); - if (url_blacklist_->HasKey(key)) - return; - url_blacklist_->SetBoolean(key, true); + history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites(); + if (ts) + ts->AddBlacklistedURL(url); } std::string MostVisitedHandler::GetDictionaryKeyForURL(const std::string& url) { diff --git a/chrome/browser/dom_ui/most_visited_handler.h b/chrome/browser/dom_ui/most_visited_handler.h index 469aad9..c0a78e2 100644 --- a/chrome/browser/dom_ui/most_visited_handler.h +++ b/chrome/browser/dom_ui/most_visited_handler.h @@ -73,13 +73,6 @@ class MostVisitedHandler : public DOMMessageHandler, // Send a request to the HistoryService to get the most visited pages. void StartQueryForMostVisited(); - // Callback from the history system when the most visited list is available. - void OnSegmentUsageAvailable(CancelableRequestProvider::Handle handle, - std::vector<PageUsageData*>* data); - - // Sets pages_value_ from a vector of URLs. - void SetPagesValue(std::vector<PageUsageData*>* data); - // Sets pages_value_ from a format produced by TopSites. void SetPagesValueFromTopSites(const history::MostVisitedURLList& data); @@ -106,11 +99,6 @@ class MostVisitedHandler : public DOMMessageHandler, // Returns true if we should treat this as the first run of the new tab page. bool IsFirstRun(); - // Adds the fields in the page to the dictionary. - static void SetMostVisistedPage( - DictionaryValue* dict, - const MostVisitedHandler::MostVisitedPage& page); - static const std::vector<MostVisitedPage>& GetPrePopulatedPages(); NotificationRegistrar registrar_; diff --git a/chrome/browser/history/history.cc b/chrome/browser/history/history.cc index 0736fc2..09434e1 100644 --- a/chrome/browser/history/history.cc +++ b/chrome/browser/history/history.cc @@ -791,7 +791,7 @@ void HistoryService::OnDBLoaded() { NotificationService::current()->Notify(NotificationType::HISTORY_LOADED, Source<Profile>(profile_), Details<HistoryService>(this)); - if (thread_ && profile_ && history::TopSites::IsEnabled()) { + if (thread_ && profile_) { // We don't want to force creation of TopSites. history::TopSites* ts = profile_->GetTopSitesWithoutCreating(); if (ts) @@ -801,7 +801,7 @@ void HistoryService::OnDBLoaded() { void HistoryService::StartTopSitesMigration() { needs_top_sites_migration_ = true; - if (thread_ && profile_ && history::TopSites::IsEnabled()) { + if (thread_ && profile_) { // We don't want to force creation of TopSites. history::TopSites* ts = profile_->GetTopSitesWithoutCreating(); if (ts) diff --git a/chrome/browser/history/history_backend.cc b/chrome/browser/history/history_backend.cc index 90be733..a02d3e9 100644 --- a/chrome/browser/history/history_backend.cc +++ b/chrome/browser/history/history_backend.cc @@ -583,7 +583,7 @@ void HistoryBackend::InitImpl(const std::string& languages) { // Thumbnail database. thumbnail_db_.reset(new ThumbnailDatabase()); - if (history::TopSites::IsEnabled() && !db_->GetNeedsThumbnailMigration()) { + if (!db_->GetNeedsThumbnailMigration()) { // No convertion needed - use new filename right away. thumbnail_name = GetFaviconsFileName(); } @@ -598,7 +598,7 @@ void HistoryBackend::InitImpl(const std::string& languages) { thumbnail_db_.reset(); } - if (history::TopSites::IsEnabled() && db_->GetNeedsThumbnailMigration()) { + if (db_->GetNeedsThumbnailMigration()) { VLOG(1) << "Starting TopSites migration"; delegate_->StartTopSitesMigration(); } diff --git a/chrome/browser/history/history_backend_unittest.cc b/chrome/browser/history/history_backend_unittest.cc index e65d36b..8922568 100644 --- a/chrome/browser/history/history_backend_unittest.cc +++ b/chrome/browser/history/history_backend_unittest.cc @@ -18,7 +18,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/browser/history/top_sites.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/notification_details.h" @@ -415,45 +414,6 @@ TEST_F(HistoryBackendTest, URLsNoLongerBookmarked) { backend_->thumbnail_db_->GetFavIconIDForFavIconURL(favicon_url1)); } -TEST_F(HistoryBackendTest, GetPageThumbnailAfterRedirects) { - ASSERT_TRUE(backend_.get()); - if (history::TopSites::IsEnabled()) - return; - - const char* base_url = "http://mail"; - const char* thumbnail_url = "http://mail.google.com"; - const char* first_chain[] = { - base_url, - thumbnail_url, - NULL - }; - AddRedirectChain(first_chain, 0); - - // Add a thumbnail for the end of that redirect chain. - scoped_ptr<SkBitmap> thumbnail( - gfx::JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); - backend_->SetPageThumbnail(GURL(thumbnail_url), *thumbnail, - ThumbnailScore(0.25, true, true)); - - // Write a second URL chain so that if you were to simply check what - // "http://mail" redirects to, you wouldn't see the URL that has - // contains the thumbnail. - const char* second_chain[] = { - base_url, - "http://mail.google.com/somewhere/else", - NULL - }; - AddRedirectChain(second_chain, 1); - - // Now try to get the thumbnail for the base url. It shouldn't be - // distracted by the second chain and should return the thumbnail - // attached to thumbnail_url_. - scoped_refptr<RefCountedBytes> data; - backend_->GetPageThumbnailDirectly(GURL(base_url), &data); - - EXPECT_TRUE(data.get()); -} - // Tests a handful of assertions for a navigation with a type of // KEYWORD_GENERATED. TEST_F(HistoryBackendTest, KeywordGenerated) { @@ -616,15 +576,6 @@ TEST_F(HistoryBackendTest, StripUsernamePasswordTest) { ASSERT_EQ(1U, visits.size()); } -TEST_F(HistoryBackendTest, DeleteThumbnailsDatabaseTest) { - if (history::TopSites::IsEnabled()) - return; - - EXPECT_TRUE(backend_->thumbnail_db_->NeedsMigrationToTopSites()); - backend_->delegate_->StartTopSitesMigration(); - EXPECT_FALSE(backend_->thumbnail_db_->NeedsMigrationToTopSites()); -} - TEST_F(HistoryBackendTest, AddPageVisitSource) { ASSERT_TRUE(backend_.get()); diff --git a/chrome/browser/history/history_unittest.cc b/chrome/browser/history/history_unittest.cc index a4fcb4f..1357888 100644 --- a/chrome/browser/history/history_unittest.cc +++ b/chrome/browser/history/history_unittest.cc @@ -45,7 +45,6 @@ #include "chrome/browser/history/in_memory_database.h" #include "chrome/browser/history/in_memory_history_backend.h" #include "chrome/browser/history/page_usage_data.h" -#include "chrome/browser/history/top_sites.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/notification_details.h" #include "chrome/common/notification_source.h" @@ -113,19 +112,6 @@ class HistoryTest : public testing::Test { ~HistoryTest() { } - // Thumbnail callback: we save the data and exit the message loop so the - // unit test can read the data - void OnThumbnailDataAvailable( - HistoryService::Handle request_handle, - scoped_refptr<RefCountedBytes> jpeg_data) { - got_thumbnail_callback_ = true; - if (jpeg_data.get()) { - std::copy(jpeg_data->data.begin(), jpeg_data->data.end(), - std::back_inserter(thumbnail_data_)); - } - MessageLoop::current()->Quit(); - } - // Creates the HistoryBackend and HistoryDatabase on the current thread, // assigning the values to backend_ and db_. void CreateBackendAndDatabase() { @@ -682,73 +668,6 @@ TEST_F(HistoryTest, Segments) { EXPECT_GT(page_usage_data_[0]->GetScore(), 5.0); } -// This just tests history system -> thumbnail database integration, the actual -// thumbnail tests are in its own file. -TEST_F(HistoryTest, Thumbnails) { - if (history::TopSites::IsEnabled()) - return; // TopSitesTest replaces this. - - scoped_refptr<HistoryService> history(new HistoryService); - history_service_ = history; - ASSERT_TRUE(history->Init(history_dir_, NULL)); - - scoped_ptr<SkBitmap> thumbnail( - gfx::JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); - static const double boringness = 0.25; - - const GURL url("http://www.google.com/thumbnail_test/"); - // Must be visited before adding a thumbnail. - history->AddPage(url, history::SOURCE_BROWSED); - history->SetPageThumbnail(url, *thumbnail, - ThumbnailScore(boringness, true, true)); - - // Make sure we get the correct thumbnail data. - EXPECT_TRUE(history->GetPageThumbnail(url, &consumer_, - NewCallback(static_cast<HistoryTest*>(this), - &HistoryTest::OnThumbnailDataAvailable))); - thumbnail_data_.clear(); - MessageLoop::current()->Run(); - // Make sure we got a valid JPEG back. This isn't equivalent to - // being correct, but when we're roundtripping through JPEG - // compression and we don't have a similarity measure. - EXPECT_TRUE(thumbnail_data_.size()); - scoped_ptr<SkBitmap> decoded_thumbnail( - gfx::JPEGCodec::Decode(&thumbnail_data_[0], thumbnail_data_.size())); - EXPECT_TRUE(decoded_thumbnail.get()); - - // Request a nonexistent thumbnail and make sure we get - // a callback and no data. - EXPECT_TRUE(history->GetPageThumbnail(GURL("http://asdfasdf.com/"), - &consumer_, - NewCallback(static_cast<HistoryTest*>(this), - &HistoryTest::OnThumbnailDataAvailable))); - thumbnail_data_.clear(); - MessageLoop::current()->Run(); - EXPECT_EQ(0U, thumbnail_data_.size()); - - // Request the thumbnail and cancel the request.. - got_thumbnail_callback_ = false; - thumbnail_data_.clear(); - HistoryService::Handle handle = history->GetPageThumbnail(url, &consumer_, - NewCallback(static_cast<HistoryTest*>(this), - &HistoryTest::OnThumbnailDataAvailable)); - EXPECT_TRUE(handle); - - history->CancelRequest(handle); - - // We create a task with a timeout so we can make sure we don't get and - // data in that time. - class QuitMessageLoop : public Task { - public: - virtual void Run() { - MessageLoop::current()->Quit(); - } - }; - MessageLoop::current()->PostDelayedTask(FROM_HERE, new QuitMessageLoop, 2000); - MessageLoop::current()->Run(); - EXPECT_FALSE(got_thumbnail_callback_); -} - TEST_F(HistoryTest, MostVisitedURLs) { scoped_refptr<HistoryService> history(new HistoryService); history_service_ = history; diff --git a/chrome/browser/history/thumbnail_database.cc b/chrome/browser/history/thumbnail_database.cc index 69c5708..965d3ab 100644 --- a/chrome/browser/history/thumbnail_database.cc +++ b/chrome/browser/history/thumbnail_database.cc @@ -123,18 +123,7 @@ sql::InitStatus ThumbnailDatabase::OpenDatabase(sql::Connection* db, bool ThumbnailDatabase::InitThumbnailTable() { if (!db_.DoesTableExist("thumbnails")) { - if (history::TopSites::IsEnabled()) { - use_top_sites_ = true; - return true; - } - if (!db_.Execute("CREATE TABLE thumbnails (" - "url_id INTEGER PRIMARY KEY," - "boring_score DOUBLE DEFAULT 1.0," - "good_clipping INTEGER DEFAULT 0," - "at_top INTEGER DEFAULT 0," - "last_updated INTEGER DEFAULT 0," - "data BLOB)")) - return false; + use_top_sites_ = true; } return true; } diff --git a/chrome/browser/history/thumbnail_database_unittest.cc b/chrome/browser/history/thumbnail_database_unittest.cc index 369486e..8347bad 100644 --- a/chrome/browser/history/thumbnail_database_unittest.cc +++ b/chrome/browser/history/thumbnail_database_unittest.cc @@ -14,7 +14,6 @@ #include "base/scoped_temp_dir.h" #include "chrome/browser/history/thumbnail_database.h" #include "chrome/common/chrome_paths.h" -#include "chrome/browser/history/top_sites.h" #include "chrome/common/thumbnail_score.h" #include "chrome/tools/profiles/thumbnail-inl.h" #include "gfx/codec/jpeg_codec.h" @@ -71,297 +70,6 @@ class ThumbnailDatabaseTest : public testing::Test { FilePath new_file_name_; }; -TEST_F(ThumbnailDatabaseTest, AddDelete) { - if (history::TopSites::IsEnabled()) - return; // TopSitesTest replaces this. - - ThumbnailDatabase db; - ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL)); - - // Add one page & verify it got added. - ThumbnailScore boring(kBoringness, true, true); - Time time; - GURL gurl; - db.SetPageThumbnail(gurl, kPage1, *google_bitmap_, boring, time); - ThumbnailScore score_output; - ASSERT_TRUE(db.ThumbnailScoreForId(kPage1, &score_output)); - ASSERT_TRUE(boring.Equals(score_output)); - - // Verify a random page is not found. - int64 page2 = 5678; - std::vector<unsigned char> jpeg_data; - EXPECT_FALSE(db.GetPageThumbnail(page2, &jpeg_data)); - EXPECT_FALSE(db.ThumbnailScoreForId(page2, &score_output)); - - // Add another page with a better boringness & verify it got added. - ThumbnailScore better_boringness(kBetterBoringness, true, true); - - db.SetPageThumbnail(gurl, page2, *google_bitmap_, better_boringness, time); - ASSERT_TRUE(db.ThumbnailScoreForId(page2, &score_output)); - ASSERT_TRUE(better_boringness.Equals(score_output)); - - // Delete the thumbnail for the second page. - ThumbnailScore worse_boringness(kWorseBoringness, true, true); - db.SetPageThumbnail(gurl, page2, SkBitmap(), worse_boringness, time); - ASSERT_FALSE(db.GetPageThumbnail(page2, &jpeg_data)); - ASSERT_FALSE(db.ThumbnailScoreForId(page2, &score_output)); - - // Delete the first thumbnail using the explicit delete API. - ASSERT_TRUE(db.DeleteThumbnail(kPage1)); - - // Make sure it is gone - ASSERT_FALSE(db.ThumbnailScoreForId(kPage1, &score_output)); - ASSERT_FALSE(db.GetPageThumbnail(kPage1, &jpeg_data)); - ASSERT_FALSE(db.ThumbnailScoreForId(page2, &score_output)); - ASSERT_FALSE(db.GetPageThumbnail(page2, &jpeg_data)); -} - -TEST_F(ThumbnailDatabaseTest, UseLessBoringThumbnails) { - if (history::TopSites::IsEnabled()) - return; // TopSitesTest replaces this. - - ThumbnailDatabase db; - Time now = Time::Now(); - ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL)); - - // Add one page & verify it got added. - ThumbnailScore boring(kBoringness, true, true); - - Time time; - GURL gurl; - db.SetPageThumbnail(gurl, kPage1, *google_bitmap_, boring, time); - std::vector<unsigned char> jpeg_data; - ThumbnailScore score_out; - ASSERT_TRUE(db.GetPageThumbnail(kPage1, &jpeg_data)); - ASSERT_TRUE(db.ThumbnailScoreForId(kPage1, &score_out)); - ASSERT_TRUE(boring.Equals(score_out)); - - // Attempt to update the first page entry with a thumbnail that - // is more boring and verify that it doesn't change. - ThumbnailScore more_boring(kWorseBoringness, true, true); - db.SetPageThumbnail(gurl, kPage1, *google_bitmap_, more_boring, time); - ASSERT_TRUE(db.GetPageThumbnail(kPage1, &jpeg_data)); - ASSERT_TRUE(db.ThumbnailScoreForId(kPage1, &score_out)); - ASSERT_TRUE(boring.Equals(score_out)); - - // Attempt to update the first page entry with a thumbnail that - // is less boring and verify that we update it. - ThumbnailScore less_boring(kBetterBoringness, true, true); - db.SetPageThumbnail(gurl, kPage1, *google_bitmap_, less_boring, time); - ASSERT_TRUE(db.GetPageThumbnail(kPage1, &jpeg_data)); - ASSERT_TRUE(db.ThumbnailScoreForId(kPage1, &score_out)); - ASSERT_TRUE(less_boring.Equals(score_out)); -} - -TEST_F(ThumbnailDatabaseTest, UseAtTopThumbnails) { - if (history::TopSites::IsEnabled()) - return; // TopSitesTest replaces this. - - ThumbnailDatabase db; - Time now = Time::Now(); - ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL)); - - // Add one page & verify it got added. Note that it doesn't have - // |good_clipping| and isn't |at_top|. - ThumbnailScore boring_and_bad(kBoringness, false, false); - - Time time; - GURL gurl; - db.SetPageThumbnail(gurl, kPage1, *google_bitmap_, boring_and_bad, time); - std::vector<unsigned char> jpeg_data; - ThumbnailScore score_out; - ASSERT_TRUE(db.GetPageThumbnail(kPage1, &jpeg_data)); - ASSERT_TRUE(db.ThumbnailScoreForId(kPage1, &score_out)); - ASSERT_TRUE(boring_and_bad.Equals(score_out)); - - // A thumbnail that's at the top of the page should replace - // thumbnails that are in the middle, for the same boringness. - ThumbnailScore boring_but_better(kBoringness, false, true); - db.SetPageThumbnail(gurl, kPage1, *google_bitmap_, boring_but_better, time); - ASSERT_TRUE(db.GetPageThumbnail(kPage1, &jpeg_data)); - ASSERT_TRUE(db.ThumbnailScoreForId(kPage1, &score_out)); - ASSERT_TRUE(boring_but_better.Equals(score_out)); - - // The only case where we should replace a thumbnail at the top with - // a thumbnail in the middle/bottom is when the current thumbnail is - // weirdly stretched and the incoming thumbnail isn't. - ThumbnailScore better_boring_bad_framing(kBetterBoringness, false, false); - db.SetPageThumbnail(gurl, kPage1, *google_bitmap_, better_boring_bad_framing, - time); - ASSERT_TRUE(db.GetPageThumbnail(kPage1, &jpeg_data)); - ASSERT_TRUE(db.ThumbnailScoreForId(kPage1, &score_out)); - ASSERT_TRUE(boring_but_better.Equals(score_out)); - - ThumbnailScore boring_good_clipping(kBoringness, true, false); - db.SetPageThumbnail(gurl, kPage1, *google_bitmap_, boring_good_clipping, - time); - ASSERT_TRUE(db.GetPageThumbnail(kPage1, &jpeg_data)); - ASSERT_TRUE(db.ThumbnailScoreForId(kPage1, &score_out)); - ASSERT_TRUE(boring_good_clipping.Equals(score_out)); - - // Now that we have a non-stretched, middle of the page thumbnail, - // we shouldn't be able to replace it with: - - // 1) A stretched thumbnail in the middle of the page - db.SetPageThumbnail(gurl, kPage1, *google_bitmap_, - ThumbnailScore(kBetterBoringness, false, false, now), - time); - ASSERT_TRUE(db.GetPageThumbnail(kPage1, &jpeg_data)); - ASSERT_TRUE(db.ThumbnailScoreForId(kPage1, &score_out)); - ASSERT_TRUE(boring_good_clipping.Equals(score_out)); - - // 2) A stretched thumbnail at the top of the page - db.SetPageThumbnail(gurl, kPage1, *google_bitmap_, - ThumbnailScore(kBetterBoringness, false, true, now), - time); - ASSERT_TRUE(db.GetPageThumbnail(kPage1, &jpeg_data)); - ASSERT_TRUE(db.ThumbnailScoreForId(kPage1, &score_out)); - ASSERT_TRUE(boring_good_clipping.Equals(score_out)); - - // But it should be replaced by a thumbnail that's clipped properly - // and is at the top - ThumbnailScore best_score(kBetterBoringness, true, true); - db.SetPageThumbnail(gurl, kPage1, *google_bitmap_, best_score, time); - ASSERT_TRUE(db.GetPageThumbnail(kPage1, &jpeg_data)); - ASSERT_TRUE(db.ThumbnailScoreForId(kPage1, &score_out)); - ASSERT_TRUE(best_score.Equals(score_out)); -} - -TEST_F(ThumbnailDatabaseTest, ThumbnailTimeDegradation) { - if (history::TopSites::IsEnabled()) - return; // TopSitesTest replaces this. - - ThumbnailDatabase db; - const Time kNow = Time::Now(); - const Time kThreeHoursAgo = kNow - TimeDelta::FromHours(4); - const Time kFiveHoursAgo = kNow - TimeDelta::FromHours(6); - const double kBaseBoringness = 0.305; - const double kWorseBoringness = 0.345; - - ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL)); - - // add one page & verify it got added. - ThumbnailScore base_boringness(kBaseBoringness, true, true, kFiveHoursAgo); - - Time time; - GURL gurl; - db.SetPageThumbnail(gurl, kPage1, *google_bitmap_, base_boringness, time); - std::vector<unsigned char> jpeg_data; - ThumbnailScore score_out; - ASSERT_TRUE(db.GetPageThumbnail(kPage1, &jpeg_data)); - ASSERT_TRUE(db.ThumbnailScoreForId(kPage1, &score_out)); - ASSERT_TRUE(base_boringness.Equals(score_out)); - - // Try to add a different thumbnail with a worse score an hour later - // (but not enough to trip the boringness degradation threshold). - ThumbnailScore hour_later(kWorseBoringness, true, true, kThreeHoursAgo); - db.SetPageThumbnail(gurl, kPage1, *google_bitmap_, hour_later, time); - ASSERT_TRUE(db.GetPageThumbnail(kPage1, &jpeg_data)); - ASSERT_TRUE(db.ThumbnailScoreForId(kPage1, &score_out)); - ASSERT_TRUE(base_boringness.Equals(score_out)); - - // After a full five hours, things should have degraded enough - // that we'll allow the same thumbnail with the same (worse) - // boringness that we previous rejected. - ThumbnailScore five_hours_later(kWorseBoringness, true, true, kNow); - db.SetPageThumbnail(gurl, kPage1, *google_bitmap_, five_hours_later, time); - ASSERT_TRUE(db.GetPageThumbnail(kPage1, &jpeg_data)); - ASSERT_TRUE(db.ThumbnailScoreForId(kPage1, &score_out)); - ASSERT_TRUE(five_hours_later.Equals(score_out)); -} - -TEST_F(ThumbnailDatabaseTest, NeverAcceptTotallyBoringThumbnail) { - // We enforce a maximum boringness score: even in cases where we - // should replace a thumbnail with another because of reasons other - // than straight up boringness score, still reject because the - // thumbnail is totally boring. - if (history::TopSites::IsEnabled()) - return; // TopSitesTest replaces this. - - ThumbnailDatabase db; - Time now = Time::Now(); - ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL)); - - std::vector<unsigned char> jpeg_data; - ThumbnailScore score_out; - const double kBaseBoringness = 0.50; - const Time kNow = Time::Now(); - const int kSizeOfTable = 4; - struct { - bool good_scaling; - bool at_top; - } const heiarchy_table[] = { - {false, false}, - {false, true}, - {true, false}, - {true, true} - }; - - Time time; - GURL gurl; - - // Test that for each entry type, all entry types that are better - // than it still will reject thumbnails which are totally boring. - for (int i = 0; i < kSizeOfTable; ++i) { - ThumbnailScore base(kBaseBoringness, - heiarchy_table[i].good_scaling, - heiarchy_table[i].at_top, - kNow); - - db.SetPageThumbnail(gurl, kPage1, *google_bitmap_, base, time); - ASSERT_TRUE(db.GetPageThumbnail(kPage1, &jpeg_data)); - ASSERT_TRUE(db.ThumbnailScoreForId(kPage1, &score_out)); - ASSERT_TRUE(base.Equals(score_out)); - - for (int j = i; j < kSizeOfTable; ++j) { - ThumbnailScore shouldnt_replace( - kTotallyBoring, heiarchy_table[j].good_scaling, - heiarchy_table[j].at_top, kNow); - - db.SetPageThumbnail(gurl, kPage1, *google_bitmap_, shouldnt_replace, - time); - ASSERT_TRUE(db.GetPageThumbnail(kPage1, &jpeg_data)); - ASSERT_TRUE(db.ThumbnailScoreForId(kPage1, &score_out)); - ASSERT_TRUE(base.Equals(score_out)); - } - - // Clean up for the next iteration - ASSERT_TRUE(db.DeleteThumbnail(kPage1)); - ASSERT_FALSE(db.GetPageThumbnail(kPage1, &jpeg_data)); - ASSERT_FALSE(db.ThumbnailScoreForId(kPage1, &score_out)); - } - - // We should never accept a totally boring thumbnail no matter how - // much old the current thumbnail is. - ThumbnailScore base_boring(kBaseBoringness, true, true, kNow); - db.SetPageThumbnail(gurl, kPage1, *google_bitmap_, base_boring, time); - ASSERT_TRUE(db.GetPageThumbnail(kPage1, &jpeg_data)); - ASSERT_TRUE(db.ThumbnailScoreForId(kPage1, &score_out)); - ASSERT_TRUE(base_boring.Equals(score_out)); - - ThumbnailScore totally_boring_in_the_future( - kTotallyBoring, true, true, kNow + TimeDelta::FromDays(365)); - db.SetPageThumbnail(gurl, kPage1, *google_bitmap_, - totally_boring_in_the_future, time); - ASSERT_TRUE(db.GetPageThumbnail(kPage1, &jpeg_data)); - ASSERT_TRUE(db.ThumbnailScoreForId(kPage1, &score_out)); - ASSERT_TRUE(base_boring.Equals(score_out)); -} - -TEST_F(ThumbnailDatabaseTest, NeedsMigrationToTopSites) { - if (history::TopSites::IsEnabled()) - return; // TopSitesTest replaces this. - - ThumbnailDatabase db; - ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL)); - db.BeginTransaction(); - EXPECT_TRUE(db.NeedsMigrationToTopSites()); - EXPECT_TRUE(db.RenameAndDropThumbnails(file_name_, new_file_name_)); - EXPECT_FALSE(db.NeedsMigrationToTopSites()); - EXPECT_FALSE(file_util::PathExists(file_name_)); - EXPECT_TRUE(file_util::PathExists(new_file_name_)); -} - TEST_F(ThumbnailDatabaseTest, GetFaviconAfterMigrationToTopSites) { ThumbnailDatabase db; ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL)); diff --git a/chrome/browser/history/top_sites.cc b/chrome/browser/history/top_sites.cc index a1c0a17..ac0cc7c 100644 --- a/chrome/browser/history/top_sites.cc +++ b/chrome/browser/history/top_sites.cc @@ -153,14 +153,6 @@ TopSites::TopSites(Profile* profile) GetMutableDictionary(prefs::kNTPMostVisitedPinnedURLs); } -// static -bool TopSites::IsEnabled() { - std::string switch_value = - CommandLine::ForCurrentProcess()->GetSwitchValueASCII( - switches::kEnableTopSites); - return switch_value.empty() || switch_value == "true"; -} - void TopSites::Init(const FilePath& db_name) { backend_->Init(db_name); backend_->GetMostVisitedThumbnails( diff --git a/chrome/browser/history/top_sites.h b/chrome/browser/history/top_sites.h index 9eeb715..556bc131 100644 --- a/chrome/browser/history/top_sites.h +++ b/chrome/browser/history/top_sites.h @@ -51,9 +51,6 @@ class TopSites public: explicit TopSites(Profile* profile); - // Returns whether top sites is enabled. - static bool IsEnabled(); - // Initializes TopSites. void Init(const FilePath& db_name); diff --git a/chrome/browser/history/top_sites_unittest.cc b/chrome/browser/history/top_sites_unittest.cc index 9f43800..22998d7 100644 --- a/chrome/browser/history/top_sites_unittest.cc +++ b/chrome/browser/history/top_sites_unittest.cc @@ -133,7 +133,6 @@ class TopSitesTest : public testing::Test { } virtual void SetUp() { - CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTopSites); profile_.reset(new TestingProfile); if (CreateHistoryAndTopSites()) { profile_->CreateHistoryService(false, false); diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 0de1784..5c838f3 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -2715,16 +2715,9 @@ void TabContents::UpdateThumbnail(const GURL& url, return; // Tell History about this thumbnail - if (history::TopSites::IsEnabled()) { - history::TopSites* ts = profile()->GetTopSites(); - if (ts) - ts->SetPageThumbnail(url, bitmap, score); - } else { - HistoryService* hs = - profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); - if (hs) - hs->SetPageThumbnail(url, bitmap, score); - } + history::TopSites* ts = profile()->GetTopSites(); + if (ts) + ts->SetPageThumbnail(url, bitmap, score); } void TabContents::UpdateInspectorSetting(const std::string& key, diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index 2918166..d153943 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -577,9 +577,6 @@ const char kEnableSyncTypedUrls[] = "enable-sync-typed-urls"; // SYN packet. const char kEnableTcpFastOpen[] = "enable-tcp-fastopen"; -// Enables TopSites. -const char kEnableTopSites[] = "enable-top-sites"; - // Whether or not the touch events API is exposed. const char kEnableTouch[] = "enable-touch"; diff --git a/chrome/tools/profiles/generate_profile.cc b/chrome/tools/profiles/generate_profile.cc index 9bf4b83..445d8bb 100644 --- a/chrome/tools/profiles/generate_profile.cc +++ b/chrome/tools/profiles/generate_profile.cc @@ -139,8 +139,7 @@ void InsertURLBatch(Profile* profile, GURL previous_url; PageTransition::Type transition = PageTransition::TYPED; const int end_page_id = page_id + batch_size; - history::TopSites* top_sites = - history::TopSites::IsEnabled() ? profile->GetTopSites() : NULL; + history::TopSites* top_sites = profile->GetTopSites(); for (; page_id < end_page_id; ++page_id) { // Randomly decide whether this new URL simulates following a link or // whether it's a jump to a new URL. |