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

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

Issue 71233003: [SyncFS] Delete local file on rename and reorganize completion (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@00_completion
Patch Set: Created 7 years, 1 month 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
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_database.h" 5 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <stack> 8 #include <stack>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 tracker->clear_synced_details(); 879 tracker->clear_synced_details();
880 tracker->set_dirty(true); 880 tracker->set_dirty(true);
881 tracker->set_active(false); 881 tracker->set_active(false);
882 PutTrackerToBatch(*tracker, batch.get()); 882 PutTrackerToBatch(*tracker, batch.get());
883 } 883 }
884 884
885 WriteToDatabase(batch.Pass(), callback); 885 WriteToDatabase(batch.Pass(), callback);
886 return; 886 return;
887 } 887 }
888 888
889 // Check if the tracker was retitled. If it was, update the title and its 889 if (tracker->has_synced_details()) {
890 // index in advance. 890 // Check if the tracker was retitled. If it was, there should exist another
891 if (!tracker->has_synced_details() || 891 // tracker for the new title, so delete old tracker.
892 tracker->synced_details().title() != updated_details.title()) { 892 if (tracker->synced_details().title() != updated_details.title()) {
893 UpdateTrackerTitle(tracker, updated_details.title(), batch.get()); 893 RemoveTracker(tracker->tracker_id(), batch.get());
894 WriteToDatabase(batch.Pass(), callback);
895 return;
896 }
897
898 // Check if the tracker's parent is still in |parent_tracker_ids|.
899 // If not, there should exist another tracker for the new parent, so delete
900 // old tracker.
901 DCHECK(ContainsKey(tracker_by_id_, tracker->parent_tracker_id()));
902 FileTracker* parent_tracker = tracker_by_id_[tracker->parent_tracker_id()];
903 if (!HasFileAsParent(tracker->synced_details(),
904 parent_tracker->file_id())) {
905 RemoveTracker(tracker->tracker_id(), batch.get());
906 WriteToDatabase(batch.Pass(), callback);
907 return;
908 }
894 } 909 }
895 910
896 *tracker->mutable_synced_details() = updated_details; 911 *tracker->mutable_synced_details() = updated_details;
897 912
898 // Activate the tracker if: 913 // Activate the tracker if:
899 // - There is no active tracker that tracks |tracker->file_id()|. 914 // - There is no active tracker that tracks |tracker->file_id()|.
900 // - There is no active tracker that has the same |parent| and |title|. 915 // - There is no active tracker that has the same |parent| and |title|.
901 if (!tracker->active() && CanActivateTracker(*tracker)) 916 if (!tracker->active() && CanActivateTracker(*tracker))
902 MakeTrackerActive(tracker->tracker_id(), batch.get()); 917 MakeTrackerActive(tracker->tracker_id(), batch.get());
903 if (tracker->dirty() && !ShouldKeepDirty(*tracker)) { 918 if (tracker->dirty() && !ShouldKeepDirty(*tracker)) {
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 TrackersByParentAndTitle::const_iterator found_by_parent = 1458 TrackersByParentAndTitle::const_iterator found_by_parent =
1444 trackers_by_parent_and_title_.find(parent_tracker_id); 1459 trackers_by_parent_and_title_.find(parent_tracker_id);
1445 if (found_by_parent == trackers_by_parent_and_title_.end()) 1460 if (found_by_parent == trackers_by_parent_and_title_.end())
1446 return false; 1461 return false;
1447 1462
1448 const TrackersByTitle& trackers_by_title = found_by_parent->second; 1463 const TrackersByTitle& trackers_by_title = found_by_parent->second;
1449 TrackersByTitle::const_iterator found = trackers_by_title.find(title); 1464 TrackersByTitle::const_iterator found = trackers_by_title.find(title);
1450 return found != trackers_by_title.end() && found->second.has_active(); 1465 return found != trackers_by_title.end() && found->second.has_active();
1451 } 1466 }
1452 1467
1453 void MetadataDatabase::UpdateTrackerTitle(FileTracker* tracker, 1468 void MetadataDatabase::UpdateTrackerTitle(FileTracker* tracker,
kinuko 2013/11/14 08:01:12 This one's no longer used?
tzik 2013/11/14 08:15:27 Done.
1454 const std::string& new_title, 1469 const std::string& new_title,
1455 leveldb::WriteBatch* batch) { 1470 leveldb::WriteBatch* batch) {
1456 int64 parent_id = tracker->parent_tracker_id(); 1471 int64 parent_id = tracker->parent_tracker_id();
1457 std::string old_title = GetTrackerTitle(*tracker); 1472 std::string old_title = GetTrackerTitle(*tracker);
1458 DCHECK_NE(old_title, new_title); 1473 DCHECK_NE(old_title, new_title);
1459 DCHECK(!new_title.empty()); 1474 DCHECK(!new_title.empty());
1460 1475
1461 TrackersByTitle* trackers_by_title = 1476 TrackersByTitle* trackers_by_title =
1462 &trackers_by_parent_and_title_[parent_id]; 1477 &trackers_by_parent_and_title_[parent_id];
1463 TrackerSet* old_siblings = &(*trackers_by_title)[old_title]; 1478 TrackerSet* old_siblings = &(*trackers_by_title)[old_title];
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1498 FROM_HERE, 1513 FROM_HERE,
1499 base::Bind(&leveldb::DB::Write, 1514 base::Bind(&leveldb::DB::Write,
1500 base::Unretained(db_.get()), 1515 base::Unretained(db_.get()),
1501 leveldb::WriteOptions(), 1516 leveldb::WriteOptions(),
1502 base::Owned(batch.release())), 1517 base::Owned(batch.release())),
1503 base::Bind(&AdaptLevelDBStatusToSyncStatusCode, callback)); 1518 base::Bind(&AdaptLevelDBStatusToSyncStatusCode, callback));
1504 } 1519 }
1505 1520
1506 } // namespace drive_backend 1521 } // namespace drive_backend
1507 } // namespace sync_file_system 1522 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698