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

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

Issue 1545223002: Switch to standard integer types in chrome/browser/, part 4 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 years, 12 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_index_ on_disk.h" 5 #include "chrome/browser/sync_file_system/drive_backend/metadata_database_index_ on_disk.h"
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/macros.h"
9 #include "base/stl_util.h" 10 #include "base/stl_util.h"
10 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
12 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_constants. h" 13 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_constants. h"
13 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_util.h" 14 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_util.h"
14 #include "chrome/browser/sync_file_system/drive_backend/leveldb_wrapper.h" 15 #include "chrome/browser/sync_file_system/drive_backend/leveldb_wrapper.h"
15 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.pb.h" 16 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.pb.h"
16 #include "chrome/browser/sync_file_system/logger.h" 17 #include "chrome/browser/sync_file_system/logger.h"
17 #include "third_party/leveldatabase/src/include/leveldb/status.h" 18 #include "third_party/leveldatabase/src/include/leveldb/status.h"
18 19
19 // LevelDB database schema 20 // LevelDB database schema
20 // ======================= 21 // =======================
21 // 22 //
22 // NOTE 23 // NOTE
23 // - Entries are sorted by keys. 24 // - Entries are sorted by keys.
24 // - int64 value is serialized as a string by base::Int64ToString(). 25 // - int64_t value is serialized as a string by base::Int64ToString().
25 // - ServiceMetadata, FileMetadata, and FileTracker values are serialized 26 // - ServiceMetadata, FileMetadata, and FileTracker values are serialized
26 // as a string by SerializeToString() of protocol buffers. 27 // as a string by SerializeToString() of protocol buffers.
27 // 28 //
28 // Version 4: 29 // Version 4:
29 // # Version of this schema 30 // # Version of this schema
30 // key: "VERSION" 31 // key: "VERSION"
31 // value: "4" 32 // value: "4"
32 // 33 //
33 // # Metadata of the SyncFS service (compatible with version 3) 34 // # Metadata of the SyncFS service (compatible with version 3)
34 // key: "SERVICE" 35 // key: "SERVICE"
35 // value: <ServiceMetadata 'service_metadata'> 36 // value: <ServiceMetadata 'service_metadata'>
36 // 37 //
37 // # Metadata of remote files (compatible with version 3) 38 // # Metadata of remote files (compatible with version 3)
38 // key: "FILE: " + <string 'file_id'> 39 // key: "FILE: " + <string 'file_id'>
39 // value: <FileMetadata 'metadata'> 40 // value: <FileMetadata 'metadata'>
40 // 41 //
41 // # Trackers of remote file updates (compatible with version 3) 42 // # Trackers of remote file updates (compatible with version 3)
42 // key: "TRACKER: " + <int64 'tracker_id'> 43 // key: "TRACKER: " + <int64_t 'tracker_id'>
43 // value: <FileTracker 'tracker'> 44 // value: <FileTracker 'tracker'>
44 // 45 //
45 // # Index from App ID to the tracker ID 46 // # Index from App ID to the tracker ID
46 // key: "APP_ROOT: " + <string 'app_id'> 47 // key: "APP_ROOT: " + <string 'app_id'>
47 // value: <int64 'app_root_tracker_id'> 48 // value: <int64_t 'app_root_tracker_id'>
48 // 49 //
49 // # Index from file ID to the active tracker ID 50 // # Index from file ID to the active tracker ID
50 // key: "ACTIVE_FILE: " + <string 'file_id'> 51 // key: "ACTIVE_FILE: " + <string 'file_id'>
51 // value: <int64 'active_tracker_id'> 52 // value: <int64_t 'active_tracker_id'>
52 // 53 //
53 // # Index from file ID to a tracker ID 54 // # Index from file ID to a tracker ID
54 // key: "TRACKER_FILE: " + <string 'file_id'> + '\x00' + <int64 'tracker_id'> 55 // key: "TRACKER_FILE: " + <string 'file_id'> + '\x00' +
56 // <int64_t'tracker_id'>
55 // value: <empty> 57 // value: <empty>
56 // 58 //
57 // # Tracker IDs; a file metadata linked to multiple tracker IDs. 59 // # Tracker IDs; a file metadata linked to multiple tracker IDs.
58 // key: "MULTI_FILE: " + <int64 'tracker_id'> 60 // key: "MULTI_FILE: " + <int64_t 'tracker_id'>
59 // value: <empty> 61 // value: <empty>
60 // 62 //
61 // # Index from the parent tracker ID and the title to the active tracker ID 63 // # Index from the parent tracker ID and the title to the active tracker ID
62 // key: "ACTIVE_PATH: " + <int64 'parent_tracker_id'> + 64 // key: "ACTIVE_PATH: " + <int64_t 'parent_tracker_id'> +
63 // '\x00' + <string 'title'> 65 // '\x00' + <string 'title'>
64 // value: <int64 'active_tracker_id'> 66 // value: <int64_t 'active_tracker_id'>
65 // 67 //
66 // # Index from the parent tracker ID and the title to a tracker ID 68 // # Index from the parent tracker ID and the title to a tracker ID
67 // key: "TRACKER_PATH: " + <int64 'parent_tracker_id'> + 69 // key: "TRACKER_PATH: " + <int64_t 'parent_tracker_id'> +
68 // '\x00' + <string 'title'> + '\x00' + <int64 'tracker_id'> 70 // '\x00' + <string 'title'> + '\x00' + <int64_t 'tracker_id'>
69 // value: <empty> 71 // value: <empty>
70 // 72 //
71 // # Tracker IDs; a parent tracker ID and a title figure multiple tracker IDs 73 // # Tracker IDs; a parent tracker ID and a title figure multiple tracker IDs
72 // key: "MULTI_PATH: " + <int64 'tracker_id'> 74 // key: "MULTI_PATH: " + <int64_t 'tracker_id'>
73 // value: <empty> 75 // value: <empty>
74 // 76 //
75 // # Dirty tracker IDs 77 // # Dirty tracker IDs
76 // key: "DIRTY: " + <int64 'dirty_tracker_id'> 78 // key: "DIRTY: " + <int64_t 'dirty_tracker_id'>
77 // value: <empty> 79 // value: <empty>
78 // 80 //
79 // # Demoted dirty tracker IDs 81 // # Demoted dirty tracker IDs
80 // key: "DEMOTED_DIRTY: " + <int64 'demoted_dirty_tracker_id'> 82 // key: "DEMOTED_DIRTY: " + <int64_t 'demoted_dirty_tracker_id'>
81 // value: <empty> 83 // value: <empty>
82 // 84 //
83 // # Timestamp when the last validation ran 85 // # Timestamp when the last validation ran
84 // key: "LAST_VALID" 86 // key: "LAST_VALID"
85 // value: <time_t 'last_valid_time'> 87 // value: <time_t 'last_valid_time'>
86 88
87 namespace sync_file_system { 89 namespace sync_file_system {
88 namespace drive_backend { 90 namespace drive_backend {
89 91
90 namespace { 92 namespace {
(...skipping 10 matching lines...) Expand all
101 std::ostringstream oss; 103 std::ostringstream oss;
102 oss << kTrackerIDByFileIDKeyPrefix << file_id << '\0'; 104 oss << kTrackerIDByFileIDKeyPrefix << file_id << '\0';
103 return oss.str(); 105 return oss.str();
104 } 106 }
105 107
106 std::string GenerateMultiTrackerKey(const std::string& file_id) { 108 std::string GenerateMultiTrackerKey(const std::string& file_id) {
107 return kMultiTrackerByFileIDKeyPrefix + file_id; 109 return kMultiTrackerByFileIDKeyPrefix + file_id;
108 } 110 }
109 111
110 std::string GenerateActiveTrackerIDByParentAndTitleKey( 112 std::string GenerateActiveTrackerIDByParentAndTitleKey(
111 int64 parent_id, const std::string& title) { 113 int64_t parent_id,
114 const std::string& title) {
112 std::ostringstream oss; 115 std::ostringstream oss;
113 oss << kActiveTrackerIDByParentAndTitleKeyPrefix << parent_id 116 oss << kActiveTrackerIDByParentAndTitleKeyPrefix << parent_id
114 << '\0' << title; 117 << '\0' << title;
115 return oss.str(); 118 return oss.str();
116 } 119 }
117 120
118 std::string GenerateTrackerIDByParentAndTitleKeyPrefix( 121 std::string GenerateTrackerIDByParentAndTitleKeyPrefix(
119 int64 parent_id, const std::string& title) { 122 int64_t parent_id,
123 const std::string& title) {
120 std::ostringstream oss; 124 std::ostringstream oss;
121 oss << kTrackerIDByParentAndTitleKeyPrefix << parent_id << '\0' 125 oss << kTrackerIDByParentAndTitleKeyPrefix << parent_id << '\0'
122 << title << '\0'; 126 << title << '\0';
123 return oss.str(); 127 return oss.str();
124 } 128 }
125 129
126 std::string GenerateTrackerIDsByParentIDKeyPrefix(int64 parent_id) { 130 std::string GenerateTrackerIDsByParentIDKeyPrefix(int64_t parent_id) {
127 std::ostringstream oss; 131 std::ostringstream oss;
128 oss << kTrackerIDByParentAndTitleKeyPrefix << parent_id << '\0'; 132 oss << kTrackerIDByParentAndTitleKeyPrefix << parent_id << '\0';
129 return oss.str(); 133 return oss.str();
130 } 134 }
131 135
132 std::string GenerateMultiBackingParentAndTitleKey( 136 std::string GenerateMultiBackingParentAndTitleKey(int64_t parent_id,
133 int64 parent_id, const std::string& title) { 137 const std::string& title) {
134 std::ostringstream oss; 138 std::ostringstream oss;
135 oss << kMultiBackingParentAndTitleKeyPrefix << parent_id << '\0' 139 oss << kMultiBackingParentAndTitleKeyPrefix << parent_id << '\0'
136 << title; 140 << title;
137 return oss.str(); 141 return oss.str();
138 } 142 }
139 143
140 std::string GenerateDirtyIDKey(int64 tracker_id) { 144 std::string GenerateDirtyIDKey(int64_t tracker_id) {
141 return kDirtyIDKeyPrefix + base::Int64ToString(tracker_id); 145 return kDirtyIDKeyPrefix + base::Int64ToString(tracker_id);
142 } 146 }
143 147
144 std::string GenerateDemotedDirtyIDKey(int64 tracker_id) { 148 std::string GenerateDemotedDirtyIDKey(int64_t tracker_id) {
145 return kDemotedDirtyIDKeyPrefix + base::Int64ToString(tracker_id); 149 return kDemotedDirtyIDKeyPrefix + base::Int64ToString(tracker_id);
146 } 150 }
147 151
148 void RemoveUnreachableItemsFromDB(LevelDBWrapper* db, 152 void RemoveUnreachableItemsFromDB(LevelDBWrapper* db,
149 int64 sync_root_tracker_id) { 153 int64_t sync_root_tracker_id) {
150 DCHECK(db); 154 DCHECK(db);
151 155
152 typedef std::map<int64, std::set<int64> > ChildTrackersByParent; 156 typedef std::map<int64_t, std::set<int64_t>> ChildTrackersByParent;
153 ChildTrackersByParent trackers_by_parent; 157 ChildTrackersByParent trackers_by_parent;
154 { 158 {
155 // Set up links from parent tracker to child trackers. 159 // Set up links from parent tracker to child trackers.
156 std::set<int64> inactive_trackers; 160 std::set<int64_t> inactive_trackers;
157 scoped_ptr<LevelDBWrapper::Iterator> itr = db->NewIterator(); 161 scoped_ptr<LevelDBWrapper::Iterator> itr = db->NewIterator();
158 for (itr->Seek(kFileTrackerKeyPrefix); itr->Valid(); itr->Next()) { 162 for (itr->Seek(kFileTrackerKeyPrefix); itr->Valid(); itr->Next()) {
159 if (!RemovePrefix(itr->key().ToString(), kFileTrackerKeyPrefix, nullptr)) 163 if (!RemovePrefix(itr->key().ToString(), kFileTrackerKeyPrefix, nullptr))
160 break; 164 break;
161 165
162 scoped_ptr<FileTracker> tracker(new FileTracker); 166 scoped_ptr<FileTracker> tracker(new FileTracker);
163 if (!tracker->ParseFromString(itr->value().ToString())) { 167 if (!tracker->ParseFromString(itr->value().ToString())) {
164 util::Log(logging::LOG_WARNING, FROM_HERE, 168 util::Log(logging::LOG_WARNING, FROM_HERE,
165 "Failed to parse a Tracker"); 169 "Failed to parse a Tracker");
166 continue; 170 continue;
167 } 171 }
168 172
169 int64 parent_tracker_id = tracker->parent_tracker_id(); 173 int64_t parent_tracker_id = tracker->parent_tracker_id();
170 int64 tracker_id = tracker->tracker_id(); 174 int64_t tracker_id = tracker->tracker_id();
171 trackers_by_parent[parent_tracker_id].insert(tracker_id); 175 trackers_by_parent[parent_tracker_id].insert(tracker_id);
172 if (!tracker->active()) 176 if (!tracker->active())
173 inactive_trackers.insert(tracker_id); 177 inactive_trackers.insert(tracker_id);
174 } 178 }
175 179
176 // Drop links from inactive trackers. 180 // Drop links from inactive trackers.
177 for (std::set<int64>::iterator iter = inactive_trackers.begin(); 181 for (std::set<int64_t>::iterator iter = inactive_trackers.begin();
178 iter != inactive_trackers.end(); ++iter) { 182 iter != inactive_trackers.end(); ++iter) {
179 trackers_by_parent.erase(*iter); 183 trackers_by_parent.erase(*iter);
180 } 184 }
181 } 185 }
182 186
183 // Traverse tracker tree from sync-root. 187 // Traverse tracker tree from sync-root.
184 std::set<int64> visited_trackers; 188 std::set<int64_t> visited_trackers;
185 { 189 {
186 std::vector<int64> pending; 190 std::vector<int64_t> pending;
187 if (sync_root_tracker_id != kInvalidTrackerID) 191 if (sync_root_tracker_id != kInvalidTrackerID)
188 pending.push_back(sync_root_tracker_id); 192 pending.push_back(sync_root_tracker_id);
189 193
190 while (!pending.empty()) { 194 while (!pending.empty()) {
191 int64 tracker_id = pending.back(); 195 int64_t tracker_id = pending.back();
192 DCHECK_NE(kInvalidTrackerID, tracker_id); 196 DCHECK_NE(kInvalidTrackerID, tracker_id);
193 pending.pop_back(); 197 pending.pop_back();
194 198
195 if (!visited_trackers.insert(tracker_id).second) { 199 if (!visited_trackers.insert(tracker_id).second) {
196 NOTREACHED(); 200 NOTREACHED();
197 continue; 201 continue;
198 } 202 }
199 203
200 AppendContents( 204 AppendContents(
201 LookUpMap(trackers_by_parent, tracker_id, std::set<int64>()), 205 LookUpMap(trackers_by_parent, tracker_id, std::set<int64_t>()),
202 &pending); 206 &pending);
203 } 207 }
204 } 208 }
205 209
206 // Delete all unreachable trackers, and list all |file_id| referred by 210 // Delete all unreachable trackers, and list all |file_id| referred by
207 // remained trackers. 211 // remained trackers.
208 base::hash_set<std::string> referred_file_ids; 212 base::hash_set<std::string> referred_file_ids;
209 { 213 {
210 scoped_ptr<LevelDBWrapper::Iterator> itr = db->NewIterator(); 214 scoped_ptr<LevelDBWrapper::Iterator> itr = db->NewIterator();
211 for (itr->Seek(kFileTrackerKeyPrefix); itr->Valid(); itr->Next()) { 215 for (itr->Seek(kFileTrackerKeyPrefix); itr->Valid(); itr->Next()) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 "Failed to parse a FileMetadata for ID: %s", 302 "Failed to parse a FileMetadata for ID: %s",
299 file_id.c_str()); 303 file_id.c_str());
300 return false; 304 return false;
301 } 305 }
302 if (metadata) 306 if (metadata)
303 metadata->CopyFrom(tmp_metadata); 307 metadata->CopyFrom(tmp_metadata);
304 308
305 return true; 309 return true;
306 } 310 }
307 311
308 bool MetadataDatabaseIndexOnDisk::GetFileTracker( 312 bool MetadataDatabaseIndexOnDisk::GetFileTracker(int64_t tracker_id,
309 int64 tracker_id, FileTracker* tracker) const { 313 FileTracker* tracker) const {
310 const std::string key = 314 const std::string key =
311 kFileTrackerKeyPrefix + base::Int64ToString(tracker_id); 315 kFileTrackerKeyPrefix + base::Int64ToString(tracker_id);
312 std::string value; 316 std::string value;
313 leveldb::Status status = db_->Get(key, &value); 317 leveldb::Status status = db_->Get(key, &value);
314 318
315 if (status.IsNotFound()) 319 if (status.IsNotFound())
316 return false; 320 return false;
317 321
318 if (!status.ok()) { 322 if (!status.ok()) {
319 util::Log(logging::LOG_WARNING, FROM_HERE, 323 util::Log(logging::LOG_WARNING, FROM_HERE,
(...skipping 19 matching lines...) Expand all
339 void MetadataDatabaseIndexOnDisk::StoreFileMetadata( 343 void MetadataDatabaseIndexOnDisk::StoreFileMetadata(
340 scoped_ptr<FileMetadata> metadata) { 344 scoped_ptr<FileMetadata> metadata) {
341 DCHECK(metadata); 345 DCHECK(metadata);
342 PutFileMetadataToDB(*metadata, db_); 346 PutFileMetadataToDB(*metadata, db_);
343 } 347 }
344 348
345 void MetadataDatabaseIndexOnDisk::StoreFileTracker( 349 void MetadataDatabaseIndexOnDisk::StoreFileTracker(
346 scoped_ptr<FileTracker> tracker) { 350 scoped_ptr<FileTracker> tracker) {
347 DCHECK(tracker); 351 DCHECK(tracker);
348 352
349 int64 tracker_id = tracker->tracker_id(); 353 int64_t tracker_id = tracker->tracker_id();
350 FileTracker old_tracker; 354 FileTracker old_tracker;
351 if (!GetFileTracker(tracker_id, &old_tracker)) { 355 if (!GetFileTracker(tracker_id, &old_tracker)) {
352 DVLOG(3) << "Adding new tracker: " << tracker->tracker_id() 356 DVLOG(3) << "Adding new tracker: " << tracker->tracker_id()
353 << " " << GetTrackerTitle(*tracker); 357 << " " << GetTrackerTitle(*tracker);
354 AddToAppIDIndex(*tracker); 358 AddToAppIDIndex(*tracker);
355 AddToFileIDIndexes(*tracker); 359 AddToFileIDIndexes(*tracker);
356 AddToPathIndexes(*tracker); 360 AddToPathIndexes(*tracker);
357 AddToDirtyTrackerIndexes(*tracker); 361 AddToDirtyTrackerIndexes(*tracker);
358 } else { 362 } else {
359 DVLOG(3) << "Updating tracker: " << tracker->tracker_id() 363 DVLOG(3) << "Updating tracker: " << tracker->tracker_id()
360 << " " << GetTrackerTitle(*tracker); 364 << " " << GetTrackerTitle(*tracker);
361 UpdateInAppIDIndex(old_tracker, *tracker); 365 UpdateInAppIDIndex(old_tracker, *tracker);
362 UpdateInFileIDIndexes(old_tracker, *tracker); 366 UpdateInFileIDIndexes(old_tracker, *tracker);
363 UpdateInPathIndexes(old_tracker, *tracker); 367 UpdateInPathIndexes(old_tracker, *tracker);
364 UpdateInDirtyTrackerIndexes(old_tracker, *tracker); 368 UpdateInDirtyTrackerIndexes(old_tracker, *tracker);
365 } 369 }
366 370
367 PutFileTrackerToDB(*tracker, db_); 371 PutFileTrackerToDB(*tracker, db_);
368 } 372 }
369 373
370 void MetadataDatabaseIndexOnDisk::RemoveFileMetadata( 374 void MetadataDatabaseIndexOnDisk::RemoveFileMetadata(
371 const std::string& file_id) { 375 const std::string& file_id) {
372 PutFileMetadataDeletionToDB(file_id, db_); 376 PutFileMetadataDeletionToDB(file_id, db_);
373 } 377 }
374 378
375 void MetadataDatabaseIndexOnDisk::RemoveFileTracker(int64 tracker_id) { 379 void MetadataDatabaseIndexOnDisk::RemoveFileTracker(int64_t tracker_id) {
376 FileTracker tracker; 380 FileTracker tracker;
377 if (!GetFileTracker(tracker_id, &tracker)) { 381 if (!GetFileTracker(tracker_id, &tracker)) {
378 NOTREACHED(); 382 NOTREACHED();
379 return; 383 return;
380 } 384 }
381 385
382 DVLOG(1) << "Removing tracker: " 386 DVLOG(1) << "Removing tracker: "
383 << tracker.tracker_id() << " " << GetTrackerTitle(tracker); 387 << tracker.tracker_id() << " " << GetTrackerTitle(tracker);
384 RemoveFromAppIDIndex(tracker); 388 RemoveFromAppIDIndex(tracker);
385 RemoveFromFileIDIndexes(tracker); 389 RemoveFromFileIDIndexes(tracker);
386 RemoveFromPathIndexes(tracker); 390 RemoveFromPathIndexes(tracker);
387 RemoveFromDirtyTrackerIndexes(tracker); 391 RemoveFromDirtyTrackerIndexes(tracker);
388 392
389 PutFileTrackerDeletionToDB(tracker_id, db_); 393 PutFileTrackerDeletionToDB(tracker_id, db_);
390 } 394 }
391 395
392 TrackerIDSet MetadataDatabaseIndexOnDisk::GetFileTrackerIDsByFileID( 396 TrackerIDSet MetadataDatabaseIndexOnDisk::GetFileTrackerIDsByFileID(
393 const std::string& file_id) const { 397 const std::string& file_id) const {
394 return GetTrackerIDSetByPrefix( 398 return GetTrackerIDSetByPrefix(
395 GenerateActiveTrackerIDByFileIDKey(file_id), 399 GenerateActiveTrackerIDByFileIDKey(file_id),
396 GenerateTrackerIDByFileIDKeyPrefix(file_id)); 400 GenerateTrackerIDByFileIDKeyPrefix(file_id));
397 } 401 }
398 402
399 int64 MetadataDatabaseIndexOnDisk::GetAppRootTracker( 403 int64_t MetadataDatabaseIndexOnDisk::GetAppRootTracker(
400 const std::string& app_id) const { 404 const std::string& app_id) const {
401 const std::string key = GenerateAppRootIDByAppIDKey(app_id); 405 const std::string key = GenerateAppRootIDByAppIDKey(app_id);
402 std::string value; 406 std::string value;
403 leveldb::Status status = db_->Get(key, &value); 407 leveldb::Status status = db_->Get(key, &value);
404 408
405 if (status.IsNotFound()) 409 if (status.IsNotFound())
406 return kInvalidTrackerID; 410 return kInvalidTrackerID;
407 411
408 if (!status.ok()) { 412 if (!status.ok()) {
409 util::Log(logging::LOG_WARNING, FROM_HERE, 413 util::Log(logging::LOG_WARNING, FROM_HERE,
410 "LevelDB error (%s) in getting AppRoot for AppID: %s", 414 "LevelDB error (%s) in getting AppRoot for AppID: %s",
411 status.ToString().c_str(), 415 status.ToString().c_str(),
412 app_id.c_str()); 416 app_id.c_str());
413 return kInvalidTrackerID; 417 return kInvalidTrackerID;
414 } 418 }
415 419
416 int64 root_id; 420 int64_t root_id;
417 if (!base::StringToInt64(value, &root_id)) { 421 if (!base::StringToInt64(value, &root_id)) {
418 util::Log(logging::LOG_WARNING, FROM_HERE, 422 util::Log(logging::LOG_WARNING, FROM_HERE,
419 "Failed to parse a root ID (%s) for an App ID: %s", 423 "Failed to parse a root ID (%s) for an App ID: %s",
420 value.c_str(), 424 value.c_str(),
421 app_id.c_str()); 425 app_id.c_str());
422 return kInvalidTrackerID; 426 return kInvalidTrackerID;
423 } 427 }
424 428
425 return root_id; 429 return root_id;
426 } 430 }
427 431
428 TrackerIDSet MetadataDatabaseIndexOnDisk::GetFileTrackerIDsByParentAndTitle( 432 TrackerIDSet MetadataDatabaseIndexOnDisk::GetFileTrackerIDsByParentAndTitle(
429 int64 parent_tracker_id, const std::string& title) const { 433 int64_t parent_tracker_id,
434 const std::string& title) const {
430 return GetTrackerIDSetByPrefix( 435 return GetTrackerIDSetByPrefix(
431 GenerateActiveTrackerIDByParentAndTitleKey(parent_tracker_id, title), 436 GenerateActiveTrackerIDByParentAndTitleKey(parent_tracker_id, title),
432 GenerateTrackerIDByParentAndTitleKeyPrefix(parent_tracker_id, title)); 437 GenerateTrackerIDByParentAndTitleKeyPrefix(parent_tracker_id, title));
433 } 438 }
434 439
435 std::vector<int64> MetadataDatabaseIndexOnDisk::GetFileTrackerIDsByParent( 440 std::vector<int64_t> MetadataDatabaseIndexOnDisk::GetFileTrackerIDsByParent(
436 int64 parent_id) const { 441 int64_t parent_id) const {
437 std::vector<int64> result; 442 std::vector<int64_t> result;
438 443
439 const std::string prefix = GenerateTrackerIDsByParentIDKeyPrefix(parent_id); 444 const std::string prefix = GenerateTrackerIDsByParentIDKeyPrefix(parent_id);
440 scoped_ptr<LevelDBWrapper::Iterator> itr(db_->NewIterator()); 445 scoped_ptr<LevelDBWrapper::Iterator> itr(db_->NewIterator());
441 for (itr->Seek(prefix); itr->Valid(); itr->Next()) { 446 for (itr->Seek(prefix); itr->Valid(); itr->Next()) {
442 const std::string& key(itr->key().ToString()); 447 const std::string& key(itr->key().ToString());
443 std::string title_and_id; 448 std::string title_and_id;
444 if (!RemovePrefix(key, prefix, &title_and_id)) 449 if (!RemovePrefix(key, prefix, &title_and_id))
445 break; 450 break;
446 451
447 size_t pos = title_and_id.rfind('\0'); 452 size_t pos = title_and_id.rfind('\0');
448 DCHECK(pos != std::string::npos); 453 DCHECK(pos != std::string::npos);
449 454
450 int64 tracker_id; 455 int64_t tracker_id;
451 if (!base::StringToInt64(title_and_id.substr(pos + 1), &tracker_id)) 456 if (!base::StringToInt64(title_and_id.substr(pos + 1), &tracker_id))
452 continue; 457 continue;
453 result.push_back(tracker_id); 458 result.push_back(tracker_id);
454 } 459 }
455 return result; 460 return result;
456 } 461 }
457 462
458 std::string MetadataDatabaseIndexOnDisk::PickMultiTrackerFileID() const { 463 std::string MetadataDatabaseIndexOnDisk::PickMultiTrackerFileID() const {
459 scoped_ptr<LevelDBWrapper::Iterator> itr(db_->NewIterator()); 464 scoped_ptr<LevelDBWrapper::Iterator> itr(db_->NewIterator());
460 itr->Seek(kMultiTrackerByFileIDKeyPrefix); 465 itr->Seek(kMultiTrackerByFileIDKeyPrefix);
(...skipping 16 matching lines...) Expand all
477 482
478 std::string value; 483 std::string value;
479 if (!RemovePrefix(itr->key().ToString(), 484 if (!RemovePrefix(itr->key().ToString(),
480 kMultiBackingParentAndTitleKeyPrefix, &value)) 485 kMultiBackingParentAndTitleKeyPrefix, &value))
481 return ParentIDAndTitle(); 486 return ParentIDAndTitle();
482 487
483 size_t pos = value.find('\0'); // '\0' is a separator. 488 size_t pos = value.find('\0'); // '\0' is a separator.
484 if (pos == std::string::npos) 489 if (pos == std::string::npos)
485 return ParentIDAndTitle(); 490 return ParentIDAndTitle();
486 491
487 int64 parent_id; 492 int64_t parent_id;
488 return base::StringToInt64(value.substr(0, pos), &parent_id) ? 493 return base::StringToInt64(value.substr(0, pos), &parent_id) ?
489 ParentIDAndTitle(parent_id, value.substr(pos + 1)) : ParentIDAndTitle(); 494 ParentIDAndTitle(parent_id, value.substr(pos + 1)) : ParentIDAndTitle();
490 } 495 }
491 496
492 int64 MetadataDatabaseIndexOnDisk::PickDirtyTracker() const { 497 int64_t MetadataDatabaseIndexOnDisk::PickDirtyTracker() const {
493 scoped_ptr<LevelDBWrapper::Iterator> itr(db_->NewIterator()); 498 scoped_ptr<LevelDBWrapper::Iterator> itr(db_->NewIterator());
494 itr->Seek(kDirtyIDKeyPrefix); 499 itr->Seek(kDirtyIDKeyPrefix);
495 if (!itr->Valid()) 500 if (!itr->Valid())
496 return kInvalidTrackerID; 501 return kInvalidTrackerID;
497 502
498 std::string id_str; 503 std::string id_str;
499 if (!RemovePrefix(itr->key().ToString(), kDirtyIDKeyPrefix, &id_str)) 504 if (!RemovePrefix(itr->key().ToString(), kDirtyIDKeyPrefix, &id_str))
500 return kInvalidTrackerID; 505 return kInvalidTrackerID;
501 506
502 int64 tracker_id; 507 int64_t tracker_id;
503 if (!base::StringToInt64(id_str, &tracker_id)) 508 if (!base::StringToInt64(id_str, &tracker_id))
504 return kInvalidTrackerID; 509 return kInvalidTrackerID;
505 510
506 return tracker_id; 511 return tracker_id;
507 } 512 }
508 513
509 void MetadataDatabaseIndexOnDisk::DemoteDirtyTracker(int64 tracker_id) { 514 void MetadataDatabaseIndexOnDisk::DemoteDirtyTracker(int64_t tracker_id) {
510 const std::string key = GenerateDirtyIDKey(tracker_id); 515 const std::string key = GenerateDirtyIDKey(tracker_id);
511 516
512 std::string value; 517 std::string value;
513 leveldb::Status status = db_->Get(key, &value); 518 leveldb::Status status = db_->Get(key, &value);
514 if (status.IsNotFound()) 519 if (status.IsNotFound())
515 return; 520 return;
516 if (!status.ok()) { 521 if (!status.ok()) {
517 util::Log(logging::LOG_WARNING, FROM_HERE, 522 util::Log(logging::LOG_WARNING, FROM_HERE,
518 "LevelDB error (%s) in getting a dirty tracker for ID: %" PRId64, 523 "LevelDB error (%s) in getting a dirty tracker for ID: %" PRId64,
519 status.ToString().c_str(), 524 status.ToString().c_str(),
520 tracker_id); 525 tracker_id);
521 return; 526 return;
522 } 527 }
523 528
524 db_->Delete(key); 529 db_->Delete(key);
525 db_->Put(GenerateDemotedDirtyIDKey(tracker_id), std::string()); 530 db_->Put(GenerateDemotedDirtyIDKey(tracker_id), std::string());
526 --num_dirty_trackers_; 531 --num_dirty_trackers_;
527 } 532 }
528 533
529 bool MetadataDatabaseIndexOnDisk::HasDemotedDirtyTracker() const { 534 bool MetadataDatabaseIndexOnDisk::HasDemotedDirtyTracker() const {
530 scoped_ptr<LevelDBWrapper::Iterator> itr(db_->NewIterator()); 535 scoped_ptr<LevelDBWrapper::Iterator> itr(db_->NewIterator());
531 itr->Seek(kDemotedDirtyIDKeyPrefix); 536 itr->Seek(kDemotedDirtyIDKeyPrefix);
532 if (!itr->Valid()) 537 if (!itr->Valid())
533 return false; 538 return false;
534 return base::StartsWith(itr->key().ToString(), kDemotedDirtyIDKeyPrefix, 539 return base::StartsWith(itr->key().ToString(), kDemotedDirtyIDKeyPrefix,
535 base::CompareCase::SENSITIVE); 540 base::CompareCase::SENSITIVE);
536 } 541 }
537 542
538 bool MetadataDatabaseIndexOnDisk::IsDemotedDirtyTracker( 543 bool MetadataDatabaseIndexOnDisk::IsDemotedDirtyTracker(
539 int64 tracker_id) const { 544 int64_t tracker_id) const {
540 return DBHasKey(GenerateDemotedDirtyIDKey(tracker_id)); 545 return DBHasKey(GenerateDemotedDirtyIDKey(tracker_id));
541 } 546 }
542 547
543 void MetadataDatabaseIndexOnDisk::PromoteDemotedDirtyTracker(int64 tracker_id) { 548 void MetadataDatabaseIndexOnDisk::PromoteDemotedDirtyTracker(
549 int64_t tracker_id) {
544 std::string demoted_key = GenerateDemotedDirtyIDKey(tracker_id); 550 std::string demoted_key = GenerateDemotedDirtyIDKey(tracker_id);
545 551
546 std::string empty; 552 std::string empty;
547 if (db_->Get(demoted_key, &empty).ok()) { 553 if (db_->Get(demoted_key, &empty).ok()) {
548 db_->Delete(demoted_key); 554 db_->Delete(demoted_key);
549 db_->Put(GenerateDirtyIDKey(tracker_id), std::string()); 555 db_->Put(GenerateDirtyIDKey(tracker_id), std::string());
550 ++num_dirty_trackers_; 556 ++num_dirty_trackers_;
551 } 557 }
552 } 558 }
553 559
554 bool MetadataDatabaseIndexOnDisk::PromoteDemotedDirtyTrackers() { 560 bool MetadataDatabaseIndexOnDisk::PromoteDemotedDirtyTrackers() {
555 bool promoted = false; 561 bool promoted = false;
556 scoped_ptr<LevelDBWrapper::Iterator> itr(db_->NewIterator()); 562 scoped_ptr<LevelDBWrapper::Iterator> itr(db_->NewIterator());
557 for (itr->Seek(kDemotedDirtyIDKeyPrefix); itr->Valid(); itr->Next()) { 563 for (itr->Seek(kDemotedDirtyIDKeyPrefix); itr->Valid(); itr->Next()) {
558 std::string id_str; 564 std::string id_str;
559 if (!RemovePrefix(itr->key().ToString(), kDemotedDirtyIDKeyPrefix, &id_str)) 565 if (!RemovePrefix(itr->key().ToString(), kDemotedDirtyIDKeyPrefix, &id_str))
560 break; 566 break;
561 567
562 int64 tracker_id; 568 int64_t tracker_id;
563 if (!base::StringToInt64(id_str, &tracker_id)) 569 if (!base::StringToInt64(id_str, &tracker_id))
564 continue; 570 continue;
565 571
566 db_->Delete(itr->key().ToString()); 572 db_->Delete(itr->key().ToString());
567 db_->Put(GenerateDirtyIDKey(tracker_id), std::string()); 573 db_->Put(GenerateDirtyIDKey(tracker_id), std::string());
568 ++num_dirty_trackers_; 574 ++num_dirty_trackers_;
569 promoted = true; 575 promoted = true;
570 } 576 }
571 return promoted; 577 return promoted;
572 } 578 }
(...skipping 27 matching lines...) Expand all
600 } 606 }
601 return count; 607 return count;
602 } 608 }
603 609
604 void MetadataDatabaseIndexOnDisk::SetSyncRootRevalidated() const { 610 void MetadataDatabaseIndexOnDisk::SetSyncRootRevalidated() const {
605 service_metadata_->set_sync_root_revalidated(true); 611 service_metadata_->set_sync_root_revalidated(true);
606 PutServiceMetadataToDB(*service_metadata_, db_); 612 PutServiceMetadataToDB(*service_metadata_, db_);
607 } 613 }
608 614
609 void MetadataDatabaseIndexOnDisk::SetSyncRootTrackerID( 615 void MetadataDatabaseIndexOnDisk::SetSyncRootTrackerID(
610 int64 sync_root_id) const { 616 int64_t sync_root_id) const {
611 service_metadata_->set_sync_root_tracker_id(sync_root_id); 617 service_metadata_->set_sync_root_tracker_id(sync_root_id);
612 PutServiceMetadataToDB(*service_metadata_, db_); 618 PutServiceMetadataToDB(*service_metadata_, db_);
613 } 619 }
614 620
615 void MetadataDatabaseIndexOnDisk::SetLargestChangeID( 621 void MetadataDatabaseIndexOnDisk::SetLargestChangeID(
616 int64 largest_change_id) const { 622 int64_t largest_change_id) const {
617 service_metadata_->set_largest_change_id(largest_change_id); 623 service_metadata_->set_largest_change_id(largest_change_id);
618 PutServiceMetadataToDB(*service_metadata_, db_); 624 PutServiceMetadataToDB(*service_metadata_, db_);
619 } 625 }
620 626
621 void MetadataDatabaseIndexOnDisk::SetNextTrackerID( 627 void MetadataDatabaseIndexOnDisk::SetNextTrackerID(
622 int64 next_tracker_id) const { 628 int64_t next_tracker_id) const {
623 service_metadata_->set_next_tracker_id(next_tracker_id); 629 service_metadata_->set_next_tracker_id(next_tracker_id);
624 PutServiceMetadataToDB(*service_metadata_, db_); 630 PutServiceMetadataToDB(*service_metadata_, db_);
625 } 631 }
626 632
627 bool MetadataDatabaseIndexOnDisk::IsSyncRootRevalidated() const { 633 bool MetadataDatabaseIndexOnDisk::IsSyncRootRevalidated() const {
628 return service_metadata_->has_sync_root_revalidated() && 634 return service_metadata_->has_sync_root_revalidated() &&
629 service_metadata_->sync_root_revalidated(); 635 service_metadata_->sync_root_revalidated();
630 } 636 }
631 637
632 int64 MetadataDatabaseIndexOnDisk::GetSyncRootTrackerID() const { 638 int64_t MetadataDatabaseIndexOnDisk::GetSyncRootTrackerID() const {
633 if (!service_metadata_->has_sync_root_tracker_id()) 639 if (!service_metadata_->has_sync_root_tracker_id())
634 return kInvalidTrackerID; 640 return kInvalidTrackerID;
635 return service_metadata_->sync_root_tracker_id(); 641 return service_metadata_->sync_root_tracker_id();
636 } 642 }
637 643
638 int64 MetadataDatabaseIndexOnDisk::GetLargestChangeID() const { 644 int64_t MetadataDatabaseIndexOnDisk::GetLargestChangeID() const {
639 if (!service_metadata_->has_largest_change_id()) 645 if (!service_metadata_->has_largest_change_id())
640 return kInvalidTrackerID; 646 return kInvalidTrackerID;
641 return service_metadata_->largest_change_id(); 647 return service_metadata_->largest_change_id();
642 } 648 }
643 649
644 int64 MetadataDatabaseIndexOnDisk::GetNextTrackerID() const { 650 int64_t MetadataDatabaseIndexOnDisk::GetNextTrackerID() const {
645 if (!service_metadata_->has_next_tracker_id()) 651 if (!service_metadata_->has_next_tracker_id())
646 return kInvalidTrackerID; 652 return kInvalidTrackerID;
647 return service_metadata_->next_tracker_id(); 653 return service_metadata_->next_tracker_id();
648 } 654 }
649 655
650 std::vector<std::string> 656 std::vector<std::string>
651 MetadataDatabaseIndexOnDisk::GetRegisteredAppIDs() const { 657 MetadataDatabaseIndexOnDisk::GetRegisteredAppIDs() const {
652 std::vector<std::string> result; 658 std::vector<std::string> result;
653 scoped_ptr<LevelDBWrapper::Iterator> itr(db_->NewIterator()); 659 scoped_ptr<LevelDBWrapper::Iterator> itr(db_->NewIterator());
654 for (itr->Seek(kAppRootIDByAppIDKeyPrefix); itr->Valid(); itr->Next()) { 660 for (itr->Seek(kAppRootIDByAppIDKeyPrefix); itr->Valid(); itr->Next()) {
655 std::string id; 661 std::string id;
656 if (!RemovePrefix(itr->key().ToString(), kAppRootIDByAppIDKeyPrefix, &id)) 662 if (!RemovePrefix(itr->key().ToString(), kAppRootIDByAppIDKeyPrefix, &id))
657 break; 663 break;
658 result.push_back(id); 664 result.push_back(id);
659 } 665 }
660 return result; 666 return result;
661 } 667 }
662 668
663 std::vector<int64> MetadataDatabaseIndexOnDisk::GetAllTrackerIDs() const { 669 std::vector<int64_t> MetadataDatabaseIndexOnDisk::GetAllTrackerIDs() const {
664 std::vector<int64> tracker_ids; 670 std::vector<int64_t> tracker_ids;
665 scoped_ptr<LevelDBWrapper::Iterator> itr(db_->NewIterator()); 671 scoped_ptr<LevelDBWrapper::Iterator> itr(db_->NewIterator());
666 for (itr->Seek(kFileTrackerKeyPrefix); itr->Valid(); itr->Next()) { 672 for (itr->Seek(kFileTrackerKeyPrefix); itr->Valid(); itr->Next()) {
667 std::string id_str; 673 std::string id_str;
668 if (!RemovePrefix(itr->key().ToString(), kFileTrackerKeyPrefix, &id_str)) 674 if (!RemovePrefix(itr->key().ToString(), kFileTrackerKeyPrefix, &id_str))
669 break; 675 break;
670 676
671 int64 tracker_id; 677 int64_t tracker_id;
672 if (!base::StringToInt64(id_str, &tracker_id)) 678 if (!base::StringToInt64(id_str, &tracker_id))
673 continue; 679 continue;
674 tracker_ids.push_back(tracker_id); 680 tracker_ids.push_back(tracker_id);
675 } 681 }
676 return tracker_ids; 682 return tracker_ids;
677 } 683 }
678 684
679 std::vector<std::string> 685 std::vector<std::string>
680 MetadataDatabaseIndexOnDisk::GetAllMetadataIDs() const { 686 MetadataDatabaseIndexOnDisk::GetAllMetadataIDs() const {
681 std::vector<std::string> file_ids; 687 std::vector<std::string> file_ids;
682 scoped_ptr<LevelDBWrapper::Iterator> itr(db_->NewIterator()); 688 scoped_ptr<LevelDBWrapper::Iterator> itr(db_->NewIterator());
683 for (itr->Seek(kFileMetadataKeyPrefix); itr->Valid(); itr->Next()) { 689 for (itr->Seek(kFileMetadataKeyPrefix); itr->Valid(); itr->Next()) {
684 std::string file_id; 690 std::string file_id;
685 if (!RemovePrefix(itr->key().ToString(), kFileMetadataKeyPrefix, &file_id)) 691 if (!RemovePrefix(itr->key().ToString(), kFileMetadataKeyPrefix, &file_id))
686 break; 692 break;
687 file_ids.push_back(file_id); 693 file_ids.push_back(file_id);
688 } 694 }
689 return file_ids; 695 return file_ids;
690 } 696 }
691 697
692 int64 MetadataDatabaseIndexOnDisk::BuildTrackerIndexes() { 698 int64_t MetadataDatabaseIndexOnDisk::BuildTrackerIndexes() {
693 int64 num_puts_before = db_->num_puts(); 699 int64_t num_puts_before = db_->num_puts();
694 700
695 scoped_ptr<LevelDBWrapper::Iterator> itr(db_->NewIterator()); 701 scoped_ptr<LevelDBWrapper::Iterator> itr(db_->NewIterator());
696 for (itr->Seek(kFileTrackerKeyPrefix); itr->Valid(); itr->Next()) { 702 for (itr->Seek(kFileTrackerKeyPrefix); itr->Valid(); itr->Next()) {
697 if (!RemovePrefix(itr->key().ToString(), kFileTrackerKeyPrefix, nullptr)) 703 if (!RemovePrefix(itr->key().ToString(), kFileTrackerKeyPrefix, nullptr))
698 break; 704 break;
699 705
700 FileTracker tracker; 706 FileTracker tracker;
701 if (!tracker.ParseFromString(itr->value().ToString())) { 707 if (!tracker.ParseFromString(itr->value().ToString())) {
702 util::Log(logging::LOG_WARNING, FROM_HERE, 708 util::Log(logging::LOG_WARNING, FROM_HERE,
703 "Failed to parse a Tracker"); 709 "Failed to parse a Tracker");
704 continue; 710 continue;
705 } 711 }
706 712
707 AddToAppIDIndex(tracker); 713 AddToAppIDIndex(tracker);
708 AddToFileIDIndexes(tracker); 714 AddToFileIDIndexes(tracker);
709 AddToPathIndexes(tracker); 715 AddToPathIndexes(tracker);
710 AddToDirtyTrackerIndexes(tracker); 716 AddToDirtyTrackerIndexes(tracker);
711 } 717 }
712 718
713 return db_->num_puts() - num_puts_before; 719 return db_->num_puts() - num_puts_before;
714 } 720 }
715 721
716 int64 MetadataDatabaseIndexOnDisk::DeleteTrackerIndexes() { 722 int64_t MetadataDatabaseIndexOnDisk::DeleteTrackerIndexes() {
717 const char* kIndexPrefixes[] = { 723 const char* kIndexPrefixes[] = {
718 kAppRootIDByAppIDKeyPrefix, kActiveTrackerIDByFileIDKeyPrefix, 724 kAppRootIDByAppIDKeyPrefix, kActiveTrackerIDByFileIDKeyPrefix,
719 kTrackerIDByFileIDKeyPrefix, kMultiTrackerByFileIDKeyPrefix, 725 kTrackerIDByFileIDKeyPrefix, kMultiTrackerByFileIDKeyPrefix,
720 kActiveTrackerIDByParentAndTitleKeyPrefix, 726 kActiveTrackerIDByParentAndTitleKeyPrefix,
721 kTrackerIDByParentAndTitleKeyPrefix, kMultiBackingParentAndTitleKeyPrefix, 727 kTrackerIDByParentAndTitleKeyPrefix, kMultiBackingParentAndTitleKeyPrefix,
722 kDirtyIDKeyPrefix, kDemotedDirtyIDKeyPrefix 728 kDirtyIDKeyPrefix, kDemotedDirtyIDKeyPrefix
723 }; 729 };
724 730
725 int64 num_deletes_before = db_->num_deletes(); 731 int64_t num_deletes_before = db_->num_deletes();
726 for (size_t i = 0; i < arraysize(kIndexPrefixes); ++i) 732 for (size_t i = 0; i < arraysize(kIndexPrefixes); ++i)
727 DeleteKeyStartsWith(kIndexPrefixes[i]); 733 DeleteKeyStartsWith(kIndexPrefixes[i]);
728 num_dirty_trackers_ = 0; 734 num_dirty_trackers_ = 0;
729 return db_->num_deletes() - num_deletes_before; 735 return db_->num_deletes() - num_deletes_before;
730 } 736 }
731 737
732 LevelDBWrapper* MetadataDatabaseIndexOnDisk::GetDBForTesting() { 738 LevelDBWrapper* MetadataDatabaseIndexOnDisk::GetDBForTesting() {
733 return db_; 739 return db_;
734 } 740 }
735 741
736 MetadataDatabaseIndexOnDisk::MetadataDatabaseIndexOnDisk(LevelDBWrapper* db) 742 MetadataDatabaseIndexOnDisk::MetadataDatabaseIndexOnDisk(LevelDBWrapper* db)
737 : db_(db), 743 : db_(db),
738 num_dirty_trackers_(0) { 744 num_dirty_trackers_(0) {
739 // TODO(peria): Add UMA to measure the number of FileMetadata, FileTracker, 745 // TODO(peria): Add UMA to measure the number of FileMetadata, FileTracker,
740 // and AppRootId. 746 // and AppRootId.
741 service_metadata_ = InitializeServiceMetadata(db_); 747 service_metadata_ = InitializeServiceMetadata(db_);
742 748
743 // Check if index is valid, if no validations run in 7 days. 749 // Check if index is valid, if no validations run in 7 days.
744 const int64 kThresholdToValidateInDays = 7; 750 const int64_t kThresholdToValidateInDays = 7;
745 751
746 int64 last_check_time = 0; 752 int64_t last_check_time = 0;
747 std::string value; 753 std::string value;
748 if (db_->Get(kLastValidationTimeKey, &value).ok()) 754 if (db_->Get(kLastValidationTimeKey, &value).ok())
749 base::StringToInt64(value, &last_check_time); 755 base::StringToInt64(value, &last_check_time);
750 base::TimeDelta since_last_check = 756 base::TimeDelta since_last_check =
751 base::Time::Now() - base::Time::FromInternalValue(last_check_time); 757 base::Time::Now() - base::Time::FromInternalValue(last_check_time);
752 int64 since_last_check_in_days = since_last_check.InDays(); 758 int64_t since_last_check_in_days = since_last_check.InDays();
753 if (since_last_check_in_days >= kThresholdToValidateInDays || 759 if (since_last_check_in_days >= kThresholdToValidateInDays ||
754 since_last_check_in_days < 0) { 760 since_last_check_in_days < 0) {
755 // TODO(peria): Add UMA to check if the number of deleted entries and the 761 // TODO(peria): Add UMA to check if the number of deleted entries and the
756 // number of built entries are different or not. 762 // number of built entries are different or not.
757 DeleteTrackerIndexes(); 763 DeleteTrackerIndexes();
758 BuildTrackerIndexes(); 764 BuildTrackerIndexes();
759 db_->Put(kLastValidationTimeKey, 765 db_->Put(kLastValidationTimeKey,
760 base::Int64ToString(base::Time::Now().ToInternalValue())); 766 base::Int64ToString(base::Time::Now().ToInternalValue()));
761 } else { 767 } else {
762 num_dirty_trackers_ = CountDirtyTrackerInternal(); 768 num_dirty_trackers_ = CountDirtyTrackerInternal();
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 const std::string multi_key = GenerateMultiTrackerKey(file_id); 876 const std::string multi_key = GenerateMultiTrackerKey(file_id);
871 if (DBHasKey(multi_key) && 877 if (DBHasKey(multi_key) &&
872 CountWithPrefix(prefix, tracker.tracker_id()) != MULTIPLE) { 878 CountWithPrefix(prefix, tracker.tracker_id()) != MULTIPLE) {
873 DVLOG(1) << " Remove from multi-tracker file IDs: " << file_id; 879 DVLOG(1) << " Remove from multi-tracker file IDs: " << file_id;
874 db_->Delete(multi_key); 880 db_->Delete(multi_key);
875 } 881 }
876 } 882 }
877 883
878 void MetadataDatabaseIndexOnDisk::AddToPathIndexes( 884 void MetadataDatabaseIndexOnDisk::AddToPathIndexes(
879 const FileTracker& new_tracker) { 885 const FileTracker& new_tracker) {
880 int64 parent_id = new_tracker.parent_tracker_id(); 886 int64_t parent_id = new_tracker.parent_tracker_id();
881 std::string title = GetTrackerTitle(new_tracker); 887 std::string title = GetTrackerTitle(new_tracker);
882 888
883 DVLOG(1) << " Add to trackers by parent and title: " 889 DVLOG(1) << " Add to trackers by parent and title: "
884 << parent_id << " " << title; 890 << parent_id << " " << title;
885 891
886 const std::string prefix = 892 const std::string prefix =
887 GenerateTrackerIDByParentAndTitleKeyPrefix(parent_id, title); 893 GenerateTrackerIDByParentAndTitleKeyPrefix(parent_id, title);
888 if (!title.empty()) { 894 if (!title.empty()) {
889 scoped_ptr<LevelDBWrapper::Iterator> itr(db_->NewIterator()); 895 scoped_ptr<LevelDBWrapper::Iterator> itr(db_->NewIterator());
890 for (itr->Seek(prefix); itr->Valid(); itr->Next()) { 896 for (itr->Seek(prefix); itr->Valid(); itr->Next()) {
891 std::string id_str; 897 std::string id_str;
892 if (!RemovePrefix(itr->key().ToString(), prefix, &id_str)) 898 if (!RemovePrefix(itr->key().ToString(), prefix, &id_str))
893 break; 899 break;
894 900
895 int64 tracker_id; 901 int64_t tracker_id;
896 if (!base::StringToInt64(id_str, &tracker_id)) 902 if (!base::StringToInt64(id_str, &tracker_id))
897 continue; 903 continue;
898 if (tracker_id == new_tracker.tracker_id()) { 904 if (tracker_id == new_tracker.tracker_id()) {
899 NOTREACHED(); 905 NOTREACHED();
900 continue; 906 continue;
901 } 907 }
902 908
903 const std::string multi_key = 909 const std::string multi_key =
904 GenerateMultiBackingParentAndTitleKey(parent_id, title); 910 GenerateMultiBackingParentAndTitleKey(parent_id, title);
905 DVLOG_IF(1, !DBHasKey(multi_key)) 911 DVLOG_IF(1, !DBHasKey(multi_key))
906 << " Add to multi backing file paths: " << parent_id << " " << title; 912 << " Add to multi backing file paths: " << parent_id << " " << title;
907 db_->Put(multi_key, std::string()); 913 db_->Put(multi_key, std::string());
908 break; 914 break;
909 } 915 }
910 } 916 }
911 917
912 AddToTrackerIDSetWithPrefix( 918 AddToTrackerIDSetWithPrefix(
913 GenerateActiveTrackerIDByParentAndTitleKey(parent_id, title), 919 GenerateActiveTrackerIDByParentAndTitleKey(parent_id, title),
914 prefix, new_tracker); 920 prefix, new_tracker);
915 } 921 }
916 922
917 void MetadataDatabaseIndexOnDisk::UpdateInPathIndexes( 923 void MetadataDatabaseIndexOnDisk::UpdateInPathIndexes(
918 const FileTracker& old_tracker, 924 const FileTracker& old_tracker,
919 const FileTracker& new_tracker) { 925 const FileTracker& new_tracker) {
920 DCHECK_EQ(old_tracker.tracker_id(), new_tracker.tracker_id()); 926 DCHECK_EQ(old_tracker.tracker_id(), new_tracker.tracker_id());
921 DCHECK_EQ(old_tracker.parent_tracker_id(), new_tracker.parent_tracker_id()); 927 DCHECK_EQ(old_tracker.parent_tracker_id(), new_tracker.parent_tracker_id());
922 DCHECK(GetTrackerTitle(old_tracker) == GetTrackerTitle(new_tracker) || 928 DCHECK(GetTrackerTitle(old_tracker) == GetTrackerTitle(new_tracker) ||
923 !old_tracker.has_synced_details()); 929 !old_tracker.has_synced_details());
924 930
925 int64 tracker_id = new_tracker.tracker_id(); 931 int64_t tracker_id = new_tracker.tracker_id();
926 int64 parent_id = new_tracker.parent_tracker_id(); 932 int64_t parent_id = new_tracker.parent_tracker_id();
927 const std::string old_title = GetTrackerTitle(old_tracker); 933 const std::string old_title = GetTrackerTitle(old_tracker);
928 const std::string title = GetTrackerTitle(new_tracker); 934 const std::string title = GetTrackerTitle(new_tracker);
929 935
930 if (old_title != title) { 936 if (old_title != title) {
931 const std::string old_prefix = 937 const std::string old_prefix =
932 GenerateTrackerIDByParentAndTitleKeyPrefix(parent_id, old_title); 938 GenerateTrackerIDByParentAndTitleKeyPrefix(parent_id, old_title);
933 EraseInTrackerIDSetWithPrefix( 939 EraseInTrackerIDSetWithPrefix(
934 GenerateActiveTrackerIDByParentAndTitleKey(parent_id, old_title), 940 GenerateActiveTrackerIDByParentAndTitleKey(parent_id, old_title),
935 old_prefix, tracker_id); 941 old_prefix, tracker_id);
936 942
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 DeactivateInTrackerIDSetWithPrefix( 979 DeactivateInTrackerIDSetWithPrefix(
974 active_tracker_key, prefix, tracker_id); 980 active_tracker_key, prefix, tracker_id);
975 } else if (!old_tracker.active() && new_tracker.active()) { 981 } else if (!old_tracker.active() && new_tracker.active()) {
976 ActivateInTrackerIDSetWithPrefix( 982 ActivateInTrackerIDSetWithPrefix(
977 active_tracker_key, prefix, tracker_id); 983 active_tracker_key, prefix, tracker_id);
978 } 984 }
979 } 985 }
980 986
981 void MetadataDatabaseIndexOnDisk::RemoveFromPathIndexes( 987 void MetadataDatabaseIndexOnDisk::RemoveFromPathIndexes(
982 const FileTracker& tracker) { 988 const FileTracker& tracker) {
983 int64 tracker_id = tracker.tracker_id(); 989 int64_t tracker_id = tracker.tracker_id();
984 int64 parent_id = tracker.parent_tracker_id(); 990 int64_t parent_id = tracker.parent_tracker_id();
985 std::string title = GetTrackerTitle(tracker); 991 std::string title = GetTrackerTitle(tracker);
986 992
987 DVLOG(1) << " Remove from trackers by parent and title: " 993 DVLOG(1) << " Remove from trackers by parent and title: "
988 << parent_id << " " << title; 994 << parent_id << " " << title;
989 995
990 const std::string active_tracker_key = 996 const std::string active_tracker_key =
991 GenerateActiveTrackerIDByParentAndTitleKey(parent_id, title); 997 GenerateActiveTrackerIDByParentAndTitleKey(parent_id, title);
992 const std::string key_prefix = 998 const std::string key_prefix =
993 GenerateTrackerIDByParentAndTitleKeyPrefix(parent_id, title); 999 GenerateTrackerIDByParentAndTitleKeyPrefix(parent_id, title);
994 if (!EraseInTrackerIDSetWithPrefix( 1000 if (!EraseInTrackerIDSetWithPrefix(
(...skipping 21 matching lines...) Expand all
1016 db_->Put(dirty_key, std::string()); 1022 db_->Put(dirty_key, std::string());
1017 ++num_dirty_trackers_; 1023 ++num_dirty_trackers_;
1018 } 1024 }
1019 } 1025 }
1020 1026
1021 void MetadataDatabaseIndexOnDisk::UpdateInDirtyTrackerIndexes( 1027 void MetadataDatabaseIndexOnDisk::UpdateInDirtyTrackerIndexes(
1022 const FileTracker& old_tracker, 1028 const FileTracker& old_tracker,
1023 const FileTracker& new_tracker) { 1029 const FileTracker& new_tracker) {
1024 DCHECK_EQ(old_tracker.tracker_id(), new_tracker.tracker_id()); 1030 DCHECK_EQ(old_tracker.tracker_id(), new_tracker.tracker_id());
1025 1031
1026 int64 tracker_id = new_tracker.tracker_id(); 1032 int64_t tracker_id = new_tracker.tracker_id();
1027 const std::string dirty_key = GenerateDirtyIDKey(tracker_id); 1033 const std::string dirty_key = GenerateDirtyIDKey(tracker_id);
1028 const std::string demoted_key = GenerateDemotedDirtyIDKey(tracker_id); 1034 const std::string demoted_key = GenerateDemotedDirtyIDKey(tracker_id);
1029 if (old_tracker.dirty() && !new_tracker.dirty()) { 1035 if (old_tracker.dirty() && !new_tracker.dirty()) {
1030 DCHECK(DBHasKey(dirty_key) || DBHasKey(demoted_key)); 1036 DCHECK(DBHasKey(dirty_key) || DBHasKey(demoted_key));
1031 1037
1032 DVLOG(1) << " Remove from dirty trackers IDs: " << tracker_id; 1038 DVLOG(1) << " Remove from dirty trackers IDs: " << tracker_id;
1033 1039
1034 if (DBHasKey(dirty_key)) 1040 if (DBHasKey(dirty_key))
1035 --num_dirty_trackers_; 1041 --num_dirty_trackers_;
1036 db_->Delete(dirty_key); 1042 db_->Delete(dirty_key);
1037 db_->Delete(demoted_key); 1043 db_->Delete(demoted_key);
1038 } else if (!old_tracker.dirty() && new_tracker.dirty()) { 1044 } else if (!old_tracker.dirty() && new_tracker.dirty()) {
1039 DCHECK(!DBHasKey(dirty_key)); 1045 DCHECK(!DBHasKey(dirty_key));
1040 DCHECK(!DBHasKey(demoted_key)); 1046 DCHECK(!DBHasKey(demoted_key));
1041 1047
1042 DVLOG(1) << " Add to dirty tracker IDs: " << tracker_id; 1048 DVLOG(1) << " Add to dirty tracker IDs: " << tracker_id;
1043 1049
1044 db_->Put(dirty_key, std::string()); 1050 db_->Put(dirty_key, std::string());
1045 ++num_dirty_trackers_; 1051 ++num_dirty_trackers_;
1046 } 1052 }
1047 } 1053 }
1048 1054
1049 void MetadataDatabaseIndexOnDisk::RemoveFromDirtyTrackerIndexes( 1055 void MetadataDatabaseIndexOnDisk::RemoveFromDirtyTrackerIndexes(
1050 const FileTracker& tracker) { 1056 const FileTracker& tracker) {
1051 if (tracker.dirty()) { 1057 if (tracker.dirty()) {
1052 int64 tracker_id = tracker.tracker_id(); 1058 int64_t tracker_id = tracker.tracker_id();
1053 const std::string dirty_key = GenerateDirtyIDKey(tracker_id); 1059 const std::string dirty_key = GenerateDirtyIDKey(tracker_id);
1054 const std::string demoted_key = GenerateDemotedDirtyIDKey(tracker_id); 1060 const std::string demoted_key = GenerateDemotedDirtyIDKey(tracker_id);
1055 DCHECK(DBHasKey(dirty_key) || DBHasKey(demoted_key)); 1061 DCHECK(DBHasKey(dirty_key) || DBHasKey(demoted_key));
1056 1062
1057 DVLOG(1) << " Remove from dirty tracker IDs: " << tracker_id; 1063 DVLOG(1) << " Remove from dirty tracker IDs: " << tracker_id;
1058 if (DBHasKey(dirty_key)) 1064 if (DBHasKey(dirty_key))
1059 --num_dirty_trackers_; 1065 --num_dirty_trackers_;
1060 db_->Delete(dirty_key); 1066 db_->Delete(dirty_key);
1061 db_->Delete(demoted_key); 1067 db_->Delete(demoted_key);
1062 } 1068 }
1063 } 1069 }
1064 1070
1065 TrackerIDSet MetadataDatabaseIndexOnDisk::GetTrackerIDSetByPrefix( 1071 TrackerIDSet MetadataDatabaseIndexOnDisk::GetTrackerIDSetByPrefix(
1066 const std::string& active_tracker_key, 1072 const std::string& active_tracker_key,
1067 const std::string& ids_prefix) const { 1073 const std::string& ids_prefix) const {
1068 TrackerIDSet trackers; 1074 TrackerIDSet trackers;
1069 1075
1070 // Seek IDs. 1076 // Seek IDs.
1071 scoped_ptr<LevelDBWrapper::Iterator> itr(db_->NewIterator()); 1077 scoped_ptr<LevelDBWrapper::Iterator> itr(db_->NewIterator());
1072 for (itr->Seek(ids_prefix); itr->Valid(); itr->Next()) { 1078 for (itr->Seek(ids_prefix); itr->Valid(); itr->Next()) {
1073 const std::string& key(itr->key().ToString()); 1079 const std::string& key(itr->key().ToString());
1074 std::string id_str; 1080 std::string id_str;
1075 if (!RemovePrefix(key, ids_prefix, &id_str)) 1081 if (!RemovePrefix(key, ids_prefix, &id_str))
1076 break; 1082 break;
1077 1083
1078 int64 tracker_id; 1084 int64_t tracker_id;
1079 if (!base::StringToInt64(id_str, &tracker_id)) 1085 if (!base::StringToInt64(id_str, &tracker_id))
1080 continue; 1086 continue;
1081 trackers.InsertInactiveTracker(tracker_id); 1087 trackers.InsertInactiveTracker(tracker_id);
1082 } 1088 }
1083 1089
1084 // Set an active tracker ID, if available. 1090 // Set an active tracker ID, if available.
1085 std::string value; 1091 std::string value;
1086 leveldb::Status status = db_->Get(active_tracker_key, &value); 1092 leveldb::Status status = db_->Get(active_tracker_key, &value);
1087 int64 active_tracker; 1093 int64_t active_tracker;
1088 if (status.ok() && base::StringToInt64(value, &active_tracker)) { 1094 if (status.ok() && base::StringToInt64(value, &active_tracker)) {
1089 DCHECK_NE(kInvalidTrackerID, active_tracker); 1095 DCHECK_NE(kInvalidTrackerID, active_tracker);
1090 trackers.Activate(active_tracker); 1096 trackers.Activate(active_tracker);
1091 } 1097 }
1092 1098
1093 return trackers; 1099 return trackers;
1094 } 1100 }
1095 1101
1096 void MetadataDatabaseIndexOnDisk::AddToTrackerIDSetWithPrefix( 1102 void MetadataDatabaseIndexOnDisk::AddToTrackerIDSetWithPrefix(
1097 const std::string& active_tracker_key, const std::string& key_prefix, 1103 const std::string& active_tracker_key, const std::string& key_prefix,
1098 const FileTracker& tracker) { 1104 const FileTracker& tracker) {
1099 DCHECK(tracker.tracker_id()); 1105 DCHECK(tracker.tracker_id());
1100 1106
1101 const std::string id_str = base::Int64ToString(tracker.tracker_id()); 1107 const std::string id_str = base::Int64ToString(tracker.tracker_id());
1102 db_->Put(key_prefix + id_str, std::string()); 1108 db_->Put(key_prefix + id_str, std::string());
1103 if (tracker.active()) 1109 if (tracker.active())
1104 db_->Put(active_tracker_key, id_str); 1110 db_->Put(active_tracker_key, id_str);
1105 } 1111 }
1106 1112
1107 bool MetadataDatabaseIndexOnDisk::EraseInTrackerIDSetWithPrefix( 1113 bool MetadataDatabaseIndexOnDisk::EraseInTrackerIDSetWithPrefix(
1108 const std::string& active_tracker_key, const std::string& key_prefix, 1114 const std::string& active_tracker_key,
1109 int64 tracker_id) { 1115 const std::string& key_prefix,
1116 int64_t tracker_id) {
1110 std::string value; 1117 std::string value;
1111 const std::string del_key = key_prefix + base::Int64ToString(tracker_id); 1118 const std::string del_key = key_prefix + base::Int64ToString(tracker_id);
1112 leveldb::Status status = db_->Get(del_key, &value); 1119 leveldb::Status status = db_->Get(del_key, &value);
1113 if (status.IsNotFound()) 1120 if (status.IsNotFound())
1114 return false; 1121 return false;
1115 1122
1116 db_->Delete(del_key); 1123 db_->Delete(del_key);
1117 1124
1118 status = db_->Get(active_tracker_key, &value); 1125 status = db_->Get(active_tracker_key, &value);
1119 int64 active_tracker_id; 1126 int64_t active_tracker_id;
1120 if (status.ok() && base::StringToInt64(value, &active_tracker_id) && 1127 if (status.ok() && base::StringToInt64(value, &active_tracker_id) &&
1121 active_tracker_id == tracker_id) { 1128 active_tracker_id == tracker_id) {
1122 db_->Delete(active_tracker_key); 1129 db_->Delete(active_tracker_key);
1123 } 1130 }
1124 1131
1125 return true; 1132 return true;
1126 } 1133 }
1127 1134
1128 void MetadataDatabaseIndexOnDisk::ActivateInTrackerIDSetWithPrefix( 1135 void MetadataDatabaseIndexOnDisk::ActivateInTrackerIDSetWithPrefix(
1129 const std::string& active_tracker_key, const std::string& key_prefix, 1136 const std::string& active_tracker_key,
1130 int64 tracker_id) { 1137 const std::string& key_prefix,
1138 int64_t tracker_id) {
1131 DCHECK(DBHasKey(key_prefix + base::Int64ToString(tracker_id))); 1139 DCHECK(DBHasKey(key_prefix + base::Int64ToString(tracker_id)));
1132 1140
1133 std::string value; 1141 std::string value;
1134 leveldb::Status status = db_->Get(active_tracker_key, &value); 1142 leveldb::Status status = db_->Get(active_tracker_key, &value);
1135 int64 active_tracker_id = kInvalidTrackerID; 1143 int64_t active_tracker_id = kInvalidTrackerID;
1136 if (status.IsNotFound() || 1144 if (status.IsNotFound() ||
1137 (status.ok() && base::StringToInt64(value, &active_tracker_id))) { 1145 (status.ok() && base::StringToInt64(value, &active_tracker_id))) {
1138 DCHECK(active_tracker_id != tracker_id); 1146 DCHECK(active_tracker_id != tracker_id);
1139 db_->Put(active_tracker_key, base::Int64ToString(tracker_id)); 1147 db_->Put(active_tracker_key, base::Int64ToString(tracker_id));
1140 } 1148 }
1141 } 1149 }
1142 1150
1143 void MetadataDatabaseIndexOnDisk::DeactivateInTrackerIDSetWithPrefix( 1151 void MetadataDatabaseIndexOnDisk::DeactivateInTrackerIDSetWithPrefix(
1144 const std::string& active_tracker_key, const std::string& key_prefix, 1152 const std::string& active_tracker_key,
1145 int64 tracker_id) { 1153 const std::string& key_prefix,
1154 int64_t tracker_id) {
1146 DCHECK(DBHasKey(key_prefix + base::Int64ToString(tracker_id))); 1155 DCHECK(DBHasKey(key_prefix + base::Int64ToString(tracker_id)));
1147 1156
1148 std::string value; 1157 std::string value;
1149 leveldb::Status status = db_->Get(active_tracker_key, &value); 1158 leveldb::Status status = db_->Get(active_tracker_key, &value);
1150 int64 active_tracker_id; 1159 int64_t active_tracker_id;
1151 if (status.ok() && base::StringToInt64(value, &active_tracker_id)) { 1160 if (status.ok() && base::StringToInt64(value, &active_tracker_id)) {
1152 DCHECK(active_tracker_id == tracker_id); 1161 DCHECK(active_tracker_id == tracker_id);
1153 db_->Delete(active_tracker_key); 1162 db_->Delete(active_tracker_key);
1154 } 1163 }
1155 } 1164 }
1156 1165
1157 bool MetadataDatabaseIndexOnDisk::DBHasKey(const std::string& key) const { 1166 bool MetadataDatabaseIndexOnDisk::DBHasKey(const std::string& key) const {
1158 scoped_ptr<LevelDBWrapper::Iterator> itr(db_->NewIterator()); 1167 scoped_ptr<LevelDBWrapper::Iterator> itr(db_->NewIterator());
1159 itr->Seek(key); 1168 itr->Seek(key);
1160 return itr->Valid() && (itr->key() == key); 1169 return itr->Valid() && (itr->key() == key);
1161 } 1170 }
1162 1171
1163 size_t MetadataDatabaseIndexOnDisk::CountDirtyTrackerInternal() const { 1172 size_t MetadataDatabaseIndexOnDisk::CountDirtyTrackerInternal() const {
1164 size_t num_dirty_trackers = 0; 1173 size_t num_dirty_trackers = 0;
1165 1174
1166 scoped_ptr<LevelDBWrapper::Iterator> itr(db_->NewIterator()); 1175 scoped_ptr<LevelDBWrapper::Iterator> itr(db_->NewIterator());
1167 for (itr->Seek(kDirtyIDKeyPrefix); itr->Valid(); itr->Next()) { 1176 for (itr->Seek(kDirtyIDKeyPrefix); itr->Valid(); itr->Next()) {
1168 if (!base::StartsWith(itr->key().ToString(), kDirtyIDKeyPrefix, 1177 if (!base::StartsWith(itr->key().ToString(), kDirtyIDKeyPrefix,
1169 base::CompareCase::SENSITIVE)) 1178 base::CompareCase::SENSITIVE))
1170 break; 1179 break;
1171 ++num_dirty_trackers; 1180 ++num_dirty_trackers;
1172 } 1181 }
1173 1182
1174 return num_dirty_trackers; 1183 return num_dirty_trackers;
1175 } 1184 }
1176 1185
1177 MetadataDatabaseIndexOnDisk::NumEntries 1186 MetadataDatabaseIndexOnDisk::NumEntries
1178 MetadataDatabaseIndexOnDisk::CountWithPrefix( 1187 MetadataDatabaseIndexOnDisk::CountWithPrefix(const std::string& prefix,
1179 const std::string& prefix, int64 ignored_id) { 1188 int64_t ignored_id) {
1180 const std::string ignored = base::Int64ToString(ignored_id); 1189 const std::string ignored = base::Int64ToString(ignored_id);
1181 1190
1182 size_t count = 0; 1191 size_t count = 0;
1183 scoped_ptr<LevelDBWrapper::Iterator> itr(db_->NewIterator()); 1192 scoped_ptr<LevelDBWrapper::Iterator> itr(db_->NewIterator());
1184 for (itr->Seek(prefix); itr->Valid() && count <= 1; itr->Next()) { 1193 for (itr->Seek(prefix); itr->Valid() && count <= 1; itr->Next()) {
1185 std::string value; 1194 std::string value;
1186 if (!RemovePrefix(itr->key().ToString(), prefix, &value)) 1195 if (!RemovePrefix(itr->key().ToString(), prefix, &value))
1187 break; 1196 break;
1188 if (value == ignored) 1197 if (value == ignored)
1189 continue; 1198 continue;
(...skipping 12 matching lines...) Expand all
1202 for (itr->Seek(prefix); itr->Valid();) { 1211 for (itr->Seek(prefix); itr->Valid();) {
1203 const std::string key = itr->key().ToString(); 1212 const std::string key = itr->key().ToString();
1204 if (!base::StartsWith(key, prefix, base::CompareCase::SENSITIVE)) 1213 if (!base::StartsWith(key, prefix, base::CompareCase::SENSITIVE))
1205 break; 1214 break;
1206 itr->Delete(); 1215 itr->Delete();
1207 } 1216 }
1208 } 1217 }
1209 1218
1210 } // namespace drive_backend 1219 } // namespace drive_backend
1211 } // namespace sync_file_system 1220 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698