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

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: 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();
kinuko 2014/03/24 09:56:58 Why are you removing these NOTREACHED?
rvargas (doing something else) 2014/03/24 23:02:48 Because they are DCHECKing at the same time that h
kinuko 2014/03/25 03:15:26 I'm not original author of this code, and fine wit
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 error = NativeFileUtil::CreateOrOpen(dest_local_path, file_flags, &file);
1094 if (error == base::File::FILE_OK) {
1095 created = file.created();
1096 *handle = file.TakePlatformFile();
1097 }
1094 // If this succeeds, we must close handle on any subsequent error. 1098 // If this succeeds, we must close handle on any subsequent error.
1095 } else { 1099 } else {
1096 DCHECK(!file_flags); // file_flags is only used by CreateOrOpen. 1100 DCHECK(!file_flags); // file_flags is only used by CreateOrOpen.
1097 error = NativeFileUtil::EnsureFileExists(dest_local_path, &created); 1101 error = NativeFileUtil::EnsureFileExists(dest_local_path, &created);
1098 } 1102 }
1099 } 1103 }
1100 if (error != base::File::FILE_OK) 1104 if (error != base::File::FILE_OK)
1101 return error; 1105 return error;
1102 1106
1103 if (!created) { 1107 if (!created) {
1104 NOTREACHED();
1105 if (handle) { 1108 if (handle) {
1106 DCHECK_NE(base::kInvalidPlatformFileValue, *handle); 1109 DCHECK_NE(base::kInvalidPlatformFileValue, *handle);
1107 base::ClosePlatformFile(*handle); 1110 base::ClosePlatformFile(*handle);
1108 base::DeleteFile(dest_local_path, false /* recursive */); 1111 base::DeleteFile(dest_local_path, false /* recursive */);
1109 *handle = base::kInvalidPlatformFileValue; 1112 *handle = base::kInvalidPlatformFileValue;
1110 } 1113 }
1111 return base::File::FILE_ERROR_FAILED; 1114 return base::File::FILE_ERROR_FAILED;
1112 } 1115 }
1113 1116
1114 // This removes the root, including the trailing slash, leaving a relative 1117 // 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; 1392 return base::File::FILE_ERROR_NOT_A_FILE;
1390 1393
1391 int64 delta = 0; 1394 int64 delta = 0;
1392 if (file_flags & (base::PLATFORM_FILE_CREATE_ALWAYS | 1395 if (file_flags & (base::PLATFORM_FILE_CREATE_ALWAYS |
1393 base::PLATFORM_FILE_OPEN_TRUNCATED)) { 1396 base::PLATFORM_FILE_OPEN_TRUNCATED)) {
1394 // The file exists and we're truncating. 1397 // The file exists and we're truncating.
1395 delta = -platform_file_info.size; 1398 delta = -platform_file_info.size;
1396 AllocateQuota(context, delta); 1399 AllocateQuota(context, delta);
1397 } 1400 }
1398 1401
1399 error = NativeFileUtil::CreateOrOpen( 1402 // TODO(rvargas): make FileSystemFileUtil use base::File.
1400 local_path, file_flags, file_handle, created); 1403 base::File file;
1404 error = NativeFileUtil::CreateOrOpen(local_path, file_flags, &file);
1401 if (error == base::File::FILE_ERROR_NOT_FOUND) { 1405 if (error == base::File::FILE_ERROR_NOT_FOUND) {
1402 // TODO(tzik): Also invalidate on-memory usage cache in UsageTracker. 1406 // TODO(tzik): Also invalidate on-memory usage cache in UsageTracker.
1403 // TODO(tzik): Delete database entry after ensuring the file lost. 1407 // TODO(tzik): Delete database entry after ensuring the file lost.
1404 InvalidateUsageCache(context, url.origin(), url.type()); 1408 InvalidateUsageCache(context, url.origin(), url.type());
1405 LOG(WARNING) << "Lost a backing file."; 1409 LOG(WARNING) << "Lost a backing file.";
1406 error = base::File::FILE_ERROR_FAILED; 1410 error = base::File::FILE_ERROR_FAILED;
1407 } 1411 }
1408 1412
1413 if (error != base::File::FILE_OK)
1414 return error;
1415
1416 *created = file.created();
1417 *file_handle = file.TakePlatformFile();
1418
1409 // If truncating we need to update the usage. 1419 // If truncating we need to update the usage.
1410 if (error == base::File::FILE_OK && delta) { 1420 if (delta) {
1411 UpdateUsage(context, url, delta); 1421 UpdateUsage(context, url, delta);
1412 context->change_observers()->Notify( 1422 context->change_observers()->Notify(
1413 &FileChangeObserver::OnModifyFile, MakeTuple(url)); 1423 &FileChangeObserver::OnModifyFile, MakeTuple(url));
1414 } 1424 }
1415 return error; 1425 return error;
1416 } 1426 }
1417 1427
1418 bool ObfuscatedFileUtil::HasIsolatedStorage(const GURL& origin) { 1428 bool ObfuscatedFileUtil::HasIsolatedStorage(const GURL& origin) {
1419 return special_storage_policy_.get() && 1429 return special_storage_policy_.get() &&
1420 special_storage_policy_->HasIsolatedStorage(origin); 1430 special_storage_policy_->HasIsolatedStorage(origin);
1421 } 1431 }
1422 1432
1423 } // namespace fileapi 1433 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698