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" |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 ui_task_runner_->PostTask(FROM_HERE, on_syncable_callback); | 167 ui_task_runner_->PostTask(FROM_HERE, on_syncable_callback); |
168 return; | 168 return; |
169 } | 169 } |
170 url_waiting_sync_on_io_ = url; | 170 url_waiting_sync_on_io_ = url; |
171 url_syncable_callback_ = on_syncable_callback; | 171 url_syncable_callback_ = on_syncable_callback; |
172 } | 172 } |
173 | 173 |
174 void LocalFileSyncContext::ApplyRemoteChange( | 174 void LocalFileSyncContext::ApplyRemoteChange( |
175 FileSystemContext* file_system_context, | 175 FileSystemContext* file_system_context, |
176 const FileChange& change, | 176 const FileChange& change, |
177 const FilePath& local_path, | 177 const base::FilePath& local_path, |
178 const FileSystemURL& url, | 178 const FileSystemURL& url, |
179 const SyncStatusCallback& callback) { | 179 const SyncStatusCallback& callback) { |
180 if (!io_task_runner_->RunsTasksOnCurrentThread()) { | 180 if (!io_task_runner_->RunsTasksOnCurrentThread()) { |
181 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 181 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
182 io_task_runner_->PostTask( | 182 io_task_runner_->PostTask( |
183 FROM_HERE, | 183 FROM_HERE, |
184 base::Bind(&LocalFileSyncContext::ApplyRemoteChange, this, | 184 base::Bind(&LocalFileSyncContext::ApplyRemoteChange, this, |
185 make_scoped_refptr(file_system_context), | 185 make_scoped_refptr(file_system_context), |
186 change, local_path, url, callback)); | 186 change, local_path, url, callback)); |
187 return; | 187 return; |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 base::Bind(&LocalFileSyncContext::DidGetWritingStatusForSync, | 557 base::Bind(&LocalFileSyncContext::DidGetWritingStatusForSync, |
558 this, make_scoped_refptr(file_system_context), | 558 this, make_scoped_refptr(file_system_context), |
559 status, url, callback)); | 559 status, url, callback)); |
560 return; | 560 return; |
561 } | 561 } |
562 | 562 |
563 DCHECK(file_system_context->change_tracker()); | 563 DCHECK(file_system_context->change_tracker()); |
564 FileChangeList changes; | 564 FileChangeList changes; |
565 file_system_context->change_tracker()->GetChangesForURL(url, &changes); | 565 file_system_context->change_tracker()->GetChangesForURL(url, &changes); |
566 | 566 |
567 FilePath platform_path; | 567 base::FilePath platform_path; |
568 base::PlatformFileInfo file_info; | 568 base::PlatformFileInfo file_info; |
569 FileSystemFileUtil* file_util = file_system_context->GetFileUtil(url.type()); | 569 FileSystemFileUtil* file_util = file_system_context->GetFileUtil(url.type()); |
570 DCHECK(file_util); | 570 DCHECK(file_util); |
571 base::PlatformFileError file_error = file_util->GetFileInfo( | 571 base::PlatformFileError file_error = file_util->GetFileInfo( |
572 make_scoped_ptr( | 572 make_scoped_ptr( |
573 new FileSystemOperationContext(file_system_context)).get(), | 573 new FileSystemOperationContext(file_system_context)).get(), |
574 url, | 574 url, |
575 &file_info, | 575 &file_info, |
576 &platform_path); | 576 &platform_path); |
577 if (status == SYNC_STATUS_OK && | 577 if (status == SYNC_STATUS_OK && |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 FROM_HERE, | 617 FROM_HERE, |
618 base::Bind(callback_on_ui, | 618 base::Bind(callback_on_ui, |
619 PlatformFileErrorToSyncStatusCode(file_error))); | 619 PlatformFileErrorToSyncStatusCode(file_error))); |
620 EnableWritingOnIOThread(url); | 620 EnableWritingOnIOThread(url); |
621 } | 621 } |
622 | 622 |
623 void LocalFileSyncContext::DidGetFileMetadata( | 623 void LocalFileSyncContext::DidGetFileMetadata( |
624 const SyncFileMetadataCallback& callback, | 624 const SyncFileMetadataCallback& callback, |
625 base::PlatformFileError file_error, | 625 base::PlatformFileError file_error, |
626 const base::PlatformFileInfo& file_info, | 626 const base::PlatformFileInfo& file_info, |
627 const FilePath& platform_path) { | 627 const base::FilePath& platform_path) { |
628 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 628 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
629 SyncFileMetadata metadata; | 629 SyncFileMetadata metadata; |
630 if (file_error == base::PLATFORM_FILE_OK) { | 630 if (file_error == base::PLATFORM_FILE_OK) { |
631 metadata.file_type = file_info.is_directory ? SYNC_FILE_TYPE_DIRECTORY | 631 metadata.file_type = file_info.is_directory ? SYNC_FILE_TYPE_DIRECTORY |
632 : SYNC_FILE_TYPE_FILE; | 632 : SYNC_FILE_TYPE_FILE; |
633 metadata.size = file_info.size; | 633 metadata.size = file_info.size; |
634 metadata.last_modified = file_info.last_modified; | 634 metadata.last_modified = file_info.last_modified; |
635 } | 635 } |
636 ui_task_runner_->PostTask( | 636 ui_task_runner_->PostTask( |
637 FROM_HERE, | 637 FROM_HERE, |
638 base::Bind(callback, | 638 base::Bind(callback, |
639 PlatformFileErrorToSyncStatusCode(file_error), | 639 PlatformFileErrorToSyncStatusCode(file_error), |
640 metadata)); | 640 metadata)); |
641 } | 641 } |
642 | 642 |
643 base::TimeDelta LocalFileSyncContext::NotifyChangesDuration() { | 643 base::TimeDelta LocalFileSyncContext::NotifyChangesDuration() { |
644 if (mock_notify_changes_duration_in_sec_ >= 0) | 644 if (mock_notify_changes_duration_in_sec_ >= 0) |
645 return base::TimeDelta::FromSeconds(mock_notify_changes_duration_in_sec_); | 645 return base::TimeDelta::FromSeconds(mock_notify_changes_duration_in_sec_); |
646 return base::TimeDelta::FromSeconds(kNotifyChangesDurationInSec); | 646 return base::TimeDelta::FromSeconds(kNotifyChangesDurationInSec); |
647 } | 647 } |
648 | 648 |
649 } // namespace fileapi | 649 } // namespace fileapi |
OLD | NEW |