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

Unified Diff: chrome/browser/sync_file_system/drive_backend/metadata_database_index_on_disk.cc

Issue 372843007: [SyncFS] Implement getters and counters of FileMetadata and FileTracker (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix build error Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/sync_file_system/drive_backend/metadata_database_index_on_disk_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/sync_file_system/drive_backend/metadata_database_index_on_disk.cc
diff --git a/chrome/browser/sync_file_system/drive_backend/metadata_database_index_on_disk.cc b/chrome/browser/sync_file_system/drive_backend/metadata_database_index_on_disk.cc
index 54d9ecc4273fcbec06cc19ef941bc25472b0e524..7a73cd3504d10163d5b759099acadedfb4c8d2dd 100644
--- a/chrome/browser/sync_file_system/drive_backend/metadata_database_index_on_disk.cc
+++ b/chrome/browser/sync_file_system/drive_backend/metadata_database_index_on_disk.cc
@@ -359,15 +359,27 @@ size_t MetadataDatabaseIndexOnDisk::CountDirtyTracker() const {
}
size_t MetadataDatabaseIndexOnDisk::CountFileMetadata() const {
- // TODO(peria): Implement here
- NOTIMPLEMENTED();
- return 0;
+ // TODO(peria): Cache the number of FileMetadata in the DB.
+ size_t count = 0;
+ scoped_ptr<leveldb::Iterator> itr(db_->NewIterator(leveldb::ReadOptions()));
+ for (itr->Seek(kFileMetadataKeyPrefix); itr->Valid(); itr->Next()) {
+ if (!StartsWithASCII(itr->key().ToString(), kFileMetadataKeyPrefix, true))
+ break;
+ ++count;
+ }
+ return count;
}
size_t MetadataDatabaseIndexOnDisk::CountFileTracker() const {
- // TODO(peria): Implement here
- NOTIMPLEMENTED();
- return 0;
+ // TODO(peria): Cache the number of FileTracker in the DB.
+ size_t count = 0;
+ scoped_ptr<leveldb::Iterator> itr(db_->NewIterator(leveldb::ReadOptions()));
+ for (itr->Seek(kFileTrackerKeyPrefix); itr->Valid(); itr->Next()) {
+ if (!StartsWithASCII(itr->key().ToString(), kFileTrackerKeyPrefix, true))
+ break;
+ ++count;
+ }
+ return count;
}
std::vector<std::string>
@@ -384,16 +396,32 @@ MetadataDatabaseIndexOnDisk::GetRegisteredAppIDs() const {
}
std::vector<int64> MetadataDatabaseIndexOnDisk::GetAllTrackerIDs() const {
- // TODO(peria): Implement here
- NOTIMPLEMENTED();
- return std::vector<int64>();
+ std::vector<int64> tracker_ids;
+ scoped_ptr<leveldb::Iterator> itr(db_->NewIterator(leveldb::ReadOptions()));
+ for (itr->Seek(kFileTrackerKeyPrefix); itr->Valid(); itr->Next()) {
+ std::string id_str;
+ if (!RemovePrefix(itr->key().ToString(), kFileTrackerKeyPrefix, &id_str))
+ break;
+
+ int64 tracker_id;
+ if (!base::StringToInt64(id_str, &tracker_id))
+ continue;
+ tracker_ids.push_back(tracker_id);
+ }
+ return tracker_ids;
}
std::vector<std::string>
MetadataDatabaseIndexOnDisk::GetAllMetadataIDs() const {
- // TODO(peria): Implement here
- NOTIMPLEMENTED();
- return std::vector<std::string>();
+ std::vector<std::string> file_ids;
+ scoped_ptr<leveldb::Iterator> itr(db_->NewIterator(leveldb::ReadOptions()));
+ for (itr->Seek(kFileMetadataKeyPrefix); itr->Valid(); itr->Next()) {
+ std::string file_id;
+ if (!RemovePrefix(itr->key().ToString(), kFileMetadataKeyPrefix, &file_id))
+ break;
+ file_ids.push_back(file_id);
+ }
+ return file_ids;
}
void MetadataDatabaseIndexOnDisk::AddToAppIDIndex(
« no previous file with comments | « no previous file | chrome/browser/sync_file_system/drive_backend/metadata_database_index_on_disk_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698