Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: chrome/browser/sync_file_system/drive_backend/metadata_db_migration_util.cc

Issue 446653003: [SyncFS] Rollback function from version 4 to version 3. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add test Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 if (StartsWithASCII(key, kDriveDisabledOriginKeyPrefix, true)) { 237 if (StartsWithASCII(key, kDriveDisabledOriginKeyPrefix, true)) {
238 write_batch.Put(key, RemoveWapiIdPrefix(itr->value().ToString())); 238 write_batch.Put(key, RemoveWapiIdPrefix(itr->value().ToString()));
239 continue; 239 continue;
240 } 240 }
241 } 241 }
242 242
243 return LevelDBStatusToSyncStatusCode( 243 return LevelDBStatusToSyncStatusCode(
244 db->Write(leveldb::WriteOptions(), &write_batch)); 244 db->Write(leveldb::WriteOptions(), &write_batch));
245 } 245 }
246 246
247 SyncStatusCode MigrateDatabaseFromV4ToV3(leveldb::DB* db) {
248 // Rollback from version 4 to version 3.
249 // Please see metadata_database_index.cc for version 3 format, and
250 // metadata_database_index_on_disk.cc for version 4 format.
251
252 const char kDatabaseVersionKey[] = "VERSION";
253 const char kServiceMetadataKey[] = "SERVICE";
254 const char kFileMetadataKeyPrefix[] = "FILE: ";
255 const char kFileTrackerKeyPrefix[] = "TRACKER: ";
256
257 // Key prefixes used in version 4.
258 const char kAppRootIDByAppIDKeyPrefix[] = "APP_ROOT: ";
259 const char kActiveTrackerIDByFileIDKeyPrefix[] = "ACTIVE_FILE: ";
260 const char kTrackerIDByFileIDKeyPrefix[] = "TRACKER_FILE: ";
261 const char kMultiTrackerByFileIDKeyPrefix[] = "MULTI_FILE: ";
262 const char kActiveTrackerIDByParentAndTitleKeyPrefix[] = "ACTIVE_PATH: ";
263 const char kTrackerIDByParentAndTitleKeyPrefix[] = "TRACKER_PATH: ";
264 const char kMultiBackingParentAndTitleKeyPrefix[] = "MULTI_PATH: ";
265 const char kDirtyIDKeyPrefix[] = "DIRTY: ";
266 const char kDemotedDirtyIDKeyPrefix[] = "DEMOTED_DIRTY: ";
267
268 leveldb::WriteBatch write_batch;
269 write_batch.Put(kDatabaseVersionKey, "3");
270
271 scoped_ptr<leveldb::Iterator> itr(db->NewIterator(leveldb::ReadOptions()));
272 for (itr->SeekToFirst(); itr->Valid(); itr->Next()) {
273 std::string key = itr->key().ToString();
274
275 // Do nothing for valid entries in both versions.
276 if (StartsWithASCII(key, kServiceMetadataKey, true) ||
277 StartsWithASCII(key, kFileMetadataKeyPrefix, true) ||
278 StartsWithASCII(key, kFileTrackerKeyPrefix, true)) {
279 continue;
280 }
281
282 // Drop entries used in version 4 only.
283 if (StartsWithASCII(key, kAppRootIDByAppIDKeyPrefix, true) ||
284 StartsWithASCII(key, kActiveTrackerIDByFileIDKeyPrefix, true) ||
285 StartsWithASCII(key, kTrackerIDByFileIDKeyPrefix, true) ||
286 StartsWithASCII(key, kMultiTrackerByFileIDKeyPrefix, true) ||
287 StartsWithASCII(key, kActiveTrackerIDByParentAndTitleKeyPrefix, true) ||
288 StartsWithASCII(key, kTrackerIDByParentAndTitleKeyPrefix, true) ||
289 StartsWithASCII(key, kMultiBackingParentAndTitleKeyPrefix, true) ||
290 StartsWithASCII(key, kDirtyIDKeyPrefix, true) ||
291 StartsWithASCII(key, kDemotedDirtyIDKeyPrefix, true)) {
292 write_batch.Delete(key);
293 continue;
294 }
295
296 DVLOG(3) << "Unknown key: " << key << " was found.";
297 }
298
299 return LevelDBStatusToSyncStatusCode(
300 db->Write(leveldb::WriteOptions(), &write_batch));
301 }
302
247 } // namespace drive_backend 303 } // namespace drive_backend
248 } // namespace sync_file_system 304 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698