| 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 class FileSystemOperation::ScopedQuotaUtilHelper { | 26 class FileSystemOperation::ScopedQuotaUtilHelper { |
| 27 public: | 27 public: |
| 28 ScopedQuotaUtilHelper(FileSystemContext* context, | 28 ScopedQuotaUtilHelper(FileSystemContext* context, |
| 29 const GURL& origin_url, | 29 const GURL& origin_url, |
| 30 FileSystemType type); | 30 FileSystemType type); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 53 if (quota_util_) { | 53 if (quota_util_) { |
| 54 DCHECK(quota_util_->proxy()); | 54 DCHECK(quota_util_->proxy()); |
| 55 quota_util_->proxy()->EndUpdateOrigin(origin_url_, type_); | 55 quota_util_->proxy()->EndUpdateOrigin(origin_url_, type_); |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 FileSystemOperation::FileSystemOperation( | 59 FileSystemOperation::FileSystemOperation( |
| 60 FileSystemCallbackDispatcher* dispatcher, | 60 FileSystemCallbackDispatcher* dispatcher, |
| 61 scoped_refptr<base::MessageLoopProxy> proxy, | 61 scoped_refptr<base::MessageLoopProxy> proxy, |
| 62 FileSystemContext* file_system_context, | 62 FileSystemContext* file_system_context, |
| 63 FileSystemFileUtil* file_system_file_util) | 63 FileSystemFileUtil* file_util) |
| 64 : proxy_(proxy), | 64 : proxy_(proxy), |
| 65 dispatcher_(dispatcher), | 65 dispatcher_(dispatcher), |
| 66 file_system_operation_context_( | 66 file_system_operation_context_(file_system_context, file_util), |
| 67 file_system_context, file_system_file_util), | |
| 68 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 67 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 69 DCHECK(dispatcher); | 68 DCHECK(dispatcher); |
| 70 #ifndef NDEBUG | 69 #ifndef NDEBUG |
| 71 pending_operation_ = kOperationNone; | 70 pending_operation_ = kOperationNone; |
| 72 #endif | 71 #endif |
| 73 } | 72 } |
| 74 | 73 |
| 75 FileSystemOperation::~FileSystemOperation() { | 74 FileSystemOperation::~FileSystemOperation() { |
| 76 if (file_writer_delegate_.get()) | 75 if (file_writer_delegate_.get()) |
| 77 FileSystemFileUtilProxy::Close( | 76 FileSystemFileUtilProxy::Close( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 102 } | 101 } |
| 103 | 102 |
| 104 void FileSystemOperation::CreateFile(const GURL& path, | 103 void FileSystemOperation::CreateFile(const GURL& path, |
| 105 bool exclusive) { | 104 bool exclusive) { |
| 106 #ifndef NDEBUG | 105 #ifndef NDEBUG |
| 107 DCHECK(kOperationNone == pending_operation_); | 106 DCHECK(kOperationNone == pending_operation_); |
| 108 pending_operation_ = kOperationCreateFile; | 107 pending_operation_ = kOperationCreateFile; |
| 109 #endif | 108 #endif |
| 110 GURL origin_url; | 109 GURL origin_url; |
| 111 FileSystemType type; | 110 FileSystemType type; |
| 112 FileSystemFileUtil* file_system_file_util; | 111 FileSystemFileUtil* file_util; |
| 113 if (!VerifyFileSystemPathForWrite( | 112 if (!VerifyFileSystemPathForWrite(path, true /* create */, &origin_url, |
| 114 path, true /* create */, &origin_url, &type, &src_virtual_path_, | 113 &type, &src_virtual_path_, &file_util)) { |
| 115 &file_system_file_util)) { | |
| 116 delete this; | 114 delete this; |
| 117 return; | 115 return; |
| 118 } | 116 } |
| 119 file_system_operation_context_.set_src_origin_url(origin_url); | 117 file_system_operation_context_.set_src_origin_url(origin_url); |
| 120 file_system_operation_context_.set_src_type(type); | 118 file_system_operation_context_.set_src_type(type); |
| 121 if (!file_system_operation_context_.src_file_system_file_util()) | 119 if (!file_system_operation_context_.src_file_util()) |
| 122 file_system_operation_context_.set_src_file_system_file_util( | 120 file_system_operation_context_.set_src_file_util(file_util); |
| 123 file_system_file_util); | |
| 124 exclusive_ = exclusive; | 121 exclusive_ = exclusive; |
| 125 | 122 |
| 126 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( | 123 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( |
| 127 &FileSystemOperation::DelayedCreateFileForQuota)); | 124 &FileSystemOperation::DelayedCreateFileForQuota)); |
| 128 } | 125 } |
| 129 | 126 |
| 130 void FileSystemOperation::DelayedCreateFileForQuota( | 127 void FileSystemOperation::DelayedCreateFileForQuota( |
| 131 quota::QuotaStatusCode status, int64 usage, int64 quota) { | 128 quota::QuotaStatusCode status, int64 usage, int64 quota) { |
| 132 if (file_system_context()->IsStorageUnlimited( | 129 if (file_system_context()->IsStorageUnlimited( |
| 133 file_system_operation_context()->src_origin_url()) || | 130 file_system_operation_context()->src_origin_url()) || |
| (...skipping 20 matching lines...) Expand all Loading... |
| 154 | 151 |
| 155 void FileSystemOperation::CreateDirectory(const GURL& path, | 152 void FileSystemOperation::CreateDirectory(const GURL& path, |
| 156 bool exclusive, | 153 bool exclusive, |
| 157 bool recursive) { | 154 bool recursive) { |
| 158 #ifndef NDEBUG | 155 #ifndef NDEBUG |
| 159 DCHECK(kOperationNone == pending_operation_); | 156 DCHECK(kOperationNone == pending_operation_); |
| 160 pending_operation_ = kOperationCreateDirectory; | 157 pending_operation_ = kOperationCreateDirectory; |
| 161 #endif | 158 #endif |
| 162 GURL origin_url; | 159 GURL origin_url; |
| 163 FileSystemType type; | 160 FileSystemType type; |
| 164 FileSystemFileUtil* file_system_file_util; | 161 FileSystemFileUtil* file_util; |
| 165 | 162 |
| 166 if (!VerifyFileSystemPathForWrite( | 163 if (!VerifyFileSystemPathForWrite(path, true /* create */, &origin_url, |
| 167 path, true /* create */, &origin_url, &type, &src_virtual_path_, | 164 &type, &src_virtual_path_, &file_util)) { |
| 168 &file_system_file_util)) { | |
| 169 delete this; | 165 delete this; |
| 170 return; | 166 return; |
| 171 } | 167 } |
| 172 file_system_operation_context_.set_src_origin_url(origin_url); | 168 file_system_operation_context_.set_src_origin_url(origin_url); |
| 173 file_system_operation_context_.set_src_type(type); | 169 file_system_operation_context_.set_src_type(type); |
| 174 if (!file_system_operation_context_.src_file_system_file_util()) | 170 if (!file_system_operation_context_.src_file_util()) |
| 175 file_system_operation_context_.set_src_file_system_file_util( | 171 file_system_operation_context_.set_src_file_util(file_util); |
| 176 file_system_file_util); | |
| 177 exclusive_ = exclusive; | 172 exclusive_ = exclusive; |
| 178 recursive_ = recursive; | 173 recursive_ = recursive; |
| 179 | 174 |
| 180 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( | 175 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( |
| 181 &FileSystemOperation::DelayedCreateDirectoryForQuota)); | 176 &FileSystemOperation::DelayedCreateDirectoryForQuota)); |
| 182 } | 177 } |
| 183 | 178 |
| 184 void FileSystemOperation::DelayedCreateDirectoryForQuota( | 179 void FileSystemOperation::DelayedCreateDirectoryForQuota( |
| 185 quota::QuotaStatusCode status, int64 usage, int64 quota) { | 180 quota::QuotaStatusCode status, int64 usage, int64 quota) { |
| 186 if (file_system_context()->IsStorageUnlimited( | 181 if (file_system_context()->IsStorageUnlimited( |
| (...skipping 23 matching lines...) Expand all Loading... |
| 210 void FileSystemOperation::Copy(const GURL& src_path, | 205 void FileSystemOperation::Copy(const GURL& src_path, |
| 211 const GURL& dest_path) { | 206 const GURL& dest_path) { |
| 212 #ifndef NDEBUG | 207 #ifndef NDEBUG |
| 213 DCHECK(kOperationNone == pending_operation_); | 208 DCHECK(kOperationNone == pending_operation_); |
| 214 pending_operation_ = kOperationCopy; | 209 pending_operation_ = kOperationCopy; |
| 215 #endif | 210 #endif |
| 216 GURL src_origin_url; | 211 GURL src_origin_url; |
| 217 GURL dest_origin_url; | 212 GURL dest_origin_url; |
| 218 FileSystemType src_type; | 213 FileSystemType src_type; |
| 219 FileSystemType dest_type; | 214 FileSystemType dest_type; |
| 220 FileSystemFileUtil* src_file_system_file_util; | 215 FileSystemFileUtil* src_file_util; |
| 221 FileSystemFileUtil* dest_file_system_file_util; | 216 FileSystemFileUtil* dest_file_util; |
| 222 | 217 |
| 223 if (!VerifyFileSystemPathForRead(src_path, &src_origin_url, &src_type, | 218 if (!VerifyFileSystemPathForRead(src_path, &src_origin_url, &src_type, |
| 224 &src_virtual_path_, &src_file_system_file_util) || | 219 &src_virtual_path_, &src_file_util) || |
| 225 !VerifyFileSystemPathForWrite(dest_path, true /* create */, | 220 !VerifyFileSystemPathForWrite(dest_path, true /* create */, |
| 226 &dest_origin_url, &dest_type, &dest_virtual_path_, | 221 &dest_origin_url, &dest_type, &dest_virtual_path_, &dest_file_util)) { |
| 227 &dest_file_system_file_util)) { | |
| 228 delete this; | 222 delete this; |
| 229 return; | 223 return; |
| 230 } | 224 } |
| 231 file_system_operation_context_.set_src_origin_url(src_origin_url); | 225 file_system_operation_context_.set_src_origin_url(src_origin_url); |
| 232 file_system_operation_context_.set_dest_origin_url(dest_origin_url); | 226 file_system_operation_context_.set_dest_origin_url(dest_origin_url); |
| 233 file_system_operation_context_.set_src_type(src_type); | 227 file_system_operation_context_.set_src_type(src_type); |
| 234 file_system_operation_context_.set_dest_type(dest_type); | 228 file_system_operation_context_.set_dest_type(dest_type); |
| 235 if (!file_system_operation_context_.src_file_system_file_util()) | 229 if (!file_system_operation_context_.src_file_util()) |
| 236 file_system_operation_context_.set_src_file_system_file_util( | 230 file_system_operation_context_.set_src_file_util(src_file_util); |
| 237 src_file_system_file_util); | 231 if (!file_system_operation_context_.dest_file_util()) |
| 238 if (!file_system_operation_context_.dest_file_system_file_util()) | 232 file_system_operation_context_.set_dest_file_util(dest_file_util); |
| 239 file_system_operation_context_.set_dest_file_system_file_util( | |
| 240 dest_file_system_file_util); | |
| 241 | 233 |
| 242 GetUsageAndQuotaThenCallback(dest_origin_url, callback_factory_.NewCallback( | 234 GetUsageAndQuotaThenCallback(dest_origin_url, callback_factory_.NewCallback( |
| 243 &FileSystemOperation::DelayedCopyForQuota)); | 235 &FileSystemOperation::DelayedCopyForQuota)); |
| 244 } | 236 } |
| 245 | 237 |
| 246 void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status, | 238 void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status, |
| 247 int64 usage, int64 quota) { | 239 int64 usage, int64 quota) { |
| 248 if (file_system_context()->IsStorageUnlimited( | 240 if (file_system_context()->IsStorageUnlimited( |
| 249 file_system_operation_context()->dest_origin_url()) || | 241 file_system_operation_context()->dest_origin_url()) || |
| 250 quota == QuotaFileUtil::kNoLimit) { | 242 quota == QuotaFileUtil::kNoLimit) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 271 void FileSystemOperation::Move(const GURL& src_path, | 263 void FileSystemOperation::Move(const GURL& src_path, |
| 272 const GURL& dest_path) { | 264 const GURL& dest_path) { |
| 273 #ifndef NDEBUG | 265 #ifndef NDEBUG |
| 274 DCHECK(kOperationNone == pending_operation_); | 266 DCHECK(kOperationNone == pending_operation_); |
| 275 pending_operation_ = kOperationMove; | 267 pending_operation_ = kOperationMove; |
| 276 #endif | 268 #endif |
| 277 GURL src_origin_url; | 269 GURL src_origin_url; |
| 278 GURL dest_origin_url; | 270 GURL dest_origin_url; |
| 279 FileSystemType src_type; | 271 FileSystemType src_type; |
| 280 FileSystemType dest_type; | 272 FileSystemType dest_type; |
| 281 FileSystemFileUtil* src_file_system_file_util; | 273 FileSystemFileUtil* src_file_util; |
| 282 FileSystemFileUtil* dest_file_system_file_util; | 274 FileSystemFileUtil* dest_file_util; |
| 283 | 275 |
| 284 if (!VerifyFileSystemPathForWrite(src_path, false, &src_origin_url, &src_type, | 276 if (!VerifyFileSystemPathForWrite(src_path, false, &src_origin_url, &src_type, |
| 285 &src_virtual_path_, &src_file_system_file_util) || | 277 &src_virtual_path_, &src_file_util) || |
| 286 !VerifyFileSystemPathForWrite(dest_path, true /* create */, | 278 !VerifyFileSystemPathForWrite(dest_path, true /* create */, |
| 287 &dest_origin_url, &dest_type, &dest_virtual_path_, | 279 &dest_origin_url, &dest_type, &dest_virtual_path_, &dest_file_util)) { |
| 288 &dest_file_system_file_util)) { | |
| 289 delete this; | 280 delete this; |
| 290 return; | 281 return; |
| 291 } | 282 } |
| 292 file_system_operation_context_.set_src_origin_url(src_origin_url); | 283 file_system_operation_context_.set_src_origin_url(src_origin_url); |
| 293 file_system_operation_context_.set_dest_origin_url(dest_origin_url); | 284 file_system_operation_context_.set_dest_origin_url(dest_origin_url); |
| 294 file_system_operation_context_.set_src_type(src_type); | 285 file_system_operation_context_.set_src_type(src_type); |
| 295 file_system_operation_context_.set_dest_type(dest_type); | 286 file_system_operation_context_.set_dest_type(dest_type); |
| 296 if (!file_system_operation_context_.src_file_system_file_util()) | 287 if (!file_system_operation_context_.src_file_util()) |
| 297 file_system_operation_context_.set_src_file_system_file_util( | 288 file_system_operation_context_.set_src_file_util(src_file_util); |
| 298 src_file_system_file_util); | 289 if (!file_system_operation_context_.dest_file_util()) |
| 299 if (!file_system_operation_context_.dest_file_system_file_util()) | 290 file_system_operation_context_.set_dest_file_util(dest_file_util); |
| 300 file_system_operation_context_.set_dest_file_system_file_util( | |
| 301 dest_file_system_file_util); | |
| 302 | 291 |
| 303 GetUsageAndQuotaThenCallback(dest_origin_url, callback_factory_.NewCallback( | 292 GetUsageAndQuotaThenCallback(dest_origin_url, callback_factory_.NewCallback( |
| 304 &FileSystemOperation::DelayedMoveForQuota)); | 293 &FileSystemOperation::DelayedMoveForQuota)); |
| 305 } | 294 } |
| 306 | 295 |
| 307 void FileSystemOperation::DelayedMoveForQuota(quota::QuotaStatusCode status, | 296 void FileSystemOperation::DelayedMoveForQuota(quota::QuotaStatusCode status, |
| 308 int64 usage, int64 quota) { | 297 int64 usage, int64 quota) { |
| 309 if (file_system_context()->IsStorageUnlimited( | 298 if (file_system_context()->IsStorageUnlimited( |
| 310 file_system_operation_context()->dest_origin_url()) || | 299 file_system_operation_context()->dest_origin_url()) || |
| 311 quota == QuotaFileUtil::kNoLimit) { | 300 quota == QuotaFileUtil::kNoLimit) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 331 | 320 |
| 332 void FileSystemOperation::DirectoryExists(const GURL& path) { | 321 void FileSystemOperation::DirectoryExists(const GURL& path) { |
| 333 #ifndef NDEBUG | 322 #ifndef NDEBUG |
| 334 DCHECK(kOperationNone == pending_operation_); | 323 DCHECK(kOperationNone == pending_operation_); |
| 335 pending_operation_ = kOperationDirectoryExists; | 324 pending_operation_ = kOperationDirectoryExists; |
| 336 #endif | 325 #endif |
| 337 | 326 |
| 338 FilePath virtual_path; | 327 FilePath virtual_path; |
| 339 GURL origin_url; | 328 GURL origin_url; |
| 340 FileSystemType type; | 329 FileSystemType type; |
| 341 FileSystemFileUtil* file_system_file_util; | 330 FileSystemFileUtil* file_util; |
| 342 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path, | 331 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path, |
| 343 &file_system_file_util)) { | 332 &file_util)) { |
| 344 delete this; | 333 delete this; |
| 345 return; | 334 return; |
| 346 } | 335 } |
| 347 file_system_operation_context_.set_src_origin_url(origin_url); | 336 file_system_operation_context_.set_src_origin_url(origin_url); |
| 348 file_system_operation_context_.set_src_type(type); | 337 file_system_operation_context_.set_src_type(type); |
| 349 if (!file_system_operation_context_.src_file_system_file_util()) | 338 if (!file_system_operation_context_.src_file_util()) |
| 350 file_system_operation_context_.set_src_file_system_file_util( | 339 file_system_operation_context_.set_src_file_util(file_util); |
| 351 file_system_file_util); | |
| 352 FileSystemFileUtilProxy::GetFileInfo( | 340 FileSystemFileUtilProxy::GetFileInfo( |
| 353 file_system_operation_context_, | 341 file_system_operation_context_, |
| 354 proxy_, virtual_path, callback_factory_.NewCallback( | 342 proxy_, virtual_path, callback_factory_.NewCallback( |
| 355 &FileSystemOperation::DidDirectoryExists)); | 343 &FileSystemOperation::DidDirectoryExists)); |
| 356 } | 344 } |
| 357 | 345 |
| 358 void FileSystemOperation::FileExists(const GURL& path) { | 346 void FileSystemOperation::FileExists(const GURL& path) { |
| 359 #ifndef NDEBUG | 347 #ifndef NDEBUG |
| 360 DCHECK(kOperationNone == pending_operation_); | 348 DCHECK(kOperationNone == pending_operation_); |
| 361 pending_operation_ = kOperationFileExists; | 349 pending_operation_ = kOperationFileExists; |
| 362 #endif | 350 #endif |
| 363 | 351 |
| 364 FilePath virtual_path; | 352 FilePath virtual_path; |
| 365 GURL origin_url; | 353 GURL origin_url; |
| 366 FileSystemType type; | 354 FileSystemType type; |
| 367 FileSystemFileUtil* file_system_file_util; | 355 FileSystemFileUtil* file_util; |
| 368 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path, | 356 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path, |
| 369 &file_system_file_util)) { | 357 &file_util)) { |
| 370 delete this; | 358 delete this; |
| 371 return; | 359 return; |
| 372 } | 360 } |
| 373 file_system_operation_context_.set_src_origin_url(origin_url); | 361 file_system_operation_context_.set_src_origin_url(origin_url); |
| 374 file_system_operation_context_.set_src_type(type); | 362 file_system_operation_context_.set_src_type(type); |
| 375 if (!file_system_operation_context_.src_file_system_file_util()) | 363 if (!file_system_operation_context_.src_file_util()) |
| 376 file_system_operation_context_.set_src_file_system_file_util( | 364 file_system_operation_context_.set_src_file_util(file_util); |
| 377 file_system_file_util); | |
| 378 FileSystemFileUtilProxy::GetFileInfo( | 365 FileSystemFileUtilProxy::GetFileInfo( |
| 379 file_system_operation_context_, | 366 file_system_operation_context_, |
| 380 proxy_, virtual_path, callback_factory_.NewCallback( | 367 proxy_, virtual_path, callback_factory_.NewCallback( |
| 381 &FileSystemOperation::DidFileExists)); | 368 &FileSystemOperation::DidFileExists)); |
| 382 } | 369 } |
| 383 | 370 |
| 384 void FileSystemOperation::GetMetadata(const GURL& path) { | 371 void FileSystemOperation::GetMetadata(const GURL& path) { |
| 385 #ifndef NDEBUG | 372 #ifndef NDEBUG |
| 386 DCHECK(kOperationNone == pending_operation_); | 373 DCHECK(kOperationNone == pending_operation_); |
| 387 pending_operation_ = kOperationGetMetadata; | 374 pending_operation_ = kOperationGetMetadata; |
| 388 #endif | 375 #endif |
| 389 | 376 |
| 390 FilePath virtual_path; | 377 FilePath virtual_path; |
| 391 GURL origin_url; | 378 GURL origin_url; |
| 392 FileSystemType type; | 379 FileSystemType type; |
| 393 FileSystemFileUtil* file_system_file_util; | 380 FileSystemFileUtil* file_util; |
| 394 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path, | 381 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path, |
| 395 &file_system_file_util)) { | 382 &file_util)) { |
| 396 delete this; | 383 delete this; |
| 397 return; | 384 return; |
| 398 } | 385 } |
| 399 file_system_operation_context_.set_src_origin_url(origin_url); | 386 file_system_operation_context_.set_src_origin_url(origin_url); |
| 400 file_system_operation_context_.set_src_type(type); | 387 file_system_operation_context_.set_src_type(type); |
| 401 if (!file_system_operation_context_.src_file_system_file_util()) | 388 if (!file_system_operation_context_.src_file_util()) |
| 402 file_system_operation_context_.set_src_file_system_file_util( | 389 file_system_operation_context_.set_src_file_util(file_util); |
| 403 file_system_file_util); | |
| 404 FileSystemFileUtilProxy::GetFileInfo( | 390 FileSystemFileUtilProxy::GetFileInfo( |
| 405 file_system_operation_context_, | 391 file_system_operation_context_, |
| 406 proxy_, virtual_path, callback_factory_.NewCallback( | 392 proxy_, virtual_path, callback_factory_.NewCallback( |
| 407 &FileSystemOperation::DidGetMetadata)); | 393 &FileSystemOperation::DidGetMetadata)); |
| 408 } | 394 } |
| 409 | 395 |
| 410 void FileSystemOperation::ReadDirectory(const GURL& path) { | 396 void FileSystemOperation::ReadDirectory(const GURL& path) { |
| 411 #ifndef NDEBUG | 397 #ifndef NDEBUG |
| 412 DCHECK(kOperationNone == pending_operation_); | 398 DCHECK(kOperationNone == pending_operation_); |
| 413 pending_operation_ = kOperationReadDirectory; | 399 pending_operation_ = kOperationReadDirectory; |
| 414 #endif | 400 #endif |
| 415 | 401 |
| 416 FilePath virtual_path; | 402 FilePath virtual_path; |
| 417 GURL origin_url; | 403 GURL origin_url; |
| 418 FileSystemType type; | 404 FileSystemType type; |
| 419 FileSystemFileUtil* file_system_file_util; | 405 FileSystemFileUtil* file_util; |
| 420 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path, | 406 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path, |
| 421 &file_system_file_util)) { | 407 &file_util)) { |
| 422 delete this; | 408 delete this; |
| 423 return; | 409 return; |
| 424 } | 410 } |
| 425 file_system_operation_context_.set_src_origin_url(origin_url); | 411 file_system_operation_context_.set_src_origin_url(origin_url); |
| 426 file_system_operation_context_.set_src_type(type); | 412 file_system_operation_context_.set_src_type(type); |
| 427 if (!file_system_operation_context_.src_file_system_file_util()) | 413 if (!file_system_operation_context_.src_file_util()) |
| 428 file_system_operation_context_.set_src_file_system_file_util( | 414 file_system_operation_context_.set_src_file_util(file_util); |
| 429 file_system_file_util); | |
| 430 FileSystemFileUtilProxy::ReadDirectory( | 415 FileSystemFileUtilProxy::ReadDirectory( |
| 431 file_system_operation_context_, | 416 file_system_operation_context_, |
| 432 proxy_, virtual_path, callback_factory_.NewCallback( | 417 proxy_, virtual_path, callback_factory_.NewCallback( |
| 433 &FileSystemOperation::DidReadDirectory)); | 418 &FileSystemOperation::DidReadDirectory)); |
| 434 } | 419 } |
| 435 | 420 |
| 436 void FileSystemOperation::Remove(const GURL& path, bool recursive) { | 421 void FileSystemOperation::Remove(const GURL& path, bool recursive) { |
| 437 #ifndef NDEBUG | 422 #ifndef NDEBUG |
| 438 DCHECK(kOperationNone == pending_operation_); | 423 DCHECK(kOperationNone == pending_operation_); |
| 439 pending_operation_ = kOperationRemove; | 424 pending_operation_ = kOperationRemove; |
| 440 #endif | 425 #endif |
| 441 | 426 |
| 442 FilePath virtual_path; | 427 FilePath virtual_path; |
| 443 GURL origin_url; | 428 GURL origin_url; |
| 444 FileSystemType type; | 429 FileSystemType type; |
| 445 FileSystemFileUtil* file_system_file_util; | 430 FileSystemFileUtil* file_util; |
| 446 if (!VerifyFileSystemPathForWrite(path, false /* create */, &origin_url, | 431 if (!VerifyFileSystemPathForWrite(path, false /* create */, &origin_url, |
| 447 &type, &virtual_path, &file_system_file_util)) { | 432 &type, &virtual_path, &file_util)) { |
| 448 delete this; | 433 delete this; |
| 449 return; | 434 return; |
| 450 } | 435 } |
| 451 file_system_operation_context_.set_src_origin_url(origin_url); | 436 file_system_operation_context_.set_src_origin_url(origin_url); |
| 452 file_system_operation_context_.set_src_type(type); | 437 file_system_operation_context_.set_src_type(type); |
| 453 if (!file_system_operation_context_.src_file_system_file_util()) | 438 if (!file_system_operation_context_.src_file_util()) |
| 454 file_system_operation_context_.set_src_file_system_file_util( | 439 file_system_operation_context_.set_src_file_util(file_util); |
| 455 file_system_file_util); | |
| 456 FileSystemFileUtilProxy::Delete( | 440 FileSystemFileUtilProxy::Delete( |
| 457 file_system_operation_context_, | 441 file_system_operation_context_, |
| 458 proxy_, virtual_path, recursive, callback_factory_.NewCallback( | 442 proxy_, virtual_path, recursive, callback_factory_.NewCallback( |
| 459 &FileSystemOperation::DidFinishFileOperation)); | 443 &FileSystemOperation::DidFinishFileOperation)); |
| 460 } | 444 } |
| 461 | 445 |
| 462 void FileSystemOperation::Write( | 446 void FileSystemOperation::Write( |
| 463 scoped_refptr<net::URLRequestContext> url_request_context, | 447 scoped_refptr<net::URLRequestContext> url_request_context, |
| 464 const GURL& path, | 448 const GURL& path, |
| 465 const GURL& blob_url, | 449 const GURL& blob_url, |
| 466 int64 offset) { | 450 int64 offset) { |
| 467 #ifndef NDEBUG | 451 #ifndef NDEBUG |
| 468 DCHECK(kOperationNone == pending_operation_); | 452 DCHECK(kOperationNone == pending_operation_); |
| 469 pending_operation_ = kOperationWrite; | 453 pending_operation_ = kOperationWrite; |
| 470 #endif | 454 #endif |
| 471 GURL origin_url; | 455 GURL origin_url; |
| 472 FileSystemType type; | 456 FileSystemType type; |
| 473 FileSystemFileUtil* file_system_file_util; | 457 FileSystemFileUtil* file_util; |
| 474 if (!VerifyFileSystemPathForWrite(path, true /* create */, &origin_url, | 458 if (!VerifyFileSystemPathForWrite(path, true /* create */, &origin_url, |
| 475 &type, &src_virtual_path_, &file_system_file_util)) { | 459 &type, &src_virtual_path_, &file_util)) { |
| 476 delete this; | 460 delete this; |
| 477 return; | 461 return; |
| 478 } | 462 } |
| 479 file_system_operation_context_.set_src_origin_url(origin_url); | 463 file_system_operation_context_.set_src_origin_url(origin_url); |
| 480 file_system_operation_context_.set_src_type(type); | 464 file_system_operation_context_.set_src_type(type); |
| 481 if (!file_system_operation_context_.src_file_system_file_util()) | 465 if (!file_system_operation_context_.src_file_util()) |
| 482 file_system_operation_context_.set_src_file_system_file_util( | 466 file_system_operation_context_.set_src_file_util(file_util); |
| 483 file_system_file_util); | |
| 484 DCHECK(blob_url.is_valid()); | 467 DCHECK(blob_url.is_valid()); |
| 485 file_writer_delegate_.reset(new FileWriterDelegate(this, offset, proxy_)); | 468 file_writer_delegate_.reset(new FileWriterDelegate(this, offset, proxy_)); |
| 486 blob_request_.reset( | 469 blob_request_.reset( |
| 487 new net::URLRequest(blob_url, file_writer_delegate_.get())); | 470 new net::URLRequest(blob_url, file_writer_delegate_.get())); |
| 488 blob_request_->set_context(url_request_context); | 471 blob_request_->set_context(url_request_context); |
| 489 | 472 |
| 490 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( | 473 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( |
| 491 &FileSystemOperation::DelayedWriteForQuota)); | 474 &FileSystemOperation::DelayedWriteForQuota)); |
| 492 } | 475 } |
| 493 | 476 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 517 &FileSystemOperation::OnFileOpenedForWrite)); | 500 &FileSystemOperation::OnFileOpenedForWrite)); |
| 518 } | 501 } |
| 519 | 502 |
| 520 void FileSystemOperation::Truncate(const GURL& path, int64 length) { | 503 void FileSystemOperation::Truncate(const GURL& path, int64 length) { |
| 521 #ifndef NDEBUG | 504 #ifndef NDEBUG |
| 522 DCHECK(kOperationNone == pending_operation_); | 505 DCHECK(kOperationNone == pending_operation_); |
| 523 pending_operation_ = kOperationTruncate; | 506 pending_operation_ = kOperationTruncate; |
| 524 #endif | 507 #endif |
| 525 GURL origin_url; | 508 GURL origin_url; |
| 526 FileSystemType type; | 509 FileSystemType type; |
| 527 FileSystemFileUtil* file_system_file_util; | 510 FileSystemFileUtil* file_util; |
| 528 if (!VerifyFileSystemPathForWrite(path, false /* create */, &origin_url, | 511 if (!VerifyFileSystemPathForWrite(path, false /* create */, &origin_url, |
| 529 &type, &src_virtual_path_, &file_system_file_util)) { | 512 &type, &src_virtual_path_, &file_util)) { |
| 530 delete this; | 513 delete this; |
| 531 return; | 514 return; |
| 532 } | 515 } |
| 533 file_system_operation_context_.set_src_origin_url(origin_url); | 516 file_system_operation_context_.set_src_origin_url(origin_url); |
| 534 file_system_operation_context_.set_src_type(type); | 517 file_system_operation_context_.set_src_type(type); |
| 535 if (!file_system_operation_context_.src_file_system_file_util()) | 518 if (!file_system_operation_context_.src_file_util()) |
| 536 file_system_operation_context_.set_src_file_system_file_util( | 519 file_system_operation_context_.set_src_file_util(file_util); |
| 537 file_system_file_util); | |
| 538 length_ = length; | 520 length_ = length; |
| 539 | 521 |
| 540 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( | 522 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( |
| 541 &FileSystemOperation::DelayedTruncateForQuota)); | 523 &FileSystemOperation::DelayedTruncateForQuota)); |
| 542 } | 524 } |
| 543 | 525 |
| 544 void FileSystemOperation::DelayedTruncateForQuota(quota::QuotaStatusCode status, | 526 void FileSystemOperation::DelayedTruncateForQuota(quota::QuotaStatusCode status, |
| 545 int64 usage, int64 quota) { | 527 int64 usage, int64 quota) { |
| 546 if (file_system_context()->IsStorageUnlimited( | 528 if (file_system_context()->IsStorageUnlimited( |
| 547 file_system_operation_context()->src_origin_url()) || | 529 file_system_operation_context()->src_origin_url()) || |
| (...skipping 21 matching lines...) Expand all Loading... |
| 569 const base::Time& last_access_time, | 551 const base::Time& last_access_time, |
| 570 const base::Time& last_modified_time) { | 552 const base::Time& last_modified_time) { |
| 571 #ifndef NDEBUG | 553 #ifndef NDEBUG |
| 572 DCHECK(kOperationNone == pending_operation_); | 554 DCHECK(kOperationNone == pending_operation_); |
| 573 pending_operation_ = kOperationTouchFile; | 555 pending_operation_ = kOperationTouchFile; |
| 574 #endif | 556 #endif |
| 575 | 557 |
| 576 FilePath virtual_path; | 558 FilePath virtual_path; |
| 577 GURL origin_url; | 559 GURL origin_url; |
| 578 FileSystemType type; | 560 FileSystemType type; |
| 579 FileSystemFileUtil* file_system_file_util; | 561 FileSystemFileUtil* file_util; |
| 580 if (!VerifyFileSystemPathForWrite(path, true /* create */, &origin_url, | 562 if (!VerifyFileSystemPathForWrite(path, true /* create */, &origin_url, |
| 581 &type, &virtual_path, &file_system_file_util)) { | 563 &type, &virtual_path, &file_util)) { |
| 582 delete this; | 564 delete this; |
| 583 return; | 565 return; |
| 584 } | 566 } |
| 585 file_system_operation_context_.set_src_origin_url(origin_url); | 567 file_system_operation_context_.set_src_origin_url(origin_url); |
| 586 file_system_operation_context_.set_src_type(type); | 568 file_system_operation_context_.set_src_type(type); |
| 587 if (!file_system_operation_context_.src_file_system_file_util()) | 569 if (!file_system_operation_context_.src_file_util()) |
| 588 file_system_operation_context_.set_src_file_system_file_util( | 570 file_system_operation_context_.set_src_file_util(file_util); |
| 589 file_system_file_util); | |
| 590 FileSystemFileUtilProxy::Touch( | 571 FileSystemFileUtilProxy::Touch( |
| 591 file_system_operation_context_, | 572 file_system_operation_context_, |
| 592 proxy_, virtual_path, last_access_time, last_modified_time, | 573 proxy_, virtual_path, last_access_time, last_modified_time, |
| 593 callback_factory_.NewCallback(&FileSystemOperation::DidTouchFile)); | 574 callback_factory_.NewCallback(&FileSystemOperation::DidTouchFile)); |
| 594 } | 575 } |
| 595 | 576 |
| 596 void FileSystemOperation::OpenFile(const GURL& path, | 577 void FileSystemOperation::OpenFile(const GURL& path, |
| 597 int file_flags, | 578 int file_flags, |
| 598 base::ProcessHandle peer_handle) { | 579 base::ProcessHandle peer_handle) { |
| 599 #ifndef NDEBUG | 580 #ifndef NDEBUG |
| 600 DCHECK(kOperationNone == pending_operation_); | 581 DCHECK(kOperationNone == pending_operation_); |
| 601 pending_operation_ = kOperationOpenFile; | 582 pending_operation_ = kOperationOpenFile; |
| 602 #endif | 583 #endif |
| 603 | 584 |
| 604 peer_handle_ = peer_handle; | 585 peer_handle_ = peer_handle; |
| 605 GURL origin_url; | 586 GURL origin_url; |
| 606 FileSystemType type; | 587 FileSystemType type; |
| 607 FileSystemFileUtil* file_system_file_util; | 588 FileSystemFileUtil* file_util; |
| 608 if (file_flags & ( | 589 if (file_flags & ( |
| 609 (base::PLATFORM_FILE_ENUMERATE | base::PLATFORM_FILE_TEMPORARY | | 590 (base::PLATFORM_FILE_ENUMERATE | base::PLATFORM_FILE_TEMPORARY | |
| 610 base::PLATFORM_FILE_HIDDEN))) { | 591 base::PLATFORM_FILE_HIDDEN))) { |
| 611 delete this; | 592 delete this; |
| 612 return; | 593 return; |
| 613 } | 594 } |
| 614 if (file_flags & | 595 if (file_flags & |
| 615 (base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_OPEN_ALWAYS | | 596 (base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_OPEN_ALWAYS | |
| 616 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_TRUNCATED | | 597 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_TRUNCATED | |
| 617 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE | | 598 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE | |
| 618 base::PLATFORM_FILE_DELETE_ON_CLOSE | | 599 base::PLATFORM_FILE_DELETE_ON_CLOSE | |
| 619 base::PLATFORM_FILE_WRITE_ATTRIBUTES)) { | 600 base::PLATFORM_FILE_WRITE_ATTRIBUTES)) { |
| 620 if (!VerifyFileSystemPathForWrite(path, true /* create */, &origin_url, | 601 if (!VerifyFileSystemPathForWrite(path, true /* create */, &origin_url, |
| 621 &type, &src_virtual_path_, &file_system_file_util)) { | 602 &type, &src_virtual_path_, &file_util)) { |
| 622 delete this; | 603 delete this; |
| 623 return; | 604 return; |
| 624 } | 605 } |
| 625 } else { | 606 } else { |
| 626 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, | 607 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, |
| 627 &src_virtual_path_, &file_system_file_util)) { | 608 &src_virtual_path_, &file_util)) { |
| 628 delete this; | 609 delete this; |
| 629 return; | 610 return; |
| 630 } | 611 } |
| 631 } | 612 } |
| 632 file_system_operation_context_.set_src_origin_url(origin_url); | 613 file_system_operation_context_.set_src_origin_url(origin_url); |
| 633 file_system_operation_context_.set_src_type(type); | 614 file_system_operation_context_.set_src_type(type); |
| 634 if (!file_system_operation_context_.src_file_system_file_util()) | 615 if (!file_system_operation_context_.src_file_util()) |
| 635 file_system_operation_context_.set_src_file_system_file_util( | 616 file_system_operation_context_.set_src_file_util(file_util); |
| 636 file_system_file_util); | |
| 637 file_flags_ = file_flags; | 617 file_flags_ = file_flags; |
| 638 | 618 |
| 639 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( | 619 GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( |
| 640 &FileSystemOperation::DelayedOpenFileForQuota)); | 620 &FileSystemOperation::DelayedOpenFileForQuota)); |
| 641 } | 621 } |
| 642 | 622 |
| 643 void FileSystemOperation::DelayedOpenFileForQuota(quota::QuotaStatusCode status, | 623 void FileSystemOperation::DelayedOpenFileForQuota(quota::QuotaStatusCode status, |
| 644 int64 usage, int64 quota) { | 624 int64 usage, int64 quota) { |
| 645 if (file_system_context()->IsStorageUnlimited( | 625 if (file_system_context()->IsStorageUnlimited( |
| 646 file_system_operation_context()->dest_origin_url()) || | 626 file_system_operation_context()->dest_origin_url()) || |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 if (base::PLATFORM_FILE_OK != rv) { | 841 if (base::PLATFORM_FILE_OK != rv) { |
| 862 dispatcher_->DidFail(rv); | 842 dispatcher_->DidFail(rv); |
| 863 delete this; | 843 delete this; |
| 864 return; | 844 return; |
| 865 } | 845 } |
| 866 file_writer_delegate_->Start(file.ReleaseValue(), blob_request_.get()); | 846 file_writer_delegate_->Start(file.ReleaseValue(), blob_request_.get()); |
| 867 } | 847 } |
| 868 | 848 |
| 869 bool FileSystemOperation::VerifyFileSystemPathForRead( | 849 bool FileSystemOperation::VerifyFileSystemPathForRead( |
| 870 const GURL& path, GURL* origin_url, FileSystemType* type, | 850 const GURL& path, GURL* origin_url, FileSystemType* type, |
| 871 FilePath* virtual_path, FileSystemFileUtil** file_system_file_util) { | 851 FilePath* virtual_path, FileSystemFileUtil** file_util) { |
| 872 | 852 |
| 873 // If we have no context, we just allow any operations, for testing. | 853 // If we have no context, we just allow any operations, for testing. |
| 874 // TODO(ericu): Revisit this hack for security. | 854 // TODO(ericu): Revisit this hack for security. |
| 875 if (!file_system_context()) { | 855 if (!file_system_context()) { |
| 876 #ifdef OS_WIN | 856 #ifdef OS_WIN |
| 877 // On Windows, the path will look like /C:/foo/bar; we need to remove the | 857 // On Windows, the path will look like /C:/foo/bar; we need to remove the |
| 878 // leading slash to make it valid. But if it's empty, we shouldn't do | 858 // leading slash to make it valid. But if it's empty, we shouldn't do |
| 879 // anything. | 859 // anything. |
| 880 std::string temp = UnescapeURLComponent(path.path(), | 860 std::string temp = UnescapeURLComponent(path.path(), |
| 881 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS); | 861 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS); |
| 882 if (temp.size()) | 862 if (temp.size()) |
| 883 temp = temp.substr(1); | 863 temp = temp.substr(1); |
| 884 *virtual_path = FilePath(UTF8ToWide(temp)).NormalizeWindowsPathSeparators(); | 864 *virtual_path = FilePath(UTF8ToWide(temp)).NormalizeWindowsPathSeparators(); |
| 885 #else | 865 #else |
| 886 *virtual_path = FilePath(path.path()); | 866 *virtual_path = FilePath(path.path()); |
| 887 #endif | 867 #endif |
| 888 *type = file_system_operation_context_.src_type(); | 868 *type = file_system_operation_context_.src_type(); |
| 889 *origin_url = file_system_operation_context_.src_origin_url(); | 869 *origin_url = file_system_operation_context_.src_origin_url(); |
| 890 *file_system_file_util = NULL; | 870 *file_util = NULL; |
| 891 return true; | 871 return true; |
| 892 } | 872 } |
| 893 | 873 |
| 894 // We may want do more checks, but for now it just checks if the given | 874 // We may want do more checks, but for now it just checks if the given |
| 895 // URL is valid. | 875 // URL is valid. |
| 896 if (!CrackFileSystemURL(path, origin_url, type, virtual_path)) { | 876 if (!CrackFileSystemURL(path, origin_url, type, virtual_path)) { |
| 897 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_INVALID_URL); | 877 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_INVALID_URL); |
| 898 return false; | 878 return false; |
| 899 } | 879 } |
| 900 if (!file_system_context()->path_manager()->IsAccessAllowed( | 880 if (!file_system_context()->path_manager()->IsAccessAllowed( |
| 901 *origin_url, *type, *virtual_path)) { | 881 *origin_url, *type, *virtual_path)) { |
| 902 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 882 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
| 903 return false; | 883 return false; |
| 904 } | 884 } |
| 905 DCHECK(file_system_file_util); | 885 DCHECK(file_util); |
| 906 *file_system_file_util = | 886 *file_util = file_system_context()->path_manager()->GetFileUtil(*type); |
| 907 file_system_context()->path_manager()->GetFileSystemFileUtil(*type); | 887 DCHECK(*file_util); |
| 908 DCHECK(*file_system_file_util); | |
| 909 | 888 |
| 910 // We notify this read access whether the read access succeeds or not. | 889 // We notify this read access whether the read access succeeds or not. |
| 911 // This must be ok since this is used to let the QM's eviction logic know | 890 // This must be ok since this is used to let the QM's eviction logic know |
| 912 // someone is interested in reading the origin data and therefore to indicate | 891 // someone is interested in reading the origin data and therefore to indicate |
| 913 // that evicting this origin may not be a good idea. | 892 // that evicting this origin may not be a good idea. |
| 914 FileSystemQuotaUtil* quota_util = file_system_context()->GetQuotaUtil(*type); | 893 FileSystemQuotaUtil* quota_util = file_system_context()->GetQuotaUtil(*type); |
| 915 if (quota_util) { | 894 if (quota_util) { |
| 916 quota_util->NotifyOriginWasAccessedOnIOThread( | 895 quota_util->NotifyOriginWasAccessedOnIOThread( |
| 917 file_system_context()->quota_manager_proxy(), | 896 file_system_context()->quota_manager_proxy(), |
| 918 *origin_url, | 897 *origin_url, |
| 919 *type); | 898 *type); |
| 920 } | 899 } |
| 921 | 900 |
| 922 return true; | 901 return true; |
| 923 } | 902 } |
| 924 | 903 |
| 925 bool FileSystemOperation::VerifyFileSystemPathForWrite( | 904 bool FileSystemOperation::VerifyFileSystemPathForWrite( |
| 926 const GURL& path, bool create, GURL* origin_url, FileSystemType* type, | 905 const GURL& path, bool create, GURL* origin_url, FileSystemType* type, |
| 927 FilePath* virtual_path, FileSystemFileUtil** file_system_file_util) { | 906 FilePath* virtual_path, FileSystemFileUtil** file_util) { |
| 928 | 907 |
| 929 // If we have no context, we just allow any operations, for testing. | 908 // If we have no context, we just allow any operations, for testing. |
| 930 // TODO(ericu): Revisit this hack for security. | 909 // TODO(ericu): Revisit this hack for security. |
| 931 if (!file_system_context()) { | 910 if (!file_system_context()) { |
| 932 #ifdef OS_WIN | 911 #ifdef OS_WIN |
| 933 // On Windows, the path will look like /C:/foo/bar; we need to remove the | 912 // On Windows, the path will look like /C:/foo/bar; we need to remove the |
| 934 // leading slash to make it valid. But if it's empty, we shouldn't do | 913 // leading slash to make it valid. But if it's empty, we shouldn't do |
| 935 // anything. | 914 // anything. |
| 936 std::string temp = UnescapeURLComponent(path.path(), | 915 std::string temp = UnescapeURLComponent(path.path(), |
| 937 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS); | 916 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS); |
| 938 if (temp.size()) | 917 if (temp.size()) |
| 939 temp = temp.substr(1); | 918 temp = temp.substr(1); |
| 940 *virtual_path = FilePath(UTF8ToWide(temp)).NormalizeWindowsPathSeparators(); | 919 *virtual_path = FilePath(UTF8ToWide(temp)).NormalizeWindowsPathSeparators(); |
| 941 #else | 920 #else |
| 942 *virtual_path = FilePath(path.path()); | 921 *virtual_path = FilePath(path.path()); |
| 943 #endif | 922 #endif |
| 944 *type = file_system_operation_context_.dest_type(); | 923 *type = file_system_operation_context_.dest_type(); |
| 945 *origin_url = file_system_operation_context_.dest_origin_url(); | 924 *origin_url = file_system_operation_context_.dest_origin_url(); |
| 946 *file_system_file_util = NULL; | 925 *file_util = NULL; |
| 947 return true; | 926 return true; |
| 948 } | 927 } |
| 949 | 928 |
| 950 if (!CrackFileSystemURL(path, origin_url, type, virtual_path)) { | 929 if (!CrackFileSystemURL(path, origin_url, type, virtual_path)) { |
| 951 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_INVALID_URL); | 930 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_INVALID_URL); |
| 952 return false; | 931 return false; |
| 953 } | 932 } |
| 954 if (!file_system_context()->path_manager()->IsAccessAllowed( | 933 if (!file_system_context()->path_manager()->IsAccessAllowed( |
| 955 *origin_url, *type, *virtual_path)) { | 934 *origin_url, *type, *virtual_path)) { |
| 956 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 935 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
| 957 return false; | 936 return false; |
| 958 } | 937 } |
| 959 // Any write access is disallowed on the root path. | 938 // Any write access is disallowed on the root path. |
| 960 if (virtual_path->value().length() == 0 || | 939 if (virtual_path->value().length() == 0 || |
| 961 virtual_path->DirName().value() == virtual_path->value()) { | 940 virtual_path->DirName().value() == virtual_path->value()) { |
| 962 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 941 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
| 963 return false; | 942 return false; |
| 964 } | 943 } |
| 965 if (create && file_system_context()->path_manager()->IsRestrictedFileName( | 944 if (create && file_system_context()->path_manager()->IsRestrictedFileName( |
| 966 *type, virtual_path->BaseName())) { | 945 *type, virtual_path->BaseName())) { |
| 967 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 946 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
| 968 return false; | 947 return false; |
| 969 } | 948 } |
| 970 DCHECK(file_system_file_util); | 949 DCHECK(file_util); |
| 971 *file_system_file_util = | 950 *file_util = file_system_context()->path_manager()->GetFileUtil(*type); |
| 972 file_system_context()->path_manager()->GetFileSystemFileUtil(*type); | 951 DCHECK(*file_util); |
| 973 DCHECK(*file_system_file_util); | |
| 974 | 952 |
| 975 return true; | 953 return true; |
| 976 } | 954 } |
| 977 | 955 |
| 978 } // namespace fileapi | 956 } // namespace fileapi |
| OLD | NEW |