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/local_file_system_operation.h" | 5 #include "webkit/fileapi/local_file_system_operation.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 18 matching lines...) Expand all Loading... | |
29 namespace fileapi { | 29 namespace fileapi { |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 bool IsMediaFileSystemType(FileSystemType type) { | 33 bool IsMediaFileSystemType(FileSystemType type) { |
34 return type == kFileSystemTypeNativeMedia || | 34 return type == kFileSystemTypeNativeMedia || |
35 type == kFileSystemTypeDeviceMedia; | 35 type == kFileSystemTypeDeviceMedia; |
36 } | 36 } |
37 | 37 |
38 bool IsCrossOperationAllowed(FileSystemType src_type, | 38 bool IsCrossOperationAllowed(FileSystemType src_type, |
39 FileSystemType dest_type) { | 39 FileSystemType dest_type) { |
40 // If two types are supposed to run on different task runners we should not | 40 // If two types are supposed to run on different task runners we should not |
41 // allow cross FileUtil operations at this layer. | 41 // allow cross FileUtil operations at this layer. |
42 return IsMediaFileSystemType(src_type) == IsMediaFileSystemType(dest_type); | 42 return IsMediaFileSystemType(src_type) == IsMediaFileSystemType(dest_type); |
43 } | 43 } |
44 | 44 |
45 } // namespace | 45 } // namespace |
46 | 46 |
47 class LocalFileSystemOperation::ScopedUpdateNotifier { | 47 class LocalFileSystemOperation::ScopedUpdateNotifier { |
48 public: | 48 public: |
49 ScopedUpdateNotifier(FileSystemOperationContext* operation_context, | 49 ScopedUpdateNotifier(FileSystemOperationContext* operation_context, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 url, | 109 url, |
110 base::Bind(&LocalFileSystemOperation::DoCreateDirectory, | 110 base::Bind(&LocalFileSystemOperation::DoCreateDirectory, |
111 base::Unretained(this), url, callback, exclusive, recursive), | 111 base::Unretained(this), url, callback, exclusive, recursive), |
112 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); | 112 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); |
113 } | 113 } |
114 | 114 |
115 void LocalFileSystemOperation::Copy(const FileSystemURL& src_url, | 115 void LocalFileSystemOperation::Copy(const FileSystemURL& src_url, |
116 const FileSystemURL& dest_url, | 116 const FileSystemURL& dest_url, |
117 const StatusCallback& callback) { | 117 const StatusCallback& callback) { |
118 DCHECK(SetPendingOperationType(kOperationCopy)); | 118 DCHECK(SetPendingOperationType(kOperationCopy)); |
119 is_cross_operation_ = (src_url.type() != dest_url.type()); | |
119 | 120 |
120 base::PlatformFileError result = SetUp(src_url, &src_util_, SETUP_FOR_READ); | 121 base::PlatformFileError result = SetUp(src_url, &src_util_, SETUP_FOR_READ); |
121 if (result == base::PLATFORM_FILE_OK) | 122 if (result == base::PLATFORM_FILE_OK) |
122 result = SetUp(dest_url, &dest_util_, SETUP_FOR_CREATE); | 123 result = SetUp(dest_url, &dest_util_, SETUP_FOR_CREATE); |
123 if (result == base::PLATFORM_FILE_OK) { | 124 if (result == base::PLATFORM_FILE_OK) { |
124 if (!IsCrossOperationAllowed(src_url.type(), dest_url.type())) | 125 if (!IsCrossOperationAllowed(src_url.type(), dest_url.type())) |
125 result = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 126 result = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
126 } | 127 } |
127 if (result != base::PLATFORM_FILE_OK) { | 128 if (result != base::PLATFORM_FILE_OK) { |
128 callback.Run(result); | 129 callback.Run(result); |
129 delete this; | 130 delete this; |
130 return; | 131 return; |
131 } | 132 } |
132 | 133 |
133 GetUsageAndQuotaThenRunTask( | 134 GetUsageAndQuotaThenRunTask( |
134 dest_url, | 135 dest_url, |
135 base::Bind(&LocalFileSystemOperation::DoCopy, | 136 base::Bind(&LocalFileSystemOperation::DoCopy, |
136 base::Unretained(this), src_url, dest_url, callback), | 137 base::Unretained(this), src_url, dest_url, callback), |
137 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); | 138 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); |
138 } | 139 } |
139 | 140 |
140 void LocalFileSystemOperation::Move(const FileSystemURL& src_url, | 141 void LocalFileSystemOperation::Move(const FileSystemURL& src_url, |
141 const FileSystemURL& dest_url, | 142 const FileSystemURL& dest_url, |
142 const StatusCallback& callback) { | 143 const StatusCallback& callback) { |
143 DCHECK(SetPendingOperationType(kOperationMove)); | 144 DCHECK(SetPendingOperationType(kOperationMove)); |
145 is_cross_operation_ = (src_url.type() != dest_url.type()); | |
146 | |
144 scoped_ptr<LocalFileSystemOperation> deleter(this); | 147 scoped_ptr<LocalFileSystemOperation> deleter(this); |
145 | 148 |
149 // Temporarily disables cross-filesystem move. | |
150 // TODO(kinuko,tzik,kinaba): This special handling must be removed once | |
151 // we support saner cross-filesystem operation. | |
152 // (See http://crbug.com/130055) | |
tzik
2012/11/30 07:00:44
Could you update the issue?
| |
153 if (is_cross_operation_) { | |
154 callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); | |
155 return; | |
156 } | |
157 | |
146 base::PlatformFileError result = SetUp(src_url, &src_util_, SETUP_FOR_WRITE); | 158 base::PlatformFileError result = SetUp(src_url, &src_util_, SETUP_FOR_WRITE); |
147 if (result == base::PLATFORM_FILE_OK) | 159 if (result == base::PLATFORM_FILE_OK) |
148 result = SetUp(dest_url, &dest_util_, SETUP_FOR_CREATE); | 160 result = SetUp(dest_url, &dest_util_, SETUP_FOR_CREATE); |
149 if (result == base::PLATFORM_FILE_OK) { | 161 if (result == base::PLATFORM_FILE_OK) { |
150 if (!IsCrossOperationAllowed(src_url.type(), dest_url.type())) | 162 if (!IsCrossOperationAllowed(src_url.type(), dest_url.type())) |
151 result = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 163 result = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
152 } | 164 } |
153 if (result != base::PLATFORM_FILE_OK) { | 165 if (result != base::PLATFORM_FILE_OK) { |
154 callback.Run(result); | 166 callback.Run(result); |
155 return; | 167 return; |
156 } | 168 } |
157 | 169 |
158 // Temporarily disables cross-filesystem move for sandbox filesystems. | |
159 // TODO(kinuko,tzik,kinaba): This special handling must be removed once | |
160 // we support saner cross-filesystem operation. | |
161 // (See http://crbug.com/130055) | |
162 if (src_url.type() != dest_url.type() && | |
163 (src_url.type() == kFileSystemTypeTemporary || | |
164 src_url.type() == kFileSystemTypePersistent)) { | |
165 callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); | |
166 return; | |
167 } | |
168 | |
169 GetUsageAndQuotaThenRunTask( | 170 GetUsageAndQuotaThenRunTask( |
170 dest_url, | 171 dest_url, |
171 base::Bind(&LocalFileSystemOperation::DoMove, | 172 base::Bind(&LocalFileSystemOperation::DoMove, |
172 base::Unretained(deleter.release()), | 173 base::Unretained(deleter.release()), |
173 src_url, dest_url, callback), | 174 src_url, dest_url, callback), |
174 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); | 175 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); |
175 } | 176 } |
176 | 177 |
177 void LocalFileSystemOperation::DirectoryExists(const FileSystemURL& url, | 178 void LocalFileSystemOperation::DirectoryExists(const FileSystemURL& url, |
178 const StatusCallback& callback) { | 179 const StatusCallback& callback) { |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
448 callback), | 449 callback), |
449 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); | 450 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); |
450 } | 451 } |
451 | 452 |
452 LocalFileSystemOperation::LocalFileSystemOperation( | 453 LocalFileSystemOperation::LocalFileSystemOperation( |
453 FileSystemContext* file_system_context, | 454 FileSystemContext* file_system_context, |
454 scoped_ptr<FileSystemOperationContext> operation_context) | 455 scoped_ptr<FileSystemOperationContext> operation_context) |
455 : operation_context_(operation_context.Pass()), | 456 : operation_context_(operation_context.Pass()), |
456 src_util_(NULL), | 457 src_util_(NULL), |
457 dest_util_(NULL), | 458 dest_util_(NULL), |
459 is_cross_operation_(false), | |
458 peer_handle_(base::kNullProcessHandle), | 460 peer_handle_(base::kNullProcessHandle), |
459 pending_operation_(kOperationNone), | 461 pending_operation_(kOperationNone), |
460 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 462 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
461 DCHECK(operation_context_.get()); | 463 DCHECK(operation_context_.get()); |
462 } | 464 } |
463 | 465 |
464 void LocalFileSystemOperation::GetUsageAndQuotaThenRunTask( | 466 void LocalFileSystemOperation::GetUsageAndQuotaThenRunTask( |
465 const FileSystemURL& url, | 467 const FileSystemURL& url, |
466 const base::Closure& task, | 468 const base::Closure& task, |
467 const base::Closure& error_callback) { | 469 const base::Closure& error_callback) { |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
762 url.type())->IsAccessAllowed(url)) | 764 url.type())->IsAccessAllowed(url)) |
763 return base::PLATFORM_FILE_ERROR_SECURITY; | 765 return base::PLATFORM_FILE_ERROR_SECURITY; |
764 | 766 |
765 DCHECK(file_util); | 767 DCHECK(file_util); |
766 if (!*file_util) | 768 if (!*file_util) |
767 *file_util = file_system_context()->GetFileUtil(url.type()); | 769 *file_util = file_system_context()->GetFileUtil(url.type()); |
768 if (!*file_util) | 770 if (!*file_util) |
769 return base::PLATFORM_FILE_ERROR_SECURITY; | 771 return base::PLATFORM_FILE_ERROR_SECURITY; |
770 | 772 |
771 if (mode == SETUP_FOR_READ) { | 773 if (mode == SETUP_FOR_READ) { |
772 operation_context_->access_observers()->Notify( | 774 // TODO(kinuko): This doesn't work well for cross-filesystem operation |
773 &FileAccessObserver::OnAccess, MakeTuple(url)); | 775 // in the current architecture since the operation context (thus the |
776 // observers) is configured for the destination URL while this method | |
777 // could be called for both src and dest URL. | |
778 if (!is_cross_operation_) { | |
779 operation_context_->access_observers()->Notify( | |
780 &FileAccessObserver::OnAccess, MakeTuple(url)); | |
781 } | |
774 return base::PLATFORM_FILE_OK; | 782 return base::PLATFORM_FILE_OK; |
775 } | 783 } |
776 | 784 |
777 DCHECK(mode == SETUP_FOR_WRITE || mode == SETUP_FOR_CREATE); | 785 DCHECK(mode == SETUP_FOR_WRITE || mode == SETUP_FOR_CREATE); |
778 | 786 |
779 scoped_update_notifiers_.push_back(new ScopedUpdateNotifier( | 787 scoped_update_notifiers_.push_back(new ScopedUpdateNotifier( |
780 operation_context_.get(), url)); | 788 operation_context_.get(), url)); |
781 | 789 |
782 // Any write access is disallowed on the root path. | 790 // Any write access is disallowed on the root path. |
783 if (url.path().value().length() == 0 || | 791 if (url.path().value().length() == 0 || |
(...skipping 13 matching lines...) Expand all Loading... | |
797 } | 805 } |
798 | 806 |
799 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) { | 807 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) { |
800 if (pending_operation_ != kOperationNone) | 808 if (pending_operation_ != kOperationNone) |
801 return false; | 809 return false; |
802 pending_operation_ = type; | 810 pending_operation_ = type; |
803 return true; | 811 return true; |
804 } | 812 } |
805 | 813 |
806 } // namespace fileapi | 814 } // namespace fileapi |
OLD | NEW |