From a4feef8f23c9aed533bcd8b35e594fe3cf300a23 Mon Sep 17 00:00:00 2001 From: "deanm@google.com" Date: Thu, 2 Oct 2008 15:11:22 +0000 Subject: Port some more of chrome/ to Linux. Original review: http://codereview.chromium.org/4247 Patch from Pawel Hajdan Jr. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2793 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/history/history_types.h | 4 ++-- chrome/browser/history/history_types_unittest.cc | 24 +++++++++++----------- .../browser/history/in_memory_history_backend.cc | 1 - chrome/browser/history/snippet.h | 1 + chrome/browser/history/text_database.cc | 16 ++++++++------- chrome/browser/history/text_database_manager.cc | 4 ++-- chrome/browser/history/text_database_unittest.cc | 14 ++++++------- chrome/browser/history/thumbnail_database.h | 3 ++- chrome/browser/history/url_database.h | 2 +- chrome/browser/history/visit_tracker.cc | 4 ++-- chrome/browser/history/visitsegment_database.cc | 2 +- 11 files changed, 39 insertions(+), 36 deletions(-) (limited to 'chrome/browser/history') diff --git a/chrome/browser/history/history_types.h b/chrome/browser/history/history_types.h index 9224c2a..5ad53205 100644 --- a/chrome/browser/history/history_types.h +++ b/chrome/browser/history/history_types.h @@ -125,8 +125,8 @@ class URLRow { private: // This class writes directly into this structure and clears our dirty bits // when reading out of the DB. - friend URLDatabase; - friend HistoryBackend; + friend class URLDatabase; + friend class HistoryBackend; // Initializes all values that need initialization to their defaults. // This excludes objects which autoinitialize such as strings. diff --git a/chrome/browser/history/history_types_unittest.cc b/chrome/browser/history/history_types_unittest.cc index 2fbfd36..7365e53 100644 --- a/chrome/browser/history/history_types_unittest.cc +++ b/chrome/browser/history/history_types_unittest.cc @@ -75,13 +75,13 @@ TEST(HistoryQueryResult, DeleteRange) { // order. size_t match_count; const size_t* matches = results.MatchesForURL(url1, &match_count); - ASSERT_EQ(2, match_count); + ASSERT_EQ(2U, match_count); EXPECT_TRUE((matches[0] == 0 && matches[1] == 1) || (matches[0] == 1 && matches[1] == 0)); // Check the second one. matches = results.MatchesForURL(url2, &match_count); - ASSERT_EQ(1, match_count); + ASSERT_EQ(1U, match_count); EXPECT_TRUE(matches[0] == 2); // Delete the first instance of the first URL. @@ -90,15 +90,15 @@ TEST(HistoryQueryResult, DeleteRange) { // Check the two URLs. matches = results.MatchesForURL(url1, &match_count); - ASSERT_EQ(1, match_count); + ASSERT_EQ(1U, match_count); EXPECT_TRUE(matches[0] == 0); matches = results.MatchesForURL(url2, &match_count); - ASSERT_EQ(1, match_count); + ASSERT_EQ(1U, match_count); EXPECT_TRUE(matches[0] == 1); // Now delete everything and make sure it's deleted. results.DeleteRange(0, 1); - EXPECT_EQ(0, results.size()); + EXPECT_EQ(0U, results.size()); EXPECT_FALSE(results.MatchesForURL(url1, NULL)); EXPECT_FALSE(results.MatchesForURL(url2, NULL)); } @@ -113,18 +113,18 @@ TEST(HistoryQueryResult, ResultDeleteURL) { // Delete the first URL. results.DeleteURL(url1); CheckHistoryResultConsistency(results); - EXPECT_EQ(1, results.size()); + EXPECT_EQ(1U, results.size()); // The first one should be gone, and the second one should be at [0]. size_t match_count; EXPECT_FALSE(results.MatchesForURL(url1, NULL)); const size_t* matches = results.MatchesForURL(url2, &match_count); - ASSERT_EQ(1, match_count); + ASSERT_EQ(1U, match_count); EXPECT_TRUE(matches[0] == 0); // Delete the second URL, there should be nothing left. results.DeleteURL(url2); - EXPECT_EQ(0, results.size()); + EXPECT_EQ(0U, results.size()); EXPECT_FALSE(results.MatchesForURL(url2, NULL)); } @@ -146,23 +146,23 @@ TEST(HistoryQueryResult, AppendResults) { // There should be 3 results, the second one of the appendee should be // deleted because it was already in the first one and we said remove dupes. - ASSERT_EQ(4, results.size()); + ASSERT_EQ(4U, results.size()); // The first URL should be unchanged in the first two spots. size_t match_count; const size_t* matches = results.MatchesForURL(url1, &match_count); - ASSERT_EQ(2, match_count); + ASSERT_EQ(2U, match_count); EXPECT_TRUE((matches[0] == 0 && matches[1] == 1) || (matches[0] == 1 && matches[1] == 0)); // The second URL should be there once after that matches = results.MatchesForURL(url2, &match_count); - ASSERT_EQ(1, match_count); + ASSERT_EQ(1U, match_count); EXPECT_TRUE(matches[0] == 2); // The third one should be after that. matches = results.MatchesForURL(url3, &match_count); - ASSERT_EQ(1, match_count); + ASSERT_EQ(1U, match_count); EXPECT_TRUE(matches[0] == 3); } diff --git a/chrome/browser/history/in_memory_history_backend.cc b/chrome/browser/history/in_memory_history_backend.cc index 4868f68..5e942d6 100644 --- a/chrome/browser/history/in_memory_history_backend.cc +++ b/chrome/browser/history/in_memory_history_backend.cc @@ -5,7 +5,6 @@ #include "chrome/browser/history/in_memory_history_backend.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/history/history_database.h" #include "chrome/browser/history/history_notifications.h" #include "chrome/browser/history/in_memory_database.h" #include "chrome/browser/profile.h" diff --git a/chrome/browser/history/snippet.h b/chrome/browser/history/snippet.h index fb17a22..b741c6c 100644 --- a/chrome/browser/history/snippet.h +++ b/chrome/browser/history/snippet.h @@ -8,6 +8,7 @@ #ifndef CHROME_BROWSER_HISTORY_SNIPPET_H__ #define CHROME_BROWSER_HISTORY_SNIPPET_H__ +#include #include class Snippet { diff --git a/chrome/browser/history/text_database.cc b/chrome/browser/history/text_database.cc index 414b133..46fd8c0 100644 --- a/chrome/browser/history/text_database.cc +++ b/chrome/browser/history/text_database.cc @@ -115,15 +115,17 @@ TextDatabase::DBIdent TextDatabase::FileNameToID(const std::wstring& file_path){ // We don't actually check the prefix here. Since the file system could // be case insensitive in ways we can't predict (NTFS), checking could // potentially be the wrong thing to do. Instead, we just look for a suffix. - static const int kIDStringLength = 7; // Room for "xxxx-xx". + static const size_t kIDStringLength = 7; // Room for "xxxx-xx". if (file_name.length() < kIDStringLength) return 0; - const wchar_t* number_begin = - &file_name[file_name.length() - kIDStringLength]; + const std::wstring suffix(&file_name[file_name.length() - kIDStringLength]); - int year, month; - if (swscanf_s(number_begin, L"%d-%d", &year, &month) != 2) - return 0; // Unable to get both numbers. + if (suffix.length() != kIDStringLength || suffix[4] != L'-') { + return 0; + } + + int year = StringToInt(suffix.substr(0, 4)); + int month = StringToInt(suffix.substr(5, 2)); return year * 100 + month; } @@ -348,7 +350,7 @@ void TextDatabase::GetTextMatches(const std::string& query, Match& match = results->at(results->size() - 1); match.url.Swap(&url); - match.title = statement->column_string16(1); + match.title = UTF8ToWide(statement->column_string(1)); match.time = Time::FromInternalValue(statement->column_int64(2)); // Extract any matches in the title. diff --git a/chrome/browser/history/text_database_manager.cc b/chrome/browser/history/text_database_manager.cc index 9bb1ba7..e96aa5b 100644 --- a/chrome/browser/history/text_database_manager.cc +++ b/chrome/browser/history/text_database_manager.cc @@ -4,6 +4,7 @@ #include "chrome/browser/history/text_database_manager.h" +#include "base/compiler_specific.h" #include "base/file_util.h" #include "base/histogram.h" #include "base/logging.h" @@ -70,8 +71,7 @@ TextDatabaseManager::TextDatabaseManager(const std::wstring& dir, transaction_nesting_(0), db_cache_(DBCache::NO_AUTO_EVICT), present_databases_loaded_(false), -#pragma warning(suppress: 4355) // Okay to pass "this" here. - factory_(this) { + ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) { } TextDatabaseManager::~TextDatabaseManager() { diff --git a/chrome/browser/history/text_database_unittest.cc b/chrome/browser/history/text_database_unittest.cc index c041012..b16abe0 100644 --- a/chrome/browser/history/text_database_unittest.cc +++ b/chrome/browser/history/text_database_unittest.cc @@ -202,7 +202,7 @@ TEST_F(TextDatabaseTest, Query) { EXPECT_TRUE(unique_urls.empty()) << "Didn't ask for unique URLs"; // All 3 sites should be returned in order. - ASSERT_EQ(3, results.size()); + ASSERT_EQ(3U, results.size()); EXPECT_EQ(GURL(kURL1), results[2].url); EXPECT_EQ(GURL(kURL2), results[1].url); EXPECT_EQ(GURL(kURL3), results[0].url); @@ -217,9 +217,9 @@ TEST_F(TextDatabaseTest, Query) { EXPECT_EQ(UTF8ToWide(std::string(kTitle3)), results[0].title); // Should have no matches in the title. - EXPECT_EQ(0, results[0].title_match_positions.size()); - EXPECT_EQ(0, results[1].title_match_positions.size()); - EXPECT_EQ(0, results[2].title_match_positions.size()); + EXPECT_EQ(0U, results[0].title_match_positions.size()); + EXPECT_EQ(0U, results[1].title_match_positions.size()); + EXPECT_EQ(0U, results[2].title_match_positions.size()); // We don't want to be dependent on the exact snippet algorithm, but we know // since we searched for "COUNTTAG" which occurs at the beginning of each @@ -253,7 +253,7 @@ TEST_F(TextDatabaseTest, TimeRange) { EXPECT_TRUE(unique_urls.empty()) << "Didn't ask for unique URLs"; // The first and second should have been returned. - EXPECT_EQ(2, results.size()); + EXPECT_EQ(2U, results.size()); EXPECT_TRUE(ResultsHaveURL(results, kURL1)); EXPECT_TRUE(ResultsHaveURL(results, kURL2)); EXPECT_FALSE(ResultsHaveURL(results, kURL3)); @@ -273,7 +273,7 @@ TEST_F(TextDatabaseTest, TimeRange) { first_time_searched.ToInternalValue()); // Should have two results, the second and third. - EXPECT_EQ(2, results.size()); + EXPECT_EQ(2U, results.size()); EXPECT_FALSE(ResultsHaveURL(results, kURL1)); EXPECT_TRUE(ResultsHaveURL(results, kURL2)); EXPECT_TRUE(ResultsHaveURL(results, kURL3)); @@ -311,7 +311,7 @@ TEST_F(TextDatabaseTest, MaxCount) { EXPECT_TRUE(unique_urls.empty()) << "Didn't ask for unique URLs"; // There should be one result, the most recent one. - EXPECT_EQ(1, results.size()); + EXPECT_EQ(1U, results.size()); EXPECT_TRUE(ResultsHaveURL(results, kURL2)); // The max time considered should be the date of the returned item. diff --git a/chrome/browser/history/thumbnail_database.h b/chrome/browser/history/thumbnail_database.h index 15a81ee..f98d8e9 100644 --- a/chrome/browser/history/thumbnail_database.h +++ b/chrome/browser/history/thumbnail_database.h @@ -7,10 +7,11 @@ #include -#include "chrome/browser/history/history_database.h" #include "chrome/browser/history/history_types.h" #include "chrome/browser/history/url_database.h" // For DBCloseScoper. +#include "chrome/browser/meta_table_helper.h" #include "chrome/common/sqlite_compiled_statement.h" +#include "skia/include/SkBitmap.h" struct sqlite3; struct ThumbnailScore; diff --git a/chrome/browser/history/url_database.h b/chrome/browser/history/url_database.h index 4dfcdcc..745c7e3 100644 --- a/chrome/browser/history/url_database.h +++ b/chrome/browser/history/url_database.h @@ -230,7 +230,7 @@ class URLDatabase { bool MigrateFromVersion11ToVersion12(); protected: - friend VisitDatabase; + friend class VisitDatabase; // See HISTORY_URL_ROW_FIELDS below. static const char kURLRowFields[]; diff --git a/chrome/browser/history/visit_tracker.cc b/chrome/browser/history/visit_tracker.cc index dd32d54..26bcaf8 100644 --- a/chrome/browser/history/visit_tracker.cc +++ b/chrome/browser/history/visit_tracker.cc @@ -11,8 +11,8 @@ namespace history { // When the list gets longer than 'MaxItems', CleanupTransitionList will resize // the list down to 'ResizeTo' size. This is so we only do few block moves of // the data rather than constantly shuffle stuff around in the vector. -static const int kMaxItemsInTransitionList = 96; -static const int kResizeBigTransitionListTo = 64; +static const size_t kMaxItemsInTransitionList = 96; +static const size_t kResizeBigTransitionListTo = 64; COMPILE_ASSERT(kResizeBigTransitionListTo < kMaxItemsInTransitionList, max_items_must_be_larger_than_resize_to); diff --git a/chrome/browser/history/visitsegment_database.cc b/chrome/browser/history/visitsegment_database.cc index 2e07df6..8754018 100644 --- a/chrome/browser/history/visitsegment_database.cc +++ b/chrome/browser/history/visitsegment_database.cc @@ -240,7 +240,7 @@ void VisitSegmentDatabase::QuerySegmentUsage( // does as well. // How many results we return, as promised in the header file. - const int kResultCount = 9; + const size_t kResultCount = 9; // Gather all the segment scores: SQLITE_UNIQUE_STATEMENT(statement, GetStatementCache(), -- cgit v1.1