OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/fileapi/syncable/local_file_sync_context.h" | 5 #include "webkit/fileapi/syncable/local_file_sync_context.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/platform_file.h" | 9 #include "base/platform_file.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/task_runner_util.h" | 12 #include "base/task_runner_util.h" |
13 #include "webkit/fileapi/file_system_context.h" | 13 #include "webkit/fileapi/file_system_context.h" |
14 #include "webkit/fileapi/file_system_file_util.h" | 14 #include "webkit/fileapi/file_system_file_util.h" |
15 #include "webkit/fileapi/file_system_operation_context.h" | 15 #include "webkit/fileapi/file_system_operation_context.h" |
16 #include "webkit/fileapi/file_system_task_runners.h" | 16 #include "webkit/fileapi/file_system_task_runners.h" |
17 #include "webkit/fileapi/local_file_system_operation.h" | 17 #include "webkit/fileapi/local_file_system_operation.h" |
18 #include "webkit/fileapi/syncable/file_change.h" | 18 #include "webkit/fileapi/syncable/file_change.h" |
19 #include "webkit/fileapi/syncable/local_file_change_tracker.h" | 19 #include "webkit/fileapi/syncable/local_file_change_tracker.h" |
20 #include "webkit/fileapi/syncable/local_origin_change_observer.h" | 20 #include "webkit/fileapi/syncable/local_origin_change_observer.h" |
21 #include "webkit/fileapi/syncable/sync_file_metadata.h" | 21 #include "webkit/fileapi/syncable/sync_file_metadata.h" |
22 #include "webkit/fileapi/syncable/syncable_file_operation_runner.h" | 22 #include "webkit/fileapi/syncable/syncable_file_operation_runner.h" |
23 #include "webkit/fileapi/syncable/syncable_file_system_util.h" | 23 #include "webkit/fileapi/syncable/syncable_file_system_util.h" |
24 | 24 |
| 25 using sync_file_system::FileChangeList; |
| 26 using sync_file_system::SyncFileType; |
| 27 |
25 namespace fileapi { | 28 namespace fileapi { |
26 | 29 |
27 namespace { | 30 namespace { |
28 const int kMaxConcurrentSyncableOperation = 3; | 31 const int kMaxConcurrentSyncableOperation = 3; |
29 const int kNotifyChangesDurationInSec = 1; | 32 const int kNotifyChangesDurationInSec = 1; |
30 const int kMaxURLsToFetchForLocalSync = 5; | 33 const int kMaxURLsToFetchForLocalSync = 5; |
31 } // namespace | 34 } // namespace |
32 | 35 |
33 LocalFileSyncContext::LocalFileSyncContext( | 36 LocalFileSyncContext::LocalFileSyncContext( |
34 base::SingleThreadTaskRunner* ui_task_runner, | 37 base::SingleThreadTaskRunner* ui_task_runner, |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 // No need to register; fire the callback now. | 169 // No need to register; fire the callback now. |
167 ui_task_runner_->PostTask(FROM_HERE, on_syncable_callback); | 170 ui_task_runner_->PostTask(FROM_HERE, on_syncable_callback); |
168 return; | 171 return; |
169 } | 172 } |
170 url_waiting_sync_on_io_ = url; | 173 url_waiting_sync_on_io_ = url; |
171 url_syncable_callback_ = on_syncable_callback; | 174 url_syncable_callback_ = on_syncable_callback; |
172 } | 175 } |
173 | 176 |
174 void LocalFileSyncContext::ApplyRemoteChange( | 177 void LocalFileSyncContext::ApplyRemoteChange( |
175 FileSystemContext* file_system_context, | 178 FileSystemContext* file_system_context, |
176 const FileChange& change, | 179 const sync_file_system::FileChange& change, |
177 const base::FilePath& local_path, | 180 const base::FilePath& local_path, |
178 const FileSystemURL& url, | 181 const FileSystemURL& url, |
179 const SyncStatusCallback& callback) { | 182 const SyncStatusCallback& callback) { |
180 if (!io_task_runner_->RunsTasksOnCurrentThread()) { | 183 if (!io_task_runner_->RunsTasksOnCurrentThread()) { |
181 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 184 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
182 io_task_runner_->PostTask( | 185 io_task_runner_->PostTask( |
183 FROM_HERE, | 186 FROM_HERE, |
184 base::Bind(&LocalFileSyncContext::ApplyRemoteChange, this, | 187 base::Bind(&LocalFileSyncContext::ApplyRemoteChange, this, |
185 make_scoped_refptr(file_system_context), | 188 make_scoped_refptr(file_system_context), |
186 change, local_path, url, callback)); | 189 change, local_path, url, callback)); |
187 return; | 190 return; |
188 } | 191 } |
189 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 192 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
190 DCHECK(!sync_status()->IsWritable(url)); | 193 DCHECK(!sync_status()->IsWritable(url)); |
191 DCHECK(!sync_status()->IsWriting(url)); | 194 DCHECK(!sync_status()->IsWriting(url)); |
192 LocalFileSystemOperation* operation = CreateFileSystemOperationForSync( | 195 LocalFileSystemOperation* operation = CreateFileSystemOperationForSync( |
193 file_system_context); | 196 file_system_context); |
194 DCHECK(operation); | 197 DCHECK(operation); |
195 FileSystemOperation::StatusCallback operation_callback = | 198 FileSystemOperation::StatusCallback operation_callback = |
196 base::Bind(&LocalFileSyncContext::DidApplyRemoteChange, | 199 base::Bind(&LocalFileSyncContext::DidApplyRemoteChange, |
197 this, url, callback); | 200 this, url, callback); |
198 switch (change.change()) { | 201 switch (change.change()) { |
199 case FileChange::FILE_CHANGE_ADD_OR_UPDATE: | 202 case sync_file_system::FileChange::FILE_CHANGE_ADD_OR_UPDATE: |
200 switch (change.file_type()) { | 203 switch (change.file_type()) { |
201 case SYNC_FILE_TYPE_FILE: | 204 case sync_file_system::SYNC_FILE_TYPE_FILE: |
202 DCHECK(!local_path.empty()); | 205 DCHECK(!local_path.empty()); |
203 operation->CopyInForeignFile(local_path, url, operation_callback); | 206 operation->CopyInForeignFile(local_path, url, operation_callback); |
204 break; | 207 break; |
205 case SYNC_FILE_TYPE_DIRECTORY: | 208 case sync_file_system::SYNC_FILE_TYPE_DIRECTORY: |
206 operation->CreateDirectory( | 209 operation->CreateDirectory( |
207 url, false /* exclusive */, true /* recursive */, | 210 url, false /* exclusive */, true /* recursive */, |
208 operation_callback); | 211 operation_callback); |
209 break; | 212 break; |
210 case SYNC_FILE_TYPE_UNKNOWN: | 213 case sync_file_system::SYNC_FILE_TYPE_UNKNOWN: |
211 NOTREACHED() << "File type unknown for ADD_OR_UPDATE change"; | 214 NOTREACHED() << "File type unknown for ADD_OR_UPDATE change"; |
212 } | 215 } |
213 break; | 216 break; |
214 case FileChange::FILE_CHANGE_DELETE: | 217 case sync_file_system::FileChange::FILE_CHANGE_DELETE: |
215 operation->Remove(url, true /* recursive */, operation_callback); | 218 operation->Remove(url, true /* recursive */, operation_callback); |
216 break; | 219 break; |
217 } | 220 } |
218 } | 221 } |
219 | 222 |
220 void LocalFileSyncContext::RecordFakeLocalChange( | 223 void LocalFileSyncContext::RecordFakeLocalChange( |
221 FileSystemContext* file_system_context, | 224 FileSystemContext* file_system_context, |
222 const fileapi::FileSystemURL& url, | 225 const fileapi::FileSystemURL& url, |
223 const fileapi::FileChange& change, | 226 const sync_file_system::FileChange& change, |
224 const fileapi::SyncStatusCallback& callback) { | 227 const fileapi::SyncStatusCallback& callback) { |
225 // This is called on UI thread and to be relayed to FILE thread. | 228 // This is called on UI thread and to be relayed to FILE thread. |
226 DCHECK(file_system_context); | 229 DCHECK(file_system_context); |
227 if (!file_system_context->task_runners()->file_task_runner()-> | 230 if (!file_system_context->task_runners()->file_task_runner()-> |
228 RunsTasksOnCurrentThread()) { | 231 RunsTasksOnCurrentThread()) { |
229 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 232 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
230 file_system_context->task_runners()->file_task_runner()->PostTask( | 233 file_system_context->task_runners()->file_task_runner()->PostTask( |
231 FROM_HERE, | 234 FROM_HERE, |
232 base::Bind(&LocalFileSyncContext::RecordFakeLocalChange, | 235 base::Bind(&LocalFileSyncContext::RecordFakeLocalChange, |
233 this, make_scoped_refptr(file_system_context), | 236 this, make_scoped_refptr(file_system_context), |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 url, | 580 url, |
578 &file_info, | 581 &file_info, |
579 &platform_path); | 582 &platform_path); |
580 if (status == SYNC_STATUS_OK && | 583 if (status == SYNC_STATUS_OK && |
581 file_error != base::PLATFORM_FILE_OK && | 584 file_error != base::PLATFORM_FILE_OK && |
582 file_error != base::PLATFORM_FILE_ERROR_NOT_FOUND) | 585 file_error != base::PLATFORM_FILE_ERROR_NOT_FOUND) |
583 status = PlatformFileErrorToSyncStatusCode(file_error); | 586 status = PlatformFileErrorToSyncStatusCode(file_error); |
584 | 587 |
585 DCHECK(!file_info.is_symbolic_link); | 588 DCHECK(!file_info.is_symbolic_link); |
586 | 589 |
587 SyncFileType file_type = SYNC_FILE_TYPE_FILE; | 590 SyncFileType file_type = sync_file_system::SYNC_FILE_TYPE_FILE; |
588 if (file_error == base::PLATFORM_FILE_ERROR_NOT_FOUND) | 591 if (file_error == base::PLATFORM_FILE_ERROR_NOT_FOUND) |
589 file_type = SYNC_FILE_TYPE_UNKNOWN; | 592 file_type = sync_file_system::SYNC_FILE_TYPE_UNKNOWN; |
590 else if (file_info.is_directory) | 593 else if (file_info.is_directory) |
591 file_type = SYNC_FILE_TYPE_DIRECTORY; | 594 file_type = sync_file_system::SYNC_FILE_TYPE_DIRECTORY; |
592 | 595 |
593 LocalFileSyncInfo sync_file_info; | 596 LocalFileSyncInfo sync_file_info; |
594 sync_file_info.url = url; | 597 sync_file_info.url = url; |
595 sync_file_info.local_file_path = platform_path; | 598 sync_file_info.local_file_path = platform_path; |
596 sync_file_info.metadata.file_type = file_type; | 599 sync_file_info.metadata.file_type = file_type; |
597 sync_file_info.metadata.size = file_info.size; | 600 sync_file_info.metadata.size = file_info.size; |
598 sync_file_info.metadata.last_modified = file_info.last_modified; | 601 sync_file_info.metadata.last_modified = file_info.last_modified; |
599 sync_file_info.changes = changes; | 602 sync_file_info.changes = changes; |
600 | 603 |
601 ui_task_runner_->PostTask(FROM_HERE, | 604 ui_task_runner_->PostTask(FROM_HERE, |
(...skipping 22 matching lines...) Expand all Loading... |
624 } | 627 } |
625 | 628 |
626 void LocalFileSyncContext::DidGetFileMetadata( | 629 void LocalFileSyncContext::DidGetFileMetadata( |
627 const SyncFileMetadataCallback& callback, | 630 const SyncFileMetadataCallback& callback, |
628 base::PlatformFileError file_error, | 631 base::PlatformFileError file_error, |
629 const base::PlatformFileInfo& file_info, | 632 const base::PlatformFileInfo& file_info, |
630 const base::FilePath& platform_path) { | 633 const base::FilePath& platform_path) { |
631 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 634 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
632 SyncFileMetadata metadata; | 635 SyncFileMetadata metadata; |
633 if (file_error == base::PLATFORM_FILE_OK) { | 636 if (file_error == base::PLATFORM_FILE_OK) { |
634 metadata.file_type = file_info.is_directory ? SYNC_FILE_TYPE_DIRECTORY | 637 metadata.file_type = file_info.is_directory ? |
635 : SYNC_FILE_TYPE_FILE; | 638 sync_file_system::SYNC_FILE_TYPE_DIRECTORY : |
| 639 sync_file_system::SYNC_FILE_TYPE_FILE; |
636 metadata.size = file_info.size; | 640 metadata.size = file_info.size; |
637 metadata.last_modified = file_info.last_modified; | 641 metadata.last_modified = file_info.last_modified; |
638 } | 642 } |
639 ui_task_runner_->PostTask( | 643 ui_task_runner_->PostTask( |
640 FROM_HERE, | 644 FROM_HERE, |
641 base::Bind(callback, | 645 base::Bind(callback, |
642 PlatformFileErrorToSyncStatusCode(file_error), | 646 PlatformFileErrorToSyncStatusCode(file_error), |
643 metadata)); | 647 metadata)); |
644 } | 648 } |
645 | 649 |
646 base::TimeDelta LocalFileSyncContext::NotifyChangesDuration() { | 650 base::TimeDelta LocalFileSyncContext::NotifyChangesDuration() { |
647 if (mock_notify_changes_duration_in_sec_ >= 0) | 651 if (mock_notify_changes_duration_in_sec_ >= 0) |
648 return base::TimeDelta::FromSeconds(mock_notify_changes_duration_in_sec_); | 652 return base::TimeDelta::FromSeconds(mock_notify_changes_duration_in_sec_); |
649 return base::TimeDelta::FromSeconds(kNotifyChangesDurationInSec); | 653 return base::TimeDelta::FromSeconds(kNotifyChangesDurationInSec); |
650 } | 654 } |
651 | 655 |
652 } // namespace fileapi | 656 } // namespace fileapi |
OLD | NEW |