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/local/local_file_sync_context.h" | 5 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 DCHECK(backend); | 166 DCHECK(backend); |
167 DCHECK(backend->change_tracker()); | 167 DCHECK(backend->change_tracker()); |
168 | 168 |
169 if (sync_finish_status == SYNC_STATUS_OK || | 169 if (sync_finish_status == SYNC_STATUS_OK || |
170 sync_finish_status == SYNC_STATUS_HAS_CONFLICT) { | 170 sync_finish_status == SYNC_STATUS_HAS_CONFLICT) { |
171 // Commit the in-memory mirror change. | 171 // Commit the in-memory mirror change. |
172 backend->change_tracker()->ResetToMirrorAndCommitChangesForURL(url); | 172 backend->change_tracker()->ResetToMirrorAndCommitChangesForURL(url); |
173 } else { | 173 } else { |
174 // Abort in-memory mirror change. | 174 // Abort in-memory mirror change. |
175 backend->change_tracker()->RemoveMirrorAndCommitChangesForURL(url); | 175 backend->change_tracker()->RemoveMirrorAndCommitChangesForURL(url); |
176 if (sync_finish_status == SYNC_STATUS_FILE_BUSY) | |
177 backend->change_tracker()->DemoteChangesForURL(url); | |
178 } | 176 } |
179 | 177 |
180 // We've been keeping it in writing mode, so clear the writing counter | 178 // We've been keeping it in writing mode, so clear the writing counter |
181 // to unblock sync activities. | 179 // to unblock sync activities. |
182 io_task_runner_->PostTask( | 180 io_task_runner_->PostTask( |
183 FROM_HERE, base::Bind( | 181 FROM_HERE, base::Bind( |
184 &LocalFileSyncContext::FinalizeSnapshotSyncOnIOThread, this, url)); | 182 &LocalFileSyncContext::FinalizeSnapshotSyncOnIOThread, this, url)); |
185 | 183 |
186 // Call the completion callback on UI thread. | 184 // Call the completion callback on UI thread. |
187 ui_task_runner_->PostTask(FROM_HERE, done_callback); | 185 ui_task_runner_->PostTask(FROM_HERE, done_callback); |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 DCHECK(origins_with_changes); | 688 DCHECK(origins_with_changes); |
691 tracker_ptr->reset(new LocalFileChangeTracker( | 689 tracker_ptr->reset(new LocalFileChangeTracker( |
692 file_system_context->partition_path(), | 690 file_system_context->partition_path(), |
693 env_override_, | 691 env_override_, |
694 file_system_context->default_file_task_runner())); | 692 file_system_context->default_file_task_runner())); |
695 const SyncStatusCode status = (*tracker_ptr)->Initialize(file_system_context); | 693 const SyncStatusCode status = (*tracker_ptr)->Initialize(file_system_context); |
696 if (status != SYNC_STATUS_OK) | 694 if (status != SYNC_STATUS_OK) |
697 return status; | 695 return status; |
698 | 696 |
699 // Get all origins that have pending changes. | 697 // Get all origins that have pending changes. |
700 std::deque<FileSystemURL> urls; | 698 FileSystemURLQueue urls; |
701 (*tracker_ptr)->GetNextChangedURLs(&urls, 0); | 699 (*tracker_ptr)->GetNextChangedURLs(&urls, 0); |
702 for (std::deque<FileSystemURL>::iterator iter = urls.begin(); | 700 for (FileSystemURLQueue::iterator iter = urls.begin(); |
703 iter != urls.end(); ++iter) { | 701 iter != urls.end(); ++iter) { |
704 origins_with_changes->insert(iter->origin()); | 702 origins_with_changes->insert(iter->origin()); |
705 } | 703 } |
706 | 704 |
707 // Creates snapshot directory. | 705 // Creates snapshot directory. |
708 base::CreateDirectory(local_base_path_.Append(kSnapshotDir)); | 706 base::CreateDirectory(local_base_path_.Append(kSnapshotDir)); |
709 | 707 |
710 return status; | 708 return status; |
711 } | 709 } |
712 | 710 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 DCHECK(file_system_context); | 776 DCHECK(file_system_context); |
779 DCHECK(file_system_context->default_file_task_runner()-> | 777 DCHECK(file_system_context->default_file_task_runner()-> |
780 RunsTasksOnCurrentThread()); | 778 RunsTasksOnCurrentThread()); |
781 SyncFileSystemBackend* backend = | 779 SyncFileSystemBackend* backend = |
782 SyncFileSystemBackend::GetBackend(file_system_context); | 780 SyncFileSystemBackend::GetBackend(file_system_context); |
783 DCHECK(backend); | 781 DCHECK(backend); |
784 DCHECK(backend->change_tracker()); | 782 DCHECK(backend->change_tracker()); |
785 scoped_ptr<FileSystemURLQueue> urls(new FileSystemURLQueue); | 783 scoped_ptr<FileSystemURLQueue> urls(new FileSystemURLQueue); |
786 backend->change_tracker()->GetNextChangedURLs( | 784 backend->change_tracker()->GetNextChangedURLs( |
787 urls.get(), kMaxURLsToFetchForLocalSync); | 785 urls.get(), kMaxURLsToFetchForLocalSync); |
| 786 for (FileSystemURLQueue::iterator iter = urls->begin(); |
| 787 iter != urls->end(); ++iter) |
| 788 backend->change_tracker()->DemoteChangesForURL(*iter); |
| 789 |
788 return urls.Pass(); | 790 return urls.Pass(); |
789 } | 791 } |
790 | 792 |
791 void LocalFileSyncContext::TryPrepareForLocalSync( | 793 void LocalFileSyncContext::TryPrepareForLocalSync( |
792 FileSystemContext* file_system_context, | 794 FileSystemContext* file_system_context, |
793 const LocalFileSyncInfoCallback& callback, | 795 const LocalFileSyncInfoCallback& callback, |
794 scoped_ptr<FileSystemURLQueue> urls) { | 796 scoped_ptr<FileSystemURLQueue> urls) { |
795 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 797 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
796 DCHECK(urls); | 798 DCHECK(urls); |
797 | 799 |
(...skipping 21 matching lines...) Expand all Loading... |
819 | 821 |
820 void LocalFileSyncContext::DidTryPrepareForLocalSync( | 822 void LocalFileSyncContext::DidTryPrepareForLocalSync( |
821 FileSystemContext* file_system_context, | 823 FileSystemContext* file_system_context, |
822 scoped_ptr<FileSystemURLQueue> remaining_urls, | 824 scoped_ptr<FileSystemURLQueue> remaining_urls, |
823 const LocalFileSyncInfoCallback& callback, | 825 const LocalFileSyncInfoCallback& callback, |
824 SyncStatusCode status, | 826 SyncStatusCode status, |
825 const LocalFileSyncInfo& sync_file_info, | 827 const LocalFileSyncInfo& sync_file_info, |
826 webkit_blob::ScopedFile snapshot) { | 828 webkit_blob::ScopedFile snapshot) { |
827 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 829 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
828 if (status != SYNC_STATUS_FILE_BUSY) { | 830 if (status != SYNC_STATUS_FILE_BUSY) { |
| 831 PromoteDemotedChangesForURLs(file_system_context, |
| 832 remaining_urls.Pass()); |
829 callback.Run(status, sync_file_info, snapshot.Pass()); | 833 callback.Run(status, sync_file_info, snapshot.Pass()); |
830 return; | 834 return; |
831 } | 835 } |
| 836 |
| 837 PromoteDemotedChangesForURL(file_system_context, sync_file_info.url); |
| 838 |
832 // Recursively call TryPrepareForLocalSync with remaining_urls. | 839 // Recursively call TryPrepareForLocalSync with remaining_urls. |
833 TryPrepareForLocalSync(file_system_context, callback, remaining_urls.Pass()); | 840 TryPrepareForLocalSync(file_system_context, callback, remaining_urls.Pass()); |
834 } | 841 } |
835 | 842 |
| 843 void LocalFileSyncContext::PromoteDemotedChangesForURL( |
| 844 FileSystemContext* file_system_context, |
| 845 const FileSystemURL& url) { |
| 846 DCHECK(file_system_context); |
| 847 if (!file_system_context->default_file_task_runner()-> |
| 848 RunsTasksOnCurrentThread()) { |
| 849 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 850 if (shutdown_on_ui_) |
| 851 return; |
| 852 file_system_context->default_file_task_runner()->PostTask( |
| 853 FROM_HERE, |
| 854 base::Bind(&LocalFileSyncContext::PromoteDemotedChangesForURL, |
| 855 this, make_scoped_refptr(file_system_context), url)); |
| 856 return; |
| 857 } |
| 858 |
| 859 SyncFileSystemBackend* backend = |
| 860 SyncFileSystemBackend::GetBackend(file_system_context); |
| 861 DCHECK(backend); |
| 862 DCHECK(backend->change_tracker()); |
| 863 backend->change_tracker()->PromoteDemotedChangesForURL(url); |
| 864 } |
| 865 |
| 866 void LocalFileSyncContext::PromoteDemotedChangesForURLs( |
| 867 FileSystemContext* file_system_context, |
| 868 scoped_ptr<FileSystemURLQueue> urls) { |
| 869 DCHECK(file_system_context); |
| 870 if (!file_system_context->default_file_task_runner()-> |
| 871 RunsTasksOnCurrentThread()) { |
| 872 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 873 if (shutdown_on_ui_) |
| 874 return; |
| 875 file_system_context->default_file_task_runner()->PostTask( |
| 876 FROM_HERE, |
| 877 base::Bind(&LocalFileSyncContext::PromoteDemotedChangesForURLs, |
| 878 this, make_scoped_refptr(file_system_context), |
| 879 base::Passed(&urls))); |
| 880 return; |
| 881 } |
| 882 |
| 883 for (FileSystemURLQueue::iterator iter = urls->begin(); |
| 884 iter != urls->end(); ++iter) |
| 885 PromoteDemotedChangesForURL(file_system_context, *iter); |
| 886 } |
| 887 |
836 void LocalFileSyncContext::DidGetWritingStatusForSync( | 888 void LocalFileSyncContext::DidGetWritingStatusForSync( |
837 FileSystemContext* file_system_context, | 889 FileSystemContext* file_system_context, |
838 SyncStatusCode status, | 890 SyncStatusCode status, |
839 const FileSystemURL& url, | 891 const FileSystemURL& url, |
840 SyncMode sync_mode, | 892 SyncMode sync_mode, |
841 const LocalFileSyncInfoCallback& callback) { | 893 const LocalFileSyncInfoCallback& callback) { |
842 // This gets called on UI thread and relays the task on FILE thread. | 894 // This gets called on UI thread and relays the task on FILE thread. |
843 DCHECK(file_system_context); | 895 DCHECK(file_system_context); |
844 if (!file_system_context->default_file_task_runner()-> | 896 if (!file_system_context->default_file_task_runner()-> |
845 RunsTasksOnCurrentThread()) { | 897 RunsTasksOnCurrentThread()) { |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1009 return; | 1061 return; |
1010 } | 1062 } |
1011 | 1063 |
1012 FileSystemURL url_for_sync = CreateSyncableFileSystemURLForSync( | 1064 FileSystemURL url_for_sync = CreateSyncableFileSystemURLForSync( |
1013 file_system_context, dest_url); | 1065 file_system_context, dest_url); |
1014 file_system_context->operation_runner()->CopyInForeignFile( | 1066 file_system_context->operation_runner()->CopyInForeignFile( |
1015 local_path, url_for_sync, callback); | 1067 local_path, url_for_sync, callback); |
1016 } | 1068 } |
1017 | 1069 |
1018 } // namespace sync_file_system | 1070 } // namespace sync_file_system |
OLD | NEW |