OLD | NEW |
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/callback.h" | 11 #include "base/callback.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/location.h" | 14 #include "base/location.h" |
15 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
16 #include "base/message_loop/message_loop_proxy.h" | 16 #include "base/message_loop/message_loop_proxy.h" |
17 #include "base/sequenced_task_runner.h" | 17 #include "base/sequenced_task_runner.h" |
18 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
21 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
22 #include "base/task_runner_util.h" | 22 #include "base/task_runner_util.h" |
23 #include "base/threading/thread_restrictions.h" | 23 #include "base/threading/thread_restrictions.h" |
24 #include "chrome/browser/drive/drive_api_util.h" | 24 #include "chrome/browser/drive/drive_api_util.h" |
25 #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" |
26 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_util.h" | 26 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_util.h" |
27 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.pb.h" | 27 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.pb.h" |
28 #include "chrome/browser/sync_file_system/drive_backend/metadata_database_index.
h" | 28 #include "chrome/browser/sync_file_system/drive_backend/metadata_database_index.
h" |
| 29 #include "chrome/browser/sync_file_system/drive_backend/metadata_database_index_
interface.h" |
29 #include "chrome/browser/sync_file_system/drive_backend/metadata_db_migration_ut
il.h" | 30 #include "chrome/browser/sync_file_system/drive_backend/metadata_db_migration_ut
il.h" |
30 #include "chrome/browser/sync_file_system/logger.h" | 31 #include "chrome/browser/sync_file_system/logger.h" |
31 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" | 32 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" |
32 #include "google_apis/drive/drive_api_parser.h" | 33 #include "google_apis/drive/drive_api_parser.h" |
33 #include "google_apis/drive/drive_entry_kinds.h" | 34 #include "google_apis/drive/drive_entry_kinds.h" |
34 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 35 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
35 #include "third_party/leveldatabase/src/include/leveldb/env.h" | 36 #include "third_party/leveldatabase/src/include/leveldb/env.h" |
36 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" | 37 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" |
37 #include "webkit/common/fileapi/file_system_util.h" | 38 #include "webkit/common/fileapi/file_system_util.h" |
38 | 39 |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 return SYNC_STATUS_OK; | 363 return SYNC_STATUS_OK; |
363 } | 364 } |
364 | 365 |
365 bool HasInvalidTitle(const std::string& title) { | 366 bool HasInvalidTitle(const std::string& title) { |
366 return title.empty() || | 367 return title.empty() || |
367 title.find('/') != std::string::npos || | 368 title.find('/') != std::string::npos || |
368 title.find('\\') != std::string::npos; | 369 title.find('\\') != std::string::npos; |
369 } | 370 } |
370 | 371 |
371 void MarkTrackerSetDirty(const TrackerIDSet& trackers, | 372 void MarkTrackerSetDirty(const TrackerIDSet& trackers, |
372 MetadataDatabaseIndex* index, | 373 MetadataDatabaseIndexInterface* index, |
373 leveldb::WriteBatch* batch) { | 374 leveldb::WriteBatch* batch) { |
374 for (TrackerIDSet::const_iterator itr = trackers.begin(); | 375 for (TrackerIDSet::const_iterator itr = trackers.begin(); |
375 itr != trackers.end(); ++itr) { | 376 itr != trackers.end(); ++itr) { |
376 scoped_ptr<FileTracker> tracker = | 377 scoped_ptr<FileTracker> tracker = |
377 CloneFileTracker(index->GetFileTracker(*itr)); | 378 CloneFileTracker(index->GetFileTracker(*itr)); |
378 if (tracker->dirty()) | 379 if (tracker->dirty()) |
379 continue; | 380 continue; |
380 tracker->set_dirty(true); | 381 tracker->set_dirty(true); |
381 PutFileTrackerToBatch(*tracker, batch); | 382 PutFileTrackerToBatch(*tracker, batch); |
382 index->StoreFileTracker(tracker.Pass()); | 383 index->StoreFileTracker(tracker.Pass()); |
383 } | 384 } |
384 } | 385 } |
385 | 386 |
386 void MarkTrackersDirtyByPath(int64 parent_tracker_id, | 387 void MarkTrackersDirtyByPath(int64 parent_tracker_id, |
387 const std::string& title, | 388 const std::string& title, |
388 MetadataDatabaseIndex* index, | 389 MetadataDatabaseIndexInterface* index, |
389 leveldb::WriteBatch* batch) { | 390 leveldb::WriteBatch* batch) { |
390 if (parent_tracker_id == kInvalidTrackerID || title.empty()) | 391 if (parent_tracker_id == kInvalidTrackerID || title.empty()) |
391 return; | 392 return; |
392 MarkTrackerSetDirty( | 393 MarkTrackerSetDirty( |
393 index->GetFileTrackerIDsByParentAndTitle(parent_tracker_id, title), | 394 index->GetFileTrackerIDsByParentAndTitle(parent_tracker_id, title), |
394 index, batch); | 395 index, batch); |
395 } | 396 } |
396 | 397 |
397 void MarkTrackersDirtyByFileID(const std::string& file_id, | 398 void MarkTrackersDirtyByFileID(const std::string& file_id, |
398 MetadataDatabaseIndex* index, | 399 MetadataDatabaseIndexInterface* index, |
399 leveldb::WriteBatch* batch) { | 400 leveldb::WriteBatch* batch) { |
400 MarkTrackerSetDirty(index->GetFileTrackerIDsByFileID(file_id), | 401 MarkTrackerSetDirty(index->GetFileTrackerIDsByFileID(file_id), |
401 index, batch); | 402 index, batch); |
402 } | 403 } |
403 | 404 |
404 void MarkTrackersDirtyRecursively(int64 root_tracker_id, | 405 void MarkTrackersDirtyRecursively(int64 root_tracker_id, |
405 MetadataDatabaseIndex* index, | 406 MetadataDatabaseIndexInterface* index, |
406 leveldb::WriteBatch* batch) { | 407 leveldb::WriteBatch* batch) { |
407 std::vector<int64> stack; | 408 std::vector<int64> stack; |
408 stack.push_back(root_tracker_id); | 409 stack.push_back(root_tracker_id); |
409 while (!stack.empty()) { | 410 while (!stack.empty()) { |
410 int64 tracker_id = stack.back(); | 411 int64 tracker_id = stack.back(); |
411 stack.pop_back(); | 412 stack.pop_back(); |
412 AppendContents(index->GetFileTrackerIDsByParent(tracker_id), &stack); | 413 AppendContents(index->GetFileTrackerIDsByParent(tracker_id), &stack); |
413 | 414 |
414 scoped_ptr<FileTracker> tracker = | 415 scoped_ptr<FileTracker> tracker = |
415 CloneFileTracker(index->GetFileTracker(tracker_id)); | 416 CloneFileTracker(index->GetFileTracker(tracker_id)); |
416 tracker->set_dirty(true); | 417 tracker->set_dirty(true); |
417 | 418 |
418 PutFileTrackerToBatch(*tracker, batch); | 419 PutFileTrackerToBatch(*tracker, batch); |
419 index->StoreFileTracker(tracker.Pass()); | 420 index->StoreFileTracker(tracker.Pass()); |
420 } | 421 } |
421 } | 422 } |
422 | 423 |
423 void RemoveAllDescendantTrackers(int64 root_tracker_id, | 424 void RemoveAllDescendantTrackers(int64 root_tracker_id, |
424 MetadataDatabaseIndex* index, | 425 MetadataDatabaseIndexInterface* index, |
425 leveldb::WriteBatch* batch) { | 426 leveldb::WriteBatch* batch) { |
426 std::vector<int64> pending_trackers; | 427 std::vector<int64> pending_trackers; |
427 AppendContents(index->GetFileTrackerIDsByParent(root_tracker_id), | 428 AppendContents(index->GetFileTrackerIDsByParent(root_tracker_id), |
428 &pending_trackers); | 429 &pending_trackers); |
429 | 430 |
430 std::vector<int64> to_be_removed; | 431 std::vector<int64> to_be_removed; |
431 | 432 |
432 // List trackers to remove. | 433 // List trackers to remove. |
433 while (!pending_trackers.empty()) { | 434 while (!pending_trackers.empty()) { |
434 int64 tracker_id = pending_trackers.back(); | 435 int64 tracker_id = pending_trackers.back(); |
(...skipping 20 matching lines...) Expand all Loading... |
455 // Remove metadata that no longer has any tracker. | 456 // Remove metadata that no longer has any tracker. |
456 PutFileMetadataDeletionToBatch(*itr, batch); | 457 PutFileMetadataDeletionToBatch(*itr, batch); |
457 index->RemoveFileMetadata(*itr); | 458 index->RemoveFileMetadata(*itr); |
458 } else { | 459 } else { |
459 MarkTrackerSetDirty(trackers, index, batch); | 460 MarkTrackerSetDirty(trackers, index, batch); |
460 } | 461 } |
461 } | 462 } |
462 } | 463 } |
463 | 464 |
464 const FileTracker* FilterFileTrackersByParent( | 465 const FileTracker* FilterFileTrackersByParent( |
465 const MetadataDatabaseIndex& index, | 466 const MetadataDatabaseIndexInterface* index, |
466 const TrackerIDSet& trackers, | 467 const TrackerIDSet& trackers, |
467 int64 parent_tracker_id) { | 468 int64 parent_tracker_id) { |
468 for (TrackerIDSet::const_iterator itr = trackers.begin(); | 469 for (TrackerIDSet::const_iterator itr = trackers.begin(); |
469 itr != trackers.end(); ++itr) { | 470 itr != trackers.end(); ++itr) { |
470 const FileTracker* tracker = index.GetFileTracker(*itr); | 471 const FileTracker* tracker = index->GetFileTracker(*itr); |
471 if (!tracker) { | 472 if (!tracker) { |
472 NOTREACHED(); | 473 NOTREACHED(); |
473 continue; | 474 continue; |
474 } | 475 } |
475 | 476 |
476 if (tracker->parent_tracker_id() == parent_tracker_id) | 477 if (tracker->parent_tracker_id() == parent_tracker_id) |
477 return tracker; | 478 return tracker; |
478 } | 479 } |
479 return NULL; | 480 return NULL; |
480 } | 481 } |
481 | 482 |
482 const FileTracker* FilterFileTrackersByParentAndTitle( | 483 const FileTracker* FilterFileTrackersByParentAndTitle( |
483 const MetadataDatabaseIndex& index, | 484 const MetadataDatabaseIndexInterface* index, |
484 const TrackerIDSet& trackers, | 485 const TrackerIDSet& trackers, |
485 int64 parent_tracker_id, | 486 int64 parent_tracker_id, |
486 const std::string& title) { | 487 const std::string& title) { |
487 const FileTracker* result = NULL; | 488 const FileTracker* result = NULL; |
488 | 489 |
489 for (TrackerIDSet::const_iterator itr = trackers.begin(); | 490 for (TrackerIDSet::const_iterator itr = trackers.begin(); |
490 itr != trackers.end(); ++itr) { | 491 itr != trackers.end(); ++itr) { |
491 const FileTracker* tracker = index.GetFileTracker(*itr); | 492 const FileTracker* tracker = index->GetFileTracker(*itr); |
492 if (!tracker) { | 493 if (!tracker) { |
493 NOTREACHED(); | 494 NOTREACHED(); |
494 continue; | 495 continue; |
495 } | 496 } |
496 | 497 |
497 if (tracker->parent_tracker_id() != parent_tracker_id) | 498 if (tracker->parent_tracker_id() != parent_tracker_id) |
498 continue; | 499 continue; |
499 | 500 |
500 if (tracker->has_synced_details() && | 501 if (tracker->has_synced_details() && |
501 tracker->synced_details().title() != title) | 502 tracker->synced_details().title() != title) |
502 continue; | 503 continue; |
503 | 504 |
504 // Prioritize trackers that has |synced_details|. | 505 // Prioritize trackers that has |synced_details|. |
505 if (!result || !tracker->has_synced_details()) | 506 if (!result || !tracker->has_synced_details()) |
506 result = tracker; | 507 result = tracker; |
507 } | 508 } |
508 | 509 |
509 return result; | 510 return result; |
510 } | 511 } |
511 | 512 |
512 const FileTracker* FilterFileTrackersByFileID( | 513 const FileTracker* FilterFileTrackersByFileID( |
513 const MetadataDatabaseIndex& index, | 514 const MetadataDatabaseIndexInterface* index, |
514 const TrackerIDSet& trackers, | 515 const TrackerIDSet& trackers, |
515 const std::string& file_id) { | 516 const std::string& file_id) { |
516 for (TrackerIDSet::const_iterator itr = trackers.begin(); | 517 for (TrackerIDSet::const_iterator itr = trackers.begin(); |
517 itr != trackers.end(); ++itr) { | 518 itr != trackers.end(); ++itr) { |
518 const FileTracker* tracker = index.GetFileTracker(*itr); | 519 const FileTracker* tracker = index->GetFileTracker(*itr); |
519 if (!tracker) { | 520 if (!tracker) { |
520 NOTREACHED(); | 521 NOTREACHED(); |
521 continue; | 522 continue; |
522 } | 523 } |
523 | 524 |
524 if (tracker->file_id() == file_id) | 525 if (tracker->file_id() == file_id) |
525 return tracker; | 526 return tracker; |
526 } | 527 } |
527 | 528 |
528 return NULL; | 529 return NULL; |
529 } | 530 } |
530 | 531 |
531 enum DirtyingOption { | 532 enum DirtyingOption { |
532 MARK_NOTHING_DIRTY = 0, | 533 MARK_NOTHING_DIRTY = 0, |
533 MARK_ITSELF_DIRTY = 1 << 0, | 534 MARK_ITSELF_DIRTY = 1 << 0, |
534 MARK_SAME_FILE_ID_TRACKERS_DIRTY = 1 << 1, | 535 MARK_SAME_FILE_ID_TRACKERS_DIRTY = 1 << 1, |
535 MARK_SAME_PATH_TRACKERS_DIRTY = 1 << 2, | 536 MARK_SAME_PATH_TRACKERS_DIRTY = 1 << 2, |
536 }; | 537 }; |
537 | 538 |
538 void ActivateFileTracker(int64 tracker_id, | 539 void ActivateFileTracker(int64 tracker_id, |
539 int dirtying_options, | 540 int dirtying_options, |
540 MetadataDatabaseIndex* index, | 541 MetadataDatabaseIndexInterface* index, |
541 leveldb::WriteBatch* batch) { | 542 leveldb::WriteBatch* batch) { |
542 DCHECK(dirtying_options == MARK_NOTHING_DIRTY || | 543 DCHECK(dirtying_options == MARK_NOTHING_DIRTY || |
543 dirtying_options == MARK_ITSELF_DIRTY); | 544 dirtying_options == MARK_ITSELF_DIRTY); |
544 | 545 |
545 scoped_ptr<FileTracker> tracker = | 546 scoped_ptr<FileTracker> tracker = |
546 CloneFileTracker(index->GetFileTracker(tracker_id)); | 547 CloneFileTracker(index->GetFileTracker(tracker_id)); |
547 tracker->set_active(true); | 548 tracker->set_active(true); |
548 if (dirtying_options & MARK_ITSELF_DIRTY) { | 549 if (dirtying_options & MARK_ITSELF_DIRTY) { |
549 tracker->set_dirty(true); | 550 tracker->set_dirty(true); |
550 tracker->set_needs_folder_listing( | 551 tracker->set_needs_folder_listing( |
551 tracker->has_synced_details() && | 552 tracker->has_synced_details() && |
552 tracker->synced_details().file_kind() == FILE_KIND_FOLDER); | 553 tracker->synced_details().file_kind() == FILE_KIND_FOLDER); |
553 } else { | 554 } else { |
554 tracker->set_dirty(false); | 555 tracker->set_dirty(false); |
555 tracker->set_needs_folder_listing(false); | 556 tracker->set_needs_folder_listing(false); |
556 } | 557 } |
557 | 558 |
558 PutFileTrackerToBatch(*tracker, batch); | 559 PutFileTrackerToBatch(*tracker, batch); |
559 index->StoreFileTracker(tracker.Pass()); | 560 index->StoreFileTracker(tracker.Pass()); |
560 } | 561 } |
561 | 562 |
562 void DeactivateFileTracker(int64 tracker_id, | 563 void DeactivateFileTracker(int64 tracker_id, |
563 int dirtying_options, | 564 int dirtying_options, |
564 MetadataDatabaseIndex* index, | 565 MetadataDatabaseIndexInterface* index, |
565 leveldb::WriteBatch* batch) { | 566 leveldb::WriteBatch* batch) { |
566 RemoveAllDescendantTrackers(tracker_id, index, batch); | 567 RemoveAllDescendantTrackers(tracker_id, index, batch); |
567 | 568 |
568 scoped_ptr<FileTracker> tracker = | 569 scoped_ptr<FileTracker> tracker = |
569 CloneFileTracker(index->GetFileTracker(tracker_id)); | 570 CloneFileTracker(index->GetFileTracker(tracker_id)); |
570 | 571 |
571 if (dirtying_options & MARK_SAME_FILE_ID_TRACKERS_DIRTY) | 572 if (dirtying_options & MARK_SAME_FILE_ID_TRACKERS_DIRTY) |
572 MarkTrackersDirtyByFileID(tracker->file_id(), index, batch); | 573 MarkTrackersDirtyByFileID(tracker->file_id(), index, batch); |
573 if (dirtying_options & MARK_SAME_PATH_TRACKERS_DIRTY) { | 574 if (dirtying_options & MARK_SAME_PATH_TRACKERS_DIRTY) { |
574 MarkTrackersDirtyByPath(tracker->parent_tracker_id(), | 575 MarkTrackersDirtyByPath(tracker->parent_tracker_id(), |
575 GetTrackerTitle(*tracker), | 576 GetTrackerTitle(*tracker), |
576 index, batch); | 577 index, batch); |
577 } | 578 } |
578 | 579 |
579 tracker->set_dirty(dirtying_options & MARK_ITSELF_DIRTY); | 580 tracker->set_dirty(dirtying_options & MARK_ITSELF_DIRTY); |
580 tracker->set_active(false); | 581 tracker->set_active(false); |
581 PutFileTrackerToBatch(*tracker, batch); | 582 PutFileTrackerToBatch(*tracker, batch); |
582 index->StoreFileTracker(tracker.Pass()); | 583 index->StoreFileTracker(tracker.Pass()); |
583 } | 584 } |
584 | 585 |
585 void RemoveFileTracker(int64 tracker_id, | 586 void RemoveFileTracker(int64 tracker_id, |
586 int dirtying_options, | 587 int dirtying_options, |
587 MetadataDatabaseIndex* index, | 588 MetadataDatabaseIndexInterface* index, |
588 leveldb::WriteBatch* batch) { | 589 leveldb::WriteBatch* batch) { |
589 DCHECK(!(dirtying_options & MARK_ITSELF_DIRTY)); | 590 DCHECK(!(dirtying_options & MARK_ITSELF_DIRTY)); |
590 | 591 |
591 const FileTracker* tracker = index->GetFileTracker(tracker_id); | 592 const FileTracker* tracker = index->GetFileTracker(tracker_id); |
592 if (!tracker) | 593 if (!tracker) |
593 return; | 594 return; |
594 | 595 |
595 std::string file_id = tracker->file_id(); | 596 std::string file_id = tracker->file_id(); |
596 int64 parent_tracker_id = tracker->parent_tracker_id(); | 597 int64 parent_tracker_id = tracker->parent_tracker_id(); |
597 std::string title = GetTrackerTitle(*tracker); | 598 std::string title = GetTrackerTitle(*tracker); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 if (!sync_root_tracker_id) { | 778 if (!sync_root_tracker_id) { |
778 util::Log(logging::LOG_WARNING, FROM_HERE, | 779 util::Log(logging::LOG_WARNING, FROM_HERE, |
779 "Sync-root needs to be set up before registering app-root"); | 780 "Sync-root needs to be set up before registering app-root"); |
780 worker_task_runner_->PostTask( | 781 worker_task_runner_->PostTask( |
781 FROM_HERE, | 782 FROM_HERE, |
782 base::Bind(callback, SYNC_DATABASE_ERROR_NOT_FOUND)); | 783 base::Bind(callback, SYNC_DATABASE_ERROR_NOT_FOUND)); |
783 return; | 784 return; |
784 } | 785 } |
785 | 786 |
786 scoped_ptr<FileTracker> tracker = | 787 scoped_ptr<FileTracker> tracker = |
787 CloneFileTracker(FilterFileTrackersByParent(*index_, trackers, | 788 CloneFileTracker(FilterFileTrackersByParent(index_.get(), trackers, |
788 sync_root_tracker_id)); | 789 sync_root_tracker_id)); |
789 if (!tracker) { | 790 if (!tracker) { |
790 worker_task_runner_->PostTask( | 791 worker_task_runner_->PostTask( |
791 FROM_HERE, | 792 FROM_HERE, |
792 base::Bind(callback, SYNC_DATABASE_ERROR_NOT_FOUND)); | 793 base::Bind(callback, SYNC_DATABASE_ERROR_NOT_FOUND)); |
793 return; | 794 return; |
794 } | 795 } |
795 | 796 |
796 scoped_ptr<leveldb::WriteBatch> batch(new leveldb::WriteBatch); | 797 scoped_ptr<leveldb::WriteBatch> batch(new leveldb::WriteBatch); |
797 tracker->set_app_id(app_id); | 798 tracker->set_app_id(app_id); |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1162 UPDATE_TRACKER_FOR_SYNCED_FILE, | 1163 UPDATE_TRACKER_FOR_SYNCED_FILE, |
1163 batch.get()); | 1164 batch.get()); |
1164 | 1165 |
1165 DCHECK(index_->GetFileMetadata(resource.file_id())); | 1166 DCHECK(index_->GetFileMetadata(resource.file_id())); |
1166 DCHECK(!index_->GetFileTrackerIDsByFileID(resource.file_id()).has_active()); | 1167 DCHECK(!index_->GetFileTrackerIDsByFileID(resource.file_id()).has_active()); |
1167 | 1168 |
1168 TrackerIDSet same_path_trackers = | 1169 TrackerIDSet same_path_trackers = |
1169 index_->GetFileTrackerIDsByParentAndTitle( | 1170 index_->GetFileTrackerIDsByParentAndTitle( |
1170 parent_tracker_id, resource.title()); | 1171 parent_tracker_id, resource.title()); |
1171 const FileTracker* to_be_activated = | 1172 const FileTracker* to_be_activated = |
1172 FilterFileTrackersByFileID(*index_, same_path_trackers, | 1173 FilterFileTrackersByFileID(index_.get(), same_path_trackers, |
1173 resource.file_id()); | 1174 resource.file_id()); |
1174 if (!to_be_activated) { | 1175 if (!to_be_activated) { |
1175 NOTREACHED(); | 1176 NOTREACHED(); |
1176 worker_task_runner_->PostTask( | 1177 worker_task_runner_->PostTask( |
1177 FROM_HERE, | 1178 FROM_HERE, |
1178 base::Bind(callback, SYNC_STATUS_FAILED)); | 1179 base::Bind(callback, SYNC_STATUS_FAILED)); |
1179 return; | 1180 return; |
1180 } | 1181 } |
1181 | 1182 |
1182 int64 tracker_id = to_be_activated->tracker_id(); | 1183 int64 tracker_id = to_be_activated->tracker_id(); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1306 MARK_SAME_FILE_ID_TRACKERS_DIRTY, | 1307 MARK_SAME_FILE_ID_TRACKERS_DIRTY, |
1307 index_.get(), batch.get()); | 1308 index_.get(), batch.get()); |
1308 WriteToDatabase(batch.Pass(), callback); | 1309 WriteToDatabase(batch.Pass(), callback); |
1309 return; | 1310 return; |
1310 } | 1311 } |
1311 } else { | 1312 } else { |
1312 // Check if any other tracker exists has the same parent, title and | 1313 // Check if any other tracker exists has the same parent, title and |
1313 // file_id to the updated tracker. If it exists, delete the tracker being | 1314 // file_id to the updated tracker. If it exists, delete the tracker being |
1314 // updated. | 1315 // updated. |
1315 if (FilterFileTrackersByFileID( | 1316 if (FilterFileTrackersByFileID( |
1316 *index_, | 1317 index_.get(), |
1317 index_->GetFileTrackerIDsByParentAndTitle( | 1318 index_->GetFileTrackerIDsByParentAndTitle( |
1318 parent_tracker->tracker_id(), | 1319 parent_tracker->tracker_id(), |
1319 updated_details.title()), | 1320 updated_details.title()), |
1320 tracker->file_id())) { | 1321 tracker->file_id())) { |
1321 RemoveFileTracker(tracker->tracker_id(), | 1322 RemoveFileTracker(tracker->tracker_id(), |
1322 MARK_NOTHING_DIRTY, | 1323 MARK_NOTHING_DIRTY, |
1323 index_.get(), batch.get()); | 1324 index_.get(), batch.get()); |
1324 WriteToDatabase(batch.Pass(), callback); | 1325 WriteToDatabase(batch.Pass(), callback); |
1325 return; | 1326 return; |
1326 } | 1327 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1362 base::Bind(callback, SYNC_STATUS_FAILED)); | 1363 base::Bind(callback, SYNC_STATUS_FAILED)); |
1363 return ACTIVATION_PENDING; | 1364 return ACTIVATION_PENDING; |
1364 } | 1365 } |
1365 std::string title = metadata->details().title(); | 1366 std::string title = metadata->details().title(); |
1366 DCHECK(!HasInvalidTitle(title)); | 1367 DCHECK(!HasInvalidTitle(title)); |
1367 | 1368 |
1368 TrackerIDSet same_file_id_trackers = | 1369 TrackerIDSet same_file_id_trackers = |
1369 index_->GetFileTrackerIDsByFileID(file_id); | 1370 index_->GetFileTrackerIDsByFileID(file_id); |
1370 scoped_ptr<FileTracker> tracker_to_be_activated = | 1371 scoped_ptr<FileTracker> tracker_to_be_activated = |
1371 CloneFileTracker(FilterFileTrackersByParentAndTitle( | 1372 CloneFileTracker(FilterFileTrackersByParentAndTitle( |
1372 *index_, same_file_id_trackers, | 1373 index_.get(), same_file_id_trackers, |
1373 parent_tracker_id, title)); | 1374 parent_tracker_id, title)); |
1374 DCHECK(tracker_to_be_activated); | 1375 DCHECK(tracker_to_be_activated); |
1375 | 1376 |
1376 // Check if there is another active tracker that tracks |file_id|. | 1377 // Check if there is another active tracker that tracks |file_id|. |
1377 // This can happen when the tracked file has multiple parents. | 1378 // This can happen when the tracked file has multiple parents. |
1378 // In this case, report the failure to the caller. | 1379 // In this case, report the failure to the caller. |
1379 if (!tracker_to_be_activated->active() && same_file_id_trackers.has_active()) | 1380 if (!tracker_to_be_activated->active() && same_file_id_trackers.has_active()) |
1380 return ACTIVATION_FAILED_ANOTHER_ACTIVE_TRACKER; | 1381 return ACTIVATION_FAILED_ANOTHER_ACTIVE_TRACKER; |
1381 | 1382 |
1382 scoped_ptr<leveldb::WriteBatch> batch(new leveldb::WriteBatch); | 1383 scoped_ptr<leveldb::WriteBatch> batch(new leveldb::WriteBatch); |
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2103 index_->StoreFileMetadata(app_root_metadata.Pass()); | 2104 index_->StoreFileMetadata(app_root_metadata.Pass()); |
2104 index_->StoreFileTracker(app_root_tracker.Pass()); | 2105 index_->StoreFileTracker(app_root_tracker.Pass()); |
2105 } | 2106 } |
2106 | 2107 |
2107 void MetadataDatabase::DetachFromSequence() { | 2108 void MetadataDatabase::DetachFromSequence() { |
2108 worker_sequence_checker_.DetachFromSequence(); | 2109 worker_sequence_checker_.DetachFromSequence(); |
2109 } | 2110 } |
2110 | 2111 |
2111 } // namespace drive_backend | 2112 } // namespace drive_backend |
2112 } // namespace sync_file_system | 2113 } // namespace sync_file_system |
OLD | NEW |