Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(466)

Side by Side Diff: webkit/browser/fileapi/obfuscated_file_util.cc

Issue 206783004: Remove PlatforFile from fileapi/native_file_util (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Change API to return File Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/browser/fileapi/obfuscated_file_util.h" 5 #include "webkit/browser/fileapi/obfuscated_file_util.h"
6 6
7 #include <queue> 7 #include <queue>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 sandbox_delegate_) { 285 sandbox_delegate_) {
286 DCHECK_EQ(base::File::FILE_OK, error); 286 DCHECK_EQ(base::File::FILE_OK, error);
287 sandbox_delegate_->StickyInvalidateUsageCache(url.origin(), url.type()); 287 sandbox_delegate_->StickyInvalidateUsageCache(url.origin(), url.type());
288 } 288 }
289 return error; 289 return error;
290 } 290 }
291 291
292 base::File::Error ObfuscatedFileUtil::Close( 292 base::File::Error ObfuscatedFileUtil::Close(
293 FileSystemOperationContext* context, 293 FileSystemOperationContext* context,
294 base::PlatformFile file) { 294 base::PlatformFile file) {
295 return NativeFileUtil::Close(file); 295 base::File auto_closed(file);
296 return base::File::FILE_OK;
296 } 297 }
297 298
298 base::File::Error ObfuscatedFileUtil::EnsureFileExists( 299 base::File::Error ObfuscatedFileUtil::EnsureFileExists(
299 FileSystemOperationContext* context, 300 FileSystemOperationContext* context,
300 const FileSystemURL& url, 301 const FileSystemURL& url,
301 bool* created) { 302 bool* created) {
302 SandboxDirectoryDatabase* db = GetDirectoryDatabase(url, true); 303 SandboxDirectoryDatabase* db = GetDirectoryDatabase(url, true);
303 if (!db) 304 if (!db)
304 return base::File::FILE_ERROR_FAILED; 305 return base::File::FILE_ERROR_FAILED;
305 306
(...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 DCHECK(!file_flags); 1074 DCHECK(!file_flags);
1074 DCHECK(!handle); 1075 DCHECK(!handle);
1075 error = NativeFileUtil::CopyOrMoveFile( 1076 error = NativeFileUtil::CopyOrMoveFile(
1076 src_file_path, dest_local_path, 1077 src_file_path, dest_local_path,
1077 FileSystemOperation::OPTION_NONE, 1078 FileSystemOperation::OPTION_NONE,
1078 fileapi::NativeFileUtil::CopyOrMoveModeForDestination(dest_url, 1079 fileapi::NativeFileUtil::CopyOrMoveModeForDestination(dest_url,
1079 true /* copy */)); 1080 true /* copy */));
1080 created = true; 1081 created = true;
1081 } else { 1082 } else {
1082 if (base::PathExists(dest_local_path)) { 1083 if (base::PathExists(dest_local_path)) {
1083 if (!base::DeleteFile(dest_local_path, true /* recursive */)) { 1084 if (!base::DeleteFile(dest_local_path, true /* recursive */))
1084 NOTREACHED();
1085 return base::File::FILE_ERROR_FAILED; 1085 return base::File::FILE_ERROR_FAILED;
1086 }
1087 LOG(WARNING) << "A stray file detected"; 1086 LOG(WARNING) << "A stray file detected";
1088 InvalidateUsageCache(context, dest_url.origin(), dest_url.type()); 1087 InvalidateUsageCache(context, dest_url.origin(), dest_url.type());
1089 } 1088 }
1090 1089
1091 if (handle) { 1090 if (handle) {
1092 error = NativeFileUtil::CreateOrOpen( 1091 // TODO(rvargas): Remove PlatformFile from this code.
1093 dest_local_path, file_flags, handle, &created); 1092 base::File file =
1093 NativeFileUtil::CreateOrOpen(dest_local_path, file_flags);
1094 if (file.IsValid()) {
1095 created = file.created();
1096 *handle = file.TakePlatformFile();
1097 error = base::File::FILE_OK;
1098 } else {
1099 error = file.error_details();
1100 }
1094 // If this succeeds, we must close handle on any subsequent error. 1101 // If this succeeds, we must close handle on any subsequent error.
1095 } else { 1102 } else {
1096 DCHECK(!file_flags); // file_flags is only used by CreateOrOpen. 1103 DCHECK(!file_flags); // file_flags is only used by CreateOrOpen.
1097 error = NativeFileUtil::EnsureFileExists(dest_local_path, &created); 1104 error = NativeFileUtil::EnsureFileExists(dest_local_path, &created);
1098 } 1105 }
1099 } 1106 }
1100 if (error != base::File::FILE_OK) 1107 if (error != base::File::FILE_OK)
1101 return error; 1108 return error;
1102 1109
1103 if (!created) { 1110 if (!created) {
1104 NOTREACHED();
1105 if (handle) { 1111 if (handle) {
1106 DCHECK_NE(base::kInvalidPlatformFileValue, *handle); 1112 DCHECK_NE(base::kInvalidPlatformFileValue, *handle);
1107 base::ClosePlatformFile(*handle); 1113 base::ClosePlatformFile(*handle);
1108 base::DeleteFile(dest_local_path, false /* recursive */); 1114 base::DeleteFile(dest_local_path, false /* recursive */);
1109 *handle = base::kInvalidPlatformFileValue; 1115 *handle = base::kInvalidPlatformFileValue;
1110 } 1116 }
1111 return base::File::FILE_ERROR_FAILED; 1117 return base::File::FILE_ERROR_FAILED;
1112 } 1118 }
1113 1119
1114 // This removes the root, including the trailing slash, leaving a relative 1120 // This removes the root, including the trailing slash, leaving a relative
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
1389 return base::File::FILE_ERROR_NOT_A_FILE; 1395 return base::File::FILE_ERROR_NOT_A_FILE;
1390 1396
1391 int64 delta = 0; 1397 int64 delta = 0;
1392 if (file_flags & (base::PLATFORM_FILE_CREATE_ALWAYS | 1398 if (file_flags & (base::PLATFORM_FILE_CREATE_ALWAYS |
1393 base::PLATFORM_FILE_OPEN_TRUNCATED)) { 1399 base::PLATFORM_FILE_OPEN_TRUNCATED)) {
1394 // The file exists and we're truncating. 1400 // The file exists and we're truncating.
1395 delta = -platform_file_info.size; 1401 delta = -platform_file_info.size;
1396 AllocateQuota(context, delta); 1402 AllocateQuota(context, delta);
1397 } 1403 }
1398 1404
1399 error = NativeFileUtil::CreateOrOpen( 1405 // TODO(rvargas): make FileSystemFileUtil use base::File.
1400 local_path, file_flags, file_handle, created); 1406 base::File file = NativeFileUtil::CreateOrOpen(local_path, file_flags);
1401 if (error == base::File::FILE_ERROR_NOT_FOUND) { 1407 if (!file.IsValid()) {
1402 // TODO(tzik): Also invalidate on-memory usage cache in UsageTracker. 1408 error = file.error_details();
1403 // TODO(tzik): Delete database entry after ensuring the file lost. 1409 if (error == base::File::FILE_ERROR_NOT_FOUND) {
1404 InvalidateUsageCache(context, url.origin(), url.type()); 1410 // TODO(tzik): Also invalidate on-memory usage cache in UsageTracker.
1405 LOG(WARNING) << "Lost a backing file."; 1411 // TODO(tzik): Delete database entry after ensuring the file lost.
1406 error = base::File::FILE_ERROR_FAILED; 1412 InvalidateUsageCache(context, url.origin(), url.type());
1413 LOG(WARNING) << "Lost a backing file.";
1414 error = base::File::FILE_ERROR_FAILED;
1415 }
1416 return error;
1407 } 1417 }
1408 1418
1419 *created = file.created();
1420 *file_handle = file.TakePlatformFile();
1421
1409 // If truncating we need to update the usage. 1422 // If truncating we need to update the usage.
1410 if (error == base::File::FILE_OK && delta) { 1423 if (delta) {
1411 UpdateUsage(context, url, delta); 1424 UpdateUsage(context, url, delta);
1412 context->change_observers()->Notify( 1425 context->change_observers()->Notify(
1413 &FileChangeObserver::OnModifyFile, MakeTuple(url)); 1426 &FileChangeObserver::OnModifyFile, MakeTuple(url));
1414 } 1427 }
1415 return error; 1428 return base::File::FILE_OK;
1416 } 1429 }
1417 1430
1418 bool ObfuscatedFileUtil::HasIsolatedStorage(const GURL& origin) { 1431 bool ObfuscatedFileUtil::HasIsolatedStorage(const GURL& origin) {
1419 return special_storage_policy_.get() && 1432 return special_storage_policy_.get() &&
1420 special_storage_policy_->HasIsolatedStorage(origin); 1433 special_storage_policy_->HasIsolatedStorage(origin);
1421 } 1434 }
1422 1435
1423 } // namespace fileapi 1436 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698