OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/sync_file_system/drive_backend/metadata_db_migration_ut
il.h" | 5 #include "chrome/browser/sync_file_system/drive_backend/metadata_db_migration_ut
il.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_util.h" | 10 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_util.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 case DriveMetadata_ResourceType_RESOURCE_TYPE_FILE: | 75 case DriveMetadata_ResourceType_RESOURCE_TYPE_FILE: |
76 return AddWapiFilePrefix(resource_id); | 76 return AddWapiFilePrefix(resource_id); |
77 case DriveMetadata_ResourceType_RESOURCE_TYPE_FOLDER: | 77 case DriveMetadata_ResourceType_RESOURCE_TYPE_FOLDER: |
78 return AddWapiFolderPrefix(resource_id); | 78 return AddWapiFolderPrefix(resource_id); |
79 } | 79 } |
80 NOTREACHED(); | 80 NOTREACHED(); |
81 return resource_id; | 81 return resource_id; |
82 } | 82 } |
83 | 83 |
84 std::string RemoveWapiIdPrefix(const std::string& resource_id) { | 84 std::string RemoveWapiIdPrefix(const std::string& resource_id) { |
85 if (StartsWithASCII(resource_id, kWapiFileIdPrefix, true)) | 85 std::string value; |
86 return RemovePrefix(resource_id, kWapiFileIdPrefix); | 86 if (RemovePrefix(resource_id, kWapiFileIdPrefix, &value)) |
87 if (StartsWithASCII(resource_id, kWapiFolderIdPrefix, true)) | 87 return value; |
88 return RemovePrefix(resource_id, kWapiFolderIdPrefix); | 88 if (RemovePrefix(resource_id, kWapiFolderIdPrefix, &value)) |
| 89 return value; |
89 return resource_id; | 90 return resource_id; |
90 } | 91 } |
91 | 92 |
92 SyncStatusCode MigrateDatabaseFromV0ToV1(leveldb::DB* db) { | 93 SyncStatusCode MigrateDatabaseFromV0ToV1(leveldb::DB* db) { |
93 // Version 0 database format: | 94 // Version 0 database format: |
94 // key: "CHANGE_STAMP" | 95 // key: "CHANGE_STAMP" |
95 // value: <Largest Changestamp> | 96 // value: <Largest Changestamp> |
96 // | 97 // |
97 // key: "SYNC_ROOT_DIR" | 98 // key: "SYNC_ROOT_DIR" |
98 // value: <Resource ID of the sync root directory> | 99 // value: <Resource ID of the sync root directory> |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 const char kMetadataKeySeparator = ' '; | 135 const char kMetadataKeySeparator = ' '; |
135 | 136 |
136 leveldb::WriteBatch write_batch; | 137 leveldb::WriteBatch write_batch; |
137 write_batch.Put(kDatabaseVersionKey, "1"); | 138 write_batch.Put(kDatabaseVersionKey, "1"); |
138 | 139 |
139 scoped_ptr<leveldb::Iterator> itr(db->NewIterator(leveldb::ReadOptions())); | 140 scoped_ptr<leveldb::Iterator> itr(db->NewIterator(leveldb::ReadOptions())); |
140 for (itr->Seek(kDriveMetadataKeyPrefix); itr->Valid(); itr->Next()) { | 141 for (itr->Seek(kDriveMetadataKeyPrefix); itr->Valid(); itr->Next()) { |
141 std::string key = itr->key().ToString(); | 142 std::string key = itr->key().ToString(); |
142 if (!StartsWithASCII(key, kDriveMetadataKeyPrefix, true)) | 143 if (!StartsWithASCII(key, kDriveMetadataKeyPrefix, true)) |
143 break; | 144 break; |
144 std::string serialized_url(RemovePrefix(key, kDriveMetadataKeyPrefix)); | 145 std::string serialized_url; |
| 146 RemovePrefix(key, kDriveMetadataKeyPrefix, &serialized_url); |
145 | 147 |
146 GURL origin; | 148 GURL origin; |
147 base::FilePath path; | 149 base::FilePath path; |
148 bool success = ParseV0FormatFileSystemURL( | 150 bool success = ParseV0FormatFileSystemURL( |
149 GURL(serialized_url), &origin, &path); | 151 GURL(serialized_url), &origin, &path); |
150 DCHECK(success) << serialized_url; | 152 DCHECK(success) << serialized_url; |
151 std::string new_key = kDriveMetadataKeyPrefix + origin.spec() + | 153 std::string new_key = kDriveMetadataKeyPrefix + origin.spec() + |
152 kMetadataKeySeparator + path.AsUTF8Unsafe(); | 154 kMetadataKeySeparator + path.AsUTF8Unsafe(); |
153 | 155 |
154 write_batch.Put(new_key, itr->value()); | 156 write_batch.Put(new_key, itr->value()); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 continue; | 239 continue; |
238 } | 240 } |
239 } | 241 } |
240 | 242 |
241 return LevelDBStatusToSyncStatusCode( | 243 return LevelDBStatusToSyncStatusCode( |
242 db->Write(leveldb::WriteOptions(), &write_batch)); | 244 db->Write(leveldb::WriteOptions(), &write_batch)); |
243 } | 245 } |
244 | 246 |
245 } // namespace drive_backend | 247 } // namespace drive_backend |
246 } // namespace sync_file_system | 248 } // namespace sync_file_system |
OLD | NEW |