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

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

Issue 1159553007: Move Tuple to base namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
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 "storage/browser/fileapi/obfuscated_file_util.h" 5 #include "storage/browser/fileapi/obfuscated_file_util.h"
6 6
7 #include <queue> 7 #include <queue>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/format_macros.h" 10 #include "base/format_macros.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 return false; 81 return false;
82 context->set_allowed_bytes_growth(new_quota); 82 context->set_allowed_bytes_growth(new_quota);
83 return true; 83 return true;
84 } 84 }
85 85
86 void UpdateUsage( 86 void UpdateUsage(
87 FileSystemOperationContext* context, 87 FileSystemOperationContext* context,
88 const FileSystemURL& url, 88 const FileSystemURL& url,
89 int64 growth) { 89 int64 growth) {
90 context->update_observers()->Notify( 90 context->update_observers()->Notify(
91 &FileUpdateObserver::OnUpdate, MakeTuple(url, growth)); 91 &FileUpdateObserver::OnUpdate, base::MakeTuple(url, growth));
92 } 92 }
93 93
94 void TouchDirectory(SandboxDirectoryDatabase* db, FileId dir_id) { 94 void TouchDirectory(SandboxDirectoryDatabase* db, FileId dir_id) {
95 DCHECK(db); 95 DCHECK(db);
96 if (!db->UpdateModificationTime(dir_id, base::Time::Now())) 96 if (!db->UpdateModificationTime(dir_id, base::Time::Now()))
97 NOTREACHED(); 97 NOTREACHED();
98 } 98 }
99 99
100 enum IsolatedOriginStatus { 100 enum IsolatedOriginStatus {
101 kIsolatedOriginMatch, 101 kIsolatedOriginMatch,
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 312
313 int64 growth = UsageForPath(file_info.name.size()); 313 int64 growth = UsageForPath(file_info.name.size());
314 if (!AllocateQuota(context, growth)) 314 if (!AllocateQuota(context, growth))
315 return base::File::FILE_ERROR_NO_SPACE; 315 return base::File::FILE_ERROR_NO_SPACE;
316 base::File::Error error = CreateFile(context, base::FilePath(), url, 316 base::File::Error error = CreateFile(context, base::FilePath(), url,
317 &file_info); 317 &file_info);
318 if (created && base::File::FILE_OK == error) { 318 if (created && base::File::FILE_OK == error) {
319 *created = true; 319 *created = true;
320 UpdateUsage(context, url, growth); 320 UpdateUsage(context, url, growth);
321 context->change_observers()->Notify( 321 context->change_observers()->Notify(
322 &FileChangeObserver::OnCreateFile, MakeTuple(url)); 322 &FileChangeObserver::OnCreateFile, base::MakeTuple(url));
323 } 323 }
324 return error; 324 return error;
325 } 325 }
326 326
327 base::File::Error ObfuscatedFileUtil::CreateDirectory( 327 base::File::Error ObfuscatedFileUtil::CreateDirectory(
328 FileSystemOperationContext* context, 328 FileSystemOperationContext* context,
329 const FileSystemURL& url, 329 const FileSystemURL& url,
330 bool exclusive, 330 bool exclusive,
331 bool recursive) { 331 bool recursive) {
332 SandboxDirectoryDatabase* db = GetDirectoryDatabase(url, true); 332 SandboxDirectoryDatabase* db = GetDirectoryDatabase(url, true);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 file_info.modification_time = base::Time::Now(); 371 file_info.modification_time = base::Time::Now();
372 file_info.parent_id = parent_id; 372 file_info.parent_id = parent_id;
373 int64 growth = UsageForPath(file_info.name.size()); 373 int64 growth = UsageForPath(file_info.name.size());
374 if (!AllocateQuota(context, growth)) 374 if (!AllocateQuota(context, growth))
375 return base::File::FILE_ERROR_NO_SPACE; 375 return base::File::FILE_ERROR_NO_SPACE;
376 base::File::Error error = db->AddFileInfo(file_info, &parent_id); 376 base::File::Error error = db->AddFileInfo(file_info, &parent_id);
377 if (error != base::File::FILE_OK) 377 if (error != base::File::FILE_OK)
378 return error; 378 return error;
379 UpdateUsage(context, url, growth); 379 UpdateUsage(context, url, growth);
380 context->change_observers()->Notify( 380 context->change_observers()->Notify(
381 &FileChangeObserver::OnCreateDirectory, MakeTuple(url)); 381 &FileChangeObserver::OnCreateDirectory, base::MakeTuple(url));
382 if (first) { 382 if (first) {
383 first = false; 383 first = false;
384 TouchDirectory(db, file_info.parent_id); 384 TouchDirectory(db, file_info.parent_id);
385 } 385 }
386 } 386 }
387 return base::File::FILE_OK; 387 return base::File::FILE_OK;
388 } 388 }
389 389
390 base::File::Error ObfuscatedFileUtil::GetFileInfo( 390 base::File::Error ObfuscatedFileUtil::GetFileInfo(
391 FileSystemOperationContext* context, 391 FileSystemOperationContext* context,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 if (error != base::File::FILE_OK) 472 if (error != base::File::FILE_OK)
473 return error; 473 return error;
474 474
475 int64 growth = length - file_info.size; 475 int64 growth = length - file_info.size;
476 if (!AllocateQuota(context, growth)) 476 if (!AllocateQuota(context, growth))
477 return base::File::FILE_ERROR_NO_SPACE; 477 return base::File::FILE_ERROR_NO_SPACE;
478 error = NativeFileUtil::Truncate(local_path, length); 478 error = NativeFileUtil::Truncate(local_path, length);
479 if (error == base::File::FILE_OK) { 479 if (error == base::File::FILE_OK) {
480 UpdateUsage(context, url, growth); 480 UpdateUsage(context, url, growth);
481 context->change_observers()->Notify( 481 context->change_observers()->Notify(
482 &FileChangeObserver::OnModifyFile, MakeTuple(url)); 482 &FileChangeObserver::OnModifyFile, base::MakeTuple(url));
483 } 483 }
484 return error; 484 return error;
485 } 485 }
486 486
487 base::File::Error ObfuscatedFileUtil::CopyOrMoveFile( 487 base::File::Error ObfuscatedFileUtil::CopyOrMoveFile(
488 FileSystemOperationContext* context, 488 FileSystemOperationContext* context,
489 const FileSystemURL& src_url, 489 const FileSystemURL& src_url,
490 const FileSystemURL& dest_url, 490 const FileSystemURL& dest_url,
491 CopyOrMoveOption option, 491 CopyOrMoveOption option,
492 bool copy) { 492 bool copy) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 error = base::File::FILE_ERROR_FAILED; 599 error = base::File::FILE_ERROR_FAILED;
600 } 600 }
601 } 601 }
602 602
603 if (error != base::File::FILE_OK) 603 if (error != base::File::FILE_OK)
604 return error; 604 return error;
605 605
606 if (overwrite) { 606 if (overwrite) {
607 context->change_observers()->Notify( 607 context->change_observers()->Notify(
608 &FileChangeObserver::OnModifyFile, 608 &FileChangeObserver::OnModifyFile,
609 MakeTuple(dest_url)); 609 base::MakeTuple(dest_url));
610 } else { 610 } else {
611 context->change_observers()->Notify( 611 context->change_observers()->Notify(
612 &FileChangeObserver::OnCreateFileFrom, 612 &FileChangeObserver::OnCreateFileFrom,
613 MakeTuple(dest_url, src_url)); 613 base::MakeTuple(dest_url, src_url));
614 } 614 }
615 615
616 if (!copy) { 616 if (!copy) {
617 context->change_observers()->Notify( 617 context->change_observers()->Notify(
618 &FileChangeObserver::OnRemoveFile, MakeTuple(src_url)); 618 &FileChangeObserver::OnRemoveFile, base::MakeTuple(src_url));
619 TouchDirectory(db, src_file_info.parent_id); 619 TouchDirectory(db, src_file_info.parent_id);
620 } 620 }
621 621
622 TouchDirectory(db, dest_file_info.parent_id); 622 TouchDirectory(db, dest_file_info.parent_id);
623 623
624 UpdateUsage(context, dest_url, growth); 624 UpdateUsage(context, dest_url, growth);
625 return error; 625 return error;
626 } 626 }
627 627
628 base::File::Error ObfuscatedFileUtil::CopyInForeignFile( 628 base::File::Error ObfuscatedFileUtil::CopyInForeignFile(
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 true /* copy */)); 687 true /* copy */));
688 } else { 688 } else {
689 error = CreateFile(context, src_file_path, dest_url, &dest_file_info); 689 error = CreateFile(context, src_file_path, dest_url, &dest_file_info);
690 } 690 }
691 691
692 if (error != base::File::FILE_OK) 692 if (error != base::File::FILE_OK)
693 return error; 693 return error;
694 694
695 if (overwrite) { 695 if (overwrite) {
696 context->change_observers()->Notify( 696 context->change_observers()->Notify(
697 &FileChangeObserver::OnModifyFile, MakeTuple(dest_url)); 697 &FileChangeObserver::OnModifyFile, base::MakeTuple(dest_url));
698 } else { 698 } else {
699 context->change_observers()->Notify( 699 context->change_observers()->Notify(
700 &FileChangeObserver::OnCreateFile, MakeTuple(dest_url)); 700 &FileChangeObserver::OnCreateFile, base::MakeTuple(dest_url));
701 } 701 }
702 702
703 UpdateUsage(context, dest_url, growth); 703 UpdateUsage(context, dest_url, growth);
704 TouchDirectory(db, dest_file_info.parent_id); 704 TouchDirectory(db, dest_file_info.parent_id);
705 return base::File::FILE_OK; 705 return base::File::FILE_OK;
706 } 706 }
707 707
708 base::File::Error ObfuscatedFileUtil::DeleteFile( 708 base::File::Error ObfuscatedFileUtil::DeleteFile(
709 FileSystemOperationContext* context, 709 FileSystemOperationContext* context,
710 const FileSystemURL& url) { 710 const FileSystemURL& url) {
(...skipping 19 matching lines...) Expand all
730 int64 growth = -UsageForPath(file_info.name.size()) - platform_file_info.size; 730 int64 growth = -UsageForPath(file_info.name.size()) - platform_file_info.size;
731 AllocateQuota(context, growth); 731 AllocateQuota(context, growth);
732 if (!db->RemoveFileInfo(file_id)) { 732 if (!db->RemoveFileInfo(file_id)) {
733 NOTREACHED(); 733 NOTREACHED();
734 return base::File::FILE_ERROR_FAILED; 734 return base::File::FILE_ERROR_FAILED;
735 } 735 }
736 UpdateUsage(context, url, growth); 736 UpdateUsage(context, url, growth);
737 TouchDirectory(db, file_info.parent_id); 737 TouchDirectory(db, file_info.parent_id);
738 738
739 context->change_observers()->Notify( 739 context->change_observers()->Notify(
740 &FileChangeObserver::OnRemoveFile, MakeTuple(url)); 740 &FileChangeObserver::OnRemoveFile, base::MakeTuple(url));
741 741
742 if (error == base::File::FILE_ERROR_NOT_FOUND) 742 if (error == base::File::FILE_ERROR_NOT_FOUND)
743 return base::File::FILE_OK; 743 return base::File::FILE_OK;
744 744
745 error = NativeFileUtil::DeleteFile(local_path); 745 error = NativeFileUtil::DeleteFile(local_path);
746 if (base::File::FILE_OK != error) 746 if (base::File::FILE_OK != error)
747 LOG(WARNING) << "Leaked a backing file."; 747 LOG(WARNING) << "Leaked a backing file.";
748 return base::File::FILE_OK; 748 return base::File::FILE_OK;
749 } 749 }
750 750
(...skipping 14 matching lines...) Expand all
765 } 765 }
766 if (!file_info.is_directory()) 766 if (!file_info.is_directory())
767 return base::File::FILE_ERROR_NOT_A_DIRECTORY; 767 return base::File::FILE_ERROR_NOT_A_DIRECTORY;
768 if (!db->RemoveFileInfo(file_id)) 768 if (!db->RemoveFileInfo(file_id))
769 return base::File::FILE_ERROR_NOT_EMPTY; 769 return base::File::FILE_ERROR_NOT_EMPTY;
770 int64 growth = -UsageForPath(file_info.name.size()); 770 int64 growth = -UsageForPath(file_info.name.size());
771 AllocateQuota(context, growth); 771 AllocateQuota(context, growth);
772 UpdateUsage(context, url, growth); 772 UpdateUsage(context, url, growth);
773 TouchDirectory(db, file_info.parent_id); 773 TouchDirectory(db, file_info.parent_id);
774 context->change_observers()->Notify( 774 context->change_observers()->Notify(
775 &FileChangeObserver::OnRemoveDirectory, MakeTuple(url)); 775 &FileChangeObserver::OnRemoveDirectory, base::MakeTuple(url));
776 return base::File::FILE_OK; 776 return base::File::FILE_OK;
777 } 777 }
778 778
779 storage::ScopedFile ObfuscatedFileUtil::CreateSnapshotFile( 779 storage::ScopedFile ObfuscatedFileUtil::CreateSnapshotFile(
780 FileSystemOperationContext* context, 780 FileSystemOperationContext* context,
781 const FileSystemURL& url, 781 const FileSystemURL& url,
782 base::File::Error* error, 782 base::File::Error* error,
783 base::File::Info* file_info, 783 base::File::Info* file_info,
784 base::FilePath* platform_path) { 784 base::FilePath* platform_path) {
785 // We're just returning the local file information. 785 // We're just returning the local file information.
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 InitFileInfo(&file_info, parent_id, 1359 InitFileInfo(&file_info, parent_id,
1360 VirtualPath::BaseName(url.path()).value()); 1360 VirtualPath::BaseName(url.path()).value());
1361 1361
1362 int64 growth = UsageForPath(file_info.name.size()); 1362 int64 growth = UsageForPath(file_info.name.size());
1363 if (!AllocateQuota(context, growth)) 1363 if (!AllocateQuota(context, growth))
1364 return base::File(base::File::FILE_ERROR_NO_SPACE); 1364 return base::File(base::File::FILE_ERROR_NO_SPACE);
1365 base::File file = CreateAndOpenFile(context, url, &file_info, file_flags); 1365 base::File file = CreateAndOpenFile(context, url, &file_info, file_flags);
1366 if (file.IsValid()) { 1366 if (file.IsValid()) {
1367 UpdateUsage(context, url, growth); 1367 UpdateUsage(context, url, growth);
1368 context->change_observers()->Notify( 1368 context->change_observers()->Notify(
1369 &FileChangeObserver::OnCreateFile, MakeTuple(url)); 1369 &FileChangeObserver::OnCreateFile, base::MakeTuple(url));
1370 } 1370 }
1371 return file.Pass(); 1371 return file.Pass();
1372 } 1372 }
1373 1373
1374 if (file_flags & base::File::FLAG_CREATE) 1374 if (file_flags & base::File::FLAG_CREATE)
1375 return base::File(base::File::FILE_ERROR_EXISTS); 1375 return base::File(base::File::FILE_ERROR_EXISTS);
1376 1376
1377 base::File::Info platform_file_info; 1377 base::File::Info platform_file_info;
1378 base::FilePath local_path; 1378 base::FilePath local_path;
1379 FileInfo file_info; 1379 FileInfo file_info;
(...skipping 22 matching lines...) Expand all
1402 LOG(WARNING) << "Lost a backing file."; 1402 LOG(WARNING) << "Lost a backing file.";
1403 return base::File(base::File::FILE_ERROR_FAILED); 1403 return base::File(base::File::FILE_ERROR_FAILED);
1404 } 1404 }
1405 return file.Pass(); 1405 return file.Pass();
1406 } 1406 }
1407 1407
1408 // If truncating we need to update the usage. 1408 // If truncating we need to update the usage.
1409 if (delta) { 1409 if (delta) {
1410 UpdateUsage(context, url, delta); 1410 UpdateUsage(context, url, delta);
1411 context->change_observers()->Notify( 1411 context->change_observers()->Notify(
1412 &FileChangeObserver::OnModifyFile, MakeTuple(url)); 1412 &FileChangeObserver::OnModifyFile, base::MakeTuple(url));
1413 } 1413 }
1414 return file.Pass(); 1414 return file.Pass();
1415 } 1415 }
1416 1416
1417 bool ObfuscatedFileUtil::HasIsolatedStorage(const GURL& origin) { 1417 bool ObfuscatedFileUtil::HasIsolatedStorage(const GURL& origin) {
1418 return special_storage_policy_.get() && 1418 return special_storage_policy_.get() &&
1419 special_storage_policy_->HasIsolatedStorage(origin); 1419 special_storage_policy_->HasIsolatedStorage(origin);
1420 } 1420 }
1421 1421
1422 } // namespace storage 1422 } // namespace storage
OLDNEW
« no previous file with comments | « storage/browser/fileapi/file_system_operation_runner.cc ('k') | storage/browser/fileapi/sandbox_file_stream_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698