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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 FROM_HERE, | 100 FROM_HERE, |
101 base::Bind(&LocalFileSyncContext::ShutdownOnIOThread, this)); | 101 base::Bind(&LocalFileSyncContext::ShutdownOnIOThread, this)); |
102 } | 102 } |
103 | 103 |
104 void LocalFileSyncContext::GetFileForLocalSync( | 104 void LocalFileSyncContext::GetFileForLocalSync( |
105 FileSystemContext* file_system_context, | 105 FileSystemContext* file_system_context, |
106 const LocalFileSyncInfoCallback& callback) { | 106 const LocalFileSyncInfoCallback& callback) { |
107 DCHECK(file_system_context); | 107 DCHECK(file_system_context); |
108 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 108 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
109 | 109 |
110 std::deque<FileSystemURL>* urls = new std::deque<FileSystemURL>; | 110 base::PostTaskAndReplyWithResult( |
111 file_system_context->default_file_task_runner()->PostTaskAndReply( | 111 file_system_context->default_file_task_runner(), |
112 FROM_HERE, | 112 FROM_HERE, |
113 base::Bind(&LocalFileSyncContext::GetNextURLsForSyncOnFileThread, | 113 base::Bind(&LocalFileSyncContext::GetNextURLsForSyncOnFileThread, |
114 this, make_scoped_refptr(file_system_context), | 114 this, make_scoped_refptr(file_system_context)), |
115 base::Unretained(urls)), | |
116 base::Bind(&LocalFileSyncContext::TryPrepareForLocalSync, | 115 base::Bind(&LocalFileSyncContext::TryPrepareForLocalSync, |
117 this, make_scoped_refptr(file_system_context), | 116 this, make_scoped_refptr(file_system_context), callback)); |
118 base::Owned(urls), callback)); | |
119 } | 117 } |
120 | 118 |
121 void LocalFileSyncContext::ClearChangesForURL( | 119 void LocalFileSyncContext::ClearChangesForURL( |
122 FileSystemContext* file_system_context, | 120 FileSystemContext* file_system_context, |
123 const FileSystemURL& url, | 121 const FileSystemURL& url, |
124 const base::Closure& done_callback) { | 122 const base::Closure& done_callback) { |
125 // This is initially called on UI thread and to be relayed to FILE thread. | 123 // This is initially called on UI thread and to be relayed to FILE thread. |
126 DCHECK(file_system_context); | 124 DCHECK(file_system_context); |
127 if (!file_system_context->default_file_task_runner()-> | 125 if (!file_system_context->default_file_task_runner()-> |
128 RunsTasksOnCurrentThread()) { | 126 RunsTasksOnCurrentThread()) { |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 | 753 |
756 StatusCallbackQueue& callback_queue = | 754 StatusCallbackQueue& callback_queue = |
757 pending_initialize_callbacks_[file_system_context]; | 755 pending_initialize_callbacks_[file_system_context]; |
758 for (StatusCallbackQueue::iterator iter = callback_queue.begin(); | 756 for (StatusCallbackQueue::iterator iter = callback_queue.begin(); |
759 iter != callback_queue.end(); ++iter) { | 757 iter != callback_queue.end(); ++iter) { |
760 ui_task_runner_->PostTask(FROM_HERE, base::Bind(*iter, status)); | 758 ui_task_runner_->PostTask(FROM_HERE, base::Bind(*iter, status)); |
761 } | 759 } |
762 pending_initialize_callbacks_.erase(file_system_context); | 760 pending_initialize_callbacks_.erase(file_system_context); |
763 } | 761 } |
764 | 762 |
765 void LocalFileSyncContext::GetNextURLsForSyncOnFileThread( | 763 scoped_ptr<LocalFileSyncContext::FileSystemURLQueue> |
766 FileSystemContext* file_system_context, | 764 LocalFileSyncContext::GetNextURLsForSyncOnFileThread( |
767 std::deque<FileSystemURL>* urls) { | 765 FileSystemContext* file_system_context) { |
768 DCHECK(file_system_context); | 766 DCHECK(file_system_context); |
769 DCHECK(file_system_context->default_file_task_runner()-> | 767 DCHECK(file_system_context->default_file_task_runner()-> |
770 RunsTasksOnCurrentThread()); | 768 RunsTasksOnCurrentThread()); |
771 SyncFileSystemBackend* backend = | 769 SyncFileSystemBackend* backend = |
772 SyncFileSystemBackend::GetBackend(file_system_context); | 770 SyncFileSystemBackend::GetBackend(file_system_context); |
773 DCHECK(backend); | 771 DCHECK(backend); |
774 DCHECK(backend->change_tracker()); | 772 DCHECK(backend->change_tracker()); |
| 773 scoped_ptr<FileSystemURLQueue> urls(new FileSystemURLQueue); |
775 backend->change_tracker()->GetNextChangedURLs( | 774 backend->change_tracker()->GetNextChangedURLs( |
776 urls, kMaxURLsToFetchForLocalSync); | 775 urls.get(), kMaxURLsToFetchForLocalSync); |
| 776 return urls.Pass(); |
777 } | 777 } |
778 | 778 |
779 void LocalFileSyncContext::TryPrepareForLocalSync( | 779 void LocalFileSyncContext::TryPrepareForLocalSync( |
780 FileSystemContext* file_system_context, | 780 FileSystemContext* file_system_context, |
781 std::deque<FileSystemURL>* urls, | 781 const LocalFileSyncInfoCallback& callback, |
782 const LocalFileSyncInfoCallback& callback) { | 782 scoped_ptr<FileSystemURLQueue> urls) { |
783 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 783 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
784 DCHECK(urls); | 784 DCHECK(urls); |
785 | 785 |
786 if (shutdown_on_ui_) { | 786 if (shutdown_on_ui_) { |
787 callback.Run(SYNC_STATUS_ABORT, LocalFileSyncInfo(), | 787 callback.Run(SYNC_STATUS_ABORT, LocalFileSyncInfo(), |
788 webkit_blob::ScopedFile()); | 788 webkit_blob::ScopedFile()); |
789 return; | 789 return; |
790 } | 790 } |
791 | 791 |
792 if (urls->empty()) { | 792 if (urls->empty()) { |
793 callback.Run(SYNC_STATUS_NO_CHANGE_TO_SYNC, LocalFileSyncInfo(), | 793 callback.Run(SYNC_STATUS_NO_CHANGE_TO_SYNC, LocalFileSyncInfo(), |
794 webkit_blob::ScopedFile()); | 794 webkit_blob::ScopedFile()); |
795 return; | 795 return; |
796 } | 796 } |
797 | 797 |
798 const FileSystemURL url = urls->front(); | 798 const FileSystemURL url = urls->front(); |
799 urls->pop_front(); | 799 urls->pop_front(); |
800 std::deque<FileSystemURL>* remaining = new std::deque<FileSystemURL>; | |
801 remaining->swap(*urls); | |
802 | 800 |
803 PrepareForSync( | 801 PrepareForSync( |
804 file_system_context, url, SYNC_SNAPSHOT, | 802 file_system_context, url, SYNC_SNAPSHOT, |
805 base::Bind(&LocalFileSyncContext::DidTryPrepareForLocalSync, | 803 base::Bind(&LocalFileSyncContext::DidTryPrepareForLocalSync, |
806 this, make_scoped_refptr(file_system_context), | 804 this, make_scoped_refptr(file_system_context), |
807 base::Owned(remaining), callback)); | 805 base::Passed(&urls), callback)); |
808 } | 806 } |
809 | 807 |
810 void LocalFileSyncContext::DidTryPrepareForLocalSync( | 808 void LocalFileSyncContext::DidTryPrepareForLocalSync( |
811 FileSystemContext* file_system_context, | 809 FileSystemContext* file_system_context, |
812 std::deque<FileSystemURL>* remaining_urls, | 810 scoped_ptr<FileSystemURLQueue> remaining_urls, |
813 const LocalFileSyncInfoCallback& callback, | 811 const LocalFileSyncInfoCallback& callback, |
814 SyncStatusCode status, | 812 SyncStatusCode status, |
815 const LocalFileSyncInfo& sync_file_info, | 813 const LocalFileSyncInfo& sync_file_info, |
816 webkit_blob::ScopedFile snapshot) { | 814 webkit_blob::ScopedFile snapshot) { |
817 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 815 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
818 if (status != SYNC_STATUS_FILE_BUSY) { | 816 if (status != SYNC_STATUS_FILE_BUSY) { |
819 callback.Run(status, sync_file_info, snapshot.Pass()); | 817 callback.Run(status, sync_file_info, snapshot.Pass()); |
820 return; | 818 return; |
821 } | 819 } |
822 // Recursively call TryPrepareForLocalSync with remaining_urls. | 820 // Recursively call TryPrepareForLocalSync with remaining_urls. |
823 TryPrepareForLocalSync(file_system_context, remaining_urls, callback); | 821 TryPrepareForLocalSync(file_system_context, callback, remaining_urls.Pass()); |
824 } | 822 } |
825 | 823 |
826 void LocalFileSyncContext::DidGetWritingStatusForSync( | 824 void LocalFileSyncContext::DidGetWritingStatusForSync( |
827 FileSystemContext* file_system_context, | 825 FileSystemContext* file_system_context, |
828 SyncStatusCode status, | 826 SyncStatusCode status, |
829 const FileSystemURL& url, | 827 const FileSystemURL& url, |
830 SyncMode sync_mode, | 828 SyncMode sync_mode, |
831 const LocalFileSyncInfoCallback& callback) { | 829 const LocalFileSyncInfoCallback& callback) { |
832 // This gets called on UI thread and relays the task on FILE thread. | 830 // This gets called on UI thread and relays the task on FILE thread. |
833 DCHECK(file_system_context); | 831 DCHECK(file_system_context); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
999 return; | 997 return; |
1000 } | 998 } |
1001 | 999 |
1002 FileSystemURL url_for_sync = CreateSyncableFileSystemURLForSync( | 1000 FileSystemURL url_for_sync = CreateSyncableFileSystemURLForSync( |
1003 file_system_context, dest_url); | 1001 file_system_context, dest_url); |
1004 file_system_context->operation_runner()->CopyInForeignFile( | 1002 file_system_context->operation_runner()->CopyInForeignFile( |
1005 local_path, url_for_sync, callback); | 1003 local_path, url_for_sync, callback); |
1006 } | 1004 } |
1007 | 1005 |
1008 } // namespace sync_file_system | 1006 } // namespace sync_file_system |
OLD | NEW |