| 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" |
| 11 #include "net/base/escape.h" | 11 #include "net/base/escape.h" |
| 12 #include "net/url_request/url_request_context.h" | 12 #include "net/url_request/url_request_context.h" |
| 13 #include "webkit/blob/shareable_file_reference.h" | 13 #include "webkit/blob/shareable_file_reference.h" |
| 14 #include "webkit/fileapi/cross_operation_delegate.h" |
| 14 #include "webkit/fileapi/file_observers.h" | 15 #include "webkit/fileapi/file_observers.h" |
| 15 #include "webkit/fileapi/file_system_context.h" | 16 #include "webkit/fileapi/file_system_context.h" |
| 16 #include "webkit/fileapi/file_system_file_util_proxy.h" | 17 #include "webkit/fileapi/file_system_file_util_proxy.h" |
| 17 #include "webkit/fileapi/file_system_mount_point_provider.h" | 18 #include "webkit/fileapi/file_system_mount_point_provider.h" |
| 18 #include "webkit/fileapi/file_system_task_runners.h" | 19 #include "webkit/fileapi/file_system_task_runners.h" |
| 19 #include "webkit/fileapi/file_system_types.h" | 20 #include "webkit/fileapi/file_system_types.h" |
| 20 #include "webkit/fileapi/file_system_url.h" | 21 #include "webkit/fileapi/file_system_url.h" |
| 21 #include "webkit/fileapi/file_system_util.h" | 22 #include "webkit/fileapi/file_system_util.h" |
| 22 #include "webkit/fileapi/file_writer_delegate.h" | 23 #include "webkit/fileapi/file_writer_delegate.h" |
| 23 #include "webkit/fileapi/remove_operation_delegate.h" | 24 #include "webkit/fileapi/remove_operation_delegate.h" |
| 24 #include "webkit/fileapi/sandbox_file_stream_writer.h" | 25 #include "webkit/fileapi/sandbox_file_stream_writer.h" |
| 25 #include "webkit/quota/quota_manager.h" | 26 #include "webkit/quota/quota_manager.h" |
| 26 #include "webkit/quota/quota_types.h" | 27 #include "webkit/quota/quota_types.h" |
| 27 | 28 |
| 28 using webkit_blob::ShareableFileReference; | 29 using webkit_blob::ShareableFileReference; |
| 29 | 30 |
| 30 namespace fileapi { | 31 namespace fileapi { |
| 31 | 32 |
| 32 namespace { | 33 namespace { |
| 33 | 34 |
| 34 bool IsMediaFileSystemType(FileSystemType type) { | 35 bool IsMediaFileSystemType(FileSystemType type) { |
| 35 return type == kFileSystemTypeNativeMedia || | 36 return type == kFileSystemTypeNativeMedia || |
| 36 type == kFileSystemTypeDeviceMedia; | 37 type == kFileSystemTypeDeviceMedia; |
| 37 } | 38 } |
| 38 | 39 |
| 39 bool IsCrossOperationAllowed(FileSystemType src_type, | |
| 40 FileSystemType dest_type) { | |
| 41 // If two types are supposed to run on different task runners we should not | |
| 42 // allow cross FileUtil operations at this layer. | |
| 43 return IsMediaFileSystemType(src_type) == IsMediaFileSystemType(dest_type); | |
| 44 } | |
| 45 | |
| 46 } // namespace | 40 } // namespace |
| 47 | 41 |
| 48 // LocalFileSystemOperation::ScopedUpdateNotifier ----------------------------- | 42 // LocalFileSystemOperation::ScopedUpdateNotifier ----------------------------- |
| 49 | 43 |
| 50 class LocalFileSystemOperation::ScopedUpdateNotifier { | 44 class LocalFileSystemOperation::ScopedUpdateNotifier { |
| 51 public: | 45 public: |
| 52 ScopedUpdateNotifier(FileSystemOperationContext* operation_context, | 46 ScopedUpdateNotifier(FileSystemOperationContext* operation_context, |
| 53 const FileSystemURL& url); | 47 const FileSystemURL& url); |
| 54 ~ScopedUpdateNotifier(); | 48 ~ScopedUpdateNotifier(); |
| 55 | 49 |
| 56 private: | 50 private: |
| 57 // Not owned; owned by the owner of this instance | 51 UpdateObserverList update_observers_; |
| 58 // (i.e. LocalFileSystemOperation). | |
| 59 FileSystemOperationContext* operation_context_; | |
| 60 FileSystemURL url_; | 52 FileSystemURL url_; |
| 61 DISALLOW_COPY_AND_ASSIGN(ScopedUpdateNotifier); | 53 DISALLOW_COPY_AND_ASSIGN(ScopedUpdateNotifier); |
| 62 }; | 54 }; |
| 63 | 55 |
| 64 LocalFileSystemOperation::ScopedUpdateNotifier::ScopedUpdateNotifier( | 56 LocalFileSystemOperation::ScopedUpdateNotifier::ScopedUpdateNotifier( |
| 65 FileSystemOperationContext* operation_context, | 57 FileSystemOperationContext* operation_context, |
| 66 const FileSystemURL& url) | 58 const FileSystemURL& url) |
| 67 : operation_context_(operation_context), url_(url) { | 59 : update_observers_(*operation_context->update_observers()), url_(url) { |
| 68 operation_context_->update_observers()->Notify( | 60 update_observers_.Notify(&FileUpdateObserver::OnStartUpdate, MakeTuple(url_)); |
| 69 &FileUpdateObserver::OnStartUpdate, MakeTuple(url_)); | |
| 70 } | 61 } |
| 71 | 62 |
| 72 LocalFileSystemOperation::ScopedUpdateNotifier::~ScopedUpdateNotifier() { | 63 LocalFileSystemOperation::ScopedUpdateNotifier::~ScopedUpdateNotifier() { |
| 73 operation_context_->update_observers()->Notify( | 64 update_observers_.Notify(&FileUpdateObserver::OnEndUpdate, MakeTuple(url_)); |
| 74 &FileUpdateObserver::OnEndUpdate, MakeTuple(url_)); | |
| 75 } | 65 } |
| 76 | 66 |
| 77 // LocalFileSystemOperation --------------------------------------------------- | 67 // LocalFileSystemOperation --------------------------------------------------- |
| 78 | 68 |
| 79 LocalFileSystemOperation::~LocalFileSystemOperation() { | 69 LocalFileSystemOperation::~LocalFileSystemOperation() { |
| 80 if (!termination_callback_.is_null()) | 70 if (!termination_callback_.is_null()) |
| 81 termination_callback_.Run(); | 71 termination_callback_.Run(); |
| 82 } | 72 } |
| 83 | 73 |
| 84 void LocalFileSystemOperation::CreateFile(const FileSystemURL& url, | 74 void LocalFileSystemOperation::CreateFile(const FileSystemURL& url, |
| 85 bool exclusive, | 75 bool exclusive, |
| 86 const StatusCallback& callback) { | 76 const StatusCallback& callback) { |
| 87 DCHECK(SetPendingOperationType(kOperationCreateFile)); | 77 DCHECK(SetPendingOperationType(kOperationCreateFile)); |
| 88 | 78 |
| 89 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_CREATE); | 79 base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_CREATE); |
| 90 if (result != base::PLATFORM_FILE_OK) { | 80 if (result != base::PLATFORM_FILE_OK) { |
| 91 callback.Run(result); | 81 callback.Run(result); |
| 92 delete this; | 82 delete this; |
| 93 return; | 83 return; |
| 94 } | 84 } |
| 95 | 85 |
| 96 GetUsageAndQuotaThenRunTask( | 86 GetUsageAndQuotaThenRunTask( |
| 97 url, | 87 url, |
| 98 base::Bind(&LocalFileSystemOperation::DoCreateFile, | 88 base::Bind(&LocalFileSystemOperation::DoCreateFile, |
| 99 base::Unretained(this), url, callback, exclusive), | 89 base::Unretained(this), url, callback, exclusive), |
| 100 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); | 90 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); |
| 101 } | 91 } |
| 102 | 92 |
| 103 void LocalFileSystemOperation::CreateDirectory(const FileSystemURL& url, | 93 void LocalFileSystemOperation::CreateDirectory(const FileSystemURL& url, |
| 104 bool exclusive, | 94 bool exclusive, |
| 105 bool recursive, | 95 bool recursive, |
| 106 const StatusCallback& callback) { | 96 const StatusCallback& callback) { |
| 107 DCHECK(SetPendingOperationType(kOperationCreateDirectory)); | 97 DCHECK(SetPendingOperationType(kOperationCreateDirectory)); |
| 108 | 98 |
| 109 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_CREATE); | 99 base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_CREATE); |
| 110 if (result != base::PLATFORM_FILE_OK) { | 100 if (result != base::PLATFORM_FILE_OK) { |
| 111 callback.Run(result); | 101 callback.Run(result); |
| 112 delete this; | 102 delete this; |
| 113 return; | 103 return; |
| 114 } | 104 } |
| 115 GetUsageAndQuotaThenRunTask( | 105 GetUsageAndQuotaThenRunTask( |
| 116 url, | 106 url, |
| 117 base::Bind(&LocalFileSystemOperation::DoCreateDirectory, | 107 base::Bind(&LocalFileSystemOperation::DoCreateDirectory, |
| 118 base::Unretained(this), url, callback, exclusive, recursive), | 108 base::Unretained(this), url, callback, exclusive, recursive), |
| 119 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); | 109 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); |
| 120 } | 110 } |
| 121 | 111 |
| 122 void LocalFileSystemOperation::Copy(const FileSystemURL& src_url, | 112 void LocalFileSystemOperation::Copy(const FileSystemURL& src_url, |
| 123 const FileSystemURL& dest_url, | 113 const FileSystemURL& dest_url, |
| 124 const StatusCallback& callback) { | 114 const StatusCallback& callback) { |
| 125 DCHECK(SetPendingOperationType(kOperationCopy)); | 115 DCHECK(SetPendingOperationType(kOperationCopy)); |
| 126 is_cross_operation_ = (src_url.type() != dest_url.type()); | |
| 127 | 116 |
| 128 base::PlatformFileError result = SetUp(src_url, &src_util_, SETUP_FOR_READ); | 117 base::PlatformFileError result = SetUp( |
| 129 if (result == base::PLATFORM_FILE_OK) | 118 dest_url, &file_util_, SETUP_FOR_WRITE); |
| 130 result = SetUp(dest_url, &dest_util_, SETUP_FOR_CREATE); | |
| 131 if (result == base::PLATFORM_FILE_OK) { | |
| 132 if (!IsCrossOperationAllowed(src_url.type(), dest_url.type())) | |
| 133 result = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | |
| 134 } | |
| 135 if (result != base::PLATFORM_FILE_OK) { | 119 if (result != base::PLATFORM_FILE_OK) { |
| 136 callback.Run(result); | 120 callback.Run(result); |
| 137 delete this; | 121 delete this; |
| 138 return; | 122 return; |
| 139 } | 123 } |
| 140 | 124 |
| 141 GetUsageAndQuotaThenRunTask( | 125 DCHECK(!recursive_operation_delegate_); |
| 142 dest_url, | 126 recursive_operation_delegate_.reset( |
| 143 base::Bind(&LocalFileSystemOperation::DoCopy, | 127 new CrossOperationDelegate( |
| 144 base::Unretained(this), src_url, dest_url, callback), | 128 this, src_url, dest_url, |
| 145 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); | 129 CrossOperationDelegate::OPERATION_COPY, |
| 130 base::Bind(&LocalFileSystemOperation::DidFinishDelegatedOperation, |
| 131 base::Unretained(this), callback))); |
| 132 recursive_operation_delegate_->RunRecursively(); |
| 146 } | 133 } |
| 147 | 134 |
| 148 void LocalFileSystemOperation::Move(const FileSystemURL& src_url, | 135 void LocalFileSystemOperation::Move(const FileSystemURL& src_url, |
| 149 const FileSystemURL& dest_url, | 136 const FileSystemURL& dest_url, |
| 150 const StatusCallback& callback) { | 137 const StatusCallback& callback) { |
| 151 DCHECK(SetPendingOperationType(kOperationMove)); | 138 DCHECK(SetPendingOperationType(kOperationMove)); |
| 152 is_cross_operation_ = (src_url.type() != dest_url.type()); | |
| 153 | 139 |
| 154 scoped_ptr<LocalFileSystemOperation> deleter(this); | 140 base::PlatformFileError result = SetUp( |
| 155 | 141 src_url, &file_util_, SETUP_FOR_WRITE); |
| 156 // Temporarily disables cross-filesystem move. | 142 if (result != base::PLATFORM_FILE_OK) { |
| 157 // TODO(kinuko,tzik,kinaba): This special handling must be removed once | 143 callback.Run(result); |
| 158 // we support saner cross-filesystem operation. | 144 delete this; |
| 159 // (See http://crbug.com/130055) | |
| 160 if (is_cross_operation_) { | |
| 161 callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); | |
| 162 return; | 145 return; |
| 163 } | 146 } |
| 164 | 147 |
| 165 base::PlatformFileError result = SetUp(src_url, &src_util_, SETUP_FOR_WRITE); | 148 DCHECK(!recursive_operation_delegate_); |
| 166 if (result == base::PLATFORM_FILE_OK) | 149 recursive_operation_delegate_.reset( |
| 167 result = SetUp(dest_url, &dest_util_, SETUP_FOR_CREATE); | 150 new CrossOperationDelegate( |
| 168 if (result == base::PLATFORM_FILE_OK) { | 151 this, src_url, dest_url, |
| 169 if (!IsCrossOperationAllowed(src_url.type(), dest_url.type())) | 152 CrossOperationDelegate::OPERATION_MOVE, |
| 170 result = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 153 base::Bind(&LocalFileSystemOperation::DidFinishDelegatedOperation, |
| 171 } | 154 base::Unretained(this), callback))); |
| 172 if (result != base::PLATFORM_FILE_OK) { | 155 recursive_operation_delegate_->RunRecursively(); |
| 173 callback.Run(result); | |
| 174 return; | |
| 175 } | |
| 176 | |
| 177 GetUsageAndQuotaThenRunTask( | |
| 178 dest_url, | |
| 179 base::Bind(&LocalFileSystemOperation::DoMove, | |
| 180 base::Unretained(deleter.release()), | |
| 181 src_url, dest_url, callback), | |
| 182 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); | |
| 183 } | 156 } |
| 184 | 157 |
| 185 void LocalFileSystemOperation::DirectoryExists(const FileSystemURL& url, | 158 void LocalFileSystemOperation::DirectoryExists(const FileSystemURL& url, |
| 186 const StatusCallback& callback) { | 159 const StatusCallback& callback) { |
| 187 DCHECK(SetPendingOperationType(kOperationDirectoryExists)); | 160 DCHECK(SetPendingOperationType(kOperationDirectoryExists)); |
| 188 | 161 |
| 189 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); | 162 base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_READ); |
| 190 if (result != base::PLATFORM_FILE_OK) { | 163 if (result != base::PLATFORM_FILE_OK) { |
| 191 callback.Run(result); | 164 callback.Run(result); |
| 192 delete this; | 165 delete this; |
| 193 return; | 166 return; |
| 194 } | 167 } |
| 195 | 168 |
| 196 FileSystemFileUtilProxy::GetFileInfo( | 169 FileSystemFileUtilProxy::GetFileInfo( |
| 197 operation_context(), src_util_, url, | 170 operation_context(), file_util_, url, |
| 198 base::Bind(&LocalFileSystemOperation::DidDirectoryExists, | 171 base::Bind(&LocalFileSystemOperation::DidDirectoryExists, |
| 199 base::Owned(this), callback)); | 172 base::Owned(this), callback)); |
| 200 } | 173 } |
| 201 | 174 |
| 202 void LocalFileSystemOperation::FileExists(const FileSystemURL& url, | 175 void LocalFileSystemOperation::FileExists(const FileSystemURL& url, |
| 203 const StatusCallback& callback) { | 176 const StatusCallback& callback) { |
| 204 DCHECK(SetPendingOperationType(kOperationFileExists)); | 177 DCHECK(SetPendingOperationType(kOperationFileExists)); |
| 205 | 178 |
| 206 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); | 179 base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_READ); |
| 207 if (result != base::PLATFORM_FILE_OK) { | 180 if (result != base::PLATFORM_FILE_OK) { |
| 208 callback.Run(result); | 181 callback.Run(result); |
| 209 delete this; | 182 delete this; |
| 210 return; | 183 return; |
| 211 } | 184 } |
| 212 | 185 |
| 213 FileSystemFileUtilProxy::GetFileInfo( | 186 FileSystemFileUtilProxy::GetFileInfo( |
| 214 operation_context(), src_util_, url, | 187 operation_context(), file_util_, url, |
| 215 base::Bind(&LocalFileSystemOperation::DidFileExists, | 188 base::Bind(&LocalFileSystemOperation::DidFileExists, |
| 216 base::Owned(this), callback)); | 189 base::Owned(this), callback)); |
| 217 } | 190 } |
| 218 | 191 |
| 219 void LocalFileSystemOperation::GetMetadata( | 192 void LocalFileSystemOperation::GetMetadata( |
| 220 const FileSystemURL& url, const GetMetadataCallback& callback) { | 193 const FileSystemURL& url, const GetMetadataCallback& callback) { |
| 221 DCHECK(SetPendingOperationType(kOperationGetMetadata)); | 194 DCHECK(SetPendingOperationType(kOperationGetMetadata)); |
| 222 | 195 |
| 223 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); | 196 base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_READ); |
| 224 if (result != base::PLATFORM_FILE_OK) { | 197 if (result != base::PLATFORM_FILE_OK) { |
| 225 callback.Run(result, base::PlatformFileInfo(), FilePath()); | 198 callback.Run(result, base::PlatformFileInfo(), FilePath()); |
| 226 delete this; | 199 delete this; |
| 227 return; | 200 return; |
| 228 } | 201 } |
| 229 | 202 |
| 230 FileSystemFileUtilProxy::GetFileInfo( | 203 FileSystemFileUtilProxy::GetFileInfo( |
| 231 operation_context(), src_util_, url, | 204 operation_context(), file_util_, url, |
| 232 base::Bind(&LocalFileSystemOperation::DidGetMetadata, | 205 base::Bind(&LocalFileSystemOperation::DidGetMetadata, |
| 233 base::Owned(this), callback)); | 206 base::Owned(this), callback)); |
| 234 } | 207 } |
| 235 | 208 |
| 236 void LocalFileSystemOperation::ReadDirectory( | 209 void LocalFileSystemOperation::ReadDirectory( |
| 237 const FileSystemURL& url, const ReadDirectoryCallback& callback) { | 210 const FileSystemURL& url, const ReadDirectoryCallback& callback) { |
| 238 DCHECK(SetPendingOperationType(kOperationReadDirectory)); | 211 DCHECK(SetPendingOperationType(kOperationReadDirectory)); |
| 239 | 212 |
| 240 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); | 213 base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_READ); |
| 241 if (result != base::PLATFORM_FILE_OK) { | 214 if (result != base::PLATFORM_FILE_OK) { |
| 242 callback.Run(result, std::vector<base::FileUtilProxy::Entry>(), false); | 215 callback.Run(result, std::vector<base::FileUtilProxy::Entry>(), false); |
| 243 delete this; | 216 delete this; |
| 244 return; | 217 return; |
| 245 } | 218 } |
| 246 | 219 |
| 247 FileSystemFileUtilProxy::ReadDirectory( | 220 FileSystemFileUtilProxy::ReadDirectory( |
| 248 operation_context(), src_util_, url, | 221 operation_context(), file_util_, url, |
| 249 base::Bind(&LocalFileSystemOperation::DidReadDirectory, | 222 base::Bind(&LocalFileSystemOperation::DidReadDirectory, |
| 250 base::Owned(this), callback)); | 223 base::Owned(this), callback)); |
| 251 } | 224 } |
| 252 | 225 |
| 253 void LocalFileSystemOperation::Remove(const FileSystemURL& url, | 226 void LocalFileSystemOperation::Remove(const FileSystemURL& url, |
| 254 bool recursive, | 227 bool recursive, |
| 255 const StatusCallback& callback) { | 228 const StatusCallback& callback) { |
| 256 DCHECK(SetPendingOperationType(kOperationRemove)); | 229 DCHECK(SetPendingOperationType(kOperationRemove)); |
| 257 DCHECK(!remove_operation_delegate_); | 230 DCHECK(!recursive_operation_delegate_); |
| 258 remove_operation_delegate_.reset(new RemoveOperationDelegate( | 231 recursive_operation_delegate_.reset( |
| 259 this, base::Bind(&LocalFileSystemOperation::DidFinishDelegatedOperation, | 232 new RemoveOperationDelegate( |
| 260 base::Unretained(this), callback))); | 233 this, url, |
| 234 base::Bind(&LocalFileSystemOperation::DidFinishDelegatedOperation, |
| 235 base::Unretained(this), callback))); |
| 261 if (recursive) | 236 if (recursive) |
| 262 remove_operation_delegate_->RunRecursively(url); | 237 recursive_operation_delegate_->RunRecursively(); |
| 263 else | 238 else |
| 264 remove_operation_delegate_->Run(url); | 239 recursive_operation_delegate_->Run(); |
| 265 } | 240 } |
| 266 | 241 |
| 267 void LocalFileSystemOperation::Write( | 242 void LocalFileSystemOperation::Write( |
| 268 const net::URLRequestContext* url_request_context, | 243 const net::URLRequestContext* url_request_context, |
| 269 const FileSystemURL& url, | 244 const FileSystemURL& url, |
| 270 const GURL& blob_url, | 245 const GURL& blob_url, |
| 271 int64 offset, | 246 int64 offset, |
| 272 const WriteCallback& callback) { | 247 const WriteCallback& callback) { |
| 273 GetWriteClosure(url_request_context, url, blob_url, offset, callback).Run(); | 248 GetWriteClosure(url_request_context, url, blob_url, offset, callback).Run(); |
| 274 } | 249 } |
| 275 | 250 |
| 276 void LocalFileSystemOperation::Truncate(const FileSystemURL& url, int64 length, | 251 void LocalFileSystemOperation::Truncate(const FileSystemURL& url, int64 length, |
| 277 const StatusCallback& callback) { | 252 const StatusCallback& callback) { |
| 278 DCHECK(SetPendingOperationType(kOperationTruncate)); | 253 DCHECK(SetPendingOperationType(kOperationTruncate)); |
| 279 | 254 |
| 280 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_WRITE); | 255 base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_WRITE); |
| 281 if (result != base::PLATFORM_FILE_OK) { | 256 if (result != base::PLATFORM_FILE_OK) { |
| 282 callback.Run(result); | 257 callback.Run(result); |
| 283 delete this; | 258 delete this; |
| 284 return; | 259 return; |
| 285 } | 260 } |
| 286 GetUsageAndQuotaThenRunTask( | 261 GetUsageAndQuotaThenRunTask( |
| 287 url, | 262 url, |
| 288 base::Bind(&LocalFileSystemOperation::DoTruncate, | 263 base::Bind(&LocalFileSystemOperation::DoTruncate, |
| 289 base::Unretained(this), url, callback, length), | 264 base::Unretained(this), url, callback, length), |
| 290 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); | 265 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); |
| 291 } | 266 } |
| 292 | 267 |
| 293 void LocalFileSystemOperation::TouchFile(const FileSystemURL& url, | 268 void LocalFileSystemOperation::TouchFile(const FileSystemURL& url, |
| 294 const base::Time& last_access_time, | 269 const base::Time& last_access_time, |
| 295 const base::Time& last_modified_time, | 270 const base::Time& last_modified_time, |
| 296 const StatusCallback& callback) { | 271 const StatusCallback& callback) { |
| 297 DCHECK(SetPendingOperationType(kOperationTouchFile)); | 272 DCHECK(SetPendingOperationType(kOperationTouchFile)); |
| 298 | 273 |
| 299 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_WRITE); | 274 base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_WRITE); |
| 300 if (result != base::PLATFORM_FILE_OK) { | 275 if (result != base::PLATFORM_FILE_OK) { |
| 301 callback.Run(result); | 276 callback.Run(result); |
| 302 delete this; | 277 delete this; |
| 303 return; | 278 return; |
| 304 } | 279 } |
| 305 | 280 |
| 306 FileSystemFileUtilProxy::Touch( | 281 FileSystemFileUtilProxy::Touch( |
| 307 operation_context(), src_util_, url, | 282 operation_context(), file_util_, url, |
| 308 last_access_time, last_modified_time, | 283 last_access_time, last_modified_time, |
| 309 base::Bind(&LocalFileSystemOperation::DidTouchFile, | 284 base::Bind(&LocalFileSystemOperation::DidTouchFile, |
| 310 base::Owned(this), callback)); | 285 base::Owned(this), callback)); |
| 311 } | 286 } |
| 312 | 287 |
| 313 void LocalFileSystemOperation::OpenFile(const FileSystemURL& url, | 288 void LocalFileSystemOperation::OpenFile(const FileSystemURL& url, |
| 314 int file_flags, | 289 int file_flags, |
| 315 base::ProcessHandle peer_handle, | 290 base::ProcessHandle peer_handle, |
| 316 const OpenFileCallback& callback) { | 291 const OpenFileCallback& callback) { |
| 317 DCHECK(SetPendingOperationType(kOperationOpenFile)); | 292 DCHECK(SetPendingOperationType(kOperationOpenFile)); |
| 318 scoped_ptr<LocalFileSystemOperation> deleter(this); | 293 scoped_ptr<LocalFileSystemOperation> deleter(this); |
| 319 | 294 |
| 320 peer_handle_ = peer_handle; | 295 peer_handle_ = peer_handle; |
| 321 | 296 |
| 322 if (file_flags & ( | 297 if (file_flags & ( |
| 323 (base::PLATFORM_FILE_ENUMERATE | base::PLATFORM_FILE_TEMPORARY | | 298 (base::PLATFORM_FILE_ENUMERATE | base::PLATFORM_FILE_TEMPORARY | |
| 324 base::PLATFORM_FILE_HIDDEN))) { | 299 base::PLATFORM_FILE_HIDDEN))) { |
| 325 callback.Run(base::PLATFORM_FILE_ERROR_FAILED, | 300 callback.Run(base::PLATFORM_FILE_ERROR_FAILED, |
| 326 base::PlatformFile(), base::ProcessHandle()); | 301 base::PlatformFile(), base::ProcessHandle()); |
| 327 return; | 302 return; |
| 328 } | 303 } |
| 329 if (file_flags & | 304 if (file_flags & |
| 330 (base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_OPEN_ALWAYS | | 305 (base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_OPEN_ALWAYS | |
| 331 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_TRUNCATED | | 306 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_TRUNCATED | |
| 332 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE | | 307 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE | |
| 333 base::PLATFORM_FILE_DELETE_ON_CLOSE | | 308 base::PLATFORM_FILE_DELETE_ON_CLOSE | |
| 334 base::PLATFORM_FILE_WRITE_ATTRIBUTES)) { | 309 base::PLATFORM_FILE_WRITE_ATTRIBUTES)) { |
| 335 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_CREATE); | 310 base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_CREATE); |
| 336 if (result != base::PLATFORM_FILE_OK) { | 311 if (result != base::PLATFORM_FILE_OK) { |
| 337 callback.Run(result, base::PlatformFile(), base::ProcessHandle()); | 312 callback.Run(result, base::PlatformFile(), base::ProcessHandle()); |
| 338 return; | 313 return; |
| 339 } | 314 } |
| 340 } else { | 315 } else { |
| 341 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); | 316 base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_READ); |
| 342 if (result != base::PLATFORM_FILE_OK) { | 317 if (result != base::PLATFORM_FILE_OK) { |
| 343 callback.Run(result, base::PlatformFile(), base::ProcessHandle()); | 318 callback.Run(result, base::PlatformFile(), base::ProcessHandle()); |
| 344 return; | 319 return; |
| 345 } | 320 } |
| 346 } | 321 } |
| 347 GetUsageAndQuotaThenRunTask( | 322 GetUsageAndQuotaThenRunTask( |
| 348 url, | 323 url, |
| 349 base::Bind(&LocalFileSystemOperation::DoOpenFile, | 324 base::Bind(&LocalFileSystemOperation::DoOpenFile, |
| 350 base::Unretained(deleter.release()), | 325 base::Unretained(deleter.release()), |
| 351 url, callback, file_flags), | 326 url, callback, file_flags), |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 | 370 |
| 396 LocalFileSystemOperation* | 371 LocalFileSystemOperation* |
| 397 LocalFileSystemOperation::AsLocalFileSystemOperation() { | 372 LocalFileSystemOperation::AsLocalFileSystemOperation() { |
| 398 return this; | 373 return this; |
| 399 } | 374 } |
| 400 | 375 |
| 401 void LocalFileSystemOperation::SyncGetPlatformPath(const FileSystemURL& url, | 376 void LocalFileSystemOperation::SyncGetPlatformPath(const FileSystemURL& url, |
| 402 FilePath* platform_path) { | 377 FilePath* platform_path) { |
| 403 DCHECK(SetPendingOperationType(kOperationGetLocalPath)); | 378 DCHECK(SetPendingOperationType(kOperationGetLocalPath)); |
| 404 | 379 |
| 405 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); | 380 base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_READ); |
| 406 if (result != base::PLATFORM_FILE_OK) { | 381 if (result != base::PLATFORM_FILE_OK) { |
| 407 delete this; | 382 delete this; |
| 408 return; | 383 return; |
| 409 } | 384 } |
| 410 | 385 |
| 411 src_util_->GetLocalFilePath(operation_context(), url, platform_path); | 386 file_util_->GetLocalFilePath(operation_context(), url, platform_path); |
| 412 | 387 |
| 413 delete this; | 388 delete this; |
| 414 } | 389 } |
| 415 | 390 |
| 416 void LocalFileSystemOperation::CreateSnapshotFile( | 391 void LocalFileSystemOperation::CreateSnapshotFile( |
| 417 const FileSystemURL& url, | 392 const FileSystemURL& url, |
| 418 const SnapshotFileCallback& callback) { | 393 const SnapshotFileCallback& callback) { |
| 419 DCHECK(SetPendingOperationType(kOperationCreateSnapshotFile)); | 394 DCHECK(SetPendingOperationType(kOperationCreateSnapshotFile)); |
| 420 | 395 |
| 421 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ); | 396 base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_READ); |
| 422 if (result != base::PLATFORM_FILE_OK) { | 397 if (result != base::PLATFORM_FILE_OK) { |
| 423 callback.Run(result, base::PlatformFileInfo(), FilePath(), NULL); | 398 callback.Run(result, base::PlatformFileInfo(), FilePath(), NULL); |
| 424 delete this; | 399 delete this; |
| 425 return; | 400 return; |
| 426 } | 401 } |
| 427 | 402 |
| 428 FileSystemFileUtilProxy::CreateSnapshotFile( | 403 FileSystemFileUtilProxy::CreateSnapshotFile( |
| 429 operation_context(), src_util_, url, | 404 operation_context(), file_util_, url, |
| 430 base::Bind(&LocalFileSystemOperation::DidCreateSnapshotFile, | 405 base::Bind(&LocalFileSystemOperation::DidCreateSnapshotFile, |
| 431 base::Owned(this), callback)); | 406 base::Owned(this), callback)); |
| 432 } | 407 } |
| 433 | 408 |
| 434 void LocalFileSystemOperation::CopyInForeignFile( | 409 void LocalFileSystemOperation::CopyInForeignFile( |
| 435 const FilePath& src_local_disk_file_path, | 410 const FilePath& src_local_disk_file_path, |
| 436 const FileSystemURL& dest_url, | 411 const FileSystemURL& dest_url, |
| 437 const StatusCallback& callback) { | 412 const StatusCallback& callback) { |
| 438 DCHECK(SetPendingOperationType(kOperationCopyInForeignFile)); | 413 DCHECK(SetPendingOperationType(kOperationCopyInForeignFile)); |
| 439 | 414 |
| 440 base::PlatformFileError result = SetUp( | 415 base::PlatformFileError result = SetUp( |
| 441 dest_url, &dest_util_, SETUP_FOR_CREATE); | 416 dest_url, &file_util_, SETUP_FOR_CREATE); |
| 442 if (result != base::PLATFORM_FILE_OK) { | 417 if (result != base::PLATFORM_FILE_OK) { |
| 443 callback.Run(result); | 418 callback.Run(result); |
| 444 delete this; | 419 delete this; |
| 445 return; | 420 return; |
| 446 } | 421 } |
| 447 | 422 |
| 448 GetUsageAndQuotaThenRunTask( | 423 GetUsageAndQuotaThenRunTask( |
| 449 dest_url, | 424 dest_url, |
| 450 base::Bind(&LocalFileSystemOperation::DoCopyInForeignFile, | 425 base::Bind(&LocalFileSystemOperation::DoCopyInForeignFile, |
| 451 base::Unretained(this), src_local_disk_file_path, dest_url, | 426 base::Unretained(this), src_local_disk_file_path, dest_url, |
| 452 callback), | 427 callback), |
| 453 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); | 428 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); |
| 454 } | 429 } |
| 455 | 430 |
| 456 void LocalFileSystemOperation::RemoveFile( | 431 void LocalFileSystemOperation::RemoveFile( |
| 457 const FileSystemURL& url, | 432 const FileSystemURL& url, |
| 458 const StatusCallback& callback) { | 433 const StatusCallback& callback) { |
| 459 DCHECK(SetPendingOperationType(kOperationRemove)); | 434 DCHECK(SetPendingOperationType(kOperationRemove)); |
| 460 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_WRITE); | 435 base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_WRITE); |
| 461 if (result != base::PLATFORM_FILE_OK) { | 436 if (result != base::PLATFORM_FILE_OK) { |
| 462 callback.Run(result); | 437 callback.Run(result); |
| 463 delete this; | 438 delete this; |
| 464 return; | 439 return; |
| 465 } | 440 } |
| 466 | 441 |
| 467 FileSystemFileUtilProxy::DeleteFile( | 442 FileSystemFileUtilProxy::DeleteFile( |
| 468 operation_context(), src_util_, url, | 443 operation_context(), file_util_, url, |
| 469 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, | 444 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, |
| 470 base::Owned(this), callback)); | 445 base::Owned(this), callback)); |
| 471 } | 446 } |
| 472 | 447 |
| 473 void LocalFileSystemOperation::RemoveDirectory( | 448 void LocalFileSystemOperation::RemoveDirectory( |
| 474 const FileSystemURL& url, | 449 const FileSystemURL& url, |
| 475 const StatusCallback& callback) { | 450 const StatusCallback& callback) { |
| 476 DCHECK(SetPendingOperationType(kOperationRemove)); | 451 DCHECK(SetPendingOperationType(kOperationRemove)); |
| 477 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_WRITE); | 452 base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_WRITE); |
| 478 if (result != base::PLATFORM_FILE_OK) { | 453 if (result != base::PLATFORM_FILE_OK) { |
| 479 callback.Run(result); | 454 callback.Run(result); |
| 480 delete this; | 455 delete this; |
| 481 return; | 456 return; |
| 482 } | 457 } |
| 483 | 458 |
| 484 FileSystemFileUtilProxy::DeleteDirectory( | 459 FileSystemFileUtilProxy::DeleteDirectory( |
| 485 operation_context(), src_util_, url, | 460 operation_context(), file_util_, url, |
| 486 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, | 461 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, |
| 487 base::Owned(this), callback)); | 462 base::Owned(this), callback)); |
| 488 } | 463 } |
| 489 | 464 |
| 465 void LocalFileSystemOperation::CopyFileLocal( |
| 466 const FileSystemURL& src_url, |
| 467 const FileSystemURL& dest_url, |
| 468 const StatusCallback& callback) { |
| 469 DCHECK(SetPendingOperationType(kOperationCopy)); |
| 470 DCHECK_EQ(src_url.origin(), dest_url.origin()); |
| 471 DCHECK_EQ(src_url.type(), dest_url.type()); |
| 472 |
| 473 base::PlatformFileError result = SetUp(src_url, &file_util_, SETUP_FOR_READ); |
| 474 if (result == base::PLATFORM_FILE_OK) |
| 475 result = SetUp(dest_url, &file_util_, SETUP_FOR_CREATE); |
| 476 if (result != base::PLATFORM_FILE_OK) { |
| 477 callback.Run(result); |
| 478 delete this; |
| 479 return; |
| 480 } |
| 481 |
| 482 // Record read access for src_url. |
| 483 operation_context()->access_observers()->Notify( |
| 484 &FileAccessObserver::OnAccess, MakeTuple(src_url)); |
| 485 // Record update access for dest_url. |
| 486 scoped_update_notifiers_.push_back(new ScopedUpdateNotifier( |
| 487 operation_context(), dest_url)); |
| 488 |
| 489 GetUsageAndQuotaThenRunTask( |
| 490 dest_url, |
| 491 base::Bind(&LocalFileSystemOperation::DoCopyFileLocal, |
| 492 base::Unretained(this), src_url, dest_url, callback), |
| 493 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); |
| 494 } |
| 495 |
| 496 void LocalFileSystemOperation::MoveFileLocal( |
| 497 const FileSystemURL& src_url, |
| 498 const FileSystemURL& dest_url, |
| 499 const StatusCallback& callback) { |
| 500 DCHECK(SetPendingOperationType(kOperationMove)); |
| 501 DCHECK_EQ(src_url.origin(), dest_url.origin()); |
| 502 DCHECK_EQ(src_url.type(), dest_url.type()); |
| 503 |
| 504 base::PlatformFileError result = SetUp(src_url, &file_util_, SETUP_FOR_WRITE); |
| 505 if (result == base::PLATFORM_FILE_OK) |
| 506 result = SetUp(dest_url, &file_util_, SETUP_FOR_CREATE); |
| 507 if (result != base::PLATFORM_FILE_OK) { |
| 508 callback.Run(result); |
| 509 delete this; |
| 510 return; |
| 511 } |
| 512 |
| 513 // Record update access for dest_url. |
| 514 scoped_update_notifiers_.push_back(new ScopedUpdateNotifier( |
| 515 operation_context(), dest_url)); |
| 516 |
| 517 GetUsageAndQuotaThenRunTask( |
| 518 dest_url, |
| 519 base::Bind(&LocalFileSystemOperation::DoMoveFileLocal, |
| 520 base::Unretained(this), src_url, dest_url, callback), |
| 521 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); |
| 522 } |
| 523 |
| 490 LocalFileSystemOperation::LocalFileSystemOperation( | 524 LocalFileSystemOperation::LocalFileSystemOperation( |
| 491 FileSystemContext* file_system_context, | 525 FileSystemContext* file_system_context, |
| 492 scoped_ptr<FileSystemOperationContext> operation_context) | 526 scoped_ptr<FileSystemOperationContext> operation_context) |
| 493 : file_system_context_(file_system_context), | 527 : file_system_context_(file_system_context), |
| 494 operation_context_(operation_context.Pass()), | 528 operation_context_(operation_context.Pass()), |
| 495 src_util_(NULL), | 529 file_util_(NULL), |
| 496 dest_util_(NULL), | |
| 497 overriding_operation_context_(NULL), | 530 overriding_operation_context_(NULL), |
| 498 is_cross_operation_(false), | |
| 499 peer_handle_(base::kNullProcessHandle), | 531 peer_handle_(base::kNullProcessHandle), |
| 500 pending_operation_(kOperationNone), | 532 pending_operation_(kOperationNone), |
| 501 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 533 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 502 DCHECK(operation_context_.get()); | 534 DCHECK(operation_context_.get()); |
| 503 } | 535 } |
| 504 | 536 |
| 505 void LocalFileSystemOperation::GetUsageAndQuotaThenRunTask( | 537 void LocalFileSystemOperation::GetUsageAndQuotaThenRunTask( |
| 506 const FileSystemURL& url, | 538 const FileSystemURL& url, |
| 507 const base::Closure& task, | 539 const base::Closure& task, |
| 508 const base::Closure& error_callback) { | 540 const base::Closure& error_callback) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 } | 574 } |
| 543 | 575 |
| 544 base::Closure LocalFileSystemOperation::GetWriteClosure( | 576 base::Closure LocalFileSystemOperation::GetWriteClosure( |
| 545 const net::URLRequestContext* url_request_context, | 577 const net::URLRequestContext* url_request_context, |
| 546 const FileSystemURL& url, | 578 const FileSystemURL& url, |
| 547 const GURL& blob_url, | 579 const GURL& blob_url, |
| 548 int64 offset, | 580 int64 offset, |
| 549 const WriteCallback& callback) { | 581 const WriteCallback& callback) { |
| 550 DCHECK(SetPendingOperationType(kOperationWrite)); | 582 DCHECK(SetPendingOperationType(kOperationWrite)); |
| 551 | 583 |
| 552 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_WRITE); | 584 base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_WRITE); |
| 553 if (result != base::PLATFORM_FILE_OK) { | 585 if (result != base::PLATFORM_FILE_OK) { |
| 554 return base::Bind(&LocalFileSystemOperation::DidFailWrite, | 586 return base::Bind(&LocalFileSystemOperation::DidFailWrite, |
| 555 base::Owned(this), callback, result); | 587 base::Owned(this), callback, result); |
| 556 } | 588 } |
| 557 | 589 |
| 558 FileSystemMountPointProvider* provider = file_system_context()-> | 590 FileSystemMountPointProvider* provider = file_system_context()-> |
| 559 GetMountPointProvider(url.type()); | 591 GetMountPointProvider(url.type()); |
| 560 DCHECK(provider); | 592 DCHECK(provider); |
| 561 scoped_ptr<FileStreamWriter> writer(provider->CreateFileStreamWriter( | 593 scoped_ptr<FileStreamWriter> writer(provider->CreateFileStreamWriter( |
| 562 url, offset, file_system_context())); | 594 url, offset, file_system_context())); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 588 base::PlatformFileError result) { | 620 base::PlatformFileError result) { |
| 589 callback.Run(result, 0, false); | 621 callback.Run(result, 0, false); |
| 590 } | 622 } |
| 591 | 623 |
| 592 void LocalFileSystemOperation::DoCreateFile( | 624 void LocalFileSystemOperation::DoCreateFile( |
| 593 const FileSystemURL& url, | 625 const FileSystemURL& url, |
| 594 const StatusCallback& callback, | 626 const StatusCallback& callback, |
| 595 bool exclusive) { | 627 bool exclusive) { |
| 596 FileSystemFileUtilProxy::EnsureFileExists( | 628 FileSystemFileUtilProxy::EnsureFileExists( |
| 597 operation_context(), | 629 operation_context(), |
| 598 src_util_, url, | 630 file_util_, url, |
| 599 base::Bind( | 631 base::Bind( |
| 600 exclusive ? | 632 exclusive ? |
| 601 &LocalFileSystemOperation::DidEnsureFileExistsExclusive : | 633 &LocalFileSystemOperation::DidEnsureFileExistsExclusive : |
| 602 &LocalFileSystemOperation::DidEnsureFileExistsNonExclusive, | 634 &LocalFileSystemOperation::DidEnsureFileExistsNonExclusive, |
| 603 base::Owned(this), callback)); | 635 base::Owned(this), callback)); |
| 604 } | 636 } |
| 605 | 637 |
| 606 void LocalFileSystemOperation::DoCreateDirectory( | 638 void LocalFileSystemOperation::DoCreateDirectory( |
| 607 const FileSystemURL& url, | 639 const FileSystemURL& url, |
| 608 const StatusCallback& callback, | 640 const StatusCallback& callback, |
| 609 bool exclusive, bool recursive) { | 641 bool exclusive, bool recursive) { |
| 610 FileSystemFileUtilProxy::CreateDirectory( | 642 FileSystemFileUtilProxy::CreateDirectory( |
| 611 operation_context(), | 643 operation_context(), |
| 612 src_util_, url, exclusive, recursive, | 644 file_util_, url, exclusive, recursive, |
| 613 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, | 645 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, |
| 614 base::Owned(this), callback)); | 646 base::Owned(this), callback)); |
| 615 } | 647 } |
| 616 | 648 |
| 617 void LocalFileSystemOperation::DoCopy(const FileSystemURL& src_url, | 649 void LocalFileSystemOperation::DoCopyFileLocal( |
| 618 const FileSystemURL& dest_url, | 650 const FileSystemURL& src_url, |
| 619 const StatusCallback& callback) { | 651 const FileSystemURL& dest_url, |
| 620 FileSystemFileUtilProxy::Copy( | 652 const StatusCallback& callback) { |
| 653 FileSystemFileUtilProxy::CopyFileLocal( |
| 621 operation_context(), | 654 operation_context(), |
| 622 src_util_, dest_util_, | 655 file_util_, src_url, dest_url, |
| 623 src_url, dest_url, | 656 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, |
| 657 base::Owned(this), callback)); |
| 658 } |
| 659 |
| 660 void LocalFileSystemOperation::DoMoveFileLocal( |
| 661 const FileSystemURL& src_url, |
| 662 const FileSystemURL& dest_url, |
| 663 const StatusCallback& callback) { |
| 664 FileSystemFileUtilProxy::MoveFileLocal( |
| 665 operation_context(), |
| 666 file_util_, src_url, dest_url, |
| 624 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, | 667 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, |
| 625 base::Owned(this), callback)); | 668 base::Owned(this), callback)); |
| 626 } | 669 } |
| 627 | 670 |
| 628 void LocalFileSystemOperation::DoCopyInForeignFile( | 671 void LocalFileSystemOperation::DoCopyInForeignFile( |
| 629 const FilePath& src_local_disk_file_path, | 672 const FilePath& src_local_disk_file_path, |
| 630 const FileSystemURL& dest_url, | 673 const FileSystemURL& dest_url, |
| 631 const StatusCallback& callback) { | 674 const StatusCallback& callback) { |
| 632 FileSystemFileUtilProxy::CopyInForeignFile( | 675 FileSystemFileUtilProxy::CopyInForeignFile( |
| 633 operation_context(), | 676 operation_context(), |
| 634 dest_util_, | 677 file_util_, src_local_disk_file_path, dest_url, |
| 635 src_local_disk_file_path, dest_url, | |
| 636 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, | 678 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, |
| 637 base::Owned(this), callback)); | 679 base::Owned(this), callback)); |
| 638 } | 680 } |
| 639 | |
| 640 void LocalFileSystemOperation::DoMove(const FileSystemURL& src_url, | |
| 641 const FileSystemURL& dest_url, | |
| 642 const StatusCallback& callback) { | |
| 643 FileSystemFileUtilProxy::Move( | |
| 644 operation_context(), | |
| 645 src_util_, dest_util_, | |
| 646 src_url, dest_url, | |
| 647 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, | |
| 648 base::Owned(this), callback)); | |
| 649 } | |
| 650 | 681 |
| 651 void LocalFileSystemOperation::DoTruncate(const FileSystemURL& url, | 682 void LocalFileSystemOperation::DoTruncate(const FileSystemURL& url, |
| 652 const StatusCallback& callback, | 683 const StatusCallback& callback, |
| 653 int64 length) { | 684 int64 length) { |
| 654 FileSystemFileUtilProxy::Truncate( | 685 FileSystemFileUtilProxy::Truncate( |
| 655 operation_context(), src_util_, url, length, | 686 operation_context(), file_util_, url, length, |
| 656 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, | 687 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, |
| 657 base::Owned(this), callback)); | 688 base::Owned(this), callback)); |
| 658 } | 689 } |
| 659 | 690 |
| 660 void LocalFileSystemOperation::DoOpenFile(const FileSystemURL& url, | 691 void LocalFileSystemOperation::DoOpenFile(const FileSystemURL& url, |
| 661 const OpenFileCallback& callback, | 692 const OpenFileCallback& callback, |
| 662 int file_flags) { | 693 int file_flags) { |
| 663 FileSystemFileUtilProxy::CreateOrOpen( | 694 FileSystemFileUtilProxy::CreateOrOpen( |
| 664 operation_context(), src_util_, url, file_flags, | 695 operation_context(), file_util_, url, file_flags, |
| 665 base::Bind(&LocalFileSystemOperation::DidOpenFile, | 696 base::Bind(&LocalFileSystemOperation::DidOpenFile, |
| 666 base::Owned(this), callback)); | 697 base::Owned(this), callback)); |
| 667 } | 698 } |
| 668 | 699 |
| 669 void LocalFileSystemOperation::DidEnsureFileExistsExclusive( | 700 void LocalFileSystemOperation::DidEnsureFileExistsExclusive( |
| 670 const StatusCallback& callback, | 701 const StatusCallback& callback, |
| 671 base::PlatformFileError rv, bool created) { | 702 base::PlatformFileError rv, bool created) { |
| 672 if (rv == base::PLATFORM_FILE_OK && !created) { | 703 if (rv == base::PLATFORM_FILE_OK && !created) { |
| 673 callback.Run(base::PLATFORM_FILE_ERROR_EXISTS); | 704 callback.Run(base::PLATFORM_FILE_ERROR_EXISTS); |
| 674 } else { | 705 } else { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 818 // operation context is overridden from another operation) we skip | 849 // operation context is overridden from another operation) we skip |
| 819 // some duplicated security checks. | 850 // some duplicated security checks. |
| 820 if (overriding_operation_context_) | 851 if (overriding_operation_context_) |
| 821 return base::PLATFORM_FILE_OK; | 852 return base::PLATFORM_FILE_OK; |
| 822 | 853 |
| 823 if (!file_system_context()->GetMountPointProvider( | 854 if (!file_system_context()->GetMountPointProvider( |
| 824 url.type())->IsAccessAllowed(url)) | 855 url.type())->IsAccessAllowed(url)) |
| 825 return base::PLATFORM_FILE_ERROR_SECURITY; | 856 return base::PLATFORM_FILE_ERROR_SECURITY; |
| 826 | 857 |
| 827 if (mode == SETUP_FOR_READ) { | 858 if (mode == SETUP_FOR_READ) { |
| 828 // TODO(kinuko): This doesn't work well for cross-filesystem operation | 859 operation_context()->access_observers()->Notify( |
| 829 // in the current architecture since the operation context (thus the | 860 &FileAccessObserver::OnAccess, MakeTuple(url)); |
| 830 // observers) is configured for the destination URL while this method | |
| 831 // could be called for both src and dest URL. | |
| 832 if (!is_cross_operation_) { | |
| 833 operation_context()->access_observers()->Notify( | |
| 834 &FileAccessObserver::OnAccess, MakeTuple(url)); | |
| 835 } | |
| 836 return base::PLATFORM_FILE_OK; | 861 return base::PLATFORM_FILE_OK; |
| 837 } | 862 } |
| 838 | 863 |
| 839 DCHECK(mode == SETUP_FOR_WRITE || mode == SETUP_FOR_CREATE); | 864 DCHECK(mode == SETUP_FOR_WRITE || mode == SETUP_FOR_CREATE); |
| 840 | 865 |
| 841 scoped_update_notifiers_.push_back(new ScopedUpdateNotifier( | 866 scoped_update_notifiers_.push_back(new ScopedUpdateNotifier( |
| 842 operation_context(), url)); | 867 operation_context(), url)); |
| 843 | 868 |
| 844 // Any write access is disallowed on the root path. | 869 // Any write access is disallowed on the root path. |
| 845 if (url.path().value().length() == 0 || | 870 if (url.path().value().length() == 0 || |
| (...skipping 13 matching lines...) Expand all Loading... |
| 859 } | 884 } |
| 860 | 885 |
| 861 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) { | 886 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) { |
| 862 if (pending_operation_ != kOperationNone) | 887 if (pending_operation_ != kOperationNone) |
| 863 return false; | 888 return false; |
| 864 pending_operation_ = type; | 889 pending_operation_ = type; |
| 865 return true; | 890 return true; |
| 866 } | 891 } |
| 867 | 892 |
| 868 } // namespace fileapi | 893 } // namespace fileapi |
| OLD | NEW |