diff options
Diffstat (limited to 'chrome/browser/history')
22 files changed, 168 insertions, 162 deletions
diff --git a/chrome/browser/history/archived_database.cc b/chrome/browser/history/archived_database.cc index dd44a00..2c1f310 100644 --- a/chrome/browser/history/archived_database.cc +++ b/chrome/browser/history/archived_database.cc @@ -4,6 +4,7 @@ #include "base/string_util.h" #include "chrome/browser/history/archived_database.h" +#include "chrome/common/sqlite_utils.h" namespace history { @@ -22,12 +23,11 @@ ArchivedDatabase::ArchivedDatabase() ArchivedDatabase::~ArchivedDatabase() { } -bool ArchivedDatabase::Init(const std::wstring& file_name) { - // Open the history database, using the narrow version of open indicates to - // sqlite that we want the database to be in UTF-8 if it doesn't already - // exist. +bool ArchivedDatabase::Init(const FilePath& file_name) { + // OpenSqliteDb uses the narrow version of open, indicating to sqlite that we + // want the database to be in UTF-8 if it doesn't already exist. DCHECK(!db_) << "Already initialized!"; - if (sqlite3_open(WideToUTF8(file_name).c_str(), &db_) != SQLITE_OK) + if (OpenSqliteDb(file_name, &db_) != SQLITE_OK) return false; statement_cache_ = new SqliteStatementCache(db_); DBCloseScoper scoper(&db_, &statement_cache_); diff --git a/chrome/browser/history/archived_database.h b/chrome/browser/history/archived_database.h index 719fdf5..5693091 100644 --- a/chrome/browser/history/archived_database.h +++ b/chrome/browser/history/archived_database.h @@ -2,10 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_HISTORY_ARCHIVED_DATABASE_H__ -#define CHROME_BROWSER_HISTORY_ARCHIVED_DATABASE_H__ +#ifndef CHROME_BROWSER_HISTORY_ARCHIVED_DATABASE_H_ +#define CHROME_BROWSER_HISTORY_ARCHIVED_DATABASE_H_ #include "base/basictypes.h" +#include "base/file_path.h" #include "chrome/browser/history/download_database.h" #include "chrome/browser/history/url_database.h" #include "chrome/browser/history/visit_database.h" @@ -29,7 +30,7 @@ class ArchivedDatabase : public URLDatabase, // Initializes the database connection. This must return true before any other // functions on this class are called. - bool Init(const std::wstring& file_name); + bool Init(const FilePath& file_name); // Transactions on the database. We support nested transactions and only // commit when the outermost one is committed (sqlite doesn't support true @@ -64,9 +65,9 @@ class ArchivedDatabase : public URLDatabase, MetaTableHelper meta_table_; - DISALLOW_EVIL_CONSTRUCTORS(ArchivedDatabase); + DISALLOW_COPY_AND_ASSIGN(ArchivedDatabase); }; } // namespace history -#endif // CHROME_BROWSER_HISTORY_ARCHIVED_DATABASE_H__ +#endif // CHROME_BROWSER_HISTORY_ARCHIVED_DATABASE_H_ diff --git a/chrome/browser/history/expire_history_backend_unittest.cc b/chrome/browser/history/expire_history_backend_unittest.cc index 316d988..25e45f6 100644 --- a/chrome/browser/history/expire_history_backend_unittest.cc +++ b/chrome/browser/history/expire_history_backend_unittest.cc @@ -4,6 +4,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" +#include "base/file_path.h" #include "base/file_util.h" #include "base/gfx/jpeg_codec.h" #include "base/path_service.h" @@ -111,21 +112,21 @@ class ExpireHistoryTest : public testing::Test, FilePath history_name = dir_.Append(kHistoryFile); main_db_.reset(new HistoryDatabase); - if (main_db_->Init(history_name.ToWStringHack(), std::wstring()) != + if (main_db_->Init(history_name, FilePath()) != INIT_OK) main_db_.reset(); FilePath archived_name = dir_.Append(kArchivedHistoryFile); archived_db_.reset(new ArchivedDatabase); - if (!archived_db_->Init(archived_name.ToWStringHack())) + if (!archived_db_->Init(archived_name)) archived_db_.reset(); FilePath thumb_name = dir_.Append(kThumbnailFile); thumb_db_.reset(new ThumbnailDatabase); - if (thumb_db_->Init(thumb_name.ToWStringHack(), NULL) != INIT_OK) + if (thumb_db_->Init(thumb_name, NULL) != INIT_OK) thumb_db_.reset(); - text_db_.reset(new TextDatabaseManager(dir_.ToWStringHack(), + text_db_.reset(new TextDatabaseManager(dir_, main_db_.get(), main_db_.get())); if (!text_db_->Init(NULL)) text_db_.reset(); @@ -410,7 +411,7 @@ TEST_F(ExpireHistoryTest, DeleteURLAndFavicon) { // it just like the test set-up did. text_db_.reset(); EXPECT_TRUE(IsStringInFile(fts_filename, "goats")); - text_db_.reset(new TextDatabaseManager(dir_.ToWStringHack(), + text_db_.reset(new TextDatabaseManager(dir_, main_db_.get(), main_db_.get())); ASSERT_TRUE(text_db_->Init(NULL)); expirer_.SetDatabases(main_db_.get(), archived_db_.get(), thumb_db_.get(), @@ -423,7 +424,7 @@ TEST_F(ExpireHistoryTest, DeleteURLAndFavicon) { // doesn't remove it from the file, we want to be sure we're doing the latter. text_db_.reset(); EXPECT_FALSE(IsStringInFile(fts_filename, "goats")); - text_db_.reset(new TextDatabaseManager(dir_.ToWStringHack(), + text_db_.reset(new TextDatabaseManager(dir_, main_db_.get(), main_db_.get())); ASSERT_TRUE(text_db_->Init(NULL)); expirer_.SetDatabases(main_db_.get(), archived_db_.get(), thumb_db_.get(), diff --git a/chrome/browser/history/history.cc b/chrome/browser/history/history.cc index 576203f..33eb4d9 100644 --- a/chrome/browser/history/history.cc +++ b/chrome/browser/history/history.cc @@ -135,7 +135,7 @@ bool HistoryService::Init(const FilePath& history_dir, // Create the history backend. scoped_refptr<HistoryBackend> backend( - new HistoryBackend(history_dir.ToWStringHack(), + new HistoryBackend(history_dir, new BackendDelegate(this), bookmark_service)); history_backend_.swap(backend); diff --git a/chrome/browser/history/history_backend.cc b/chrome/browser/history/history_backend.cc index 861aed5..757ad85 100644 --- a/chrome/browser/history/history_backend.cc +++ b/chrome/browser/history/history_backend.cc @@ -166,7 +166,7 @@ class HistoryBackend::URLQuerier { // HistoryBackend -------------------------------------------------------------- -HistoryBackend::HistoryBackend(const std::wstring& history_dir, +HistoryBackend::HistoryBackend(const FilePath& history_dir, Delegate* delegate, BookmarkService* bookmark_service) : delegate_(delegate), @@ -238,16 +238,12 @@ void HistoryBackend::NotifyRenderProcessHostDestruction(const void* host) { tracker_.NotifyRenderProcessHostDestruction(host); } -std::wstring HistoryBackend::GetThumbnailFileName() const { - std::wstring thumbnail_name = history_dir_; - file_util::AppendToPath(&thumbnail_name, chrome::kThumbnailsFilename); - return thumbnail_name; +FilePath HistoryBackend::GetThumbnailFileName() const { + return history_dir_.Append(chrome::kThumbnailsFilename); } -std::wstring HistoryBackend::GetArchivedFileName() const { - std::wstring archived_name = history_dir_; - file_util::AppendToPath(&archived_name, chrome::kArchivedHistoryFilename); - return archived_name; +FilePath HistoryBackend::GetArchivedFileName() const { + return history_dir_.Append(chrome::kArchivedHistoryFilename); } SegmentID HistoryBackend::GetLastSegmentID(VisitID from_visit) { @@ -476,14 +472,11 @@ void HistoryBackend::InitImpl() { // Compute the file names. Note that the index file can be removed when the // text db manager is finished being hooked up. - std::wstring history_name = history_dir_; - file_util::AppendToPath(&history_name, - FilePath(chrome::kHistoryFilename).ToWStringHack()); - std::wstring thumbnail_name = GetThumbnailFileName(); - std::wstring archived_name = GetArchivedFileName(); - std::wstring tmp_bookmarks_file = history_dir_; - file_util::AppendToPath(&tmp_bookmarks_file, - FilePath(chrome::kHistoryBookmarksFileName).ToWStringHack()); + FilePath history_name = history_dir_.Append(chrome::kHistoryFilename); + FilePath thumbnail_name = GetThumbnailFileName(); + FilePath archived_name = GetArchivedFileName(); + FilePath tmp_bookmarks_file = history_dir_.Append( + chrome::kHistoryBookmarksFileName); // History database. db_.reset(new HistoryDatabase()); @@ -507,7 +500,7 @@ void HistoryBackend::InitImpl() { // Fill the in-memory database and send it back to the history service on the // main thread. InMemoryHistoryBackend* mem_backend = new InMemoryHistoryBackend; - if (mem_backend->Init(history_name)) + if (mem_backend->Init(history_name.ToWStringHack())) delegate_->SetInMemoryBackend(mem_backend); // Takes ownership of pointer. else delete mem_backend; // Error case, run without the in-memory DB. @@ -1733,7 +1726,7 @@ void HistoryBackend::DeleteAllHistory() { if (archived_db_.get()) { // Close the database and delete the file. archived_db_.reset(); - std::wstring archived_file_name = GetArchivedFileName(); + FilePath archived_file_name = GetArchivedFileName(); file_util::Delete(archived_file_name, false); // Now re-initialize the database (which may fail). diff --git a/chrome/browser/history/history_backend.h b/chrome/browser/history/history_backend.h index 5c23991..7a66008 100644 --- a/chrome/browser/history/history_backend.h +++ b/chrome/browser/history/history_backend.h @@ -2,12 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_HISTORY_HISTORY_BACKEND_H__ -#define CHROME_BROWSER_HISTORY_HISTORY_BACKEND_H__ +#ifndef CHROME_BROWSER_HISTORY_HISTORY_BACKEND_H_ +#define CHROME_BROWSER_HISTORY_HISTORY_BACKEND_H_ #include <utility> #include "base/gfx/rect.h" +#include "base/file_path.h" #include "base/lock.h" #include "base/scoped_ptr.h" #include "base/task.h" @@ -95,7 +96,7 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>, // may be NULL. // // This constructor is fast and does no I/O, so can be called at any time. - HistoryBackend(const std::wstring& history_dir, + HistoryBackend(const FilePath& history_dir, Delegate* delegate, BookmarkService* bookmark_service); @@ -263,8 +264,8 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>, friend class ::TestingProfile; // Computes the name of the specified database on disk. - std::wstring GetThumbnailFileName() const; - std::wstring GetArchivedFileName() const; + FilePath GetThumbnailFileName() const; + FilePath GetArchivedFileName() const; class URLQuerier; friend class URLQuerier; @@ -410,7 +411,7 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>, scoped_ptr<Delegate> delegate_; // Directory where database files will be stored. - std::wstring history_dir_; + FilePath history_dir_; // The history/thumbnail databases. Either MAY BE NULL if the database could // not be opened, all users must first check for NULL and return immediately @@ -489,9 +490,9 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>, // history data from us. Can be NULL if there are no listeners. scoped_ptr<HistoryPublisher> history_publisher_; - DISALLOW_EVIL_CONSTRUCTORS(HistoryBackend); + DISALLOW_COPY_AND_ASSIGN(HistoryBackend); }; } // namespace history -#endif // CHROME_BROWSER_HISTORY_HISTORY_BACKEND_H__ +#endif // CHROME_BROWSER_HISTORY_HISTORY_BACKEND_H_ diff --git a/chrome/browser/history/history_backend_unittest.cc b/chrome/browser/history/history_backend_unittest.cc index b14da22..f64c109 100644 --- a/chrome/browser/history/history_backend_unittest.cc +++ b/chrome/browser/history/history_backend_unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/file_path.h" #include "base/file_util.h" #include "base/gfx/jpeg_codec.h" #include "base/path_service.h" @@ -83,7 +84,8 @@ class HistoryBackendTest : public testing::Test { // testing::Test virtual void SetUp() { - if (!file_util::CreateNewTempDirectory(L"BackendTest", &test_dir_)) + if (!file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("BackendTest"), + &test_dir_)) return; backend_ = new HistoryBackend(test_dir_, new HistoryBackendTestDelegate(this), @@ -112,7 +114,7 @@ class HistoryBackendTest : public testing::Test { } MessageLoop message_loop_; - std::wstring test_dir_; + FilePath test_dir_; }; void HistoryBackendTestDelegate::SetInMemoryBackend( diff --git a/chrome/browser/history/history_database.cc b/chrome/browser/history/history_database.cc index 2ca1770..db63a34 100644 --- a/chrome/browser/history/history_database.cc +++ b/chrome/browser/history/history_database.cc @@ -8,10 +8,7 @@ #include <set> #include "base/string_util.h" - -// Only needed for migration. -#include "base/file_util.h" -#include "chrome/browser/history/text_database_manager.h" +#include "chrome/common/sqlite_utils.h" namespace history { @@ -31,13 +28,12 @@ HistoryDatabase::HistoryDatabase() HistoryDatabase::~HistoryDatabase() { } -InitStatus HistoryDatabase::Init(const std::wstring& history_name, - const std::wstring& bookmarks_path) { - // Open the history database, using the narrow version of open indicates to - // sqlite that we want the database to be in UTF-8 if it doesn't already - // exist. +InitStatus HistoryDatabase::Init(const FilePath& history_name, + const FilePath& bookmarks_path) { + // OpenSqliteDb uses the narrow version of open, indicating to sqlite that we + // want the database to be in UTF-8 if it doesn't already exist. DCHECK(!db_) << "Already initialized!"; - if (sqlite3_open(WideToUTF8(history_name).c_str(), &db_) != SQLITE_OK) + if (OpenSqliteDb(history_name, &db_) != SQLITE_OK) return INIT_FAILURE; statement_cache_ = new SqliteStatementCache; DBCloseScoper scoper(&db_, &statement_cache_); @@ -199,7 +195,7 @@ SqliteStatementCache& HistoryDatabase::GetStatementCache() { // Migration ------------------------------------------------------------------- InitStatus HistoryDatabase::EnsureCurrentVersion( - const std::wstring& tmp_bookmarks_path) { + const FilePath& tmp_bookmarks_path) { // We can't read databases newer than we were designed for. if (meta_table_.GetCompatibleVersionNumber() > kCurrentVersionNumber) { LOG(WARNING) << "History database is too new."; diff --git a/chrome/browser/history/history_database.h b/chrome/browser/history/history_database.h index a5819c5..5791c07 100644 --- a/chrome/browser/history/history_database.h +++ b/chrome/browser/history/history_database.h @@ -2,9 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_HISTORY_HISTORY_DATABASE_H__ -#define CHROME_BROWSER_HISTORY_HISTORY_DATABASE_H__ +#ifndef CHROME_BROWSER_HISTORY_HISTORY_DATABASE_H_ +#define CHROME_BROWSER_HISTORY_HISTORY_DATABASE_H_ +#include "base/file_path.h" #include "chrome/browser/history/download_database.h" #include "chrome/browser/history/history.h" #include "chrome/browser/history/history_types.h" @@ -62,8 +63,8 @@ class HistoryDatabase : public DownloadDatabase, // Must call this function to complete initialization. Will return true on // success. On false, no other function should be called. You may want to call // BeginExclusiveMode after this when you are ready. - InitStatus Init(const std::wstring& history_name, - const std::wstring& tmp_bookmarks_path); + InitStatus Init(const FilePath& history_name, + const FilePath& tmp_bookmarks_path); // Call to set the mode on the database to exclusive. The default locking mode // is "normal" but we want to run in exclusive mode for slightly better @@ -143,7 +144,7 @@ class HistoryDatabase : public DownloadDatabase, // // This assumes it is called from the init function inside a transaction. It // may commit the transaction and start a new one if migration requires it. - InitStatus EnsureCurrentVersion(const std::wstring& tmp_bookmarks_path); + InitStatus EnsureCurrentVersion(const FilePath& tmp_bookmarks_path); // --------------------------------------------------------------------------- @@ -162,9 +163,9 @@ class HistoryDatabase : public DownloadDatabase, MetaTableHelper meta_table_; - DISALLOW_EVIL_CONSTRUCTORS(HistoryDatabase); + DISALLOW_COPY_AND_ASSIGN(HistoryDatabase); }; } // history -#endif // CHROME_BROWSER_HISTORY_HISTORY_DATABASE_H__ +#endif // CHROME_BROWSER_HISTORY_HISTORY_DATABASE_H_ diff --git a/chrome/browser/history/history_querying_unittest.cc b/chrome/browser/history/history_querying_unittest.cc index fe9a819..72c3825 100644 --- a/chrome/browser/history/history_querying_unittest.cc +++ b/chrome/browser/history/history_querying_unittest.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "base/basictypes.h" +#include "base/file_path.h" #include "base/file_util.h" #include "base/path_service.h" #include "chrome/browser/history/history.h" @@ -83,13 +84,14 @@ class HistoryQueryTest : public testing::Test { private: virtual void SetUp() { - PathService::Get(base::DIR_TEMP, &history_dir_); - file_util::AppendToPath(&history_dir_, L"HistoryTest"); + FilePath temp_dir; + PathService::Get(base::DIR_TEMP, &temp_dir); + history_dir_ = temp_dir.AppendASCII("HistoryTest"); file_util::Delete(history_dir_, true); file_util::CreateDirectory(history_dir_); history_ = new HistoryService; - if (!history_->Init(FilePath::FromWStringHack(history_dir_), NULL)) { + if (!history_->Init(history_dir_, NULL)) { history_ = NULL; // Tests should notice this NULL ptr & fail. return; } @@ -129,7 +131,7 @@ class HistoryQueryTest : public testing::Test { MessageLoop message_loop_; - std::wstring history_dir_; + FilePath history_dir_; CancelableRequestConsumer consumer_; diff --git a/chrome/browser/history/history_unittest.cc b/chrome/browser/history/history_unittest.cc index 67c6ee5..107d845 100644 --- a/chrome/browser/history/history_unittest.cc +++ b/chrome/browser/history/history_unittest.cc @@ -21,6 +21,7 @@ #include <algorithm> #include "base/basictypes.h" +#include "base/file_path.h" #include "base/file_util.h" #include "base/gfx/jpeg_codec.h" #include "base/message_loop.h" @@ -151,8 +152,9 @@ class HistoryTest : public testing::Test { // testing::Test virtual void SetUp() { - PathService::Get(base::DIR_TEMP, &history_dir_); - file_util::AppendToPath(&history_dir_, L"HistoryTest"); + FilePath temp_dir; + PathService::Get(base::DIR_TEMP, &temp_dir); + history_dir_ = temp_dir.AppendASCII("HistoryTest"); file_util::Delete(history_dir_, true); file_util::CreateDirectory(history_dir_); } @@ -259,7 +261,7 @@ class HistoryTest : public testing::Test { scoped_refptr<HistoryService> history_service_; // names of the database files - std::wstring history_dir_; + FilePath history_dir_; // Set by the thumbnail callback when we get data, you should be sure to // clear this before issuing a thumbnail request. @@ -376,7 +378,7 @@ TEST_F(HistoryTest, ClearBrowsingData_Downloads) { TEST_F(HistoryTest, AddPage) { scoped_refptr<HistoryService> history(new HistoryService); history_service_ = history; - ASSERT_TRUE(history->Init(FilePath::FromWStringHack(history_dir_), NULL)); + ASSERT_TRUE(history->Init(history_dir_, NULL)); // Add the page once from a child frame. const GURL test_url("http://www.google.com/"); @@ -400,7 +402,7 @@ TEST_F(HistoryTest, AddPage) { TEST_F(HistoryTest, AddPageSameTimes) { scoped_refptr<HistoryService> history(new HistoryService); history_service_ = history; - ASSERT_TRUE(history->Init(FilePath::FromWStringHack(history_dir_), NULL)); + ASSERT_TRUE(history->Init(history_dir_, NULL)); Time now = Time::Now(); const GURL test_urls[] = { @@ -440,7 +442,7 @@ TEST_F(HistoryTest, AddPageSameTimes) { TEST_F(HistoryTest, AddRedirect) { scoped_refptr<HistoryService> history(new HistoryService); history_service_ = history; - ASSERT_TRUE(history->Init(FilePath::FromWStringHack(history_dir_), NULL)); + ASSERT_TRUE(history->Init(history_dir_, NULL)); const char* first_sequence[] = { "http://first.page/", @@ -511,7 +513,7 @@ TEST_F(HistoryTest, AddRedirect) { TEST_F(HistoryTest, Typed) { scoped_refptr<HistoryService> history(new HistoryService); history_service_ = history; - ASSERT_TRUE(history->Init(FilePath::FromWStringHack(history_dir_), NULL)); + ASSERT_TRUE(history->Init(history_dir_, NULL)); // Add the page once as typed. const GURL test_url("http://www.google.com/"); @@ -554,7 +556,7 @@ TEST_F(HistoryTest, Typed) { TEST_F(HistoryTest, SetTitle) { scoped_refptr<HistoryService> history(new HistoryService); history_service_ = history; - ASSERT_TRUE(history->Init(FilePath::FromWStringHack(history_dir_), NULL)); + ASSERT_TRUE(history->Init(history_dir_, NULL)); // Add a URL. const GURL existing_url("http://www.google.com/"); @@ -585,7 +587,7 @@ TEST_F(HistoryTest, Segments) { scoped_refptr<HistoryService> history(new HistoryService); history_service_ = history; - ASSERT_TRUE(history->Init(FilePath::FromWStringHack(history_dir_), NULL)); + ASSERT_TRUE(history->Init(history_dir_, NULL)); static const void* scope = static_cast<void*>(this); @@ -651,7 +653,7 @@ TEST_F(HistoryTest, Segments) { TEST_F(HistoryTest, Thumbnails) { scoped_refptr<HistoryService> history(new HistoryService); history_service_ = history; - ASSERT_TRUE(history->Init(FilePath::FromWStringHack(history_dir_), NULL)); + ASSERT_TRUE(history->Init(history_dir_, NULL)); scoped_ptr<SkBitmap> thumbnail( JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); @@ -716,17 +718,17 @@ TEST_F(HistoryTest, Thumbnails) { // See test/data/profiles/typical_history/README.txt for instructions on // how to up the version. TEST(HistoryProfileTest, TypicalProfileVersion) { - std::wstring file; + FilePath file; ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &file)); - file_util::AppendToPath(&file, L"profiles"); - file_util::AppendToPath(&file, L"typical_history"); - file_util::AppendToPath(&file, L"Default"); - file_util::AppendToPath(&file, L"History"); + file = file.AppendASCII("profiles"); + file = file.AppendASCII("typical_history"); + file = file.AppendASCII("Default"); + file = file.AppendASCII("History"); int cur_version = HistoryDatabase::GetCurrentVersion(); sqlite3* db; - ASSERT_EQ(SQLITE_OK, sqlite3_open(WideToUTF8(file).c_str(), &db)); + ASSERT_EQ(SQLITE_OK, OpenSqliteDb(file, &db)); { SQLStatement s; @@ -800,7 +802,7 @@ const int HistoryDBTaskImpl::kWantInvokeCount = 2; TEST_F(HistoryTest, HistoryDBTask) { CancelableRequestConsumerT<int, 0> request_consumer; HistoryService* history = new HistoryService(); - ASSERT_TRUE(history->Init(FilePath::FromWStringHack(history_dir_), NULL)); + ASSERT_TRUE(history->Init(history_dir_, NULL)); scoped_refptr<HistoryDBTaskImpl> task(new HistoryDBTaskImpl()); history_service_ = history; history->ScheduleDBTask(task.get(), &request_consumer); @@ -818,7 +820,7 @@ TEST_F(HistoryTest, HistoryDBTask) { TEST_F(HistoryTest, HistoryDBTaskCanceled) { CancelableRequestConsumerT<int, 0> request_consumer; HistoryService* history = new HistoryService(); - ASSERT_TRUE(history->Init(FilePath::FromWStringHack(history_dir_), NULL)); + ASSERT_TRUE(history->Init(history_dir_, NULL)); scoped_refptr<HistoryDBTaskImpl> task(new HistoryDBTaskImpl()); history_service_ = history; history->ScheduleDBTask(task.get(), &request_consumer); diff --git a/chrome/browser/history/starred_url_database.cc b/chrome/browser/history/starred_url_database.cc index ecaa72c..a2b1321c 100644 --- a/chrome/browser/history/starred_url_database.cc +++ b/chrome/browser/history/starred_url_database.cc @@ -91,7 +91,7 @@ StarredURLDatabase::StarredURLDatabase() { StarredURLDatabase::~StarredURLDatabase() { } -bool StarredURLDatabase::MigrateBookmarksToFile(const std::wstring& path) { +bool StarredURLDatabase::MigrateBookmarksToFile(const FilePath& path) { if (!DoesSqliteTableExist(GetDB(), "starred")) return true; @@ -537,7 +537,7 @@ bool StarredURLDatabase::Move(StarredNode* source, StarredNode* new_parent) { return true; } -bool StarredURLDatabase::MigrateBookmarksToFileImpl(const std::wstring& path) { +bool StarredURLDatabase::MigrateBookmarksToFileImpl(const FilePath& path) { std::vector<history::StarredEntry> entries; if (!GetAllStarredEntries(&entries)) return false; diff --git a/chrome/browser/history/starred_url_database.h b/chrome/browser/history/starred_url_database.h index 434fab7..174e1da 100644 --- a/chrome/browser/history/starred_url_database.h +++ b/chrome/browser/history/starred_url_database.h @@ -2,13 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_HISTORY_STARRED_URL_DATABASE_H__ -#define CHROME_BROWSER_HISTORY_STARRED_URL_DATABASE_H__ +#ifndef CHROME_BROWSER_HISTORY_STARRED_URL_DATABASE_H_ +#define CHROME_BROWSER_HISTORY_STARRED_URL_DATABASE_H_ #include <map> #include <set> #include "base/basictypes.h" +#include "base/file_path.h" #include "chrome/browser/history/history_types.h" #include "chrome/browser/history/url_database.h" #include "chrome/views/controls/tree/tree_node_model.h" @@ -36,7 +37,7 @@ class StarredURLDatabase : public URLDatabase { FRIEND_TEST(HistoryTest, CreateStarGroup); // Writes bookmarks to the specified file. - bool MigrateBookmarksToFile(const std::wstring& path); + bool MigrateBookmarksToFile(const FilePath& path); // Returns the database and statement cache for the functions in this // interface. The decendent of this class implements these functions to @@ -175,11 +176,11 @@ class StarredURLDatabase : public URLDatabase { // Does the work of migrating bookmarks to a temporary file that // BookmarkStorage will read from. - bool MigrateBookmarksToFileImpl(const std::wstring& path); + bool MigrateBookmarksToFileImpl(const FilePath& path); - DISALLOW_EVIL_CONSTRUCTORS(StarredURLDatabase); + DISALLOW_COPY_AND_ASSIGN(StarredURLDatabase); }; } // namespace history -#endif // CHROME_BROWSER_HISTORY_STARRED_URL_DATABASE_H__ +#endif // CHROME_BROWSER_HISTORY_STARRED_URL_DATABASE_H_ diff --git a/chrome/browser/history/starred_url_database_unittest.cc b/chrome/browser/history/starred_url_database_unittest.cc index 12610aa..1c97927 100644 --- a/chrome/browser/history/starred_url_database_unittest.cc +++ b/chrome/browser/history/starred_url_database_unittest.cc @@ -77,8 +77,7 @@ class StarredURLDatabaseTest : public testing::Test, FILE_PATH_LITERAL("History_with_empty_starred")); file_util::CopyFile(old_history_path, db_file_); - EXPECT_EQ(SQLITE_OK, - sqlite3_open(WideToUTF8(db_file_.ToWStringHack()).c_str(), &db_)); + EXPECT_EQ(SQLITE_OK, OpenSqliteDb(db_file_, &db_)); statement_cache_ = new SqliteStatementCache(db_); // Initialize the tables for this test. diff --git a/chrome/browser/history/text_database_manager.cc b/chrome/browser/history/text_database_manager.cc index 1e3687f..51cc6a8 100644 --- a/chrome/browser/history/text_database_manager.cc +++ b/chrome/browser/history/text_database_manager.cc @@ -67,10 +67,10 @@ bool TextDatabaseManager::PageInfo::Expired(TimeTicks now) const { // TextDatabaseManager --------------------------------------------------------- -TextDatabaseManager::TextDatabaseManager(const std::wstring& dir, +TextDatabaseManager::TextDatabaseManager(const FilePath& dir, URLDatabase* url_database, VisitDatabase* visit_database) - : dir_(FilePath::FromWStringHack(dir)), + : dir_(dir), db_(NULL), url_database_(url_database), visit_database_(visit_database), diff --git a/chrome/browser/history/text_database_manager.h b/chrome/browser/history/text_database_manager.h index e1d5d2e..ee96687 100644 --- a/chrome/browser/history/text_database_manager.h +++ b/chrome/browser/history/text_database_manager.h @@ -2,13 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_HISTORY_TEXT_DATABASE_MANAGER_H__ -#define CHROME_BROWSER_HISTORY_TEXT_DATABASE_MANAGER_H__ +#ifndef CHROME_BROWSER_HISTORY_TEXT_DATABASE_MANAGER_H_ +#define CHROME_BROWSER_HISTORY_TEXT_DATABASE_MANAGER_H_ #include <set> #include <vector> #include "base/basictypes.h" +#include "base/file_path.h" #include "base/task.h" #include "chrome/browser/history/history_types.h" #include "chrome/browser/history/text_database.h" @@ -72,7 +73,7 @@ class TextDatabaseManager { // The visit database is a pointer owned by the caller for the main database // (of recent visits). The visit database will be updated to refer to the // added text database entries. - explicit TextDatabaseManager(const std::wstring& dir, + explicit TextDatabaseManager(const FilePath& dir, URLDatabase* url_database, VisitDatabase* visit_database); ~TextDatabaseManager(); @@ -301,9 +302,9 @@ class TextDatabaseManager { // data from us. const HistoryPublisher* history_publisher_; - DISALLOW_EVIL_CONSTRUCTORS(TextDatabaseManager); + DISALLOW_COPY_AND_ASSIGN(TextDatabaseManager); }; } // namespace history -#endif // CHROME_BROWSER_HISTORY_TEXT_DATABASE_MANAGER_H__ +#endif // CHROME_BROWSER_HISTORY_TEXT_DATABASE_MANAGER_H_ diff --git a/chrome/browser/history/text_database_manager_unittest.cc b/chrome/browser/history/text_database_manager_unittest.cc index 14d2b90..ad7f70e 100644 --- a/chrome/browser/history/text_database_manager_unittest.cc +++ b/chrome/browser/history/text_database_manager_unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/file_path.h" #include "base/file_util.h" #include "base/message_loop.h" #include "chrome/browser/history/text_database_manager.h" @@ -35,27 +36,6 @@ const char* kURL5 = "http://www.google.com/uiop"; const wchar_t* kTitle5 = L"Google cinq"; const wchar_t* kBody5 = L"FOO page one."; -class TextDatabaseManagerTest : public testing::Test { - public: - // Called manually by the test so it can report failure to initialize. - bool Init() { - return file_util::CreateNewTempDirectory(L"TestSearchTest", &dir_); - } - - protected: - void SetUp() { - } - - void TearDown() { - file_util::Delete(dir_, true); - } - - MessageLoop message_loop_; - - // Directory containing the databases. - std::wstring dir_; -}; - // This provides a simple implementation of a URL+VisitDatabase using an // in-memory sqlite connection. The text database manager expects to be able to // update the visit database to keep in sync. @@ -164,6 +144,28 @@ bool ResultsHaveURL(const std::vector<TextDatabase::Match>& results, } // namespace +class TextDatabaseManagerTest : public testing::Test { + public: + // Called manually by the test so it can report failure to initialize. + bool Init() { + return file_util::CreateNewTempDirectory( + FILE_PATH_LITERAL("TestSearchTest"), &dir_); + } + + protected: + void SetUp() { + } + + void TearDown() { + file_util::Delete(dir_, true); + } + + MessageLoop message_loop_; + + // Directory containing the databases. + FilePath dir_; +}; + // Tests basic querying. TEST_F(TextDatabaseManagerTest, InsertQuery) { ASSERT_TRUE(Init()); diff --git a/chrome/browser/history/thumbnail_database.cc b/chrome/browser/history/thumbnail_database.cc index dd59019..fcd5332 100644 --- a/chrome/browser/history/thumbnail_database.cc +++ b/chrome/browser/history/thumbnail_database.cc @@ -33,13 +33,13 @@ ThumbnailDatabase::~ThumbnailDatabase() { // The DBCloseScoper will delete the DB and the cache. } -InitStatus ThumbnailDatabase::Init(const std::wstring& db_name, +InitStatus ThumbnailDatabase::Init(const FilePath& db_name, const HistoryPublisher* history_publisher) { history_publisher_ = history_publisher; - // Open the thumbnail database, using the narrow version of open so that - // the DB is in UTF-8. - if (sqlite3_open(WideToUTF8(db_name).c_str(), &db_) != SQLITE_OK) + // OpenSqliteDb uses the narrow version of open, so the resulting DB is in + // UTF-8. + if (OpenSqliteDb(db_name, &db_) != SQLITE_OK) return INIT_FAILURE; // Set the database page size to something larger to give us diff --git a/chrome/browser/history/thumbnail_database.h b/chrome/browser/history/thumbnail_database.h index 1fef211..e774a86 100644 --- a/chrome/browser/history/thumbnail_database.h +++ b/chrome/browser/history/thumbnail_database.h @@ -2,11 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_HISTORY_THUMBNAIL_DATABASE_H__ -#define CHROME_BROWSER_HISTORY_THUMBNAIL_DATABASE_H__ +#ifndef CHROME_BROWSER_HISTORY_THUMBNAIL_DATABASE_H_ +#define CHROME_BROWSER_HISTORY_THUMBNAIL_DATABASE_H_ #include <vector> +#include "base/file_path.h" #include "chrome/browser/history/history_types.h" #include "chrome/browser/history/url_database.h" // For DBCloseScoper. #include "chrome/browser/meta_table_helper.h" @@ -38,7 +39,7 @@ class ThumbnailDatabase { // Must be called after creation but before any other methods are called. // When not INIT_OK, no other functions should be called. - InitStatus Init(const std::wstring& db_name, + InitStatus Init(const FilePath& db_name, const HistoryPublisher* history_publisher); // Transactions on the database. @@ -174,4 +175,4 @@ class ThumbnailDatabase { } // namespace history -#endif // CHROME_BROWSER_HISTORY_THUMBNAIL_DATABASE_H__ +#endif // CHROME_BROWSER_HISTORY_THUMBNAIL_DATABASE_H_ diff --git a/chrome/browser/history/thumbnail_database_unittest.cc b/chrome/browser/history/thumbnail_database_unittest.cc index 9890aa1..620bd08 100644 --- a/chrome/browser/history/thumbnail_database_unittest.cc +++ b/chrome/browser/history/thumbnail_database_unittest.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "base/basictypes.h" +#include "base/file_path.h" #include "base/file_util.h" #include "base/gfx/jpeg_codec.h" #include "base/path_service.h" @@ -21,6 +22,22 @@ namespace history { namespace { +// data we'll put into the thumbnail database +static const unsigned char blob1[] = + "12346102356120394751634516591348710478123649165419234519234512349134"; +static const unsigned char blob2[] = + "goiwuegrqrcomizqyzkjalitbahxfjytrqvpqeroicxmnlkhlzunacxaneviawrtxcywhgef"; +static const unsigned char blob3[] = + "3716871354098370776510470746794707624107647054607467847164027"; +const double kBoringness = 0.25; +const double kWorseBoringness = 0.50; +const double kBetterBoringness = 0.10; +const double kTotallyBoring = 1.0; + +const int64 kPage1 = 1234; + +} // namespace + class ThumbnailDatabaseTest : public testing::Test { public: ThumbnailDatabaseTest() { @@ -32,8 +49,9 @@ class ThumbnailDatabaseTest : public testing::Test { // testing::Test virtual void SetUp() { // get an empty file for the test DB - PathService::Get(chrome::DIR_TEST_DATA, &file_name_); - file_util::AppendToPath(&file_name_, L"TestThumbnails.db"); + FilePath test_data_dir; + PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); + file_name_ = test_data_dir.AppendASCII("TestThumbnails.db"); file_util::Delete(file_name_, false); google_bitmap_.reset( @@ -46,26 +64,9 @@ class ThumbnailDatabaseTest : public testing::Test { scoped_ptr<SkBitmap> google_bitmap_; - std::wstring file_name_; + FilePath file_name_; }; -// data we'll put into the thumbnail database -static const unsigned char blob1[] = - "12346102356120394751634516591348710478123649165419234519234512349134"; -static const unsigned char blob2[] = - "goiwuegrqrcomizqyzkjalitbahxfjytrqvpqeroicxmnlkhlzunacxaneviawrtxcywhgef"; -static const unsigned char blob3[] = - "3716871354098370776510470746794707624107647054607467847164027"; -const double kBoringness = 0.25; -const double kWorseBoringness = 0.50; -const double kBetterBoringness = 0.10; -const double kTotallyBoring = 1.0; - -const int64 kPage1 = 1234; - -} // namespace - - TEST_F(ThumbnailDatabaseTest, AddDelete) { ThumbnailDatabase db; ASSERT_TRUE(db.Init(file_name_, NULL) == INIT_OK); diff --git a/chrome/browser/history/url_database_unittest.cc b/chrome/browser/history/url_database_unittest.cc index 1ee1351..cb05019 100644 --- a/chrome/browser/history/url_database_unittest.cc +++ b/chrome/browser/history/url_database_unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/file_path.h" #include "base/file_util.h" #include "base/path_service.h" #include "base/string_util.h" @@ -40,11 +41,11 @@ class URLDatabaseTest : public testing::Test, private: // Test setup. void SetUp() { - PathService::Get(base::DIR_TEMP, &db_file_); - db_file_.push_back(FilePath::kSeparators[0]); - db_file_.append(L"URLTest.db"); + FilePath temp_dir; + PathService::Get(base::DIR_TEMP, &temp_dir); + db_file_ = temp_dir.AppendASCII("URLTest.db"); - EXPECT_EQ(SQLITE_OK, sqlite3_open(WideToUTF8(db_file_).c_str(), &db_)); + EXPECT_EQ(SQLITE_OK, OpenSqliteDb(db_file_, &db_)); statement_cache_ = new SqliteStatementCache(db_); // Initialize the tables for this test. @@ -67,7 +68,7 @@ class URLDatabaseTest : public testing::Test, return *statement_cache_; } - std::wstring db_file_; + FilePath db_file_; sqlite3* db_; SqliteStatementCache* statement_cache_; }; diff --git a/chrome/browser/history/visit_database_unittest.cc b/chrome/browser/history/visit_database_unittest.cc index a646b2c..65197d1 100644 --- a/chrome/browser/history/visit_database_unittest.cc +++ b/chrome/browser/history/visit_database_unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/file_path.h" #include "base/file_util.h" #include "base/path_service.h" #include "base/string_util.h" @@ -42,12 +43,12 @@ class VisitDatabaseTest : public PlatformTest, // Test setup. void SetUp() { PlatformTest::SetUp(); - PathService::Get(base::DIR_TEMP, &db_file_); - db_file_.push_back(FilePath::kSeparators[0]); - db_file_.append(L"VisitTest.db"); + FilePath temp_dir; + PathService::Get(base::DIR_TEMP, &temp_dir); + db_file_ = temp_dir.AppendASCII("VisitTest.db"); file_util::Delete(db_file_, false); - EXPECT_EQ(SQLITE_OK, sqlite3_open(WideToUTF8(db_file_).c_str(), &db_)); + EXPECT_EQ(SQLITE_OK, OpenSqliteDb(db_file_, &db_)); statement_cache_ = new SqliteStatementCache(db_); // Initialize the tables for this test. @@ -71,7 +72,7 @@ class VisitDatabaseTest : public PlatformTest, return *statement_cache_; } - std::wstring db_file_; + FilePath db_file_; sqlite3* db_; SqliteStatementCache* statement_cache_; }; |