diff options
author | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-16 18:05:41 +0000 |
---|---|---|
committer | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-16 18:05:41 +0000 |
commit | e4a6eed6218d2e1c510507a07c54f3f305aaf9ee (patch) | |
tree | 8afd703d741166a2c81f26e66a20a722dc91b18a | |
parent | d24b4a7825f0f07a9a09f863aaeea011c30aad9f (diff) | |
download | chromium_src-e4a6eed6218d2e1c510507a07c54f3f305aaf9ee.zip chromium_src-e4a6eed6218d2e1c510507a07c54f3f305aaf9ee.tar.gz chromium_src-e4a6eed6218d2e1c510507a07c54f3f305aaf9ee.tar.bz2 |
Remove some dead code.
BUG=NONE
Review URL: https://chromiumcodereview.appspot.com/12285012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182982 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/media_gallery/media_gallery_database.cc | 194 | ||||
-rw-r--r-- | chrome/browser/media_gallery/media_gallery_database.h | 62 | ||||
-rw-r--r-- | chrome/browser/media_gallery/media_gallery_database_types.cc | 34 | ||||
-rw-r--r-- | chrome/browser/media_gallery/media_gallery_database_types.h | 38 | ||||
-rw-r--r-- | chrome/browser/media_gallery/media_gallery_database_unittest.cc | 79 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 4 | ||||
-rw-r--r-- | chrome/chrome_tests_unit.gypi | 1 |
7 files changed, 0 insertions, 412 deletions
diff --git a/chrome/browser/media_gallery/media_gallery_database.cc b/chrome/browser/media_gallery/media_gallery_database.cc deleted file mode 100644 index 19f964c..0000000 --- a/chrome/browser/media_gallery/media_gallery_database.cc +++ /dev/null @@ -1,194 +0,0 @@ -// Copyright (c) 2012 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. - -#include "chrome/browser/media_gallery/media_gallery_database.h" - -#include <algorithm> -#include <string> - -#include "base/file_path.h" -#include "base/logging.h" -#include "sql/statement.h" -#include "sql/transaction.h" - -#if defined(OS_WIN) -#include "base/string_util.h" -#include "base/sys_string_conversions.h" -#endif // OS_WIN - -#define MEDIA_GALLERY_COLLECTION_ROW_FIELDS \ - " collections.id, collections.path, collections.last_modified_time, " \ - "collections.entry_count, collections.all_parsed " - -namespace chrome { - -namespace { - -const int kCurrentVersionNumber = 1; -const int kCompatibleVersionNumber = 1; -const base::FilePath::CharType kMediaGalleryDatabaseName[] = - FILE_PATH_LITERAL(".media_gallery.db"); - -} // namespace - -MediaGalleryDatabase::MediaGalleryDatabase() { } - -MediaGalleryDatabase::~MediaGalleryDatabase() { } - -sql::InitStatus MediaGalleryDatabase::Init(const base::FilePath& database_dir) { - db_.set_error_histogram_name("Sqlite.MediaGallery.Error"); - - // Set the database page size to something a little larger to give us - // better performance (we're typically seek rather than bandwidth limited). - // This only has an effect before any tables have been created, otherwise - // this is a NOP. Must be a power of 2 and a max of 8192. - db_.set_page_size(4096); - - // Increase the cache size. The page size, plus a little extra, times this - // value, tells us how much memory the cache will use maximum. - // 6000 * 4KB = 24MB - db_.set_cache_size(6000); - - if (!db_.Open(database_dir.Append(base::FilePath(kMediaGalleryDatabaseName)))) - return sql::INIT_FAILURE; - - return InitInternal(&db_); -} - -sql::InitStatus MediaGalleryDatabase::InitInternal(sql::Connection* db) { - // Wrap the rest of init in a tranaction. This will prevent the database from - // getting corrupted if we crash in the middle of initialization or migration. - sql::Transaction committer(db); - if (!committer.Begin()) - return sql::INIT_FAILURE; - - // Prime the cache. - db->Preload(); - - // Create the tables and indices. - if (!meta_table_.Init(db, GetCurrentVersion(), kCompatibleVersionNumber)) - return sql::INIT_FAILURE; - - if (!CreateCollectionsTable(db)) - return sql::INIT_FAILURE; - - // Version check. - sql::InitStatus version_status = EnsureCurrentVersion(); - if (version_status != sql::INIT_OK) - return version_status; - - return committer.Commit() ? sql::INIT_OK : sql::INIT_FAILURE; -} - -sql::Connection& MediaGalleryDatabase::GetDB() { - return db_; -} - -sql::InitStatus MediaGalleryDatabase::EnsureCurrentVersion() { - // We can't read databases newer than we were designed for. - if (meta_table_.GetCompatibleVersionNumber() > kCurrentVersionNumber) { - VLOG(1) << "Media Gallery database is too new."; - return sql::INIT_TOO_NEW; - } - int cur_version = meta_table_.GetVersionNumber(); - if (cur_version == 0) { - DVLOG(1) << "Initializing the Media Gallery database."; - - ++cur_version; - meta_table_.SetVersionNumber(cur_version); - meta_table_.SetCompatibleVersionNumber( - std::min(cur_version, kCompatibleVersionNumber)); - } - return sql::INIT_OK; -} - -// static -int MediaGalleryDatabase::GetCurrentVersion() { - return kCurrentVersionNumber; -} - -CollectionId MediaGalleryDatabase::CreateCollectionRow( - CollectionRow* row) { - const char* sql = "INSERT INTO collections" - "(path, last_modified_time, entry_count, all_parsed) " - "VALUES(?, ?, ?, ?)"; - - sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, sql)); -#if defined(OS_WIN) - // We standardize on UTF8 encoding for paths. - std::string path(base::SysWideToUTF8(row->path.value())); -#elif defined(OS_POSIX) - std::string path(row->path.value()); -#endif - -#if defined(FILE_PATH_USES_WIN_SEPARATORS) - // We standardize on POSIX-style paths, since any platform can understand - // them. - ReplaceChars(path, "\\", "/", &path); -#endif // FILE_PATH_USES_WIN_SEPARATORS - - statement.BindString(0, path.c_str()); - statement.BindInt64(1, row->last_modified_time.ToInternalValue()); - statement.BindInt(2, row->entry_count); - statement.BindInt(3, row->all_parsed ? 1 : 0); - - if (!statement.Run()) { - VLOG(0) << "Failed to add collection " << row->path.value() - << " to table media_gallery.collections"; - return 0; - } - return row->id = GetDB().GetLastInsertRowId(); -} - -bool MediaGalleryDatabase::GetCollectionRow(CollectionId id, - CollectionRow* row) { - sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, - "SELECT" MEDIA_GALLERY_COLLECTION_ROW_FIELDS - "FROM collections WHERE id=?")); - statement.BindInt64(0, id); - - if (statement.Step()) { - FillCollectionRow(statement, row); - return true; - } - return false; -} - -// Convenience method to fill a row from a statement. Must be in sync with the -// columns in MEDIA_GALLERY_COLLECTION_ROW_FIELDS -void MediaGalleryDatabase::FillCollectionRow(const sql::Statement& statement, - CollectionRow* row) { - row->id = statement.ColumnInt64(0); -#if defined(OS_WIN) - row->path = base::FilePath(base::SysUTF8ToWide(statement.ColumnString(1))); -#elif defined(OS_POSIX) - row->path = base::FilePath(statement.ColumnString(1)); -#endif // OS_WIN - row->last_modified_time = base::Time::FromInternalValue( - statement.ColumnInt64(2)); - row->entry_count = statement.ColumnInt(3); - row->all_parsed = statement.ColumnInt(4) != 0; -} - -// static -bool MediaGalleryDatabase::DoesCollectionsTableExist(sql::Connection *db) { - return db->DoesTableExist("collections"); -} - -// static -bool MediaGalleryDatabase::CreateCollectionsTable(sql::Connection* db) { - if (DoesCollectionsTableExist(db)) - return true; - - // TODO(tpayne): Add unique constraint on path once we standardize on path - // format. - return db->Execute("CREATE TABLE collections" - "(id INTEGER PRIMARY KEY," - " path LONGVARCHAR NOT NULL," - " last_modified_time INTEGER NOT NULL," - " entry_count INTEGER DEFAULT 0 NOT NULL," - " all_parsed INTEGER DEFAULT 0 NOT NULL)"); -} - -} // namespace chrome diff --git a/chrome/browser/media_gallery/media_gallery_database.h b/chrome/browser/media_gallery/media_gallery_database.h deleted file mode 100644 index 2bb6548..0000000 --- a/chrome/browser/media_gallery/media_gallery_database.h +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) 2012 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. - -#ifndef CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERY_DATABASE_H_ -#define CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERY_DATABASE_H_ - -#include "base/basictypes.h" -#include "base/file_path.h" -#include "chrome/browser/media_gallery/media_gallery_database_types.h" -#include "sql/connection.h" -#include "sql/init_status.h" -#include "sql/meta_table.h" - -namespace chrome { - -// Encapsulates the SQL database that stores pre-parsed media gallery metadata -// for search and retrieval. -class MediaGalleryDatabase { - public: - MediaGalleryDatabase(); - virtual ~MediaGalleryDatabase(); - - // Must call this function to complete initialization. Will return true on - // success. On false, no other function should be called. - sql::InitStatus Init(const base::FilePath& database_path); - - // Returns the current version that we will generate media gallery databases - // with. - static int GetCurrentVersion(); - - // Sets the id field of the input collection_row to the generated unique - // key value and returns the same. On failure, returns zero. - int CreateCollectionRow(CollectionRow* collection_row); - - // Finds the row with the specified id and fills its data into the collection - // pointer passed by the caller. Returns true on success. - bool GetCollectionRow(CollectionId id, CollectionRow* collection); - - protected: - virtual sql::Connection& GetDB(); - - // Initializes an already open database. - sql::InitStatus InitInternal(sql::Connection* db); - static bool DoesCollectionsTableExist(sql::Connection* db); - - private: - static bool CreateCollectionsTable(sql::Connection* db); - sql::InitStatus EnsureCurrentVersion(); - void FillCollectionRow(const sql::Statement& statement, CollectionRow* row); - - sql::Connection db_; - sql::MetaTable meta_table_; - - DISALLOW_COPY_AND_ASSIGN(MediaGalleryDatabase); -}; - -} // namespace chrome - -std::ostream& operator<<(std::ostream& out, const chrome::CollectionRow& row); - -#endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERY_DATABASE_H_ diff --git a/chrome/browser/media_gallery/media_gallery_database_types.cc b/chrome/browser/media_gallery/media_gallery_database_types.cc deleted file mode 100644 index a42e834..0000000 --- a/chrome/browser/media_gallery/media_gallery_database_types.cc +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2012 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. - -#include "chrome/browser/media_gallery/media_gallery_database_types.h" - -namespace chrome { - -CollectionRow::CollectionRow() - : id(0), - entry_count(0), - all_parsed(false) { } - -CollectionRow::CollectionRow(const base::FilePath& path, - base::Time last_modified_time, - int entry_count, - bool all_parsed) - : id(0), - path(path), - last_modified_time(last_modified_time), - entry_count(entry_count), - all_parsed(all_parsed) { } - -CollectionRow::~CollectionRow() { } - -bool CollectionRow::operator==(const CollectionRow& row2) const { - return id == row2.id && - path == row2.path && - last_modified_time == row2.last_modified_time && - entry_count == row2.entry_count && - all_parsed == row2.all_parsed; -} - -} // namespace chrome diff --git a/chrome/browser/media_gallery/media_gallery_database_types.h b/chrome/browser/media_gallery/media_gallery_database_types.h deleted file mode 100644 index 8b2831b..0000000 --- a/chrome/browser/media_gallery/media_gallery_database_types.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2012 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. - -#ifndef CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERY_DATABASE_TYPES_H_ -#define CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERY_DATABASE_TYPES_H_ - -#include "base/basictypes.h" -#include "base/file_path.h" -#include "base/time.h" - -namespace chrome { - -typedef int CollectionId; - -struct CollectionRow { - public: - CollectionRow(); - CollectionRow(const base::FilePath& path, - base::Time last_modified_time, - int entry_count, - bool all_parsed); - ~CollectionRow(); - bool operator==(const CollectionRow& row2) const; - - CollectionId id; - base::FilePath path; - base::Time last_modified_time; - int entry_count; - bool all_parsed; - - private: - DISALLOW_COPY_AND_ASSIGN(CollectionRow); -}; - -} // namespace chrome - -#endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERY_DATABASE_TYPES_H_ diff --git a/chrome/browser/media_gallery/media_gallery_database_unittest.cc b/chrome/browser/media_gallery/media_gallery_database_unittest.cc deleted file mode 100644 index a26b86f..0000000 --- a/chrome/browser/media_gallery/media_gallery_database_unittest.cc +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright (c) 2012 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. - -#include <string> - -#include "base/file_path.h" -#include "base/files/scoped_temp_dir.h" -#include "chrome/browser/media_gallery/media_gallery_database.h" -#include "chrome/browser/media_gallery/media_gallery_database_types.h" -#include "sql/connection.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace chrome { - -class MediaGalleryDatabaseTest : public testing::Test, - public MediaGalleryDatabase { - public: - MediaGalleryDatabaseTest() { } - - protected: - virtual sql::Connection& GetDB() OVERRIDE { - return db_; - } - - private: - // Test setup. - virtual void SetUp() { - ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); - base::FilePath db_file = - temp_dir_.path().AppendASCII("MediaGalleryTest.db"); - - ASSERT_TRUE(db_.Open(db_file)); - - // Initialize the tables for this test. - ASSERT_EQ(sql::INIT_OK, InitInternal(&db_)); - } - - virtual void TearDown() { - db_.Close(); - } - - base::ScopedTempDir temp_dir_; - sql::Connection db_; -}; - -TEST_F(MediaGalleryDatabaseTest, Init) { - EXPECT_TRUE(DoesCollectionsTableExist(&GetDB())); -} - -TEST_F(MediaGalleryDatabaseTest, AddCollection) { - CollectionRow row1(base::FilePath(FILE_PATH_LITERAL("path1")), - base::Time::FromDoubleT(12345), - 123, - false); - CollectionId rowid = CreateCollectionRow(&row1); - EXPECT_EQ(rowid, row1.id); - - CollectionRow row2; - EXPECT_TRUE(GetCollectionRow(rowid, &row2)); - EXPECT_TRUE(row1 == row2); -} - -TEST_F(MediaGalleryDatabaseTest, StandardizePath) { - base::FilePath path(FILE_PATH_LITERAL("path1")); - path = path.AppendASCII("path2"); - CollectionRow row1(path, - base::Time::FromDoubleT(12345), - 123, - false); - CollectionId rowid = CreateCollectionRow(&row1); - EXPECT_EQ(rowid, row1.id); - - CollectionRow row2; - EXPECT_TRUE(GetCollectionRow(rowid, &row2)); - EXPECT_EQ(FILE_PATH_LITERAL("path1/path2"), row2.path.value()); -} - -} // namespace chrome diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 7f8130d..2045c98 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1047,10 +1047,6 @@ 'browser/media_gallery/media_galleries_preferences.h', 'browser/media_gallery/media_galleries_preferences_factory.cc', 'browser/media_gallery/media_galleries_preferences_factory.h', - 'browser/media_gallery/media_gallery_database.cc', - 'browser/media_gallery/media_gallery_database.h', - 'browser/media_gallery/media_gallery_database_types.cc', - 'browser/media_gallery/media_gallery_database_types.h', 'browser/media_gallery/mtp_device_delegate_impl.h', 'browser/media_gallery/scoped_mtp_device_map_entry.cc', 'browser/media_gallery/scoped_mtp_device_map_entry.h', diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index 4fa85a4..6cfbd96 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -883,7 +883,6 @@ 'browser/media_gallery/media_galleries_dialog_controller_mock.cc', 'browser/media_gallery/media_galleries_dialog_controller_mock.h', 'browser/media_gallery/media_galleries_preferences_unittest.cc', - 'browser/media_gallery/media_gallery_database_unittest.cc', 'browser/media_gallery/win/mtp_device_object_enumerator_unittest.cc', 'browser/metrics/metrics_log_unittest.cc', 'browser/metrics/metrics_log_serializer_unittest.cc', |