diff options
author | Kristian Monsen <kristianm@google.com> | 2011-05-31 20:30:28 +0100 |
---|---|---|
committer | Kristian Monsen <kristianm@google.com> | 2011-06-14 20:31:41 -0700 |
commit | 72a454cd3513ac24fbdd0e0cb9ad70b86a99b801 (patch) | |
tree | 382278a54ce7a744d62fa510a9a80688cc12434b /chrome/browser/history | |
parent | c4becdd46e31d261b930e4b5a539cbc1d45c23a6 (diff) | |
download | external_chromium-72a454cd3513ac24fbdd0e0cb9ad70b86a99b801.zip external_chromium-72a454cd3513ac24fbdd0e0cb9ad70b86a99b801.tar.gz external_chromium-72a454cd3513ac24fbdd0e0cb9ad70b86a99b801.tar.bz2 |
Merge Chromium.org at r11.0.672.0: Initial merge by git.
Change-Id: I8b4aaf611a2a405fe3fe10e8a94ea7658645c192
Diffstat (limited to 'chrome/browser/history')
26 files changed, 190 insertions, 528 deletions
diff --git a/chrome/browser/history/download_create_info.h b/chrome/browser/history/download_create_info.h index 49ac635..0814350 100644 --- a/chrome/browser/history/download_create_info.h +++ b/chrome/browser/history/download_create_info.h @@ -36,7 +36,11 @@ struct DownloadCreateInfo { // DownloadItem fields FilePath path; + // The URL from which we are downloading. This is the final URL after any + // redirection by the server for |original_url_|. GURL url; + // The original URL before any redirection by the server for this URL. + GURL original_url; GURL referrer_url; FilePath suggested_path; // A number that should be added to the suggested path to make it unique. diff --git a/chrome/browser/history/expire_history_backend.cc b/chrome/browser/history/expire_history_backend.cc index 8cafc82..62aa7e5 100644 --- a/chrome/browser/history/expire_history_backend.cc +++ b/chrome/browser/history/expire_history_backend.cc @@ -557,7 +557,8 @@ void ExpireHistoryBackend::ArchiveURLsAndVisits( cur_visit.url_id = main_id_to_archived_id[cur_visit.url_id]; cur_visit.referring_visit = 0; VisitSourceMap::iterator iter = visit_sources.find(visits[i].visit_id); - archived_db_->AddVisit(&cur_visit, + archived_db_->AddVisit( + &cur_visit, iter == visit_sources.end() ? SOURCE_BROWSED : iter->second); // Ignore failures, we will delete it from the main DB no matter what. } diff --git a/chrome/browser/history/expire_history_backend_unittest.cc b/chrome/browser/history/expire_history_backend_unittest.cc index 161a086..d71535b 100644 --- a/chrome/browser/history/expire_history_backend_unittest.cc +++ b/chrome/browser/history/expire_history_backend_unittest.cc @@ -26,9 +26,9 @@ #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" #include "third_party/skia/include/core/SkBitmap.h" +#include "ui/gfx/codec/jpeg_codec.h" using base::Time; using base::TimeDelta; 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.h b/chrome/browser/history/history.h index 3e604e6..6afe318 100644 --- a/chrome/browser/history/history.h +++ b/chrome/browser/history/history.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_HISTORY_HISTORY_H_ #pragma once +#include <set> #include <vector> #include "base/basictypes.h" @@ -19,6 +20,7 @@ #include "chrome/browser/favicon_service.h" #include "chrome/browser/history/history_types.h" #include "chrome/browser/search_engines/template_url_id.h" +#include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" #include "chrome/common/page_transition_types.h" #include "chrome/common/ref_counted_util.h" @@ -327,8 +329,8 @@ class HistoryService : public CancelableRequestProvider, typedef Callback4<Handle, bool, // Were we able to determine the # of visits? int, // Number of visits. - base::Time>::Type // Time of first visit. Only first bool is - // true and int is > 0. + base::Time>::Type // Time of first visit. Only first bool + // is true and int is > 0. GetVisitCountToHostCallback; // Requests the number of visits to all urls on the scheme/host/post diff --git a/chrome/browser/history/history_backend.cc b/chrome/browser/history/history_backend.cc index cd0a40b..50f47d5 100644 --- a/chrome/browser/history/history_backend.cc +++ b/chrome/browser/history/history_backend.cc @@ -4,7 +4,10 @@ #include "chrome/browser/history/history_backend.h" +#include <list> +#include <map> #include <set> +#include <vector> #include "base/command_line.h" #include "base/compiler_specific.h" @@ -24,7 +27,6 @@ #include "chrome/browser/history/page_usage_data.h" #include "chrome/browser/history/top_sites.h" #include "chrome/common/chrome_constants.h" -#include "chrome/common/chrome_switches.h" #include "chrome/common/notification_type.h" #include "chrome/common/url_constants.h" #include "googleurl/src/gurl.h" @@ -581,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(); } @@ -596,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(); } @@ -719,6 +721,9 @@ std::pair<URLID, VisitID> HistoryBackend::AddPageVisit( // Re-enable this. // GetMostRecentRedirectsTo(url, &details->redirects); BroadcastNotifications(NotificationType::HISTORY_URL_VISITED, details); + } else { + VLOG(0) << "Failed to build visit insert statement: " + << "url_id = " << url_id; } return std::make_pair(url_id, visit_id); @@ -1201,10 +1206,18 @@ void HistoryBackend::QueryHistoryBasic(URLDatabase* url_db, const VisitRow visit = visits[i]; // Add a result row for this visit, get the URL info from the DB. - if (!url_db->GetURLRow(visit.url_id, &url_result)) + if (!url_db->GetURLRow(visit.url_id, &url_result)) { + VLOG(0) << "Failed to get id " << visit.url_id + << " from history.urls."; continue; // DB out of sync and URL doesn't exist, try to recover. - if (!url_result.url().is_valid()) + } + + if (!url_result.url().is_valid()) { + VLOG(0) << "Got invalid URL from history.urls with id " + << visit.url_id << ": " + << url_result.url().possibly_invalid_spec(); continue; // Don't report invalid URLs in case of corruption. + } // The archived database may be out of sync with respect to starring, // titles, last visit date, etc. Therefore, we query the main DB if the diff --git a/chrome/browser/history/history_backend_unittest.cc b/chrome/browser/history/history_backend_unittest.cc index a3b2c86..c930558 100644 --- a/chrome/browser/history/history_backend_unittest.cc +++ b/chrome/browser/history/history_backend_unittest.cc @@ -18,17 +18,15 @@ #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/chrome_switches.h" #include "chrome/common/notification_details.h" #include "chrome/common/notification_source.h" #include "chrome/common/thumbnail_score.h" #include "chrome/tools/profiles/thumbnail-inl.h" -#include "gfx/codec/jpeg_codec.h" #include "googleurl/src/gurl.h" #include "testing/gtest/include/gtest/gtest.h" +#include "ui/gfx/codec/jpeg_codec.h" using base::Time; @@ -416,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) { @@ -617,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_browsertest.cc b/chrome/browser/history/history_browsertest.cc index 7075b16..d5dc39b 100644 --- a/chrome/browser/history/history_browsertest.cc +++ b/chrome/browser/history/history_browsertest.cc @@ -17,6 +17,14 @@ namespace { +// Helper to debug intermittent test hangs/timeouts. +// TODO(phajdan.jr): remove when http://crbug.com/57994 is fixed. +void Checkpoint(const char* message, const base::TimeTicks& start_time) { + LOG(INFO) << message << " : " + << (base::TimeTicks::Now() - start_time).InMilliseconds() + << " ms" << std::flush; +} + // Note: WaitableEvent is not used for synchronization between the main thread // and history backend thread because the history subsystem posts tasks back // to the main thread. Had we tried to Signal an event in such a task @@ -141,49 +149,50 @@ IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, SavingHistoryEnabled) { } } -// Times out on Vista only. http://crbug.com/57994 -#if defined(OS_WIN) -#define MAYBE_SavingHistoryDisabled DISABLED_SavingHistoryDisabled -#else -#define MAYBE_SavingHistoryDisabled SavingHistoryDisabled -#endif - // Test that disabling saving browser history really works. -IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, MAYBE_SavingHistoryDisabled) { +// TODO(phajdan.jr): remove debug code when http://crbug.com/57994 is fixed. +IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, SavingHistoryDisabled) { + base::TimeTicks start_time = base::TimeTicks::Now(); + GetPrefs()->SetBoolean(prefs::kSavingBrowserHistoryDisabled, true); EXPECT_TRUE(GetProfile()->GetHistoryService(Profile::EXPLICIT_ACCESS)); EXPECT_FALSE(GetProfile()->GetHistoryService(Profile::IMPLICIT_ACCESS)); + Checkpoint("Before waiting for history to load", start_time); ui_test_utils::WaitForHistoryToLoad(browser()); + Checkpoint("After waiting for history to load", start_time); ExpectEmptyHistory(); + Checkpoint("After checking history", start_time); ui_test_utils::NavigateToURL(browser(), GetTestUrl()); + Checkpoint("After NavigateToURL", start_time); WaitForHistoryBackendToRun(); + Checkpoint("After waiting for history backend to run", start_time); ExpectEmptyHistory(); + Checkpoint("After second check", start_time); } -// Times out on Vista only. http://crbug.com/57994 -#if defined(OS_WIN) -#define MAYBE_SavingHistoryEnabledThenDisabled \ - DISABLED_SavingHistoryEnabledThenDisabled -#else -#define MAYBE_SavingHistoryEnabledThenDisabled SavingHistoryEnabledThenDisabled -#endif - // Test that changing the pref takes effect immediately // when the browser is running. -IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, - MAYBE_SavingHistoryEnabledThenDisabled) { +// TODO(phajdan.jr): remove debug code when http://crbug.com/57994 is fixed. +IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, SavingHistoryEnabledThenDisabled) { + base::TimeTicks start_time = base::TimeTicks::Now(); + EXPECT_FALSE(GetPrefs()->GetBoolean(prefs::kSavingBrowserHistoryDisabled)); + Checkpoint("Before waiting for history to load", start_time); ui_test_utils::WaitForHistoryToLoad(browser()); + Checkpoint("After waiting for history to load", start_time); ui_test_utils::NavigateToURL(browser(), GetTestUrl()); + Checkpoint("After first NavigateToURL", start_time); WaitForHistoryBackendToRun(); + Checkpoint("After waiting for history backend to run", start_time); { std::vector<GURL> urls(GetHistoryContents()); + Checkpoint("After first GetHistoryContents", start_time); ASSERT_EQ(1U, urls.size()); EXPECT_EQ(GetTestUrl().spec(), urls[0].spec()); } @@ -191,11 +200,14 @@ IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, GetPrefs()->SetBoolean(prefs::kSavingBrowserHistoryDisabled, true); ui_test_utils::NavigateToURL(browser(), GetTestUrl()); + Checkpoint("After second NavigateToURL", start_time); WaitForHistoryBackendToRun(); + Checkpoint("After waiting for history backend to run (2nd time)", start_time); { // No additional entries should be present in the history. std::vector<GURL> urls(GetHistoryContents()); + Checkpoint("After second GetHistoryContents", start_time); ASSERT_EQ(1U, urls.size()); EXPECT_EQ(GetTestUrl().spec(), urls[0].spec()); } diff --git a/chrome/browser/history/history_database.cc b/chrome/browser/history/history_database.cc index c5478b8..bdd3cb4 100644 --- a/chrome/browser/history/history_database.cc +++ b/chrome/browser/history/history_database.cc @@ -14,7 +14,6 @@ #include "base/rand_util.h" #include "base/string_util.h" #include "chrome/browser/diagnostics/sqlite_diagnostics.h" -#include "chrome/common/chrome_switches.h" #if defined(OS_MACOSX) #include "base/mac/mac_util.h" diff --git a/chrome/browser/history/history_types.cc b/chrome/browser/history/history_types.cc index ecc8314..d3753bf 100644 --- a/chrome/browser/history/history_types.cc +++ b/chrome/browser/history/history_types.cc @@ -149,7 +149,7 @@ URLResult::URLResult(const GURL& url, URLResult::~URLResult() { } -void URLResult::Swap(URLResult* other) { +void URLResult::SwapResult(URLResult* other) { URLRow::Swap(other); std::swap(visit_time_, other->visit_time_); snippet_.Swap(&other->snippet_); @@ -192,7 +192,7 @@ void QueryResults::Swap(QueryResults* other) { void QueryResults::AppendURLBySwapping(URLResult* result) { URLResult* new_result = new URLResult; - new_result->Swap(result); + new_result->SwapResult(result); results_.push_back(new_result); AddURLUsageAtIndex(new_result->url(), results_.size() - 1); diff --git a/chrome/browser/history/history_types.h b/chrome/browser/history/history_types.h index 76359fc..320c991 100644 --- a/chrome/browser/history/history_types.h +++ b/chrome/browser/history/history_types.h @@ -122,10 +122,10 @@ class URLRow { favicon_id_ = favicon_id; } + protected: // Swaps the contents of this URLRow with another, which allows it to be // destructively copied without memory allocations. - // (Virtual because it's overridden by URLResult.) - virtual void Swap(URLRow* other); + void Swap(URLRow* other); private: // This class writes directly into this structure and clears our dirty bits @@ -359,7 +359,7 @@ class URLResult : public URLRow { return title_match_positions_; } - virtual void Swap(URLResult* other); + void SwapResult(URLResult* other); private: friend class HistoryBackend; diff --git a/chrome/browser/history/history_unittest.cc b/chrome/browser/history/history_unittest.cc index e139cdd..7bc76da 100644 --- a/chrome/browser/history/history_unittest.cc +++ b/chrome/browser/history/history_unittest.cc @@ -45,16 +45,14 @@ #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/chrome_switches.h" #include "chrome/common/notification_details.h" #include "chrome/common/notification_source.h" #include "chrome/common/thumbnail_score.h" #include "chrome/tools/profiles/thumbnail-inl.h" -#include "gfx/codec/jpeg_codec.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkBitmap.h" +#include "ui/gfx/codec/jpeg_codec.h" using base::Time; using base::TimeDelta; @@ -114,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() { @@ -683,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/in_memory_history_backend.cc b/chrome/browser/history/in_memory_history_backend.cc index 25219f6..cfeb618 100644 --- a/chrome/browser/history/in_memory_history_backend.cc +++ b/chrome/browser/history/in_memory_history_backend.cc @@ -16,12 +16,10 @@ #include "chrome/browser/history/in_memory_database.h" #include "chrome/browser/history/in_memory_url_index.h" #include "chrome/browser/history/url_database.h" -#include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/notification_details.h" #include "chrome/common/notification_source.h" -#include "chrome/common/pref_names.h" namespace history { diff --git a/chrome/browser/history/in_memory_url_index.cc b/chrome/browser/history/in_memory_url_index.cc index 62a22e6..9d2e925 100644 --- a/chrome/browser/history/in_memory_url_index.cc +++ b/chrome/browser/history/in_memory_url_index.cc @@ -5,9 +5,9 @@ #include "chrome/browser/history/in_memory_url_index.h" #include <algorithm> +#include <iterator> #include <limits> -#include "app/l10n_util.h" #include "base/i18n/break_iterator.h" #include "base/string_util.h" #include "base/time.h" @@ -16,6 +16,7 @@ #include "chrome/browser/history/url_database.h" #include "net/base/escape.h" #include "net/base/net_util.h" +#include "ui/base/l10n/l10n_util.h" #include "unicode/utypes.h" // for int32_t using base::Time; diff --git a/chrome/browser/history/query_parser.cc b/chrome/browser/history/query_parser.cc index 12ecc29..1037b6c 100644 --- a/chrome/browser/history/query_parser.cc +++ b/chrome/browser/history/query_parser.cc @@ -6,12 +6,12 @@ #include <algorithm> -#include "app/l10n_util.h" #include "base/i18n/break_iterator.h" #include "base/logging.h" #include "base/scoped_vector.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" +#include "ui/base/l10n/l10n_util.h" #include "unicode/uscript.h" namespace { diff --git a/chrome/browser/history/redirect_uitest.cc b/chrome/browser/history/redirect_uitest.cc index 9d2c35a..904ba86 100644 --- a/chrome/browser/history/redirect_uitest.cc +++ b/chrome/browser/history/redirect_uitest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -12,6 +12,7 @@ #include "base/scoped_temp_dir.h" #include "base/string_util.h" #include "base/string16.h" +#include "base/test/test_timeouts.h" #include "base/threading/platform_thread.h" #include "base/utf_string_conversions.h" #include "chrome/browser/ui/view_ids.h" @@ -21,7 +22,7 @@ #include "chrome/test/ui/ui_test.h" #include "net/base/net_util.h" #include "net/test/test_server.h" -#include "views/event.h" +#include "ui/base/events.h" namespace { @@ -164,9 +165,8 @@ TEST_F(RedirectTest, MAYBE_ClientCancelled) { ASSERT_TRUE(browser->BringToFront()); ASSERT_TRUE(window->GetViewBounds(VIEW_ID_TAB_CONTAINER, &tab_view_bounds, true)); - ASSERT_TRUE( - window->SimulateOSClick(tab_view_bounds.CenterPoint(), - views::Event::EF_LEFT_BUTTON_DOWN)); + ASSERT_TRUE(window->SimulateOSClick(tab_view_bounds.CenterPoint(), + ui::EF_LEFT_BUTTON_DOWN)); EXPECT_TRUE(tab_proxy->WaitForNavigation(last_nav_time)); std::vector<GURL> redirects; @@ -210,7 +210,7 @@ TEST_F(RedirectTest, ClientServerServer) { NavigateToURL(first_url); for (int i = 0; i < 10; ++i) { - base::PlatformThread::Sleep(sleep_timeout_ms()); + base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms()); scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); ASSERT_TRUE(tab_proxy.get()); ASSERT_TRUE(tab_proxy->GetRedirectsFrom(first_url, &redirects)); @@ -243,7 +243,9 @@ TEST_F(RedirectTest, ServerReference) { // Test that redirect from http:// to file:// : // A) does not crash the browser or confuse the redirect chain, see bug 1080873 // B) does not take place. -TEST_F(RedirectTest, NoHttpToFile) { +// +// Flaky on XP and Vista, http://crbug.com/69390. +TEST_F(RedirectTest, FLAKY_NoHttpToFile) { ASSERT_TRUE(test_server_.Start()); FilePath test_file(test_data_directory_); test_file = test_file.AppendASCII("http_to_file.html"); @@ -316,7 +318,7 @@ TEST_F(RedirectTest, std::wstring final_url_title = UTF8ToWide("Title Of Awesomeness"); // Wait till the final page has been loaded. for (int i = 0; i < 10; ++i) { - base::PlatformThread::Sleep(sleep_timeout_ms()); + base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms()); scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); ASSERT_TRUE(tab_proxy.get()); ASSERT_TRUE(tab_proxy->GetTabTitle(&tab_title)); diff --git a/chrome/browser/history/starred_url_database.h b/chrome/browser/history/starred_url_database.h index aab2ae5..aff2d64 100644 --- a/chrome/browser/history/starred_url_database.h +++ b/chrome/browser/history/starred_url_database.h @@ -8,12 +8,12 @@ #include <set> -#include "app/tree_node_model.h" #include "base/basictypes.h" #include "base/gtest_prod_util.h" #include "base/string16.h" #include "chrome/browser/history/history_types.h" #include "chrome/browser/history/url_database.h" +#include "ui/base/models/tree_node_model.h" class FilePath; @@ -115,7 +115,7 @@ class StarredURLDatabase : public URLDatabase { StarID CreateStarredEntry(StarredEntry* entry); // Used when checking integrity of starred table. - typedef TreeNodeWithValue<history::StarredEntry> StarredNode; + typedef ui::TreeNodeWithValue<history::StarredEntry> StarredNode; // Returns the max group id, or 0 if there is an error. UIStarID GetMaxGroupID(); diff --git a/chrome/browser/history/thumbnail_database.cc b/chrome/browser/history/thumbnail_database.cc index 7fa8bd1..3f863da 100644 --- a/chrome/browser/history/thumbnail_database.cc +++ b/chrome/browser/history/thumbnail_database.cc @@ -4,6 +4,9 @@ #include "chrome/browser/history/thumbnail_database.h" +#include <algorithm> +#include <string> + #include "app/sql/statement.h" #include "app/sql/transaction.h" #include "base/command_line.h" @@ -16,10 +19,9 @@ #include "chrome/browser/history/history_publisher.h" #include "chrome/browser/history/top_sites.h" #include "chrome/browser/history/url_database.h" -#include "chrome/common/chrome_switches.h" #include "chrome/common/thumbnail_score.h" -#include "gfx/codec/jpeg_codec.h" #include "third_party/skia/include/core/SkBitmap.h" +#include "ui/gfx/codec/jpeg_codec.h" #if defined(OS_MACOSX) #include "base/mac/mac_util.h" @@ -121,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 23eccef..6483a25 100644 --- a/chrome/browser/history/thumbnail_database_unittest.cc +++ b/chrome/browser/history/thumbnail_database_unittest.cc @@ -14,14 +14,12 @@ #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/browser/history/top_sites.h" #include "chrome/common/thumbnail_score.h" #include "chrome/tools/profiles/thumbnail-inl.h" -#include "gfx/codec/jpeg_codec.h" #include "googleurl/src/gurl.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkBitmap.h" +#include "ui/gfx/codec/jpeg_codec.h" using base::Time; using base::TimeDelta; @@ -72,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 1635523..155c3fc 100644 --- a/chrome/browser/history/top_sites.cc +++ b/chrome/browser/history/top_sites.cc @@ -7,7 +7,6 @@ #include <algorithm> #include <set> -#include "app/l10n_util.h" #include "base/command_line.h" #include "base/logging.h" #include "base/md5.h" @@ -29,11 +28,12 @@ #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" #include "chrome/common/thumbnail_score.h" -#include "gfx/codec/jpeg_codec.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" #include "third_party/skia/include/core/SkBitmap.h" +#include "ui/base/l10n/l10n_util.h" +#include "ui/gfx/codec/jpeg_codec.h" namespace history { @@ -127,7 +127,7 @@ class LoadThumbnailsFromHistoryTask : public HistoryDBTask { } // namespace TopSites::TopSites(Profile* profile) - : backend_(new TopSitesBackend()), + : backend_(NULL), cache_(new TopSitesCache()), thread_safe_cache_(new TopSitesCache()), profile_(profile), @@ -153,15 +153,10 @@ 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) { + // Create the backend here, rather than in the constructor, so that + // unit tests that do not need the backend can run without a problem. + backend_ = new TopSitesBackend; backend_->Init(db_name); backend_->GetMostVisitedThumbnails( &cancelable_consumer_, @@ -189,8 +184,8 @@ bool TopSites::SetPageThumbnail(const GURL& url, } bool add_temp_thumbnail = false; - if (!cache_->IsKnownURL(url)) { - if (cache_->top_sites().size() < kTopSitesNumber) { + if (!IsKnownURL(url)) { + if (!IsFull()) { add_temp_thumbnail = true; } else { return false; // This URL is not known to us. @@ -225,7 +220,7 @@ void TopSites::GetMostVisitedURLs(CancelableRequestConsumer* consumer, AddRequest(request, consumer); MostVisitedURLList filtered_urls; { - AutoLock lock(lock_); + base::AutoLock lock(lock_); if (!loaded_) { // A request came in before we finished loading. Put the request in // pending_callbacks_ and we'll notify it when we finish loading. @@ -241,10 +236,17 @@ void TopSites::GetMostVisitedURLs(CancelableRequestConsumer* consumer, bool TopSites::GetPageThumbnail(const GURL& url, scoped_refptr<RefCountedBytes>* bytes) { // WARNING: this may be invoked on any thread. - AutoLock lock(lock_); + base::AutoLock lock(lock_); return thread_safe_cache_->GetPageThumbnail(url, bytes); } +bool TopSites::GetPageThumbnailScore(const GURL& url, + ThumbnailScore* score) { + // WARNING: this may be invoked on any thread. + base::AutoLock lock(lock_); + return thread_safe_cache_->GetPageThumbnailScore(url, score); +} + // Returns the index of |url| in |urls|, or -1 if not found. static int IndexOf(const MostVisitedURLList& urls, const GURL& url) { for (size_t i = 0; i < urls.size(); i++) { @@ -443,7 +445,7 @@ void TopSites::DiffMostVisited(const MostVisitedURLList& old_list, CancelableRequestProvider::Handle TopSites::StartQueryForMostVisited() { DCHECK(loaded_); if (!profile_) - return NULL; + return 0; HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); // |hs| may be null during unit tests. @@ -454,7 +456,15 @@ CancelableRequestProvider::Handle TopSites::StartQueryForMostVisited() { &cancelable_consumer_, NewCallback(this, &TopSites::OnTopSitesAvailableFromHistory)); } - return NULL; + return 0; +} + +bool TopSites::IsKnownURL(const GURL& url) { + return loaded_ && cache_->IsKnownURL(url); +} + +bool TopSites::IsFull() { + return loaded_ && cache_->top_sites().size() >= kTopSitesNumber; } TopSites::~TopSites() { @@ -732,7 +742,7 @@ void TopSites::Observe(NotificationType type, } StartQueryForMostVisited(); } else if (type == NotificationType::NAV_ENTRY_COMMITTED) { - if (cache_->top_sites().size() < kTopSitesNumber) { + if (!IsFull()) { NavigationController::LoadCommittedDetails* load_details = Details<NavigationController::LoadCommittedDetails>(details).ptr(); if (!load_details) @@ -808,7 +818,7 @@ void TopSites::MoveStateToLoaded() { MostVisitedURLList filtered_urls; PendingCallbackSet pending_callbacks; { - AutoLock lock(lock_); + base::AutoLock lock(lock_); if (loaded_) return; // Don't do anything if we're already loaded. @@ -830,14 +840,14 @@ void TopSites::MoveStateToLoaded() { } void TopSites::ResetThreadSafeCache() { - AutoLock lock(lock_); + base::AutoLock lock(lock_); MostVisitedURLList cached; ApplyBlacklistAndPinnedURLs(cache_->top_sites(), &cached); thread_safe_cache_->SetTopSites(cached); } void TopSites::ResetThreadSafeImageCache() { - AutoLock lock(lock_); + base::AutoLock lock(lock_); thread_safe_cache_->SetThumbnails(cache_->images()); thread_safe_cache_->RemoveUnreferencedThumbnails(); } diff --git a/chrome/browser/history/top_sites.h b/chrome/browser/history/top_sites.h index 9eeb715..f92b877 100644 --- a/chrome/browser/history/top_sites.h +++ b/chrome/browser/history/top_sites.h @@ -13,9 +13,9 @@ #include "base/basictypes.h" #include "base/gtest_prod_util.h" -#include "base/lock.h" #include "base/ref_counted.h" #include "base/ref_counted_memory.h" +#include "base/synchronization/lock.h" #include "base/time.h" #include "base/timer.h" #include "chrome/browser/cancelable_request.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); @@ -82,6 +79,11 @@ class TopSites bool GetPageThumbnail(const GURL& url, scoped_refptr<RefCountedBytes>* bytes); + // Get a thumbnail score for a given page. Returns true iff we have the + // thumbnail score. This may be invoked on any thread. The score will + // be copied to |score|. + virtual bool GetPageThumbnailScore(const GURL& url, ThumbnailScore* score); + // Invoked from History if migration is needed. If this is invoked it will // be before HistoryLoaded is invoked. void MigrateFromHistory(); @@ -147,6 +149,19 @@ class TopSites bool loaded() const { return loaded_; } + // Returns true if the given URL is known to the top sites service. + // This function also returns false if TopSites isn't loaded yet. + virtual bool IsKnownURL(const GURL& url); + + // Returns true if the top sites list is full (i.e. we already have the + // maximum number of top sites). This function also returns false if + // TopSites isn't loaded yet. + virtual bool IsFull(); + + protected: + // For allowing inheritance. + virtual ~TopSites(); + private: friend class base::RefCountedThreadSafe<TopSites>; friend class TopSitesTest; @@ -180,8 +195,6 @@ class TopSites TOP_SITES_LOADED }; - ~TopSites(); - // Sets the thumbnail without writing to the database. Useful when // reading last known top sites from the DB. // Returns true if the thumbnail was set, false if the existing one is better. @@ -300,7 +313,7 @@ class TopSites Profile* profile_; // Lock used to access |thread_safe_cache_|. - mutable Lock lock_; + mutable base::Lock lock_; CancelableRequestConsumer cancelable_consumer_; diff --git a/chrome/browser/history/top_sites_cache.cc b/chrome/browser/history/top_sites_cache.cc index 828b701..3be7041 100644 --- a/chrome/browser/history/top_sites_cache.cc +++ b/chrome/browser/history/top_sites_cache.cc @@ -47,6 +47,17 @@ bool TopSitesCache::GetPageThumbnail(const GURL& url, return false; } +bool TopSitesCache::GetPageThumbnailScore(const GURL& url, + ThumbnailScore* score) { + std::map<GURL, Images>::const_iterator found = + images_.find(GetCanonicalURL(url)); + if (found != images_.end()) { + *score = found->second.thumbnail_score; + return true; + } + return false; +} + GURL TopSitesCache::GetCanonicalURL(const GURL& url) { CanonicalURLs::iterator i = TopSitesCache::GetCanonicalURLsIterator(url); return i == canonical_urls_.end() ? url : i->first.first->url; diff --git a/chrome/browser/history/top_sites_cache.h b/chrome/browser/history/top_sites_cache.h index 4c5d79a..ca0d7bc 100644 --- a/chrome/browser/history/top_sites_cache.h +++ b/chrome/browser/history/top_sites_cache.h @@ -45,6 +45,10 @@ class TopSitesCache { bool GetPageThumbnail(const GURL& url, scoped_refptr<RefCountedBytes>* bytes); + // Fetches the thumbnail score for the specified url. Returns true if + // there is a thumbnail score for the specified url. + bool GetPageThumbnailScore(const GURL& url, ThumbnailScore* score); + // Returns the canonical URL for |url|. GURL GetCanonicalURL(const GURL& url); diff --git a/chrome/browser/history/top_sites_unittest.cc b/chrome/browser/history/top_sites_unittest.cc index f908646..b380a57 100644 --- a/chrome/browser/history/top_sites_unittest.cc +++ b/chrome/browser/history/top_sites_unittest.cc @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "app/l10n_util.h" #include "base/command_line.h" #include "base/file_util.h" +#include "base/format_macros.h" #include "base/path_service.h" #include "base/scoped_temp_dir.h" #include "base/string_util.h" @@ -25,13 +25,14 @@ #include "chrome/common/chrome_switches.h" #include "chrome/test/testing_profile.h" #include "chrome/tools/profiles/thumbnail-inl.h" -#include "gfx/codec/jpeg_codec.h" #include "googleurl/src/gurl.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkBitmap.h" +#include "ui/base/l10n/l10n_util.h" +#include "ui/gfx/codec/jpeg_codec.h" namespace history { @@ -132,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); @@ -382,6 +382,16 @@ class TopSitesMigrationTest : public TopSitesTest { const FilePath& db_path) { std::string sql; ASSERT_TRUE(file_util::ReadFileToString(sql_path, &sql)); + + // Replace the 'last_visit_time', 'visit_time', 'time_slot' values in this + // SQL with the current time. + int64 now = base::Time::Now().ToInternalValue(); + std::vector<std::string> sql_time; + sql_time.push_back(StringPrintf("%" PRId64, now)); // last_visit_time + sql_time.push_back(StringPrintf("%" PRId64, now)); // visit_time + sql_time.push_back(StringPrintf("%" PRId64, now)); // time_slot + sql = ReplaceStringPlaceholders(sql, sql_time, NULL); + sql::Connection connection; ASSERT_TRUE(connection.Open(db_path)); ASSERT_TRUE(connection.Execute(sql.c_str())); diff --git a/chrome/browser/history/url_database.cc b/chrome/browser/history/url_database.cc index dd3346b..24decc6 100644 --- a/chrome/browser/history/url_database.cc +++ b/chrome/browser/history/url_database.cc @@ -9,11 +9,11 @@ #include <string> #include <vector> -#include "app/l10n_util.h" #include "app/sql/statement.h" #include "base/utf_string_conversions.h" #include "chrome/common/url_constants.h" #include "googleurl/src/gurl.h" +#include "ui/base/l10n/l10n_util.h" namespace history { @@ -163,8 +163,11 @@ URLID URLDatabase::AddURLInternal(const history::URLRow& info, statement.BindInt(5, info.hidden() ? 1 : 0); statement.BindInt64(6, info.favicon_id()); - if (!statement.Run()) + if (!statement.Run()) { + VLOG(0) << "Failed to add url " << info.url().possibly_invalid_spec() + << " to table history.urls."; return 0; + } return GetDB().GetLastInsertRowId(); } diff --git a/chrome/browser/history/visit_database.cc b/chrome/browser/history/visit_database.cc index d0156c2..ace5dac 100644 --- a/chrome/browser/history/visit_database.cc +++ b/chrome/browser/history/visit_database.cc @@ -111,8 +111,11 @@ VisitID VisitDatabase::AddVisit(VisitRow* visit, VisitSource source) { "INSERT INTO visits " "(url, visit_time, from_visit, transition, segment_id, is_indexed) " "VALUES (?,?,?,?,?,?)")); - if (!statement) + if (!statement) { + VLOG(0) << "Failed to build visit insert statement: " + << "url_id = " << visit->url_id; return 0; + } statement.BindInt64(0, visit->url_id); statement.BindInt64(1, visit->visit_time.ToInternalValue()); @@ -120,8 +123,12 @@ VisitID VisitDatabase::AddVisit(VisitRow* visit, VisitSource source) { statement.BindInt64(3, visit->transition); statement.BindInt64(4, visit->segment_id); statement.BindInt64(5, visit->is_indexed); - if (!statement.Run()) + + if (!statement.Run()) { + VLOG(0) << "Failed to execute visit insert statement: " + << "url_id = " << visit->url_id; return 0; + } visit->visit_id = GetDB().GetLastInsertRowId(); @@ -129,13 +136,19 @@ VisitID VisitDatabase::AddVisit(VisitRow* visit, VisitSource source) { // Record the source of this visit when it is not browsed. sql::Statement statement1(GetDB().GetCachedStatement(SQL_FROM_HERE, "INSERT INTO visit_source (id, source) VALUES (?,?)")); - if (!statement1.is_valid()) + if (!statement1.is_valid()) { + VLOG(0) << "Failed to build visit_source insert statement: " + << "url_id = " << visit->visit_id; return 0; + } statement1.BindInt64(0, visit->visit_id); statement1.BindInt64(1, source); - if (!statement1.Run()) + if (!statement1.Run()) { + VLOG(0) << "Failed to execute visit_source insert statement: " + << "url_id = " << visit->visit_id; return 0; + } } return visit->visit_id; |