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); |
777 } | 776 } |
peria
2014/07/14 10:08:37
no return
tzik
2014/07/14 10:23:36
Done.
It's surprising that this code has passed th
| |
778 | 777 |
779 void LocalFileSyncContext::TryPrepareForLocalSync( | 778 void LocalFileSyncContext::TryPrepareForLocalSync( |
780 FileSystemContext* file_system_context, | 779 FileSystemContext* file_system_context, |
781 std::deque<FileSystemURL>* urls, | 780 const LocalFileSyncInfoCallback& callback, |
782 const LocalFileSyncInfoCallback& callback) { | 781 scoped_ptr<FileSystemURLQueue> urls) { |
783 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 782 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
784 DCHECK(urls); | 783 DCHECK(urls); |
785 | 784 |
786 if (shutdown_on_ui_) { | 785 if (shutdown_on_ui_) { |
787 callback.Run(SYNC_STATUS_ABORT, LocalFileSyncInfo(), | 786 callback.Run(SYNC_STATUS_ABORT, LocalFileSyncInfo(), |
788 webkit_blob::ScopedFile()); | 787 webkit_blob::ScopedFile()); |
789 return; | 788 return; |
790 } | 789 } |
791 | 790 |
792 if (urls->empty()) { | 791 if (urls->empty()) { |
793 callback.Run(SYNC_STATUS_NO_CHANGE_TO_SYNC, LocalFileSyncInfo(), | 792 callback.Run(SYNC_STATUS_NO_CHANGE_TO_SYNC, LocalFileSyncInfo(), |
794 webkit_blob::ScopedFile()); | 793 webkit_blob::ScopedFile()); |
795 return; | 794 return; |
796 } | 795 } |
797 | 796 |
798 const FileSystemURL url = urls->front(); | 797 const FileSystemURL url = urls->front(); |
799 urls->pop_front(); | 798 urls->pop_front(); |
800 std::deque<FileSystemURL>* remaining = new std::deque<FileSystemURL>; | |
801 remaining->swap(*urls); | |
802 | 799 |
803 PrepareForSync( | 800 PrepareForSync( |
804 file_system_context, url, SYNC_SNAPSHOT, | 801 file_system_context, url, SYNC_SNAPSHOT, |
805 base::Bind(&LocalFileSyncContext::DidTryPrepareForLocalSync, | 802 base::Bind(&LocalFileSyncContext::DidTryPrepareForLocalSync, |
806 this, make_scoped_refptr(file_system_context), | 803 this, make_scoped_refptr(file_system_context), |
807 base::Owned(remaining), callback)); | 804 base::Passed(&urls), callback)); |
808 } | 805 } |
809 | 806 |
810 void LocalFileSyncContext::DidTryPrepareForLocalSync( | 807 void LocalFileSyncContext::DidTryPrepareForLocalSync( |
811 FileSystemContext* file_system_context, | 808 FileSystemContext* file_system_context, |
812 std::deque<FileSystemURL>* remaining_urls, | 809 scoped_ptr<FileSystemURLQueue> remaining_urls, |
813 const LocalFileSyncInfoCallback& callback, | 810 const LocalFileSyncInfoCallback& callback, |
814 SyncStatusCode status, | 811 SyncStatusCode status, |
815 const LocalFileSyncInfo& sync_file_info, | 812 const LocalFileSyncInfo& sync_file_info, |
816 webkit_blob::ScopedFile snapshot) { | 813 webkit_blob::ScopedFile snapshot) { |
817 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 814 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
818 if (status != SYNC_STATUS_FILE_BUSY) { | 815 if (status != SYNC_STATUS_FILE_BUSY) { |
819 callback.Run(status, sync_file_info, snapshot.Pass()); | 816 callback.Run(status, sync_file_info, snapshot.Pass()); |
820 return; | 817 return; |
821 } | 818 } |
822 // Recursively call TryPrepareForLocalSync with remaining_urls. | 819 // Recursively call TryPrepareForLocalSync with remaining_urls. |
823 TryPrepareForLocalSync(file_system_context, remaining_urls, callback); | 820 TryPrepareForLocalSync(file_system_context, callback, remaining_urls.Pass()); |
824 } | 821 } |
825 | 822 |
826 void LocalFileSyncContext::DidGetWritingStatusForSync( | 823 void LocalFileSyncContext::DidGetWritingStatusForSync( |
827 FileSystemContext* file_system_context, | 824 FileSystemContext* file_system_context, |
828 SyncStatusCode status, | 825 SyncStatusCode status, |
829 const FileSystemURL& url, | 826 const FileSystemURL& url, |
830 SyncMode sync_mode, | 827 SyncMode sync_mode, |
831 const LocalFileSyncInfoCallback& callback) { | 828 const LocalFileSyncInfoCallback& callback) { |
832 // This gets called on UI thread and relays the task on FILE thread. | 829 // This gets called on UI thread and relays the task on FILE thread. |
833 DCHECK(file_system_context); | 830 DCHECK(file_system_context); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
999 return; | 996 return; |
1000 } | 997 } |
1001 | 998 |
1002 FileSystemURL url_for_sync = CreateSyncableFileSystemURLForSync( | 999 FileSystemURL url_for_sync = CreateSyncableFileSystemURLForSync( |
1003 file_system_context, dest_url); | 1000 file_system_context, dest_url); |
1004 file_system_context->operation_runner()->CopyInForeignFile( | 1001 file_system_context->operation_runner()->CopyInForeignFile( |
1005 local_path, url_for_sync, callback); | 1002 local_path, url_for_sync, callback); |
1006 } | 1003 } |
1007 | 1004 |
1008 } // namespace sync_file_system | 1005 } // namespace sync_file_system |
OLD | NEW |