| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/file_system_operation.h" | 5 #include "webkit/fileapi/file_system_operation.h" |
| 6 | 6 |
| 7 #include "base/time.h" | 7 #include "base/time.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "net/base/escape.h" | 9 #include "net/base/escape.h" |
| 10 #include "net/url_request/url_request_context.h" | 10 #include "net/url_request/url_request_context.h" |
| 11 #include "webkit/fileapi/file_system_callback_dispatcher.h" | 11 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
| 12 #include "webkit/fileapi/file_system_context.h" | 12 #include "webkit/fileapi/file_system_context.h" |
| 13 #include "webkit/fileapi/file_system_file_util_proxy.h" | 13 #include "webkit/fileapi/file_system_file_util_proxy.h" |
| 14 #include "webkit/fileapi/file_system_operation_context.h" | 14 #include "webkit/fileapi/file_system_operation_context.h" |
| 15 #include "webkit/fileapi/file_system_path_manager.h" | 15 #include "webkit/fileapi/file_system_path_manager.h" |
| 16 #include "webkit/fileapi/file_system_quota_util.h" | 16 #include "webkit/fileapi/file_system_quota_util.h" |
| 17 #include "webkit/fileapi/file_system_types.h" | 17 #include "webkit/fileapi/file_system_types.h" |
| 18 #include "webkit/fileapi/file_system_util.h" | 18 #include "webkit/fileapi/file_system_util.h" |
| 19 #include "webkit/fileapi/file_writer_delegate.h" | 19 #include "webkit/fileapi/file_writer_delegate.h" |
| 20 #include "webkit/fileapi/local_file_system_file_util.h" | 20 #include "webkit/fileapi/local_file_util.h" |
| 21 #include "webkit/fileapi/quota_file_util.h" | 21 #include "webkit/fileapi/quota_file_util.h" |
| 22 #include "webkit/quota/quota_types.h" | 22 #include "webkit/quota/quota_types.h" |
| 23 | 23 |
| 24 namespace fileapi { | 24 namespace fileapi { |
| 25 | 25 |
| 26 FileSystemOperation::FileSystemOperation( | 26 FileSystemOperation::FileSystemOperation( |
| 27 FileSystemCallbackDispatcher* dispatcher, | 27 FileSystemCallbackDispatcher* dispatcher, |
| 28 scoped_refptr<base::MessageLoopProxy> proxy, | 28 scoped_refptr<base::MessageLoopProxy> proxy, |
| 29 FileSystemContext* file_system_context, | 29 FileSystemContext* file_system_context, |
| 30 FileSystemFileUtil* file_system_file_util) | 30 FileSystemFileUtil* file_util) |
| 31 : proxy_(proxy), | 31 : proxy_(proxy), |
| 32 dispatcher_(dispatcher), | 32 dispatcher_(dispatcher), |
| 33 file_system_operation_context_( | 33 file_system_operation_context_(file_system_context, file_util), |
| 34 file_system_context, file_system_file_util), | |
| 35 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 34 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 36 DCHECK(dispatcher); | 35 DCHECK(dispatcher); |
| 37 #ifndef NDEBUG | 36 #ifndef NDEBUG |
| 38 pending_operation_ = kOperationNone; | 37 pending_operation_ = kOperationNone; |
| 39 #endif | 38 #endif |
| 40 } | 39 } |
| 41 | 40 |
| 42 FileSystemOperation::~FileSystemOperation() { | 41 FileSystemOperation::~FileSystemOperation() { |
| 43 if (file_writer_delegate_.get()) | 42 if (file_writer_delegate_.get()) |
| 44 FileSystemFileUtilProxy::Close( | 43 FileSystemFileUtilProxy::Close( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 69 } | 68 } |
| 70 | 69 |
| 71 void FileSystemOperation::CreateFile(const GURL& path, | 70 void FileSystemOperation::CreateFile(const GURL& path, |
| 72 bool exclusive) { | 71 bool exclusive) { |
| 73 #ifndef NDEBUG | 72 #ifndef NDEBUG |
| 74 DCHECK(kOperationNone == pending_operation_); | 73 DCHECK(kOperationNone == pending_operation_); |
| 75 pending_operation_ = kOperationCreateFile; | 74 pending_operation_ = kOperationCreateFile; |
| 76 #endif | 75 #endif |
| 77 GURL origin_url; | 76 GURL origin_url; |
| 78 FileSystemType type; | 77 FileSystemType type; |
| 79 FileSystemFileUtil* file_system_file_util; | 78 FileSystemFileUtil* file_util; |
| 80 if (!VerifyFileSystemPathForWrite( | 79 if (!VerifyFileSystemPathForWrite(path, true /* create */, &origin_url, |
| 81 path, true /* create */, &origin_url, &type, &src_virtual_path_, | 80 &type, &src_virtual_path_, &file_util)) { |
| 82 &file_system_file_util)) { | |
| 83 delete this; | 81 delete this; |
| 84 return; | 82 return; |
| 85 } | 83 } |
| 86 file_system_operation_context_.set_src_origin_url(origin_url); | 84 file_system_operation_context_.set_src_origin_url(origin_url); |
| 87 file_system_operation_context_.set_src_type(type); | 85 file_system_operation_context_.set_src_type(type); |
| 88 if (!file_system_operation_context_.src_file_system_file_util()) | 86 if (!file_system_operation_context_.src_file_util()) |
| 89 file_system_operation_context_.set_src_file_system_file_util( | 87 file_system_operation_context_.set_src_file_util(file_util); |
| 90 file_system_file_util); | |
| 91 exclusive_ = exclusive; | 88 exclusive_ = exclusive; |
| 92 | 89 |
| 93 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( | 90 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( |
| 94 &FileSystemOperation::DelayedCreateFileForQuota)); | 91 &FileSystemOperation::DelayedCreateFileForQuota)); |
| 95 } | 92 } |
| 96 | 93 |
| 97 void FileSystemOperation::DelayedCreateFileForQuota( | 94 void FileSystemOperation::DelayedCreateFileForQuota( |
| 98 quota::QuotaStatusCode status, int64 usage, int64 quota) { | 95 quota::QuotaStatusCode status, int64 usage, int64 quota) { |
| 99 if (file_system_context()->IsStorageUnlimited( | 96 if (file_system_context()->IsStorageUnlimited( |
| 100 file_system_operation_context()->src_origin_url()) || | 97 file_system_operation_context()->src_origin_url()) || |
| (...skipping 14 matching lines...) Expand all Loading... |
| 115 | 112 |
| 116 void FileSystemOperation::CreateDirectory(const GURL& path, | 113 void FileSystemOperation::CreateDirectory(const GURL& path, |
| 117 bool exclusive, | 114 bool exclusive, |
| 118 bool recursive) { | 115 bool recursive) { |
| 119 #ifndef NDEBUG | 116 #ifndef NDEBUG |
| 120 DCHECK(kOperationNone == pending_operation_); | 117 DCHECK(kOperationNone == pending_operation_); |
| 121 pending_operation_ = kOperationCreateDirectory; | 118 pending_operation_ = kOperationCreateDirectory; |
| 122 #endif | 119 #endif |
| 123 GURL origin_url; | 120 GURL origin_url; |
| 124 FileSystemType type; | 121 FileSystemType type; |
| 125 FileSystemFileUtil* file_system_file_util; | 122 FileSystemFileUtil* file_util; |
| 126 | 123 |
| 127 if (!VerifyFileSystemPathForWrite( | 124 if (!VerifyFileSystemPathForWrite(path, true /* create */, &origin_url, |
| 128 path, true /* create */, &origin_url, &type, &src_virtual_path_, | 125 &type, &src_virtual_path_, &file_util)) { |
| 129 &file_system_file_util)) { | |
| 130 delete this; | 126 delete this; |
| 131 return; | 127 return; |
| 132 } | 128 } |
| 133 file_system_operation_context_.set_src_origin_url(origin_url); | 129 file_system_operation_context_.set_src_origin_url(origin_url); |
| 134 file_system_operation_context_.set_src_type(type); | 130 file_system_operation_context_.set_src_type(type); |
| 135 if (!file_system_operation_context_.src_file_system_file_util()) | 131 if (!file_system_operation_context_.src_file_util()) |
| 136 file_system_operation_context_.set_src_file_system_file_util( | 132 file_system_operation_context_.set_src_file_util(file_util); |
| 137 file_system_file_util); | |
| 138 exclusive_ = exclusive; | 133 exclusive_ = exclusive; |
| 139 recursive_ = recursive; | 134 recursive_ = recursive; |
| 140 | 135 |
| 141 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( | 136 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( |
| 142 &FileSystemOperation::DelayedCreateDirectoryForQuota)); | 137 &FileSystemOperation::DelayedCreateDirectoryForQuota)); |
| 143 } | 138 } |
| 144 | 139 |
| 145 void FileSystemOperation::DelayedCreateDirectoryForQuota( | 140 void FileSystemOperation::DelayedCreateDirectoryForQuota( |
| 146 quota::QuotaStatusCode status, int64 usage, int64 quota) { | 141 quota::QuotaStatusCode status, int64 usage, int64 quota) { |
| 147 if (file_system_context()->IsStorageUnlimited( | 142 if (file_system_context()->IsStorageUnlimited( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 165 void FileSystemOperation::Copy(const GURL& src_path, | 160 void FileSystemOperation::Copy(const GURL& src_path, |
| 166 const GURL& dest_path) { | 161 const GURL& dest_path) { |
| 167 #ifndef NDEBUG | 162 #ifndef NDEBUG |
| 168 DCHECK(kOperationNone == pending_operation_); | 163 DCHECK(kOperationNone == pending_operation_); |
| 169 pending_operation_ = kOperationCopy; | 164 pending_operation_ = kOperationCopy; |
| 170 #endif | 165 #endif |
| 171 GURL src_origin_url; | 166 GURL src_origin_url; |
| 172 GURL dest_origin_url; | 167 GURL dest_origin_url; |
| 173 FileSystemType src_type; | 168 FileSystemType src_type; |
| 174 FileSystemType dest_type; | 169 FileSystemType dest_type; |
| 175 FileSystemFileUtil* src_file_system_file_util; | 170 FileSystemFileUtil* src_file_util; |
| 176 FileSystemFileUtil* dest_file_system_file_util; | 171 FileSystemFileUtil* dest_file_util; |
| 177 | 172 |
| 178 if (!VerifyFileSystemPathForRead(src_path, &src_origin_url, &src_type, | 173 if (!VerifyFileSystemPathForRead(src_path, &src_origin_url, &src_type, |
| 179 &src_virtual_path_, &src_file_system_file_util) || | 174 &src_virtual_path_, &src_file_util) || |
| 180 !VerifyFileSystemPathForWrite(dest_path, true /* create */, | 175 !VerifyFileSystemPathForWrite(dest_path, true /* create */, |
| 181 &dest_origin_url, &dest_type, &dest_virtual_path_, | 176 &dest_origin_url, &dest_type, &dest_virtual_path_, &dest_file_util)) { |
| 182 &dest_file_system_file_util)) { | |
| 183 delete this; | 177 delete this; |
| 184 return; | 178 return; |
| 185 } | 179 } |
| 186 file_system_operation_context_.set_src_origin_url(src_origin_url); | 180 file_system_operation_context_.set_src_origin_url(src_origin_url); |
| 187 file_system_operation_context_.set_dest_origin_url(dest_origin_url); | 181 file_system_operation_context_.set_dest_origin_url(dest_origin_url); |
| 188 file_system_operation_context_.set_src_type(src_type); | 182 file_system_operation_context_.set_src_type(src_type); |
| 189 file_system_operation_context_.set_dest_type(dest_type); | 183 file_system_operation_context_.set_dest_type(dest_type); |
| 190 if (!file_system_operation_context_.src_file_system_file_util()) | 184 if (!file_system_operation_context_.src_file_util()) |
| 191 file_system_operation_context_.set_src_file_system_file_util( | 185 file_system_operation_context_.set_src_file_util(src_file_util); |
| 192 src_file_system_file_util); | 186 if (!file_system_operation_context_.dest_file_util()) |
| 193 if (!file_system_operation_context_.dest_file_system_file_util()) | 187 file_system_operation_context_.set_dest_file_util(dest_file_util); |
| 194 file_system_operation_context_.set_dest_file_system_file_util( | |
| 195 dest_file_system_file_util); | |
| 196 | 188 |
| 197 GetUsageAndQuotaThenCallback(dest_origin_url, callback_factory_.NewCallback( | 189 GetUsageAndQuotaThenCallback(dest_origin_url, callback_factory_.NewCallback( |
| 198 &FileSystemOperation::DelayedCopyForQuota)); | 190 &FileSystemOperation::DelayedCopyForQuota)); |
| 199 } | 191 } |
| 200 | 192 |
| 201 void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status, | 193 void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status, |
| 202 int64 usage, int64 quota) { | 194 int64 usage, int64 quota) { |
| 203 if (file_system_context()->IsStorageUnlimited( | 195 if (file_system_context()->IsStorageUnlimited( |
| 204 file_system_operation_context()->dest_origin_url()) || | 196 file_system_operation_context()->dest_origin_url()) || |
| 205 quota == QuotaFileUtil::kNoLimit) { | 197 quota == QuotaFileUtil::kNoLimit) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 220 void FileSystemOperation::Move(const GURL& src_path, | 212 void FileSystemOperation::Move(const GURL& src_path, |
| 221 const GURL& dest_path) { | 213 const GURL& dest_path) { |
| 222 #ifndef NDEBUG | 214 #ifndef NDEBUG |
| 223 DCHECK(kOperationNone == pending_operation_); | 215 DCHECK(kOperationNone == pending_operation_); |
| 224 pending_operation_ = kOperationMove; | 216 pending_operation_ = kOperationMove; |
| 225 #endif | 217 #endif |
| 226 GURL src_origin_url; | 218 GURL src_origin_url; |
| 227 GURL dest_origin_url; | 219 GURL dest_origin_url; |
| 228 FileSystemType src_type; | 220 FileSystemType src_type; |
| 229 FileSystemType dest_type; | 221 FileSystemType dest_type; |
| 230 FileSystemFileUtil* src_file_system_file_util; | 222 FileSystemFileUtil* src_file_util; |
| 231 FileSystemFileUtil* dest_file_system_file_util; | 223 FileSystemFileUtil* dest_file_util; |
| 232 | 224 |
| 233 if (!VerifyFileSystemPathForWrite(src_path, false, &src_origin_url, &src_type, | 225 if (!VerifyFileSystemPathForWrite(src_path, false, &src_origin_url, &src_type, |
| 234 &src_virtual_path_, &src_file_system_file_util) || | 226 &src_virtual_path_, &src_file_util) || |
| 235 !VerifyFileSystemPathForWrite(dest_path, true /* create */, | 227 !VerifyFileSystemPathForWrite(dest_path, true /* create */, |
| 236 &dest_origin_url, &dest_type, &dest_virtual_path_, | 228 &dest_origin_url, &dest_type, &dest_virtual_path_, &dest_file_util)) { |
| 237 &dest_file_system_file_util)) { | |
| 238 delete this; | 229 delete this; |
| 239 return; | 230 return; |
| 240 } | 231 } |
| 241 file_system_operation_context_.set_src_origin_url(src_origin_url); | 232 file_system_operation_context_.set_src_origin_url(src_origin_url); |
| 242 file_system_operation_context_.set_dest_origin_url(dest_origin_url); | 233 file_system_operation_context_.set_dest_origin_url(dest_origin_url); |
| 243 file_system_operation_context_.set_src_type(src_type); | 234 file_system_operation_context_.set_src_type(src_type); |
| 244 file_system_operation_context_.set_dest_type(dest_type); | 235 file_system_operation_context_.set_dest_type(dest_type); |
| 245 if (!file_system_operation_context_.src_file_system_file_util()) | 236 if (!file_system_operation_context_.src_file_util()) |
| 246 file_system_operation_context_.set_src_file_system_file_util( | 237 file_system_operation_context_.set_src_file_util(src_file_util); |
| 247 src_file_system_file_util); | 238 if (!file_system_operation_context_.dest_file_util()) |
| 248 if (!file_system_operation_context_.dest_file_system_file_util()) | 239 file_system_operation_context_.set_dest_file_util(dest_file_util); |
| 249 file_system_operation_context_.set_dest_file_system_file_util( | |
| 250 dest_file_system_file_util); | |
| 251 | 240 |
| 252 GetUsageAndQuotaThenCallback(dest_origin_url, callback_factory_.NewCallback( | 241 GetUsageAndQuotaThenCallback(dest_origin_url, callback_factory_.NewCallback( |
| 253 &FileSystemOperation::DelayedMoveForQuota)); | 242 &FileSystemOperation::DelayedMoveForQuota)); |
| 254 } | 243 } |
| 255 | 244 |
| 256 void FileSystemOperation::DelayedMoveForQuota(quota::QuotaStatusCode status, | 245 void FileSystemOperation::DelayedMoveForQuota(quota::QuotaStatusCode status, |
| 257 int64 usage, int64 quota) { | 246 int64 usage, int64 quota) { |
| 258 if (file_system_context()->IsStorageUnlimited( | 247 if (file_system_context()->IsStorageUnlimited( |
| 259 file_system_operation_context()->dest_origin_url()) || | 248 file_system_operation_context()->dest_origin_url()) || |
| 260 quota == QuotaFileUtil::kNoLimit) { | 249 quota == QuotaFileUtil::kNoLimit) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 274 | 263 |
| 275 void FileSystemOperation::DirectoryExists(const GURL& path) { | 264 void FileSystemOperation::DirectoryExists(const GURL& path) { |
| 276 #ifndef NDEBUG | 265 #ifndef NDEBUG |
| 277 DCHECK(kOperationNone == pending_operation_); | 266 DCHECK(kOperationNone == pending_operation_); |
| 278 pending_operation_ = kOperationDirectoryExists; | 267 pending_operation_ = kOperationDirectoryExists; |
| 279 #endif | 268 #endif |
| 280 | 269 |
| 281 FilePath virtual_path; | 270 FilePath virtual_path; |
| 282 GURL origin_url; | 271 GURL origin_url; |
| 283 FileSystemType type; | 272 FileSystemType type; |
| 284 FileSystemFileUtil* file_system_file_util; | 273 FileSystemFileUtil* file_util; |
| 285 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path, | 274 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path, |
| 286 &file_system_file_util)) { | 275 &file_util)) { |
| 287 delete this; | 276 delete this; |
| 288 return; | 277 return; |
| 289 } | 278 } |
| 290 file_system_operation_context_.set_src_origin_url(origin_url); | 279 file_system_operation_context_.set_src_origin_url(origin_url); |
| 291 file_system_operation_context_.set_src_type(type); | 280 file_system_operation_context_.set_src_type(type); |
| 292 if (!file_system_operation_context_.src_file_system_file_util()) | 281 if (!file_system_operation_context_.src_file_util()) |
| 293 file_system_operation_context_.set_src_file_system_file_util( | 282 file_system_operation_context_.set_src_file_util(file_util); |
| 294 file_system_file_util); | |
| 295 FileSystemFileUtilProxy::GetFileInfo( | 283 FileSystemFileUtilProxy::GetFileInfo( |
| 296 file_system_operation_context_, | 284 file_system_operation_context_, |
| 297 proxy_, virtual_path, callback_factory_.NewCallback( | 285 proxy_, virtual_path, callback_factory_.NewCallback( |
| 298 &FileSystemOperation::DidDirectoryExists)); | 286 &FileSystemOperation::DidDirectoryExists)); |
| 299 } | 287 } |
| 300 | 288 |
| 301 void FileSystemOperation::FileExists(const GURL& path) { | 289 void FileSystemOperation::FileExists(const GURL& path) { |
| 302 #ifndef NDEBUG | 290 #ifndef NDEBUG |
| 303 DCHECK(kOperationNone == pending_operation_); | 291 DCHECK(kOperationNone == pending_operation_); |
| 304 pending_operation_ = kOperationFileExists; | 292 pending_operation_ = kOperationFileExists; |
| 305 #endif | 293 #endif |
| 306 | 294 |
| 307 FilePath virtual_path; | 295 FilePath virtual_path; |
| 308 GURL origin_url; | 296 GURL origin_url; |
| 309 FileSystemType type; | 297 FileSystemType type; |
| 310 FileSystemFileUtil* file_system_file_util; | 298 FileSystemFileUtil* file_util; |
| 311 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path, | 299 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path, |
| 312 &file_system_file_util)) { | 300 &file_util)) { |
| 313 delete this; | 301 delete this; |
| 314 return; | 302 return; |
| 315 } | 303 } |
| 316 file_system_operation_context_.set_src_origin_url(origin_url); | 304 file_system_operation_context_.set_src_origin_url(origin_url); |
| 317 file_system_operation_context_.set_src_type(type); | 305 file_system_operation_context_.set_src_type(type); |
| 318 if (!file_system_operation_context_.src_file_system_file_util()) | 306 if (!file_system_operation_context_.src_file_util()) |
| 319 file_system_operation_context_.set_src_file_system_file_util( | 307 file_system_operation_context_.set_src_file_util(file_util); |
| 320 file_system_file_util); | |
| 321 FileSystemFileUtilProxy::GetFileInfo( | 308 FileSystemFileUtilProxy::GetFileInfo( |
| 322 file_system_operation_context_, | 309 file_system_operation_context_, |
| 323 proxy_, virtual_path, callback_factory_.NewCallback( | 310 proxy_, virtual_path, callback_factory_.NewCallback( |
| 324 &FileSystemOperation::DidFileExists)); | 311 &FileSystemOperation::DidFileExists)); |
| 325 } | 312 } |
| 326 | 313 |
| 327 void FileSystemOperation::GetMetadata(const GURL& path) { | 314 void FileSystemOperation::GetMetadata(const GURL& path) { |
| 328 #ifndef NDEBUG | 315 #ifndef NDEBUG |
| 329 DCHECK(kOperationNone == pending_operation_); | 316 DCHECK(kOperationNone == pending_operation_); |
| 330 pending_operation_ = kOperationGetMetadata; | 317 pending_operation_ = kOperationGetMetadata; |
| 331 #endif | 318 #endif |
| 332 | 319 |
| 333 FilePath virtual_path; | 320 FilePath virtual_path; |
| 334 GURL origin_url; | 321 GURL origin_url; |
| 335 FileSystemType type; | 322 FileSystemType type; |
| 336 FileSystemFileUtil* file_system_file_util; | 323 FileSystemFileUtil* file_util; |
| 337 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path, | 324 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path, |
| 338 &file_system_file_util)) { | 325 &file_util)) { |
| 339 delete this; | 326 delete this; |
| 340 return; | 327 return; |
| 341 } | 328 } |
| 342 file_system_operation_context_.set_src_origin_url(origin_url); | 329 file_system_operation_context_.set_src_origin_url(origin_url); |
| 343 file_system_operation_context_.set_src_type(type); | 330 file_system_operation_context_.set_src_type(type); |
| 344 if (!file_system_operation_context_.src_file_system_file_util()) | 331 if (!file_system_operation_context_.src_file_util()) |
| 345 file_system_operation_context_.set_src_file_system_file_util( | 332 file_system_operation_context_.set_src_file_util(file_util); |
| 346 file_system_file_util); | |
| 347 FileSystemFileUtilProxy::GetFileInfo( | 333 FileSystemFileUtilProxy::GetFileInfo( |
| 348 file_system_operation_context_, | 334 file_system_operation_context_, |
| 349 proxy_, virtual_path, callback_factory_.NewCallback( | 335 proxy_, virtual_path, callback_factory_.NewCallback( |
| 350 &FileSystemOperation::DidGetMetadata)); | 336 &FileSystemOperation::DidGetMetadata)); |
| 351 } | 337 } |
| 352 | 338 |
| 353 void FileSystemOperation::ReadDirectory(const GURL& path) { | 339 void FileSystemOperation::ReadDirectory(const GURL& path) { |
| 354 #ifndef NDEBUG | 340 #ifndef NDEBUG |
| 355 DCHECK(kOperationNone == pending_operation_); | 341 DCHECK(kOperationNone == pending_operation_); |
| 356 pending_operation_ = kOperationReadDirectory; | 342 pending_operation_ = kOperationReadDirectory; |
| 357 #endif | 343 #endif |
| 358 | 344 |
| 359 FilePath virtual_path; | 345 FilePath virtual_path; |
| 360 GURL origin_url; | 346 GURL origin_url; |
| 361 FileSystemType type; | 347 FileSystemType type; |
| 362 FileSystemFileUtil* file_system_file_util; | 348 FileSystemFileUtil* file_util; |
| 363 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path, | 349 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path, |
| 364 &file_system_file_util)) { | 350 &file_util)) { |
| 365 delete this; | 351 delete this; |
| 366 return; | 352 return; |
| 367 } | 353 } |
| 368 file_system_operation_context_.set_src_origin_url(origin_url); | 354 file_system_operation_context_.set_src_origin_url(origin_url); |
| 369 file_system_operation_context_.set_src_type(type); | 355 file_system_operation_context_.set_src_type(type); |
| 370 if (!file_system_operation_context_.src_file_system_file_util()) | 356 if (!file_system_operation_context_.src_file_util()) |
| 371 file_system_operation_context_.set_src_file_system_file_util( | 357 file_system_operation_context_.set_src_file_util(file_util); |
| 372 file_system_file_util); | |
| 373 FileSystemFileUtilProxy::ReadDirectory( | 358 FileSystemFileUtilProxy::ReadDirectory( |
| 374 file_system_operation_context_, | 359 file_system_operation_context_, |
| 375 proxy_, virtual_path, callback_factory_.NewCallback( | 360 proxy_, virtual_path, callback_factory_.NewCallback( |
| 376 &FileSystemOperation::DidReadDirectory)); | 361 &FileSystemOperation::DidReadDirectory)); |
| 377 } | 362 } |
| 378 | 363 |
| 379 void FileSystemOperation::Remove(const GURL& path, bool recursive) { | 364 void FileSystemOperation::Remove(const GURL& path, bool recursive) { |
| 380 #ifndef NDEBUG | 365 #ifndef NDEBUG |
| 381 DCHECK(kOperationNone == pending_operation_); | 366 DCHECK(kOperationNone == pending_operation_); |
| 382 pending_operation_ = kOperationRemove; | 367 pending_operation_ = kOperationRemove; |
| 383 #endif | 368 #endif |
| 384 | 369 |
| 385 FilePath virtual_path; | 370 FilePath virtual_path; |
| 386 GURL origin_url; | 371 GURL origin_url; |
| 387 FileSystemType type; | 372 FileSystemType type; |
| 388 FileSystemFileUtil* file_system_file_util; | 373 FileSystemFileUtil* file_util; |
| 389 if (!VerifyFileSystemPathForWrite(path, false /* create */, &origin_url, | 374 if (!VerifyFileSystemPathForWrite(path, false /* create */, &origin_url, |
| 390 &type, &virtual_path, &file_system_file_util)) { | 375 &type, &virtual_path, &file_util)) { |
| 391 delete this; | 376 delete this; |
| 392 return; | 377 return; |
| 393 } | 378 } |
| 394 file_system_operation_context_.set_src_origin_url(origin_url); | 379 file_system_operation_context_.set_src_origin_url(origin_url); |
| 395 file_system_operation_context_.set_src_type(type); | 380 file_system_operation_context_.set_src_type(type); |
| 396 if (!file_system_operation_context_.src_file_system_file_util()) | 381 if (!file_system_operation_context_.src_file_util()) |
| 397 file_system_operation_context_.set_src_file_system_file_util( | 382 file_system_operation_context_.set_src_file_util(file_util); |
| 398 file_system_file_util); | |
| 399 FileSystemFileUtilProxy::Delete( | 383 FileSystemFileUtilProxy::Delete( |
| 400 file_system_operation_context_, | 384 file_system_operation_context_, |
| 401 proxy_, virtual_path, recursive, callback_factory_.NewCallback( | 385 proxy_, virtual_path, recursive, callback_factory_.NewCallback( |
| 402 &FileSystemOperation::DidFinishFileOperation)); | 386 &FileSystemOperation::DidFinishFileOperation)); |
| 403 } | 387 } |
| 404 | 388 |
| 405 void FileSystemOperation::Write( | 389 void FileSystemOperation::Write( |
| 406 scoped_refptr<net::URLRequestContext> url_request_context, | 390 scoped_refptr<net::URLRequestContext> url_request_context, |
| 407 const GURL& path, | 391 const GURL& path, |
| 408 const GURL& blob_url, | 392 const GURL& blob_url, |
| 409 int64 offset) { | 393 int64 offset) { |
| 410 #ifndef NDEBUG | 394 #ifndef NDEBUG |
| 411 DCHECK(kOperationNone == pending_operation_); | 395 DCHECK(kOperationNone == pending_operation_); |
| 412 pending_operation_ = kOperationWrite; | 396 pending_operation_ = kOperationWrite; |
| 413 #endif | 397 #endif |
| 414 GURL origin_url; | 398 GURL origin_url; |
| 415 FileSystemType type; | 399 FileSystemType type; |
| 416 FileSystemFileUtil* file_system_file_util; | 400 FileSystemFileUtil* file_util; |
| 417 if (!VerifyFileSystemPathForWrite(path, true /* create */, &origin_url, | 401 if (!VerifyFileSystemPathForWrite(path, true /* create */, &origin_url, |
| 418 &type, &src_virtual_path_, &file_system_file_util)) { | 402 &type, &src_virtual_path_, &file_util)) { |
| 419 delete this; | 403 delete this; |
| 420 return; | 404 return; |
| 421 } | 405 } |
| 422 file_system_operation_context_.set_src_origin_url(origin_url); | 406 file_system_operation_context_.set_src_origin_url(origin_url); |
| 423 file_system_operation_context_.set_src_type(type); | 407 file_system_operation_context_.set_src_type(type); |
| 424 if (!file_system_operation_context_.src_file_system_file_util()) | 408 if (!file_system_operation_context_.src_file_util()) |
| 425 file_system_operation_context_.set_src_file_system_file_util( | 409 file_system_operation_context_.set_src_file_util(file_util); |
| 426 file_system_file_util); | |
| 427 DCHECK(blob_url.is_valid()); | 410 DCHECK(blob_url.is_valid()); |
| 428 file_writer_delegate_.reset(new FileWriterDelegate(this, offset, proxy_)); | 411 file_writer_delegate_.reset(new FileWriterDelegate(this, offset, proxy_)); |
| 429 blob_request_.reset( | 412 blob_request_.reset( |
| 430 new net::URLRequest(blob_url, file_writer_delegate_.get())); | 413 new net::URLRequest(blob_url, file_writer_delegate_.get())); |
| 431 blob_request_->set_context(url_request_context); | 414 blob_request_->set_context(url_request_context); |
| 432 | 415 |
| 433 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( | 416 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( |
| 434 &FileSystemOperation::DelayedWriteForQuota)); | 417 &FileSystemOperation::DelayedWriteForQuota)); |
| 435 } | 418 } |
| 436 | 419 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 454 &FileSystemOperation::OnFileOpenedForWrite)); | 437 &FileSystemOperation::OnFileOpenedForWrite)); |
| 455 } | 438 } |
| 456 | 439 |
| 457 void FileSystemOperation::Truncate(const GURL& path, int64 length) { | 440 void FileSystemOperation::Truncate(const GURL& path, int64 length) { |
| 458 #ifndef NDEBUG | 441 #ifndef NDEBUG |
| 459 DCHECK(kOperationNone == pending_operation_); | 442 DCHECK(kOperationNone == pending_operation_); |
| 460 pending_operation_ = kOperationTruncate; | 443 pending_operation_ = kOperationTruncate; |
| 461 #endif | 444 #endif |
| 462 GURL origin_url; | 445 GURL origin_url; |
| 463 FileSystemType type; | 446 FileSystemType type; |
| 464 FileSystemFileUtil* file_system_file_util; | 447 FileSystemFileUtil* file_util; |
| 465 if (!VerifyFileSystemPathForWrite(path, false /* create */, &origin_url, | 448 if (!VerifyFileSystemPathForWrite(path, false /* create */, &origin_url, |
| 466 &type, &src_virtual_path_, &file_system_file_util)) { | 449 &type, &src_virtual_path_, &file_util)) { |
| 467 delete this; | 450 delete this; |
| 468 return; | 451 return; |
| 469 } | 452 } |
| 470 file_system_operation_context_.set_src_origin_url(origin_url); | 453 file_system_operation_context_.set_src_origin_url(origin_url); |
| 471 file_system_operation_context_.set_src_type(type); | 454 file_system_operation_context_.set_src_type(type); |
| 472 if (!file_system_operation_context_.src_file_system_file_util()) | 455 if (!file_system_operation_context_.src_file_util()) |
| 473 file_system_operation_context_.set_src_file_system_file_util( | 456 file_system_operation_context_.set_src_file_util(file_util); |
| 474 file_system_file_util); | |
| 475 length_ = length; | 457 length_ = length; |
| 476 | 458 |
| 477 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( | 459 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( |
| 478 &FileSystemOperation::DelayedTruncateForQuota)); | 460 &FileSystemOperation::DelayedTruncateForQuota)); |
| 479 } | 461 } |
| 480 | 462 |
| 481 void FileSystemOperation::DelayedTruncateForQuota(quota::QuotaStatusCode status, | 463 void FileSystemOperation::DelayedTruncateForQuota(quota::QuotaStatusCode status, |
| 482 int64 usage, int64 quota) { | 464 int64 usage, int64 quota) { |
| 483 if (file_system_context()->IsStorageUnlimited( | 465 if (file_system_context()->IsStorageUnlimited( |
| 484 file_system_operation_context()->src_origin_url()) || | 466 file_system_operation_context()->src_origin_url()) || |
| (...skipping 15 matching lines...) Expand all Loading... |
| 500 const base::Time& last_access_time, | 482 const base::Time& last_access_time, |
| 501 const base::Time& last_modified_time) { | 483 const base::Time& last_modified_time) { |
| 502 #ifndef NDEBUG | 484 #ifndef NDEBUG |
| 503 DCHECK(kOperationNone == pending_operation_); | 485 DCHECK(kOperationNone == pending_operation_); |
| 504 pending_operation_ = kOperationTouchFile; | 486 pending_operation_ = kOperationTouchFile; |
| 505 #endif | 487 #endif |
| 506 | 488 |
| 507 FilePath virtual_path; | 489 FilePath virtual_path; |
| 508 GURL origin_url; | 490 GURL origin_url; |
| 509 FileSystemType type; | 491 FileSystemType type; |
| 510 FileSystemFileUtil* file_system_file_util; | 492 FileSystemFileUtil* file_util; |
| 511 if (!VerifyFileSystemPathForWrite(path, true /* create */, &origin_url, | 493 if (!VerifyFileSystemPathForWrite(path, true /* create */, &origin_url, |
| 512 &type, &virtual_path, &file_system_file_util)) { | 494 &type, &virtual_path, &file_util)) { |
| 513 delete this; | 495 delete this; |
| 514 return; | 496 return; |
| 515 } | 497 } |
| 516 file_system_operation_context_.set_src_origin_url(origin_url); | 498 file_system_operation_context_.set_src_origin_url(origin_url); |
| 517 file_system_operation_context_.set_src_type(type); | 499 file_system_operation_context_.set_src_type(type); |
| 518 if (!file_system_operation_context_.src_file_system_file_util()) | 500 if (!file_system_operation_context_.src_file_util()) |
| 519 file_system_operation_context_.set_src_file_system_file_util( | 501 file_system_operation_context_.set_src_file_util(file_util); |
| 520 file_system_file_util); | |
| 521 FileSystemFileUtilProxy::Touch( | 502 FileSystemFileUtilProxy::Touch( |
| 522 file_system_operation_context_, | 503 file_system_operation_context_, |
| 523 proxy_, virtual_path, last_access_time, last_modified_time, | 504 proxy_, virtual_path, last_access_time, last_modified_time, |
| 524 callback_factory_.NewCallback(&FileSystemOperation::DidTouchFile)); | 505 callback_factory_.NewCallback(&FileSystemOperation::DidTouchFile)); |
| 525 } | 506 } |
| 526 | 507 |
| 527 void FileSystemOperation::OpenFile(const GURL& path, | 508 void FileSystemOperation::OpenFile(const GURL& path, |
| 528 int file_flags, | 509 int file_flags, |
| 529 base::ProcessHandle peer_handle) { | 510 base::ProcessHandle peer_handle) { |
| 530 #ifndef NDEBUG | 511 #ifndef NDEBUG |
| 531 DCHECK(kOperationNone == pending_operation_); | 512 DCHECK(kOperationNone == pending_operation_); |
| 532 pending_operation_ = kOperationOpenFile; | 513 pending_operation_ = kOperationOpenFile; |
| 533 #endif | 514 #endif |
| 534 | 515 |
| 535 peer_handle_ = peer_handle; | 516 peer_handle_ = peer_handle; |
| 536 GURL origin_url; | 517 GURL origin_url; |
| 537 FileSystemType type; | 518 FileSystemType type; |
| 538 FileSystemFileUtil* file_system_file_util; | 519 FileSystemFileUtil* file_util; |
| 539 if (file_flags & ( | 520 if (file_flags & ( |
| 540 (base::PLATFORM_FILE_ENUMERATE | base::PLATFORM_FILE_TEMPORARY | | 521 (base::PLATFORM_FILE_ENUMERATE | base::PLATFORM_FILE_TEMPORARY | |
| 541 base::PLATFORM_FILE_HIDDEN))) { | 522 base::PLATFORM_FILE_HIDDEN))) { |
| 542 delete this; | 523 delete this; |
| 543 return; | 524 return; |
| 544 } | 525 } |
| 545 if (file_flags & | 526 if (file_flags & |
| 546 (base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_OPEN_ALWAYS | | 527 (base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_OPEN_ALWAYS | |
| 547 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_TRUNCATED | | 528 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_TRUNCATED | |
| 548 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE | | 529 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE | |
| 549 base::PLATFORM_FILE_DELETE_ON_CLOSE | | 530 base::PLATFORM_FILE_DELETE_ON_CLOSE | |
| 550 base::PLATFORM_FILE_WRITE_ATTRIBUTES)) { | 531 base::PLATFORM_FILE_WRITE_ATTRIBUTES)) { |
| 551 if (!VerifyFileSystemPathForWrite(path, true /* create */, &origin_url, | 532 if (!VerifyFileSystemPathForWrite(path, true /* create */, &origin_url, |
| 552 &type, &src_virtual_path_, &file_system_file_util)) { | 533 &type, &src_virtual_path_, &file_util)) { |
| 553 delete this; | 534 delete this; |
| 554 return; | 535 return; |
| 555 } | 536 } |
| 556 } else { | 537 } else { |
| 557 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, | 538 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, |
| 558 &src_virtual_path_, &file_system_file_util)) { | 539 &src_virtual_path_, &file_util)) { |
| 559 delete this; | 540 delete this; |
| 560 return; | 541 return; |
| 561 } | 542 } |
| 562 } | 543 } |
| 563 file_system_operation_context_.set_src_origin_url(origin_url); | 544 file_system_operation_context_.set_src_origin_url(origin_url); |
| 564 file_system_operation_context_.set_src_type(type); | 545 file_system_operation_context_.set_src_type(type); |
| 565 if (!file_system_operation_context_.src_file_system_file_util()) | 546 if (!file_system_operation_context_.src_file_util()) |
| 566 file_system_operation_context_.set_src_file_system_file_util( | 547 file_system_operation_context_.set_src_file_util(file_util); |
| 567 file_system_file_util); | |
| 568 file_flags_ = file_flags; | 548 file_flags_ = file_flags; |
| 569 | 549 |
| 570 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( | 550 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( |
| 571 &FileSystemOperation::DelayedOpenFileForQuota)); | 551 &FileSystemOperation::DelayedOpenFileForQuota)); |
| 572 } | 552 } |
| 573 | 553 |
| 574 void FileSystemOperation::DelayedOpenFileForQuota(quota::QuotaStatusCode status, | 554 void FileSystemOperation::DelayedOpenFileForQuota(quota::QuotaStatusCode status, |
| 575 int64 usage, int64 quota) { | 555 int64 usage, int64 quota) { |
| 576 if (file_system_context()->IsStorageUnlimited( | 556 if (file_system_context()->IsStorageUnlimited( |
| 577 file_system_operation_context()->dest_origin_url()) || | 557 file_system_operation_context()->dest_origin_url()) || |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 if (base::PLATFORM_FILE_OK != rv) { | 767 if (base::PLATFORM_FILE_OK != rv) { |
| 788 dispatcher_->DidFail(rv); | 768 dispatcher_->DidFail(rv); |
| 789 delete this; | 769 delete this; |
| 790 return; | 770 return; |
| 791 } | 771 } |
| 792 file_writer_delegate_->Start(file.ReleaseValue(), blob_request_.get()); | 772 file_writer_delegate_->Start(file.ReleaseValue(), blob_request_.get()); |
| 793 } | 773 } |
| 794 | 774 |
| 795 bool FileSystemOperation::VerifyFileSystemPathForRead( | 775 bool FileSystemOperation::VerifyFileSystemPathForRead( |
| 796 const GURL& path, GURL* origin_url, FileSystemType* type, | 776 const GURL& path, GURL* origin_url, FileSystemType* type, |
| 797 FilePath* virtual_path, FileSystemFileUtil** file_system_file_util) { | 777 FilePath* virtual_path, FileSystemFileUtil** file_util) { |
| 798 | 778 |
| 799 // If we have no context, we just allow any operations, for testing. | 779 // If we have no context, we just allow any operations, for testing. |
| 800 // TODO(ericu): Revisit this hack for security. | 780 // TODO(ericu): Revisit this hack for security. |
| 801 if (!file_system_context()) { | 781 if (!file_system_context()) { |
| 802 #ifdef OS_WIN | 782 #ifdef OS_WIN |
| 803 // On Windows, the path will look like /C:/foo/bar; we need to remove the | 783 // On Windows, the path will look like /C:/foo/bar; we need to remove the |
| 804 // leading slash to make it valid. But if it's empty, we shouldn't do | 784 // leading slash to make it valid. But if it's empty, we shouldn't do |
| 805 // anything. | 785 // anything. |
| 806 std::string temp = UnescapeURLComponent(path.path(), | 786 std::string temp = UnescapeURLComponent(path.path(), |
| 807 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS); | 787 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS); |
| 808 if (temp.size()) | 788 if (temp.size()) |
| 809 temp = temp.substr(1); | 789 temp = temp.substr(1); |
| 810 *virtual_path = FilePath(UTF8ToWide(temp)).NormalizeWindowsPathSeparators(); | 790 *virtual_path = FilePath(UTF8ToWide(temp)).NormalizeWindowsPathSeparators(); |
| 811 #else | 791 #else |
| 812 *virtual_path = FilePath(path.path()); | 792 *virtual_path = FilePath(path.path()); |
| 813 #endif | 793 #endif |
| 814 *type = file_system_operation_context_.src_type(); | 794 *type = file_system_operation_context_.src_type(); |
| 815 *origin_url = file_system_operation_context_.src_origin_url(); | 795 *origin_url = file_system_operation_context_.src_origin_url(); |
| 816 *file_system_file_util = NULL; | 796 *file_util = NULL; |
| 817 return true; | 797 return true; |
| 818 } | 798 } |
| 819 | 799 |
| 820 // We may want do more checks, but for now it just checks if the given | 800 // We may want do more checks, but for now it just checks if the given |
| 821 // URL is valid. | 801 // URL is valid. |
| 822 if (!CrackFileSystemURL(path, origin_url, type, virtual_path)) { | 802 if (!CrackFileSystemURL(path, origin_url, type, virtual_path)) { |
| 823 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_INVALID_URL); | 803 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_INVALID_URL); |
| 824 return false; | 804 return false; |
| 825 } | 805 } |
| 826 if (!file_system_context()->path_manager()->IsAccessAllowed( | 806 if (!file_system_context()->path_manager()->IsAccessAllowed( |
| 827 *origin_url, *type, *virtual_path)) { | 807 *origin_url, *type, *virtual_path)) { |
| 828 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 808 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
| 829 return false; | 809 return false; |
| 830 } | 810 } |
| 831 DCHECK(file_system_file_util); | 811 DCHECK(file_util); |
| 832 *file_system_file_util = | 812 *file_util = file_system_context()->path_manager()->GetFileUtil(*type); |
| 833 file_system_context()->path_manager()->GetFileSystemFileUtil(*type); | 813 DCHECK(*file_util); |
| 834 DCHECK(*file_system_file_util); | |
| 835 | 814 |
| 836 // We notify this read access whether the read access succeeds or not. | 815 // We notify this read access whether the read access succeeds or not. |
| 837 // This must be ok since this is used to let the QM's eviction logic know | 816 // This must be ok since this is used to let the QM's eviction logic know |
| 838 // someone is interested in reading the origin data and therefore to indicate | 817 // someone is interested in reading the origin data and therefore to indicate |
| 839 // that evicting this origin may not be a good idea. | 818 // that evicting this origin may not be a good idea. |
| 840 FileSystemQuotaUtil* quota_util = file_system_context()->GetQuotaUtil(*type); | 819 FileSystemQuotaUtil* quota_util = file_system_context()->GetQuotaUtil(*type); |
| 841 if (quota_util) { | 820 if (quota_util) { |
| 842 quota_util->NotifyOriginWasAccessedOnIOThread( | 821 quota_util->NotifyOriginWasAccessedOnIOThread( |
| 843 file_system_context()->quota_manager_proxy(), | 822 file_system_context()->quota_manager_proxy(), |
| 844 *origin_url, | 823 *origin_url, |
| 845 *type); | 824 *type); |
| 846 } | 825 } |
| 847 | 826 |
| 848 return true; | 827 return true; |
| 849 } | 828 } |
| 850 | 829 |
| 851 bool FileSystemOperation::VerifyFileSystemPathForWrite( | 830 bool FileSystemOperation::VerifyFileSystemPathForWrite( |
| 852 const GURL& path, bool create, GURL* origin_url, FileSystemType* type, | 831 const GURL& path, bool create, GURL* origin_url, FileSystemType* type, |
| 853 FilePath* virtual_path, FileSystemFileUtil** file_system_file_util) { | 832 FilePath* virtual_path, FileSystemFileUtil** file_util) { |
| 854 | 833 |
| 855 // If we have no context, we just allow any operations, for testing. | 834 // If we have no context, we just allow any operations, for testing. |
| 856 // TODO(ericu): Revisit this hack for security. | 835 // TODO(ericu): Revisit this hack for security. |
| 857 if (!file_system_context()) { | 836 if (!file_system_context()) { |
| 858 #ifdef OS_WIN | 837 #ifdef OS_WIN |
| 859 // On Windows, the path will look like /C:/foo/bar; we need to remove the | 838 // On Windows, the path will look like /C:/foo/bar; we need to remove the |
| 860 // leading slash to make it valid. But if it's empty, we shouldn't do | 839 // leading slash to make it valid. But if it's empty, we shouldn't do |
| 861 // anything. | 840 // anything. |
| 862 std::string temp = UnescapeURLComponent(path.path(), | 841 std::string temp = UnescapeURLComponent(path.path(), |
| 863 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS); | 842 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS); |
| 864 if (temp.size()) | 843 if (temp.size()) |
| 865 temp = temp.substr(1); | 844 temp = temp.substr(1); |
| 866 *virtual_path = FilePath(UTF8ToWide(temp)).NormalizeWindowsPathSeparators(); | 845 *virtual_path = FilePath(UTF8ToWide(temp)).NormalizeWindowsPathSeparators(); |
| 867 #else | 846 #else |
| 868 *virtual_path = FilePath(path.path()); | 847 *virtual_path = FilePath(path.path()); |
| 869 #endif | 848 #endif |
| 870 *type = file_system_operation_context_.dest_type(); | 849 *type = file_system_operation_context_.dest_type(); |
| 871 *origin_url = file_system_operation_context_.dest_origin_url(); | 850 *origin_url = file_system_operation_context_.dest_origin_url(); |
| 872 *file_system_file_util = NULL; | 851 *file_util = NULL; |
| 873 return true; | 852 return true; |
| 874 } | 853 } |
| 875 | 854 |
| 876 if (!CrackFileSystemURL(path, origin_url, type, virtual_path)) { | 855 if (!CrackFileSystemURL(path, origin_url, type, virtual_path)) { |
| 877 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_INVALID_URL); | 856 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_INVALID_URL); |
| 878 return false; | 857 return false; |
| 879 } | 858 } |
| 880 if (!file_system_context()->path_manager()->IsAccessAllowed( | 859 if (!file_system_context()->path_manager()->IsAccessAllowed( |
| 881 *origin_url, *type, *virtual_path)) { | 860 *origin_url, *type, *virtual_path)) { |
| 882 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 861 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
| 883 return false; | 862 return false; |
| 884 } | 863 } |
| 885 // Any write access is disallowed on the root path. | 864 // Any write access is disallowed on the root path. |
| 886 if (virtual_path->value().length() == 0 || | 865 if (virtual_path->value().length() == 0 || |
| 887 virtual_path->DirName().value() == virtual_path->value()) { | 866 virtual_path->DirName().value() == virtual_path->value()) { |
| 888 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 867 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
| 889 return false; | 868 return false; |
| 890 } | 869 } |
| 891 if (create && file_system_context()->path_manager()->IsRestrictedFileName( | 870 if (create && file_system_context()->path_manager()->IsRestrictedFileName( |
| 892 *type, virtual_path->BaseName())) { | 871 *type, virtual_path->BaseName())) { |
| 893 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 872 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
| 894 return false; | 873 return false; |
| 895 } | 874 } |
| 896 DCHECK(file_system_file_util); | 875 DCHECK(file_util); |
| 897 *file_system_file_util = | 876 *file_util = file_system_context()->path_manager()->GetFileUtil(*type); |
| 898 file_system_context()->path_manager()->GetFileSystemFileUtil(*type); | 877 DCHECK(*file_util); |
| 899 DCHECK(*file_system_file_util); | |
| 900 | 878 |
| 901 return true; | 879 return true; |
| 902 } | 880 } |
| 903 | 881 |
| 904 } // namespace fileapi | 882 } // namespace fileapi |
| OLD | NEW |