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

Side by Side Diff: chrome/browser/sync_file_system/drive_backend/metadata_database.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 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"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/macros.h"
15 #include "base/memory/scoped_vector.h" 16 #include "base/memory/scoped_vector.h"
16 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
17 #include "base/stl_util.h" 18 #include "base/stl_util.h"
18 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
20 #include "base/strings/stringprintf.h" 21 #include "base/strings/stringprintf.h"
21 #include "base/task_runner_util.h" 22 #include "base/task_runner_util.h"
22 #include "base/thread_task_runner_handle.h" 23 #include "base/thread_task_runner_handle.h"
23 #include "base/threading/thread_restrictions.h" 24 #include "base/threading/thread_restrictions.h"
24 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_constants. h" 25 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_constants. h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 106
106 details->set_md5(file_resource.md5_checksum()); 107 details->set_md5(file_resource.md5_checksum());
107 details->set_etag(file_resource.etag()); 108 details->set_etag(file_resource.etag());
108 details->set_creation_time(file_resource.created_date().ToInternalValue()); 109 details->set_creation_time(file_resource.created_date().ToInternalValue());
109 details->set_modification_time( 110 details->set_modification_time(
110 file_resource.modified_date().ToInternalValue()); 111 file_resource.modified_date().ToInternalValue());
111 details->set_missing(file_resource.labels().is_trashed()); 112 details->set_missing(file_resource.labels().is_trashed());
112 } 113 }
113 114
114 scoped_ptr<FileMetadata> CreateFileMetadataFromFileResource( 115 scoped_ptr<FileMetadata> CreateFileMetadataFromFileResource(
115 int64 change_id, 116 int64_t change_id,
116 const google_apis::FileResource& resource) { 117 const google_apis::FileResource& resource) {
117 scoped_ptr<FileMetadata> file(new FileMetadata); 118 scoped_ptr<FileMetadata> file(new FileMetadata);
118 file->set_file_id(resource.file_id()); 119 file->set_file_id(resource.file_id());
119 120
120 FileDetails* details = file->mutable_details(); 121 FileDetails* details = file->mutable_details();
121 details->set_change_id(change_id); 122 details->set_change_id(change_id);
122 123
123 if (resource.labels().is_trashed()) { 124 if (resource.labels().is_trashed()) {
124 details->set_missing(true); 125 details->set_missing(true);
125 return file.Pass(); 126 return file.Pass();
(...skipping 13 matching lines...) Expand all
139 140
140 if (change.is_deleted()) { 141 if (change.is_deleted()) {
141 details->set_missing(true); 142 details->set_missing(true);
142 return file.Pass(); 143 return file.Pass();
143 } 144 }
144 145
145 PopulateFileDetailsByFileResource(*change.file(), details); 146 PopulateFileDetailsByFileResource(*change.file(), details);
146 return file.Pass(); 147 return file.Pass();
147 } 148 }
148 149
149 scoped_ptr<FileMetadata> CreateDeletedFileMetadata( 150 scoped_ptr<FileMetadata> CreateDeletedFileMetadata(int64_t change_id,
150 int64 change_id, 151 const std::string& file_id) {
151 const std::string& file_id) {
152 scoped_ptr<FileMetadata> file(new FileMetadata); 152 scoped_ptr<FileMetadata> file(new FileMetadata);
153 file->set_file_id(file_id); 153 file->set_file_id(file_id);
154 154
155 FileDetails* details = file->mutable_details(); 155 FileDetails* details = file->mutable_details();
156 details->set_change_id(change_id); 156 details->set_change_id(change_id);
157 details->set_missing(true); 157 details->set_missing(true);
158 return file.Pass(); 158 return file.Pass();
159 } 159 }
160 160
161 scoped_ptr<FileTracker> CreateSyncRootTracker( 161 scoped_ptr<FileTracker> CreateSyncRootTracker(
162 int64 tracker_id, 162 int64_t tracker_id,
163 const FileMetadata& sync_root_metadata) { 163 const FileMetadata& sync_root_metadata) {
164 scoped_ptr<FileTracker> sync_root_tracker(new FileTracker); 164 scoped_ptr<FileTracker> sync_root_tracker(new FileTracker);
165 sync_root_tracker->set_tracker_id(tracker_id); 165 sync_root_tracker->set_tracker_id(tracker_id);
166 sync_root_tracker->set_file_id(sync_root_metadata.file_id()); 166 sync_root_tracker->set_file_id(sync_root_metadata.file_id());
167 sync_root_tracker->set_parent_tracker_id(0); 167 sync_root_tracker->set_parent_tracker_id(0);
168 sync_root_tracker->set_tracker_kind(TRACKER_KIND_REGULAR); 168 sync_root_tracker->set_tracker_kind(TRACKER_KIND_REGULAR);
169 sync_root_tracker->set_dirty(false); 169 sync_root_tracker->set_dirty(false);
170 sync_root_tracker->set_active(true); 170 sync_root_tracker->set_active(true);
171 sync_root_tracker->set_needs_folder_listing(false); 171 sync_root_tracker->set_needs_folder_listing(false);
172 *sync_root_tracker->mutable_synced_details() = sync_root_metadata.details(); 172 *sync_root_tracker->mutable_synced_details() = sync_root_metadata.details();
173 return sync_root_tracker.Pass(); 173 return sync_root_tracker.Pass();
174 } 174 }
175 175
176 scoped_ptr<FileTracker> CreateInitialAppRootTracker( 176 scoped_ptr<FileTracker> CreateInitialAppRootTracker(
177 int64 tracker_id, 177 int64_t tracker_id,
178 int64 parent_tracker_id, 178 int64_t parent_tracker_id,
179 const FileMetadata& app_root_metadata) { 179 const FileMetadata& app_root_metadata) {
180 scoped_ptr<FileTracker> app_root_tracker(new FileTracker); 180 scoped_ptr<FileTracker> app_root_tracker(new FileTracker);
181 app_root_tracker->set_tracker_id(tracker_id); 181 app_root_tracker->set_tracker_id(tracker_id);
182 app_root_tracker->set_parent_tracker_id(parent_tracker_id); 182 app_root_tracker->set_parent_tracker_id(parent_tracker_id);
183 app_root_tracker->set_file_id(app_root_metadata.file_id()); 183 app_root_tracker->set_file_id(app_root_metadata.file_id());
184 app_root_tracker->set_tracker_kind(TRACKER_KIND_REGULAR); 184 app_root_tracker->set_tracker_kind(TRACKER_KIND_REGULAR);
185 app_root_tracker->set_dirty(false); 185 app_root_tracker->set_dirty(false);
186 app_root_tracker->set_active(false); 186 app_root_tracker->set_active(false);
187 app_root_tracker->set_needs_folder_listing(false); 187 app_root_tracker->set_needs_folder_listing(false);
188 *app_root_tracker->mutable_synced_details() = app_root_metadata.details(); 188 *app_root_tracker->mutable_synced_details() = app_root_metadata.details();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 *created = IsDatabaseEmpty(db_out->get()); 235 *created = IsDatabaseEmpty(db_out->get());
236 return status; 236 return status;
237 } 237 }
238 238
239 SyncStatusCode MigrateDatabaseIfNeeded(LevelDBWrapper* db) { 239 SyncStatusCode MigrateDatabaseIfNeeded(LevelDBWrapper* db) {
240 // See metadata_database_index.cc for the database schema. 240 // See metadata_database_index.cc for the database schema.
241 base::ThreadRestrictions::AssertIOAllowed(); 241 base::ThreadRestrictions::AssertIOAllowed();
242 DCHECK(db); 242 DCHECK(db);
243 std::string value; 243 std::string value;
244 leveldb::Status status = db->Get(kDatabaseVersionKey, &value); 244 leveldb::Status status = db->Get(kDatabaseVersionKey, &value);
245 int64 version = 0; 245 int64_t version = 0;
246 if (status.ok()) { 246 if (status.ok()) {
247 if (!base::StringToInt64(value, &version)) 247 if (!base::StringToInt64(value, &version))
248 return SYNC_DATABASE_ERROR_FAILED; 248 return SYNC_DATABASE_ERROR_FAILED;
249 } else { 249 } else {
250 if (!status.IsNotFound()) 250 if (!status.IsNotFound())
251 return SYNC_DATABASE_ERROR_FAILED; 251 return SYNC_DATABASE_ERROR_FAILED;
252 } 252 }
253 253
254 switch (version) { 254 switch (version) {
255 case 0: 255 case 0:
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 itr != trackers.end(); ++itr) { 287 itr != trackers.end(); ++itr) {
288 scoped_ptr<FileTracker> tracker(new FileTracker); 288 scoped_ptr<FileTracker> tracker(new FileTracker);
289 index->GetFileTracker(*itr, tracker.get()); 289 index->GetFileTracker(*itr, tracker.get());
290 if (tracker->dirty()) 290 if (tracker->dirty())
291 continue; 291 continue;
292 tracker->set_dirty(true); 292 tracker->set_dirty(true);
293 index->StoreFileTracker(tracker.Pass()); 293 index->StoreFileTracker(tracker.Pass());
294 } 294 }
295 } 295 }
296 296
297 void MarkTrackersDirtyByPath(int64 parent_tracker_id, 297 void MarkTrackersDirtyByPath(int64_t parent_tracker_id,
298 const std::string& title, 298 const std::string& title,
299 MetadataDatabaseIndexInterface* index) { 299 MetadataDatabaseIndexInterface* index) {
300 if (parent_tracker_id == kInvalidTrackerID || title.empty()) 300 if (parent_tracker_id == kInvalidTrackerID || title.empty())
301 return; 301 return;
302 MarkTrackerSetDirty( 302 MarkTrackerSetDirty(
303 index->GetFileTrackerIDsByParentAndTitle(parent_tracker_id, title), 303 index->GetFileTrackerIDsByParentAndTitle(parent_tracker_id, title),
304 index); 304 index);
305 } 305 }
306 306
307 void MarkTrackersDirtyByFileID(const std::string& file_id, 307 void MarkTrackersDirtyByFileID(const std::string& file_id,
308 MetadataDatabaseIndexInterface* index) { 308 MetadataDatabaseIndexInterface* index) {
309 MarkTrackerSetDirty(index->GetFileTrackerIDsByFileID(file_id), index); 309 MarkTrackerSetDirty(index->GetFileTrackerIDsByFileID(file_id), index);
310 } 310 }
311 311
312 void MarkTrackersDirtyRecursively(int64 root_tracker_id, 312 void MarkTrackersDirtyRecursively(int64_t root_tracker_id,
313 MetadataDatabaseIndexInterface* index) { 313 MetadataDatabaseIndexInterface* index) {
314 std::vector<int64> stack; 314 std::vector<int64_t> stack;
315 stack.push_back(root_tracker_id); 315 stack.push_back(root_tracker_id);
316 while (!stack.empty()) { 316 while (!stack.empty()) {
317 int64 tracker_id = stack.back(); 317 int64_t tracker_id = stack.back();
318 stack.pop_back(); 318 stack.pop_back();
319 AppendContents(index->GetFileTrackerIDsByParent(tracker_id), &stack); 319 AppendContents(index->GetFileTrackerIDsByParent(tracker_id), &stack);
320 320
321 scoped_ptr<FileTracker> tracker(new FileTracker); 321 scoped_ptr<FileTracker> tracker(new FileTracker);
322 index->GetFileTracker(tracker_id, tracker.get()); 322 index->GetFileTracker(tracker_id, tracker.get());
323 tracker->set_dirty(true); 323 tracker->set_dirty(true);
324 324
325 index->StoreFileTracker(tracker.Pass()); 325 index->StoreFileTracker(tracker.Pass());
326 } 326 }
327 } 327 }
328 328
329 void RemoveAllDescendantTrackers(int64 root_tracker_id, 329 void RemoveAllDescendantTrackers(int64_t root_tracker_id,
330 MetadataDatabaseIndexInterface* index) { 330 MetadataDatabaseIndexInterface* index) {
331 std::vector<int64> pending_trackers; 331 std::vector<int64_t> pending_trackers;
332 AppendContents(index->GetFileTrackerIDsByParent(root_tracker_id), 332 AppendContents(index->GetFileTrackerIDsByParent(root_tracker_id),
333 &pending_trackers); 333 &pending_trackers);
334 334
335 std::vector<int64> to_be_removed; 335 std::vector<int64_t> to_be_removed;
336 336
337 // List trackers to remove. 337 // List trackers to remove.
338 while (!pending_trackers.empty()) { 338 while (!pending_trackers.empty()) {
339 int64 tracker_id = pending_trackers.back(); 339 int64_t tracker_id = pending_trackers.back();
340 pending_trackers.pop_back(); 340 pending_trackers.pop_back();
341 AppendContents(index->GetFileTrackerIDsByParent(tracker_id), 341 AppendContents(index->GetFileTrackerIDsByParent(tracker_id),
342 &pending_trackers); 342 &pending_trackers);
343 to_be_removed.push_back(tracker_id); 343 to_be_removed.push_back(tracker_id);
344 } 344 }
345 345
346 // Remove trackers in the reversed order. 346 // Remove trackers in the reversed order.
347 base::hash_set<std::string> affected_file_ids; 347 base::hash_set<std::string> affected_file_ids;
348 for (std::vector<int64>::reverse_iterator itr = to_be_removed.rbegin(); 348 for (std::vector<int64_t>::reverse_iterator itr = to_be_removed.rbegin();
349 itr != to_be_removed.rend(); ++itr) { 349 itr != to_be_removed.rend(); ++itr) {
350 FileTracker tracker; 350 FileTracker tracker;
351 index->GetFileTracker(*itr, &tracker); 351 index->GetFileTracker(*itr, &tracker);
352 affected_file_ids.insert(tracker.file_id()); 352 affected_file_ids.insert(tracker.file_id());
353 index->RemoveFileTracker(*itr); 353 index->RemoveFileTracker(*itr);
354 } 354 }
355 355
356 for (base::hash_set<std::string>::iterator itr = affected_file_ids.begin(); 356 for (base::hash_set<std::string>::iterator itr = affected_file_ids.begin();
357 itr != affected_file_ids.end(); ++itr) { 357 itr != affected_file_ids.end(); ++itr) {
358 TrackerIDSet trackers = index->GetFileTrackerIDsByFileID(*itr); 358 TrackerIDSet trackers = index->GetFileTrackerIDsByFileID(*itr);
359 if (trackers.empty()) { 359 if (trackers.empty()) {
360 // Remove metadata that no longer has any tracker. 360 // Remove metadata that no longer has any tracker.
361 index->RemoveFileMetadata(*itr); 361 index->RemoveFileMetadata(*itr);
362 } else { 362 } else {
363 MarkTrackerSetDirty(trackers, index); 363 MarkTrackerSetDirty(trackers, index);
364 } 364 }
365 } 365 }
366 } 366 }
367 367
368 bool FilterFileTrackersByParent( 368 bool FilterFileTrackersByParent(const MetadataDatabaseIndexInterface* index,
369 const MetadataDatabaseIndexInterface* index, 369 const TrackerIDSet& trackers,
370 const TrackerIDSet& trackers, 370 int64_t parent_tracker_id,
371 int64 parent_tracker_id, 371 FileTracker* tracker_out) {
372 FileTracker* tracker_out) {
373 FileTracker tracker; 372 FileTracker tracker;
374 for (TrackerIDSet::const_iterator itr = trackers.begin(); 373 for (TrackerIDSet::const_iterator itr = trackers.begin();
375 itr != trackers.end(); ++itr) { 374 itr != trackers.end(); ++itr) {
376 if (!index->GetFileTracker(*itr, &tracker)) { 375 if (!index->GetFileTracker(*itr, &tracker)) {
377 NOTREACHED(); 376 NOTREACHED();
378 continue; 377 continue;
379 } 378 }
380 379
381 if (tracker.parent_tracker_id() == parent_tracker_id) { 380 if (tracker.parent_tracker_id() == parent_tracker_id) {
382 if (tracker_out) 381 if (tracker_out)
383 tracker_out->CopyFrom(tracker); 382 tracker_out->CopyFrom(tracker);
384 return true; 383 return true;
385 } 384 }
386 } 385 }
387 return false; 386 return false;
388 } 387 }
389 388
390 bool FilterFileTrackersByParentAndTitle( 389 bool FilterFileTrackersByParentAndTitle(
391 const MetadataDatabaseIndexInterface* index, 390 const MetadataDatabaseIndexInterface* index,
392 const TrackerIDSet& trackers, 391 const TrackerIDSet& trackers,
393 int64 parent_tracker_id, 392 int64_t parent_tracker_id,
394 const std::string& title, 393 const std::string& title,
395 FileTracker* result) { 394 FileTracker* result) {
396 bool found = false; 395 bool found = false;
397 for (TrackerIDSet::const_iterator itr = trackers.begin(); 396 for (TrackerIDSet::const_iterator itr = trackers.begin();
398 itr != trackers.end(); ++itr) { 397 itr != trackers.end(); ++itr) {
399 FileTracker tracker; 398 FileTracker tracker;
400 if (!index->GetFileTracker(*itr, &tracker)) { 399 if (!index->GetFileTracker(*itr, &tracker)) {
401 NOTREACHED(); 400 NOTREACHED();
402 continue; 401 continue;
403 } 402 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 return false; 444 return false;
446 } 445 }
447 446
448 enum DirtyingOption { 447 enum DirtyingOption {
449 MARK_NOTHING_DIRTY = 0, 448 MARK_NOTHING_DIRTY = 0,
450 MARK_ITSELF_DIRTY = 1 << 0, 449 MARK_ITSELF_DIRTY = 1 << 0,
451 MARK_SAME_FILE_ID_TRACKERS_DIRTY = 1 << 1, 450 MARK_SAME_FILE_ID_TRACKERS_DIRTY = 1 << 1,
452 MARK_SAME_PATH_TRACKERS_DIRTY = 1 << 2, 451 MARK_SAME_PATH_TRACKERS_DIRTY = 1 << 2,
453 }; 452 };
454 453
455 void ActivateFileTracker(int64 tracker_id, 454 void ActivateFileTracker(int64_t tracker_id,
456 int dirtying_options, 455 int dirtying_options,
457 MetadataDatabaseIndexInterface* index) { 456 MetadataDatabaseIndexInterface* index) {
458 DCHECK(dirtying_options == MARK_NOTHING_DIRTY || 457 DCHECK(dirtying_options == MARK_NOTHING_DIRTY ||
459 dirtying_options == MARK_ITSELF_DIRTY); 458 dirtying_options == MARK_ITSELF_DIRTY);
460 459
461 scoped_ptr<FileTracker> tracker(new FileTracker); 460 scoped_ptr<FileTracker> tracker(new FileTracker);
462 index->GetFileTracker(tracker_id, tracker.get()); 461 index->GetFileTracker(tracker_id, tracker.get());
463 tracker->set_active(true); 462 tracker->set_active(true);
464 if (dirtying_options & MARK_ITSELF_DIRTY) { 463 if (dirtying_options & MARK_ITSELF_DIRTY) {
465 tracker->set_dirty(true); 464 tracker->set_dirty(true);
466 tracker->set_needs_folder_listing( 465 tracker->set_needs_folder_listing(
467 tracker->has_synced_details() && 466 tracker->has_synced_details() &&
468 tracker->synced_details().file_kind() == FILE_KIND_FOLDER); 467 tracker->synced_details().file_kind() == FILE_KIND_FOLDER);
469 } else { 468 } else {
470 tracker->set_dirty(false); 469 tracker->set_dirty(false);
471 tracker->set_needs_folder_listing(false); 470 tracker->set_needs_folder_listing(false);
472 } 471 }
473 472
474 index->StoreFileTracker(tracker.Pass()); 473 index->StoreFileTracker(tracker.Pass());
475 } 474 }
476 475
477 void DeactivateFileTracker(int64 tracker_id, 476 void DeactivateFileTracker(int64_t tracker_id,
478 int dirtying_options, 477 int dirtying_options,
479 MetadataDatabaseIndexInterface* index) { 478 MetadataDatabaseIndexInterface* index) {
480 RemoveAllDescendantTrackers(tracker_id, index); 479 RemoveAllDescendantTrackers(tracker_id, index);
481 480
482 scoped_ptr<FileTracker> tracker(new FileTracker); 481 scoped_ptr<FileTracker> tracker(new FileTracker);
483 index->GetFileTracker(tracker_id, tracker.get()); 482 index->GetFileTracker(tracker_id, tracker.get());
484 483
485 if (dirtying_options & MARK_SAME_FILE_ID_TRACKERS_DIRTY) 484 if (dirtying_options & MARK_SAME_FILE_ID_TRACKERS_DIRTY)
486 MarkTrackersDirtyByFileID(tracker->file_id(), index); 485 MarkTrackersDirtyByFileID(tracker->file_id(), index);
487 if (dirtying_options & MARK_SAME_PATH_TRACKERS_DIRTY) { 486 if (dirtying_options & MARK_SAME_PATH_TRACKERS_DIRTY) {
488 MarkTrackersDirtyByPath(tracker->parent_tracker_id(), 487 MarkTrackersDirtyByPath(tracker->parent_tracker_id(),
489 GetTrackerTitle(*tracker), index); 488 GetTrackerTitle(*tracker), index);
490 } 489 }
491 490
492 tracker->set_dirty(dirtying_options & MARK_ITSELF_DIRTY); 491 tracker->set_dirty(dirtying_options & MARK_ITSELF_DIRTY);
493 tracker->set_active(false); 492 tracker->set_active(false);
494 index->StoreFileTracker(tracker.Pass()); 493 index->StoreFileTracker(tracker.Pass());
495 } 494 }
496 495
497 void RemoveFileTracker(int64 tracker_id, 496 void RemoveFileTracker(int64_t tracker_id,
498 int dirtying_options, 497 int dirtying_options,
499 MetadataDatabaseIndexInterface* index) { 498 MetadataDatabaseIndexInterface* index) {
500 DCHECK(!(dirtying_options & MARK_ITSELF_DIRTY)); 499 DCHECK(!(dirtying_options & MARK_ITSELF_DIRTY));
501 500
502 FileTracker tracker; 501 FileTracker tracker;
503 if (!index->GetFileTracker(tracker_id, &tracker)) 502 if (!index->GetFileTracker(tracker_id, &tracker))
504 return; 503 return;
505 504
506 std::string file_id = tracker.file_id(); 505 std::string file_id = tracker.file_id();
507 int64 parent_tracker_id = tracker.parent_tracker_id(); 506 int64_t parent_tracker_id = tracker.parent_tracker_id();
508 std::string title = GetTrackerTitle(tracker); 507 std::string title = GetTrackerTitle(tracker);
509 508
510 RemoveAllDescendantTrackers(tracker_id, index); 509 RemoveAllDescendantTrackers(tracker_id, index);
511 index->RemoveFileTracker(tracker_id); 510 index->RemoveFileTracker(tracker_id);
512 511
513 if (dirtying_options & MARK_SAME_FILE_ID_TRACKERS_DIRTY) 512 if (dirtying_options & MARK_SAME_FILE_ID_TRACKERS_DIRTY)
514 MarkTrackersDirtyByFileID(file_id, index); 513 MarkTrackersDirtyByFileID(file_id, index);
515 if (dirtying_options & MARK_SAME_PATH_TRACKERS_DIRTY) 514 if (dirtying_options & MARK_SAME_PATH_TRACKERS_DIRTY)
516 MarkTrackersDirtyByPath(parent_tracker_id, title, index); 515 MarkTrackersDirtyByPath(parent_tracker_id, title, index);
517 516
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 void MetadataDatabase::ClearDatabase( 587 void MetadataDatabase::ClearDatabase(
589 scoped_ptr<MetadataDatabase> metadata_database) { 588 scoped_ptr<MetadataDatabase> metadata_database) {
590 DCHECK(metadata_database); 589 DCHECK(metadata_database);
591 base::FilePath database_path = metadata_database->database_path_; 590 base::FilePath database_path = metadata_database->database_path_;
592 DCHECK(!database_path.empty()); 591 DCHECK(!database_path.empty());
593 metadata_database.reset(); 592 metadata_database.reset();
594 593
595 base::DeleteFile(database_path, true /* recursive */); 594 base::DeleteFile(database_path, true /* recursive */);
596 } 595 }
597 596
598 int64 MetadataDatabase::GetLargestFetchedChangeID() const { 597 int64_t MetadataDatabase::GetLargestFetchedChangeID() const {
599 return index_->GetLargestChangeID(); 598 return index_->GetLargestChangeID();
600 } 599 }
601 600
602 int64 MetadataDatabase::GetSyncRootTrackerID() const { 601 int64_t MetadataDatabase::GetSyncRootTrackerID() const {
603 return index_->GetSyncRootTrackerID(); 602 return index_->GetSyncRootTrackerID();
604 } 603 }
605 604
606 int64 MetadataDatabase::GetLargestKnownChangeID() const { 605 int64_t MetadataDatabase::GetLargestKnownChangeID() const {
607 DCHECK_LE(GetLargestFetchedChangeID(), largest_known_change_id_); 606 DCHECK_LE(GetLargestFetchedChangeID(), largest_known_change_id_);
608 return largest_known_change_id_; 607 return largest_known_change_id_;
609 } 608 }
610 609
611 void MetadataDatabase::UpdateLargestKnownChangeID(int64 change_id) { 610 void MetadataDatabase::UpdateLargestKnownChangeID(int64_t change_id) {
612 if (largest_known_change_id_ < change_id) 611 if (largest_known_change_id_ < change_id)
613 largest_known_change_id_ = change_id; 612 largest_known_change_id_ = change_id;
614 } 613 }
615 614
616 bool MetadataDatabase::NeedsSyncRootRevalidation() const { 615 bool MetadataDatabase::NeedsSyncRootRevalidation() const {
617 return !index_->IsSyncRootRevalidated(); 616 return !index_->IsSyncRootRevalidated();
618 } 617 }
619 618
620 bool MetadataDatabase::HasSyncRoot() const { 619 bool MetadataDatabase::HasSyncRoot() const {
621 return index_->GetSyncRootTrackerID() != kInvalidTrackerID; 620 return index_->GetSyncRootTrackerID() != kInvalidTrackerID;
622 } 621 }
623 622
624 SyncStatusCode MetadataDatabase::PopulateInitialData( 623 SyncStatusCode MetadataDatabase::PopulateInitialData(
625 int64 largest_change_id, 624 int64_t largest_change_id,
626 const google_apis::FileResource& sync_root_folder, 625 const google_apis::FileResource& sync_root_folder,
627 const ScopedVector<google_apis::FileResource>& app_root_folders) { 626 const ScopedVector<google_apis::FileResource>& app_root_folders) {
628 index_->SetLargestChangeID(largest_change_id); 627 index_->SetLargestChangeID(largest_change_id);
629 UpdateLargestKnownChangeID(largest_change_id); 628 UpdateLargestKnownChangeID(largest_change_id);
630 629
631 AttachSyncRoot(sync_root_folder); 630 AttachSyncRoot(sync_root_folder);
632 for (size_t i = 0; i < app_root_folders.size(); ++i) 631 for (size_t i = 0; i < app_root_folders.size(); ++i)
633 AttachInitialAppRoot(*app_root_folders[i]); 632 AttachInitialAppRoot(*app_root_folders[i]);
634 633
635 if (NeedsSyncRootRevalidation()) { 634 if (NeedsSyncRootRevalidation()) {
636 index_->RemoveUnreachableItems(); 635 index_->RemoveUnreachableItems();
637 index_->SetSyncRootRevalidated(); 636 index_->SetSyncRootRevalidated();
638 } 637 }
639 638
640 return WriteToDatabase(); 639 return WriteToDatabase();
641 } 640 }
642 641
643 bool MetadataDatabase::IsAppEnabled(const std::string& app_id) const { 642 bool MetadataDatabase::IsAppEnabled(const std::string& app_id) const {
644 int64 tracker_id = index_->GetAppRootTracker(app_id); 643 int64_t tracker_id = index_->GetAppRootTracker(app_id);
645 if (tracker_id == kInvalidTrackerID) 644 if (tracker_id == kInvalidTrackerID)
646 return false; 645 return false;
647 646
648 FileTracker tracker; 647 FileTracker tracker;
649 if (!index_->GetFileTracker(tracker_id, &tracker)) 648 if (!index_->GetFileTracker(tracker_id, &tracker))
650 return false; 649 return false;
651 return tracker.tracker_kind() == TRACKER_KIND_APP_ROOT; 650 return tracker.tracker_kind() == TRACKER_KIND_APP_ROOT;
652 } 651 }
653 652
654 SyncStatusCode MetadataDatabase::RegisterApp(const std::string& app_id, 653 SyncStatusCode MetadataDatabase::RegisterApp(const std::string& app_id,
655 const std::string& folder_id) { 654 const std::string& folder_id) {
656 if (index_->GetAppRootTracker(app_id)) { 655 if (index_->GetAppRootTracker(app_id)) {
657 // The app-root is already registered. 656 // The app-root is already registered.
658 return SYNC_STATUS_OK; 657 return SYNC_STATUS_OK;
659 } 658 }
660 659
661 TrackerIDSet trackers = index_->GetFileTrackerIDsByFileID(folder_id); 660 TrackerIDSet trackers = index_->GetFileTrackerIDsByFileID(folder_id);
662 if (trackers.empty()) { 661 if (trackers.empty()) {
663 return SYNC_DATABASE_ERROR_NOT_FOUND; 662 return SYNC_DATABASE_ERROR_NOT_FOUND;
664 } 663 }
665 664
666 if (trackers.has_active()) { 665 if (trackers.has_active()) {
667 // The folder is tracked by another tracker. 666 // The folder is tracked by another tracker.
668 util::Log(logging::LOG_WARNING, FROM_HERE, 667 util::Log(logging::LOG_WARNING, FROM_HERE,
669 "Failed to register App for %s", app_id.c_str()); 668 "Failed to register App for %s", app_id.c_str());
670 return SYNC_STATUS_HAS_CONFLICT; 669 return SYNC_STATUS_HAS_CONFLICT;
671 } 670 }
672 671
673 int64 sync_root_tracker_id = index_->GetSyncRootTrackerID(); 672 int64_t sync_root_tracker_id = index_->GetSyncRootTrackerID();
674 if (!sync_root_tracker_id) { 673 if (!sync_root_tracker_id) {
675 util::Log(logging::LOG_WARNING, FROM_HERE, 674 util::Log(logging::LOG_WARNING, FROM_HERE,
676 "Sync-root needs to be set up before registering app-root"); 675 "Sync-root needs to be set up before registering app-root");
677 return SYNC_DATABASE_ERROR_NOT_FOUND; 676 return SYNC_DATABASE_ERROR_NOT_FOUND;
678 } 677 }
679 678
680 scoped_ptr<FileTracker> tracker(new FileTracker); 679 scoped_ptr<FileTracker> tracker(new FileTracker);
681 if (!FilterFileTrackersByParent(index_.get(), trackers, 680 if (!FilterFileTrackersByParent(index_.get(), trackers,
682 sync_root_tracker_id, tracker.get())) { 681 sync_root_tracker_id, tracker.get())) {
683 return SYNC_DATABASE_ERROR_NOT_FOUND; 682 return SYNC_DATABASE_ERROR_NOT_FOUND;
684 } 683 }
685 684
686 tracker->set_app_id(app_id); 685 tracker->set_app_id(app_id);
687 tracker->set_tracker_kind(TRACKER_KIND_APP_ROOT); 686 tracker->set_tracker_kind(TRACKER_KIND_APP_ROOT);
688 tracker->set_active(true); 687 tracker->set_active(true);
689 tracker->set_needs_folder_listing(true); 688 tracker->set_needs_folder_listing(true);
690 tracker->set_dirty(true); 689 tracker->set_dirty(true);
691 690
692 index_->StoreFileTracker(tracker.Pass()); 691 index_->StoreFileTracker(tracker.Pass());
693 return WriteToDatabase(); 692 return WriteToDatabase();
694 } 693 }
695 694
696 SyncStatusCode MetadataDatabase::DisableApp(const std::string& app_id) { 695 SyncStatusCode MetadataDatabase::DisableApp(const std::string& app_id) {
697 int64 tracker_id = index_->GetAppRootTracker(app_id); 696 int64_t tracker_id = index_->GetAppRootTracker(app_id);
698 scoped_ptr<FileTracker> tracker(new FileTracker); 697 scoped_ptr<FileTracker> tracker(new FileTracker);
699 if (!index_->GetFileTracker(tracker_id, tracker.get())) { 698 if (!index_->GetFileTracker(tracker_id, tracker.get())) {
700 return SYNC_DATABASE_ERROR_NOT_FOUND; 699 return SYNC_DATABASE_ERROR_NOT_FOUND;
701 } 700 }
702 701
703 if (tracker->tracker_kind() == TRACKER_KIND_DISABLED_APP_ROOT) { 702 if (tracker->tracker_kind() == TRACKER_KIND_DISABLED_APP_ROOT) {
704 return SYNC_STATUS_OK; 703 return SYNC_STATUS_OK;
705 } 704 }
706 705
707 DCHECK_EQ(TRACKER_KIND_APP_ROOT, tracker->tracker_kind()); 706 DCHECK_EQ(TRACKER_KIND_APP_ROOT, tracker->tracker_kind());
708 DCHECK(tracker->active()); 707 DCHECK(tracker->active());
709 708
710 // Keep the app-root tracker active (but change the tracker_kind) so that 709 // Keep the app-root tracker active (but change the tracker_kind) so that
711 // other conflicting trackers won't become active. 710 // other conflicting trackers won't become active.
712 tracker->set_tracker_kind(TRACKER_KIND_DISABLED_APP_ROOT); 711 tracker->set_tracker_kind(TRACKER_KIND_DISABLED_APP_ROOT);
713 712
714 index_->StoreFileTracker(tracker.Pass()); 713 index_->StoreFileTracker(tracker.Pass());
715 return WriteToDatabase(); 714 return WriteToDatabase();
716 } 715 }
717 716
718 SyncStatusCode MetadataDatabase::EnableApp(const std::string& app_id) { 717 SyncStatusCode MetadataDatabase::EnableApp(const std::string& app_id) {
719 int64 tracker_id = index_->GetAppRootTracker(app_id); 718 int64_t tracker_id = index_->GetAppRootTracker(app_id);
720 scoped_ptr<FileTracker> tracker(new FileTracker); 719 scoped_ptr<FileTracker> tracker(new FileTracker);
721 if (!index_->GetFileTracker(tracker_id, tracker.get())) { 720 if (!index_->GetFileTracker(tracker_id, tracker.get())) {
722 return SYNC_DATABASE_ERROR_NOT_FOUND; 721 return SYNC_DATABASE_ERROR_NOT_FOUND;
723 } 722 }
724 723
725 if (tracker->tracker_kind() == TRACKER_KIND_APP_ROOT) { 724 if (tracker->tracker_kind() == TRACKER_KIND_APP_ROOT) {
726 return SYNC_STATUS_OK; 725 return SYNC_STATUS_OK;
727 } 726 }
728 727
729 DCHECK_EQ(TRACKER_KIND_DISABLED_APP_ROOT, tracker->tracker_kind()); 728 DCHECK_EQ(TRACKER_KIND_DISABLED_APP_ROOT, tracker->tracker_kind());
730 DCHECK(tracker->active()); 729 DCHECK(tracker->active());
731 730
732 tracker->set_tracker_kind(TRACKER_KIND_APP_ROOT); 731 tracker->set_tracker_kind(TRACKER_KIND_APP_ROOT);
733 index_->StoreFileTracker(tracker.Pass()); 732 index_->StoreFileTracker(tracker.Pass());
734 733
735 MarkTrackersDirtyRecursively(tracker_id, index_.get()); 734 MarkTrackersDirtyRecursively(tracker_id, index_.get());
736 return WriteToDatabase(); 735 return WriteToDatabase();
737 } 736 }
738 737
739 SyncStatusCode MetadataDatabase::UnregisterApp(const std::string& app_id) { 738 SyncStatusCode MetadataDatabase::UnregisterApp(const std::string& app_id) {
740 int64 tracker_id = index_->GetAppRootTracker(app_id); 739 int64_t tracker_id = index_->GetAppRootTracker(app_id);
741 scoped_ptr<FileTracker> tracker(new FileTracker); 740 scoped_ptr<FileTracker> tracker(new FileTracker);
742 if (!index_->GetFileTracker(tracker_id, tracker.get()) || 741 if (!index_->GetFileTracker(tracker_id, tracker.get()) ||
743 tracker->tracker_kind() == TRACKER_KIND_REGULAR) { 742 tracker->tracker_kind() == TRACKER_KIND_REGULAR) {
744 return SYNC_STATUS_OK; 743 return SYNC_STATUS_OK;
745 } 744 }
746 745
747 RemoveAllDescendantTrackers(tracker_id, index_.get()); 746 RemoveAllDescendantTrackers(tracker_id, index_.get());
748 747
749 tracker->clear_app_id(); 748 tracker->clear_app_id();
750 tracker->set_tracker_kind(TRACKER_KIND_REGULAR); 749 tracker->set_tracker_kind(TRACKER_KIND_REGULAR);
751 tracker->set_active(false); 750 tracker->set_active(false);
752 tracker->set_dirty(true); 751 tracker->set_dirty(true);
753 752
754 index_->StoreFileTracker(tracker.Pass()); 753 index_->StoreFileTracker(tracker.Pass());
755 return WriteToDatabase(); 754 return WriteToDatabase();
756 } 755 }
757 756
758 bool MetadataDatabase::FindAppRootTracker(const std::string& app_id, 757 bool MetadataDatabase::FindAppRootTracker(const std::string& app_id,
759 FileTracker* tracker_out) const { 758 FileTracker* tracker_out) const {
760 int64 app_root_tracker_id = index_->GetAppRootTracker(app_id); 759 int64_t app_root_tracker_id = index_->GetAppRootTracker(app_id);
761 if (!app_root_tracker_id) 760 if (!app_root_tracker_id)
762 return false; 761 return false;
763 762
764 if (tracker_out && 763 if (tracker_out &&
765 !index_->GetFileTracker(app_root_tracker_id, tracker_out)) { 764 !index_->GetFileTracker(app_root_tracker_id, tracker_out)) {
766 NOTREACHED(); 765 NOTREACHED();
767 return false; 766 return false;
768 } 767 }
769 768
770 return true; 769 return true;
771 } 770 }
772 771
773 bool MetadataDatabase::FindFileByFileID(const std::string& file_id, 772 bool MetadataDatabase::FindFileByFileID(const std::string& file_id,
774 FileMetadata* metadata_out) const { 773 FileMetadata* metadata_out) const {
775 return index_->GetFileMetadata(file_id, metadata_out); 774 return index_->GetFileMetadata(file_id, metadata_out);
776 } 775 }
777 776
778 bool MetadataDatabase::FindTrackersByFileID(const std::string& file_id, 777 bool MetadataDatabase::FindTrackersByFileID(const std::string& file_id,
779 TrackerIDSet* trackers_out) const { 778 TrackerIDSet* trackers_out) const {
780 TrackerIDSet trackers = index_->GetFileTrackerIDsByFileID(file_id); 779 TrackerIDSet trackers = index_->GetFileTrackerIDsByFileID(file_id);
781 if (trackers.empty()) 780 if (trackers.empty())
782 return false; 781 return false;
783 782
784 if (trackers_out) 783 if (trackers_out)
785 std::swap(trackers, *trackers_out); 784 std::swap(trackers, *trackers_out);
786 return true; 785 return true;
787 } 786 }
788 787
789 bool MetadataDatabase::FindTrackersByParentAndTitle( 788 bool MetadataDatabase::FindTrackersByParentAndTitle(
790 int64 parent_tracker_id, 789 int64_t parent_tracker_id,
791 const std::string& title, 790 const std::string& title,
792 TrackerIDSet* trackers_out) const { 791 TrackerIDSet* trackers_out) const {
793 TrackerIDSet trackers = 792 TrackerIDSet trackers =
794 index_->GetFileTrackerIDsByParentAndTitle(parent_tracker_id, title); 793 index_->GetFileTrackerIDsByParentAndTitle(parent_tracker_id, title);
795 if (trackers.empty()) 794 if (trackers.empty())
796 return false; 795 return false;
797 796
798 if (trackers_out) 797 if (trackers_out)
799 std::swap(trackers, *trackers_out); 798 std::swap(trackers, *trackers_out);
800 return true; 799 return true;
801 } 800 }
802 801
803 bool MetadataDatabase::FindTrackerByTrackerID(int64 tracker_id, 802 bool MetadataDatabase::FindTrackerByTrackerID(int64_t tracker_id,
804 FileTracker* tracker_out) const { 803 FileTracker* tracker_out) const {
805 return index_->GetFileTracker(tracker_id, tracker_out); 804 return index_->GetFileTracker(tracker_id, tracker_out);
806 } 805 }
807 806
808 bool MetadataDatabase::BuildPathForTracker(int64 tracker_id, 807 bool MetadataDatabase::BuildPathForTracker(int64_t tracker_id,
809 base::FilePath* path) const { 808 base::FilePath* path) const {
810 FileTracker current; 809 FileTracker current;
811 if (!FindTrackerByTrackerID(tracker_id, &current) || !current.active()) 810 if (!FindTrackerByTrackerID(tracker_id, &current) || !current.active())
812 return false; 811 return false;
813 812
814 std::vector<base::FilePath> components; 813 std::vector<base::FilePath> components;
815 while (!IsAppRoot(current)) { 814 while (!IsAppRoot(current)) {
816 std::string title = GetTrackerTitle(current); 815 std::string title = GetTrackerTitle(current);
817 if (title.empty()) 816 if (title.empty())
818 return false; 817 return false;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 } 882 }
884 883
885 tracker_out->CopyFrom(tracker); 884 tracker_out->CopyFrom(tracker);
886 *path_out = path_out->Append(components[i]); 885 *path_out = path_out->Append(components[i]);
887 } 886 }
888 887
889 return true; 888 return true;
890 } 889 }
891 890
892 SyncStatusCode MetadataDatabase::UpdateByChangeList( 891 SyncStatusCode MetadataDatabase::UpdateByChangeList(
893 int64 largest_change_id, 892 int64_t largest_change_id,
894 ScopedVector<google_apis::ChangeResource> changes) { 893 ScopedVector<google_apis::ChangeResource> changes) {
895 DCHECK_LE(index_->GetLargestChangeID(), largest_change_id); 894 DCHECK_LE(index_->GetLargestChangeID(), largest_change_id);
896 895
897 for (size_t i = 0; i < changes.size(); ++i) { 896 for (size_t i = 0; i < changes.size(); ++i) {
898 const google_apis::ChangeResource& change = *changes[i]; 897 const google_apis::ChangeResource& change = *changes[i];
899 if (HasNewerFileMetadata(change.file_id(), change.change_id())) 898 if (HasNewerFileMetadata(change.file_id(), change.change_id()))
900 continue; 899 continue;
901 900
902 scoped_ptr<FileMetadata> metadata( 901 scoped_ptr<FileMetadata> metadata(
903 CreateFileMetadataFromChangeResource(change)); 902 CreateFileMetadataFromChangeResource(change));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 itr != file_ids.end(); ++itr) { 946 itr != file_ids.end(); ++itr) {
948 scoped_ptr<FileMetadata> metadata( 947 scoped_ptr<FileMetadata> metadata(
949 CreateDeletedFileMetadata(GetLargestKnownChangeID(), *itr)); 948 CreateDeletedFileMetadata(GetLargestKnownChangeID(), *itr));
950 UpdateByFileMetadata(FROM_HERE, metadata.Pass(), 949 UpdateByFileMetadata(FROM_HERE, metadata.Pass(),
951 UPDATE_TRACKER_FOR_UNSYNCED_FILE); 950 UPDATE_TRACKER_FOR_UNSYNCED_FILE);
952 } 951 }
953 return WriteToDatabase(); 952 return WriteToDatabase();
954 } 953 }
955 954
956 SyncStatusCode MetadataDatabase::ReplaceActiveTrackerWithNewResource( 955 SyncStatusCode MetadataDatabase::ReplaceActiveTrackerWithNewResource(
957 int64 parent_tracker_id, 956 int64_t parent_tracker_id,
958 const google_apis::FileResource& resource) { 957 const google_apis::FileResource& resource) {
959 DCHECK(!index_->GetFileMetadata(resource.file_id(), nullptr)); 958 DCHECK(!index_->GetFileMetadata(resource.file_id(), nullptr));
960 DCHECK(index_->GetFileTracker(parent_tracker_id, nullptr)); 959 DCHECK(index_->GetFileTracker(parent_tracker_id, nullptr));
961 960
962 UpdateByFileMetadata( 961 UpdateByFileMetadata(
963 FROM_HERE, 962 FROM_HERE,
964 CreateFileMetadataFromFileResource(GetLargestKnownChangeID(), resource), 963 CreateFileMetadataFromFileResource(GetLargestKnownChangeID(), resource),
965 UPDATE_TRACKER_FOR_SYNCED_FILE); 964 UPDATE_TRACKER_FOR_SYNCED_FILE);
966 965
967 DCHECK(index_->GetFileMetadata(resource.file_id(), nullptr)); 966 DCHECK(index_->GetFileMetadata(resource.file_id(), nullptr));
968 DCHECK(!index_->GetFileTrackerIDsByFileID(resource.file_id()).has_active()); 967 DCHECK(!index_->GetFileTrackerIDsByFileID(resource.file_id()).has_active());
969 968
970 TrackerIDSet same_path_trackers = 969 TrackerIDSet same_path_trackers =
971 index_->GetFileTrackerIDsByParentAndTitle( 970 index_->GetFileTrackerIDsByParentAndTitle(
972 parent_tracker_id, resource.title()); 971 parent_tracker_id, resource.title());
973 FileTracker to_be_activated; 972 FileTracker to_be_activated;
974 if (!FilterFileTrackersByFileID(index_.get(), same_path_trackers, 973 if (!FilterFileTrackersByFileID(index_.get(), same_path_trackers,
975 resource.file_id(), &to_be_activated)) { 974 resource.file_id(), &to_be_activated)) {
976 NOTREACHED(); 975 NOTREACHED();
977 return SYNC_STATUS_FAILED; 976 return SYNC_STATUS_FAILED;
978 } 977 }
979 978
980 int64 tracker_id = to_be_activated.tracker_id(); 979 int64_t tracker_id = to_be_activated.tracker_id();
981 if (same_path_trackers.has_active()) { 980 if (same_path_trackers.has_active()) {
982 DeactivateFileTracker(same_path_trackers.active_tracker(), 981 DeactivateFileTracker(same_path_trackers.active_tracker(),
983 MARK_ITSELF_DIRTY | 982 MARK_ITSELF_DIRTY |
984 MARK_SAME_FILE_ID_TRACKERS_DIRTY, 983 MARK_SAME_FILE_ID_TRACKERS_DIRTY,
985 index_.get()); 984 index_.get());
986 } 985 }
987 986
988 ActivateFileTracker(tracker_id, MARK_NOTHING_DIRTY, index_.get()); 987 ActivateFileTracker(tracker_id, MARK_NOTHING_DIRTY, index_.get());
989 return WriteToDatabase(); 988 return WriteToDatabase();
990 } 989 }
(...skipping 11 matching lines...) Expand all
1002 scoped_ptr<FileTracker> folder_tracker(new FileTracker); 1001 scoped_ptr<FileTracker> folder_tracker(new FileTracker);
1003 if (!index_->GetFileTracker(trackers.active_tracker(), 1002 if (!index_->GetFileTracker(trackers.active_tracker(),
1004 folder_tracker.get())) { 1003 folder_tracker.get())) {
1005 NOTREACHED(); 1004 NOTREACHED();
1006 return SYNC_STATUS_FAILED; 1005 return SYNC_STATUS_FAILED;
1007 } 1006 }
1008 1007
1009 base::hash_set<std::string> children(child_file_ids.begin(), 1008 base::hash_set<std::string> children(child_file_ids.begin(),
1010 child_file_ids.end()); 1009 child_file_ids.end());
1011 1010
1012 std::vector<int64> known_children = 1011 std::vector<int64_t> known_children =
1013 index_->GetFileTrackerIDsByParent(folder_tracker->tracker_id()); 1012 index_->GetFileTrackerIDsByParent(folder_tracker->tracker_id());
1014 for (size_t i = 0; i < known_children.size(); ++i) { 1013 for (size_t i = 0; i < known_children.size(); ++i) {
1015 FileTracker tracker; 1014 FileTracker tracker;
1016 if (!index_->GetFileTracker(known_children[i], &tracker)) { 1015 if (!index_->GetFileTracker(known_children[i], &tracker)) {
1017 NOTREACHED(); 1016 NOTREACHED();
1018 continue; 1017 continue;
1019 } 1018 }
1020 children.erase(tracker.file_id()); 1019 children.erase(tracker.file_id());
1021 } 1020 }
1022 1021
1023 for (base::hash_set<std::string>::const_iterator itr = children.begin(); 1022 for (base::hash_set<std::string>::const_iterator itr = children.begin();
1024 itr != children.end(); ++itr) 1023 itr != children.end(); ++itr)
1025 CreateTrackerForParentAndFileID(*folder_tracker, *itr); 1024 CreateTrackerForParentAndFileID(*folder_tracker, *itr);
1026 folder_tracker->set_needs_folder_listing(false); 1025 folder_tracker->set_needs_folder_listing(false);
1027 if (folder_tracker->dirty() && !ShouldKeepDirty(*folder_tracker)) 1026 if (folder_tracker->dirty() && !ShouldKeepDirty(*folder_tracker))
1028 folder_tracker->set_dirty(false); 1027 folder_tracker->set_dirty(false);
1029 index_->StoreFileTracker(folder_tracker.Pass()); 1028 index_->StoreFileTracker(folder_tracker.Pass());
1030 1029
1031 return WriteToDatabase(); 1030 return WriteToDatabase();
1032 } 1031 }
1033 1032
1034 SyncStatusCode MetadataDatabase::UpdateTracker( 1033 SyncStatusCode MetadataDatabase::UpdateTracker(
1035 int64 tracker_id, 1034 int64_t tracker_id,
1036 const FileDetails& updated_details) { 1035 const FileDetails& updated_details) {
1037 FileTracker tracker; 1036 FileTracker tracker;
1038 if (!index_->GetFileTracker(tracker_id, &tracker)) { 1037 if (!index_->GetFileTracker(tracker_id, &tracker)) {
1039 return SYNC_DATABASE_ERROR_NOT_FOUND; 1038 return SYNC_DATABASE_ERROR_NOT_FOUND;
1040 } 1039 }
1041 1040
1042 // Check if the tracker is to be deleted. 1041 // Check if the tracker is to be deleted.
1043 if (updated_details.missing()) { 1042 if (updated_details.missing()) {
1044 FileMetadata metadata; 1043 FileMetadata metadata;
1045 if (!index_->GetFileMetadata(tracker.file_id(), &metadata) || 1044 if (!index_->GetFileMetadata(tracker.file_id(), &metadata) ||
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 updated_tracker->set_dirty(false); 1119 updated_tracker->set_dirty(false);
1121 } 1120 }
1122 index_->StoreFileTracker(updated_tracker.Pass()); 1121 index_->StoreFileTracker(updated_tracker.Pass());
1123 if (should_promote) 1122 if (should_promote)
1124 index_->PromoteDemotedDirtyTracker(tracker_id); 1123 index_->PromoteDemotedDirtyTracker(tracker_id);
1125 1124
1126 return WriteToDatabase(); 1125 return WriteToDatabase();
1127 } 1126 }
1128 1127
1129 MetadataDatabase::ActivationStatus MetadataDatabase::TryActivateTracker( 1128 MetadataDatabase::ActivationStatus MetadataDatabase::TryActivateTracker(
1130 int64 parent_tracker_id, 1129 int64_t parent_tracker_id,
1131 const std::string& file_id, 1130 const std::string& file_id,
1132 SyncStatusCode* status_out) { 1131 SyncStatusCode* status_out) {
1133 FileMetadata metadata; 1132 FileMetadata metadata;
1134 if (!index_->GetFileMetadata(file_id, &metadata)) { 1133 if (!index_->GetFileMetadata(file_id, &metadata)) {
1135 NOTREACHED(); 1134 NOTREACHED();
1136 *status_out = SYNC_STATUS_FAILED; 1135 *status_out = SYNC_STATUS_FAILED;
1137 return ACTIVATION_PENDING; 1136 return ACTIVATION_PENDING;
1138 } 1137 }
1139 std::string title = metadata.details().title(); 1138 std::string title = metadata.details().title();
1140 DCHECK(!HasInvalidTitle(title)); 1139 DCHECK(!HasInvalidTitle(title));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1184 tracker_to_be_activated->set_needs_folder_listing(true); 1183 tracker_to_be_activated->set_needs_folder_listing(true);
1185 } 1184 }
1186 tracker_to_be_activated->set_dirty(false); 1185 tracker_to_be_activated->set_dirty(false);
1187 1186
1188 index_->StoreFileTracker(tracker_to_be_activated.Pass()); 1187 index_->StoreFileTracker(tracker_to_be_activated.Pass());
1189 1188
1190 *status_out = WriteToDatabase(); 1189 *status_out = WriteToDatabase();
1191 return ACTIVATION_PENDING; 1190 return ACTIVATION_PENDING;
1192 } 1191 }
1193 1192
1194 void MetadataDatabase::DemoteTracker(int64 tracker_id) { 1193 void MetadataDatabase::DemoteTracker(int64_t tracker_id) {
1195 index_->DemoteDirtyTracker(tracker_id); 1194 index_->DemoteDirtyTracker(tracker_id);
1196 WriteToDatabase(); 1195 WriteToDatabase();
1197 } 1196 }
1198 1197
1199 bool MetadataDatabase::PromoteDemotedTrackers() { 1198 bool MetadataDatabase::PromoteDemotedTrackers() {
1200 bool promoted = index_->PromoteDemotedDirtyTrackers(); 1199 bool promoted = index_->PromoteDemotedDirtyTrackers();
1201 WriteToDatabase(); 1200 WriteToDatabase();
1202 return promoted; 1201 return promoted;
1203 } 1202 }
1204 1203
1205 void MetadataDatabase::PromoteDemotedTracker(int64 tracker_id) { 1204 void MetadataDatabase::PromoteDemotedTracker(int64_t tracker_id) {
1206 index_->PromoteDemotedDirtyTracker(tracker_id); 1205 index_->PromoteDemotedDirtyTracker(tracker_id);
1207 WriteToDatabase(); 1206 WriteToDatabase();
1208 } 1207 }
1209 1208
1210 bool MetadataDatabase::GetDirtyTracker( 1209 bool MetadataDatabase::GetDirtyTracker(
1211 FileTracker* tracker_out) const { 1210 FileTracker* tracker_out) const {
1212 int64 dirty_tracker_id = index_->PickDirtyTracker(); 1211 int64_t dirty_tracker_id = index_->PickDirtyTracker();
1213 if (!dirty_tracker_id) 1212 if (!dirty_tracker_id)
1214 return false; 1213 return false;
1215 1214
1216 if (tracker_out) { 1215 if (tracker_out) {
1217 if (!index_->GetFileTracker(dirty_tracker_id, tracker_out)) { 1216 if (!index_->GetFileTracker(dirty_tracker_id, tracker_out)) {
1218 NOTREACHED(); 1217 NOTREACHED();
1219 return false; 1218 return false;
1220 } 1219 }
1221 } 1220 }
1222 return true; 1221 return true;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 return true; 1279 return true;
1281 } 1280 }
1282 1281
1283 void MetadataDatabase::GetRegisteredAppIDs(std::vector<std::string>* app_ids) { 1282 void MetadataDatabase::GetRegisteredAppIDs(std::vector<std::string>* app_ids) {
1284 DCHECK(app_ids); 1283 DCHECK(app_ids);
1285 *app_ids = index_->GetRegisteredAppIDs(); 1284 *app_ids = index_->GetRegisteredAppIDs();
1286 } 1285 }
1287 1286
1288 SyncStatusCode MetadataDatabase::SweepDirtyTrackers( 1287 SyncStatusCode MetadataDatabase::SweepDirtyTrackers(
1289 const std::vector<std::string>& file_ids) { 1288 const std::vector<std::string>& file_ids) {
1290 std::set<int64> tracker_ids; 1289 std::set<int64_t> tracker_ids;
1291 for (size_t i = 0; i < file_ids.size(); ++i) { 1290 for (size_t i = 0; i < file_ids.size(); ++i) {
1292 TrackerIDSet trackers_for_file_id = 1291 TrackerIDSet trackers_for_file_id =
1293 index_->GetFileTrackerIDsByFileID(file_ids[i]); 1292 index_->GetFileTrackerIDsByFileID(file_ids[i]);
1294 for (TrackerIDSet::iterator itr = trackers_for_file_id.begin(); 1293 for (TrackerIDSet::iterator itr = trackers_for_file_id.begin();
1295 itr != trackers_for_file_id.end(); ++itr) 1294 itr != trackers_for_file_id.end(); ++itr)
1296 tracker_ids.insert(*itr); 1295 tracker_ids.insert(*itr);
1297 } 1296 }
1298 1297
1299 for (std::set<int64>::iterator itr = tracker_ids.begin(); 1298 for (std::set<int64_t>::iterator itr = tracker_ids.begin();
1300 itr != tracker_ids.end(); ++itr) { 1299 itr != tracker_ids.end(); ++itr) {
1301 scoped_ptr<FileTracker> tracker(new FileTracker); 1300 scoped_ptr<FileTracker> tracker(new FileTracker);
1302 if (!index_->GetFileTracker(*itr, tracker.get()) || 1301 if (!index_->GetFileTracker(*itr, tracker.get()) ||
1303 !CanClearDirty(*tracker)) 1302 !CanClearDirty(*tracker))
1304 continue; 1303 continue;
1305 tracker->set_dirty(false); 1304 tracker->set_dirty(false);
1306 index_->StoreFileTracker(tracker.Pass()); 1305 index_->StoreFileTracker(tracker.Pass());
1307 } 1306 }
1308 1307
1309 return WriteToDatabase(); 1308 return WriteToDatabase();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 CreateTrackerInternal(parent_tracker, 1375 CreateTrackerInternal(parent_tracker,
1377 file_metadata.file_id(), 1376 file_metadata.file_id(),
1378 &file_metadata.details(), 1377 &file_metadata.details(),
1379 option); 1378 option);
1380 } 1379 }
1381 1380
1382 void MetadataDatabase::CreateTrackerInternal(const FileTracker& parent_tracker, 1381 void MetadataDatabase::CreateTrackerInternal(const FileTracker& parent_tracker,
1383 const std::string& file_id, 1382 const std::string& file_id,
1384 const FileDetails* details, 1383 const FileDetails* details,
1385 UpdateOption option) { 1384 UpdateOption option) {
1386 int64 tracker_id = IncrementTrackerID(); 1385 int64_t tracker_id = IncrementTrackerID();
1387 scoped_ptr<FileTracker> tracker(new FileTracker); 1386 scoped_ptr<FileTracker> tracker(new FileTracker);
1388 tracker->set_tracker_id(tracker_id); 1387 tracker->set_tracker_id(tracker_id);
1389 tracker->set_parent_tracker_id(parent_tracker.tracker_id()); 1388 tracker->set_parent_tracker_id(parent_tracker.tracker_id());
1390 tracker->set_file_id(file_id); 1389 tracker->set_file_id(file_id);
1391 tracker->set_app_id(parent_tracker.app_id()); 1390 tracker->set_app_id(parent_tracker.app_id());
1392 tracker->set_tracker_kind(TRACKER_KIND_REGULAR); 1391 tracker->set_tracker_kind(TRACKER_KIND_REGULAR);
1393 tracker->set_dirty(true); 1392 tracker->set_dirty(true);
1394 tracker->set_active(false); 1393 tracker->set_active(false);
1395 tracker->set_needs_folder_listing(false); 1394 tracker->set_needs_folder_listing(false);
1396 if (details) { 1395 if (details) {
1397 *tracker->mutable_synced_details() = *details; 1396 *tracker->mutable_synced_details() = *details;
1398 if (option == UPDATE_TRACKER_FOR_UNSYNCED_FILE) { 1397 if (option == UPDATE_TRACKER_FOR_UNSYNCED_FILE) {
1399 tracker->mutable_synced_details()->set_missing(true); 1398 tracker->mutable_synced_details()->set_missing(true);
1400 tracker->mutable_synced_details()->clear_md5(); 1399 tracker->mutable_synced_details()->clear_md5();
1401 } 1400 }
1402 } 1401 }
1403 index_->StoreFileTracker(tracker.Pass()); 1402 index_->StoreFileTracker(tracker.Pass());
1404 } 1403 }
1405 1404
1406 void MetadataDatabase::MaybeAddTrackersForNewFile( 1405 void MetadataDatabase::MaybeAddTrackersForNewFile(
1407 const FileMetadata& metadata, 1406 const FileMetadata& metadata,
1408 UpdateOption option) { 1407 UpdateOption option) {
1409 std::set<int64> parents_to_exclude; 1408 std::set<int64_t> parents_to_exclude;
1410 TrackerIDSet existing_trackers = 1409 TrackerIDSet existing_trackers =
1411 index_->GetFileTrackerIDsByFileID(metadata.file_id()); 1410 index_->GetFileTrackerIDsByFileID(metadata.file_id());
1412 for (TrackerIDSet::const_iterator itr = existing_trackers.begin(); 1411 for (TrackerIDSet::const_iterator itr = existing_trackers.begin();
1413 itr != existing_trackers.end(); ++itr) { 1412 itr != existing_trackers.end(); ++itr) {
1414 FileTracker tracker; 1413 FileTracker tracker;
1415 if (!index_->GetFileTracker(*itr, &tracker)) { 1414 if (!index_->GetFileTracker(*itr, &tracker)) {
1416 NOTREACHED(); 1415 NOTREACHED();
1417 continue; 1416 continue;
1418 } 1417 }
1419 1418
1420 int64 parent_tracker_id = tracker.parent_tracker_id(); 1419 int64_t parent_tracker_id = tracker.parent_tracker_id();
1421 if (!parent_tracker_id) 1420 if (!parent_tracker_id)
1422 continue; 1421 continue;
1423 1422
1424 // Exclude |parent_tracker_id| if it already has a tracker that has 1423 // Exclude |parent_tracker_id| if it already has a tracker that has
1425 // unknown title or has the same title with |file|. 1424 // unknown title or has the same title with |file|.
1426 if (!tracker.has_synced_details() || 1425 if (!tracker.has_synced_details() ||
1427 tracker.synced_details().title() == metadata.details().title()) { 1426 tracker.synced_details().title() == metadata.details().title()) {
1428 parents_to_exclude.insert(parent_tracker_id); 1427 parents_to_exclude.insert(parent_tracker_id);
1429 } 1428 }
1430 } 1429 }
(...skipping 11 matching lines...) Expand all
1442 1441
1443 if (ContainsKey(parents_to_exclude, parent_tracker.tracker_id())) 1442 if (ContainsKey(parents_to_exclude, parent_tracker.tracker_id()))
1444 continue; 1443 continue;
1445 1444
1446 CreateTrackerForParentAndFileMetadata( 1445 CreateTrackerForParentAndFileMetadata(
1447 parent_tracker, metadata, option); 1446 parent_tracker, metadata, option);
1448 } 1447 }
1449 } 1448 }
1450 } 1449 }
1451 1450
1452 int64 MetadataDatabase::IncrementTrackerID() { 1451 int64_t MetadataDatabase::IncrementTrackerID() {
1453 int64 tracker_id = index_->GetNextTrackerID(); 1452 int64_t tracker_id = index_->GetNextTrackerID();
1454 index_->SetNextTrackerID(tracker_id + 1); 1453 index_->SetNextTrackerID(tracker_id + 1);
1455 DCHECK_GT(tracker_id, 0); 1454 DCHECK_GT(tracker_id, 0);
1456 return tracker_id; 1455 return tracker_id;
1457 } 1456 }
1458 1457
1459 bool MetadataDatabase::CanActivateTracker(const FileTracker& tracker) { 1458 bool MetadataDatabase::CanActivateTracker(const FileTracker& tracker) {
1460 DCHECK(!tracker.active()); 1459 DCHECK(!tracker.active());
1461 DCHECK_NE(index_->GetSyncRootTrackerID(), tracker.tracker_id()); 1460 DCHECK_NE(index_->GetSyncRootTrackerID(), tracker.tracker_id());
1462 1461
1463 if (HasActiveTrackerForFileID(tracker.file_id())) 1462 if (HasActiveTrackerForFileID(tracker.file_id()))
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1505 return true; 1504 return true;
1506 } 1505 }
1507 1506
1508 if (local_details.title() != remote_details.title()) 1507 if (local_details.title() != remote_details.title())
1509 return true; 1508 return true;
1510 1509
1511 return false; 1510 return false;
1512 } 1511 }
1513 1512
1514 bool MetadataDatabase::HasDisabledAppRoot(const FileTracker& tracker) const { 1513 bool MetadataDatabase::HasDisabledAppRoot(const FileTracker& tracker) const {
1515 int64 app_root_tracker_id = index_->GetAppRootTracker(tracker.app_id()); 1514 int64_t app_root_tracker_id = index_->GetAppRootTracker(tracker.app_id());
1516 if (app_root_tracker_id == kInvalidTrackerID) 1515 if (app_root_tracker_id == kInvalidTrackerID)
1517 return false; 1516 return false;
1518 1517
1519 FileTracker app_root_tracker; 1518 FileTracker app_root_tracker;
1520 if (!index_->GetFileTracker(app_root_tracker_id, &app_root_tracker)) { 1519 if (!index_->GetFileTracker(app_root_tracker_id, &app_root_tracker)) {
1521 NOTREACHED(); 1520 NOTREACHED();
1522 return false; 1521 return false;
1523 } 1522 }
1524 return app_root_tracker.tracker_kind() == TRACKER_KIND_DISABLED_APP_ROOT; 1523 return app_root_tracker.tracker_kind() == TRACKER_KIND_DISABLED_APP_ROOT;
1525 } 1524 }
1526 1525
1527 bool MetadataDatabase::HasActiveTrackerForFileID( 1526 bool MetadataDatabase::HasActiveTrackerForFileID(
1528 const std::string& file_id) const { 1527 const std::string& file_id) const {
1529 return index_->GetFileTrackerIDsByFileID(file_id).has_active(); 1528 return index_->GetFileTrackerIDsByFileID(file_id).has_active();
1530 } 1529 }
1531 1530
1532 bool MetadataDatabase::HasActiveTrackerForPath(int64 parent_tracker_id, 1531 bool MetadataDatabase::HasActiveTrackerForPath(int64_t parent_tracker_id,
1533 const std::string& title) const { 1532 const std::string& title) const {
1534 return index_->GetFileTrackerIDsByParentAndTitle(parent_tracker_id, title) 1533 return index_->GetFileTrackerIDsByParentAndTitle(parent_tracker_id, title)
1535 .has_active(); 1534 .has_active();
1536 } 1535 }
1537 1536
1538 void MetadataDatabase::RemoveUnneededTrackersForMissingFile( 1537 void MetadataDatabase::RemoveUnneededTrackersForMissingFile(
1539 const std::string& file_id) { 1538 const std::string& file_id) {
1540 TrackerIDSet trackers = index_->GetFileTrackerIDsByFileID(file_id); 1539 TrackerIDSet trackers = index_->GetFileTrackerIDsByFileID(file_id);
1541 for (TrackerIDSet::const_iterator itr = trackers.begin(); 1540 for (TrackerIDSet::const_iterator itr = trackers.begin();
1542 itr != trackers.end(); ++itr) { 1541 itr != trackers.end(); ++itr) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1585 } 1584 }
1586 1585
1587 scoped_ptr<base::ListValue> MetadataDatabase::DumpFiles( 1586 scoped_ptr<base::ListValue> MetadataDatabase::DumpFiles(
1588 const std::string& app_id) { 1587 const std::string& app_id) {
1589 scoped_ptr<base::ListValue> files(new base::ListValue); 1588 scoped_ptr<base::ListValue> files(new base::ListValue);
1590 1589
1591 FileTracker app_root_tracker; 1590 FileTracker app_root_tracker;
1592 if (!FindAppRootTracker(app_id, &app_root_tracker)) 1591 if (!FindAppRootTracker(app_id, &app_root_tracker))
1593 return files.Pass(); 1592 return files.Pass();
1594 1593
1595 std::vector<int64> stack; 1594 std::vector<int64_t> stack;
1596 AppendContents( 1595 AppendContents(
1597 index_->GetFileTrackerIDsByParent(app_root_tracker.tracker_id()), &stack); 1596 index_->GetFileTrackerIDsByParent(app_root_tracker.tracker_id()), &stack);
1598 while (!stack.empty()) { 1597 while (!stack.empty()) {
1599 int64 tracker_id = stack.back(); 1598 int64_t tracker_id = stack.back();
1600 stack.pop_back(); 1599 stack.pop_back();
1601 AppendContents(index_->GetFileTrackerIDsByParent(tracker_id), &stack); 1600 AppendContents(index_->GetFileTrackerIDsByParent(tracker_id), &stack);
1602 1601
1603 FileTracker tracker; 1602 FileTracker tracker;
1604 if (!index_->GetFileTracker(tracker_id, &tracker)) { 1603 if (!index_->GetFileTracker(tracker_id, &tracker)) {
1605 NOTREACHED(); 1604 NOTREACHED();
1606 continue; 1605 continue;
1607 } 1606 }
1608 base::DictionaryValue* file = new base::DictionaryValue; 1607 base::DictionaryValue* file = new base::DictionaryValue;
1609 1608
(...skipping 22 matching lines...) Expand all
1632 } 1631 }
1633 1632
1634 scoped_ptr<base::ListValue> MetadataDatabase::DumpDatabase() { 1633 scoped_ptr<base::ListValue> MetadataDatabase::DumpDatabase() {
1635 scoped_ptr<base::ListValue> list(new base::ListValue); 1634 scoped_ptr<base::ListValue> list(new base::ListValue);
1636 list->Append(DumpTrackers().release()); 1635 list->Append(DumpTrackers().release());
1637 list->Append(DumpMetadata().release()); 1636 list->Append(DumpMetadata().release());
1638 return list.Pass(); 1637 return list.Pass();
1639 } 1638 }
1640 1639
1641 bool MetadataDatabase::HasNewerFileMetadata(const std::string& file_id, 1640 bool MetadataDatabase::HasNewerFileMetadata(const std::string& file_id,
1642 int64 change_id) { 1641 int64_t change_id) {
1643 FileMetadata metadata; 1642 FileMetadata metadata;
1644 if (!index_->GetFileMetadata(file_id, &metadata)) 1643 if (!index_->GetFileMetadata(file_id, &metadata))
1645 return false; 1644 return false;
1646 DCHECK(metadata.has_details()); 1645 DCHECK(metadata.has_details());
1647 return metadata.details().change_id() >= change_id; 1646 return metadata.details().change_id() >= change_id;
1648 } 1647 }
1649 1648
1650 scoped_ptr<base::ListValue> MetadataDatabase::DumpTrackers() { 1649 scoped_ptr<base::ListValue> MetadataDatabase::DumpTrackers() {
1651 scoped_ptr<base::ListValue> trackers(new base::ListValue); 1650 scoped_ptr<base::ListValue> trackers(new base::ListValue);
1652 1651
1653 // Append the first element for metadata. 1652 // Append the first element for metadata.
1654 base::DictionaryValue* metadata = new base::DictionaryValue; 1653 base::DictionaryValue* metadata = new base::DictionaryValue;
1655 const char *trackerKeys[] = { 1654 const char *trackerKeys[] = {
1656 "tracker_id", "path", "file_id", "tracker_kind", "app_id", 1655 "tracker_id", "path", "file_id", "tracker_kind", "app_id",
1657 "active", "dirty", "folder_listing", "demoted", 1656 "active", "dirty", "folder_listing", "demoted",
1658 "title", "kind", "md5", "etag", "missing", "change_id", 1657 "title", "kind", "md5", "etag", "missing", "change_id",
1659 }; 1658 };
1660 std::vector<std::string> key_strings( 1659 std::vector<std::string> key_strings(
1661 trackerKeys, trackerKeys + arraysize(trackerKeys)); 1660 trackerKeys, trackerKeys + arraysize(trackerKeys));
1662 base::ListValue* keys = new base::ListValue; 1661 base::ListValue* keys = new base::ListValue;
1663 keys->AppendStrings(key_strings); 1662 keys->AppendStrings(key_strings);
1664 metadata->SetString("title", "Trackers"); 1663 metadata->SetString("title", "Trackers");
1665 metadata->Set("keys", keys); 1664 metadata->Set("keys", keys);
1666 trackers->Append(metadata); 1665 trackers->Append(metadata);
1667 1666
1668 // Append tracker data. 1667 // Append tracker data.
1669 std::vector<int64> tracker_ids(index_->GetAllTrackerIDs()); 1668 std::vector<int64_t> tracker_ids(index_->GetAllTrackerIDs());
1670 for (std::vector<int64>::const_iterator itr = tracker_ids.begin(); 1669 for (std::vector<int64_t>::const_iterator itr = tracker_ids.begin();
1671 itr != tracker_ids.end(); ++itr) { 1670 itr != tracker_ids.end(); ++itr) {
1672 const int64 tracker_id = *itr; 1671 const int64_t tracker_id = *itr;
1673 FileTracker tracker; 1672 FileTracker tracker;
1674 if (!index_->GetFileTracker(tracker_id, &tracker)) { 1673 if (!index_->GetFileTracker(tracker_id, &tracker)) {
1675 NOTREACHED(); 1674 NOTREACHED();
1676 continue; 1675 continue;
1677 } 1676 }
1678 1677
1679 base::DictionaryValue* dict = new base::DictionaryValue; 1678 base::DictionaryValue* dict = new base::DictionaryValue;
1680 base::FilePath path = BuildDisplayPathForTracker(tracker); 1679 base::FilePath path = BuildDisplayPathForTracker(tracker);
1681 dict->SetString("tracker_id", base::Int64ToString(tracker_id)); 1680 dict->SetString("tracker_id", base::Int64ToString(tracker_id));
1682 dict->SetString("path", path.AsUTF8Unsafe()); 1681 dict->SetString("path", path.AsUTF8Unsafe());
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1810 return false; 1809 return false;
1811 1810
1812 if (!parents.empty()) 1811 if (!parents.empty())
1813 return false; 1812 return false;
1814 1813
1815 return true; 1814 return true;
1816 } 1815 }
1817 1816
1818 } // namespace drive_backend 1817 } // namespace drive_backend
1819 } // namespace sync_file_system 1818 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698