Chromium Code Reviews| Index: chrome/browser/sync_file_system/drive_metadata_store.cc |
| diff --git a/chrome/browser/sync_file_system/drive_metadata_store.cc b/chrome/browser/sync_file_system/drive_metadata_store.cc |
| index 191b3601f64d84348dbf32647f224c9868fca29a..54c96294a6f03ac344ce5164121d122604d14ada 100644 |
| --- a/chrome/browser/sync_file_system/drive_metadata_store.cc |
| +++ b/chrome/browser/sync_file_system/drive_metadata_store.cc |
| @@ -53,29 +53,10 @@ const char kDriveIncrementalSyncOriginKeyPrefix[] = "ISYNC_ORIGIN: "; |
| const char kDriveDisabledOriginKeyPrefix[] = "DISABLED_ORIGIN: "; |
| const size_t kDriveMetadataKeyPrefixLength = arraysize(kDriveMetadataKeyPrefix); |
| -const base::FilePath::CharType kV0FormatPathPrefix[] = |
| - FILE_PATH_LITERAL("drive/"); |
| - |
| -bool ParseV0FormatFileSystemURLString(const GURL& url, |
| - GURL* origin, |
| - base::FilePath* path) { |
| - fileapi::FileSystemType mount_type; |
| - base::FilePath virtual_path; |
| - |
| - if (!fileapi::FileSystemURL::ParseFileSystemSchemeURL( |
| - url, origin, &mount_type, &virtual_path) || |
| - mount_type != fileapi::kFileSystemTypeExternal) { |
| - NOTREACHED() << "Failed to parse filesystem scheme URL"; |
| - return false; |
| - } |
| - |
| - base::FilePath::StringType prefix = |
| - base::FilePath(kV0FormatPathPrefix).NormalizePathSeparators().value(); |
| - if (virtual_path.value().substr(0, prefix.size()) != prefix) |
| - return false; |
| - |
| - *path = base::FilePath(virtual_path.value().substr(prefix.size())); |
| - return true; |
| +std::string RemovePrefix(const std::string& str, const std::string& prefix) { |
|
calvinlo
2013/05/29 08:36:52
Can we have a small test for this added?
nhiroki
2013/05/30 06:15:48
I think we don't have to add test since this funct
|
| + if (StartsWithASCII(str, prefix, true)) |
| + return str.substr(prefix.size()); |
| + return str; |
| } |
| std::string FileSystemURLToMetadataKey(const FileSystemURL& url) { |
| @@ -86,8 +67,7 @@ std::string FileSystemURLToMetadataKey(const FileSystemURL& url) { |
| void MetadataKeyToOriginAndPath(const std::string& metadata_key, |
| GURL* origin, |
| base::FilePath* path) { |
| - std::string key_body(metadata_key.begin() + kDriveMetadataKeyPrefixLength - 1, |
| - metadata_key.end()); |
| + std::string key_body(RemovePrefix(metadata_key, kDriveMetadataKeyPrefix)); |
| size_t separator_position = key_body.find(kMetadataKeySeparator); |
| *origin = GURL(key_body.substr(0, separator_position)); |
| *path = base::FilePath::FromUTF8Unsafe( |
| @@ -108,12 +88,6 @@ bool UpdateResourceIdMap(ResourceIdByOrigin* map, |
| return true; |
| } |
| -std::string RemovePrefix(const std::string& str, const std::string& prefix) { |
| - if (StartsWithASCII(str, prefix, true)) |
| - return str.substr(prefix.size()); |
| - return str; |
| -} |
| - |
| } // namespace |
| class DriveMetadataDB { |
| @@ -133,7 +107,6 @@ class DriveMetadataDB { |
| SyncStatusCode ReadContents(DriveMetadataDBContents* contents); |
| SyncStatusCode MigrateDatabaseIfNeeded(); |
| - SyncStatusCode MigrateFromVersion0To1Database(); |
| SyncStatusCode SetLargestChangestamp(int64 largest_changestamp); |
| SyncStatusCode SetSyncRootDirectory(const std::string& resource_id); |
| @@ -868,7 +841,7 @@ SyncStatusCode DriveMetadataDB::MigrateDatabaseIfNeeded() { |
| switch (database_version) { |
| case 0: |
| - MigrateFromVersion0To1Database(); |
| + drive::MigrateDatabaseFromV0ToV1(db_.get()); |
| // fall-through |
| case 1: |
| drive::MigrateDatabaseFromV1ToV2(db_.get()); |
| @@ -877,72 +850,6 @@ SyncStatusCode DriveMetadataDB::MigrateDatabaseIfNeeded() { |
| return SYNC_DATABASE_ERROR_FAILED; |
| } |
| -SyncStatusCode DriveMetadataDB::MigrateFromVersion0To1Database() { |
| - // Version 0 database format: |
| - // key: "CHANGE_STAMP" |
| - // value: <Largest Changestamp> |
| - // |
| - // key: "SYNC_ROOT_DIR" |
| - // value: <Resource ID of the sync root directory> |
| - // |
| - // key: "METADATA: " + |
| - // <FileSystemURL serialized by SerializeSyncableFileSystemURL> |
| - // value: <Serialized DriveMetadata> |
| - // |
| - // key: "BSYNC_ORIGIN: " + <URL string of a batch sync origin> |
| - // value: <Resource ID of the drive directory for the origin> |
| - // |
| - // key: "ISYNC_ORIGIN: " + <URL string of a incremental sync origin> |
| - // value: <Resource ID of the drive directory for the origin> |
| - // |
| - // Version 1 database format (changed keys/fields are marked with '*'): |
| - // * key: "VERSION" (new) |
| - // * value: 1 |
| - // |
| - // key: "CHANGE_STAMP" |
| - // value: <Largest Changestamp> |
| - // |
| - // key: "SYNC_ROOT_DIR" |
| - // value: <Resource ID of the sync root directory> |
| - // |
| - // * key: "METADATA: " + <Origin and URL> (changed) |
| - // * value: <Serialized DriveMetadata> |
| - // |
| - // key: "BSYNC_ORIGIN: " + <URL string of a batch sync origin> |
| - // value: <Resource ID of the drive directory for the origin> |
| - // |
| - // key: "ISYNC_ORIGIN: " + <URL string of a incremental sync origin> |
| - // value: <Resource ID of the drive directory for the origin> |
| - // |
| - // key: "DISABLED_ORIGIN: " + <URL string of a disabled origin> |
| - // value: <Resource ID of the drive directory for the origin> |
| - |
| - leveldb::WriteBatch write_batch; |
| - write_batch.Put(kDatabaseVersionKey, "1"); |
| - |
| - scoped_ptr<leveldb::Iterator> itr(db_->NewIterator(leveldb::ReadOptions())); |
| - for (itr->Seek(kDriveMetadataKeyPrefix); itr->Valid(); itr->Next()) { |
| - std::string key = itr->key().ToString(); |
| - if (!StartsWithASCII(key, kDriveMetadataKeyPrefix, true)) |
| - break; |
| - std::string serialized_url( |
| - key.begin() + kDriveMetadataKeyPrefixLength - 1, key.end()); |
| - |
| - GURL origin; |
| - base::FilePath path; |
| - bool success = ParseV0FormatFileSystemURLString( |
| - GURL(serialized_url), &origin, &path); |
| - DCHECK(success) << serialized_url; |
| - std::string new_key = kDriveMetadataKeyPrefix + origin.spec() + |
| - kMetadataKeySeparator + path.AsUTF8Unsafe(); |
| - |
| - write_batch.Put(new_key, itr->value()); |
| - write_batch.Delete(key); |
| - } |
| - return LevelDBStatusToSyncStatusCode( |
| - db_->Write(leveldb::WriteOptions(), &write_batch)); |
| -} |
| - |
| SyncStatusCode DriveMetadataDB::SetLargestChangestamp( |
| int64 largest_changestamp) { |
| DCHECK(CalledOnValidThread()); |