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

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

Issue 145303002: Convert Media Galleries to use base::File (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 10 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/sandbox_directory_database.h" 5 #include "webkit/browser/fileapi/sandbox_directory_database.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <set> 9 #include <set>
10 #include <stack> 10 #include <stack>
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 info->name = base::FilePath::StringType(); 511 info->name = base::FilePath::StringType();
512 info->data_path = base::FilePath(); 512 info->data_path = base::FilePath();
513 info->modification_time = base::Time::Now(); 513 info->modification_time = base::Time::Now();
514 info->parent_id = 0; 514 info->parent_id = 0;
515 return true; 515 return true;
516 } 516 }
517 HandleError(FROM_HERE, status); 517 HandleError(FROM_HERE, status);
518 return false; 518 return false;
519 } 519 }
520 520
521 base::PlatformFileError SandboxDirectoryDatabase::AddFileInfo( 521 base::File::Error SandboxDirectoryDatabase::AddFileInfo(
522 const FileInfo& info, FileId* file_id) { 522 const FileInfo& info, FileId* file_id) {
523 if (!Init(REPAIR_ON_CORRUPTION)) 523 if (!Init(REPAIR_ON_CORRUPTION))
524 return base::PLATFORM_FILE_ERROR_FAILED; 524 return base::File::FILE_ERROR_FAILED;
525 DCHECK(file_id); 525 DCHECK(file_id);
526 std::string child_key = GetChildLookupKey(info.parent_id, info.name); 526 std::string child_key = GetChildLookupKey(info.parent_id, info.name);
527 std::string child_id_string; 527 std::string child_id_string;
528 leveldb::Status status = 528 leveldb::Status status =
529 db_->Get(leveldb::ReadOptions(), child_key, &child_id_string); 529 db_->Get(leveldb::ReadOptions(), child_key, &child_id_string);
530 if (status.ok()) { 530 if (status.ok()) {
531 LOG(ERROR) << "File exists already!"; 531 LOG(ERROR) << "File exists already!";
532 return base::PLATFORM_FILE_ERROR_EXISTS; 532 return base::File::FILE_ERROR_EXISTS;
533 } 533 }
534 if (!status.IsNotFound()) { 534 if (!status.IsNotFound()) {
535 HandleError(FROM_HERE, status); 535 HandleError(FROM_HERE, status);
536 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 536 return base::File::FILE_ERROR_NOT_FOUND;
537 } 537 }
538 538
539 if (!IsDirectory(info.parent_id)) { 539 if (!IsDirectory(info.parent_id)) {
540 LOG(ERROR) << "New parent directory is a file!"; 540 LOG(ERROR) << "New parent directory is a file!";
541 return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; 541 return base::File::FILE_ERROR_NOT_A_DIRECTORY;
542 } 542 }
543 543
544 // This would be a fine place to limit the number of files in a directory, if 544 // This would be a fine place to limit the number of files in a directory, if
545 // we decide to add that restriction. 545 // we decide to add that restriction.
546 546
547 FileId temp_id; 547 FileId temp_id;
548 if (!GetLastFileId(&temp_id)) 548 if (!GetLastFileId(&temp_id))
549 return base::PLATFORM_FILE_ERROR_FAILED; 549 return base::File::FILE_ERROR_FAILED;
550 ++temp_id; 550 ++temp_id;
551 551
552 leveldb::WriteBatch batch; 552 leveldb::WriteBatch batch;
553 if (!AddFileInfoHelper(info, temp_id, &batch)) 553 if (!AddFileInfoHelper(info, temp_id, &batch))
554 return base::PLATFORM_FILE_ERROR_FAILED; 554 return base::File::FILE_ERROR_FAILED;
555 555
556 batch.Put(LastFileIdKey(), base::Int64ToString(temp_id)); 556 batch.Put(LastFileIdKey(), base::Int64ToString(temp_id));
557 status = db_->Write(leveldb::WriteOptions(), &batch); 557 status = db_->Write(leveldb::WriteOptions(), &batch);
558 if (!status.ok()) { 558 if (!status.ok()) {
559 HandleError(FROM_HERE, status); 559 HandleError(FROM_HERE, status);
560 return base::PLATFORM_FILE_ERROR_FAILED; 560 return base::File::FILE_ERROR_FAILED;
561 } 561 }
562 *file_id = temp_id; 562 *file_id = temp_id;
563 return base::PLATFORM_FILE_OK; 563 return base::File::FILE_OK;
564 } 564 }
565 565
566 bool SandboxDirectoryDatabase::RemoveFileInfo(FileId file_id) { 566 bool SandboxDirectoryDatabase::RemoveFileInfo(FileId file_id) {
567 if (!Init(REPAIR_ON_CORRUPTION)) 567 if (!Init(REPAIR_ON_CORRUPTION))
568 return false; 568 return false;
569 leveldb::WriteBatch batch; 569 leveldb::WriteBatch batch;
570 if (!RemoveFileInfoHelper(file_id, &batch)) 570 if (!RemoveFileInfoHelper(file_id, &batch))
571 return false; 571 return false;
572 leveldb::Status status = db_->Write(leveldb::WriteOptions(), &batch); 572 leveldb::Status status = db_->Write(leveldb::WriteOptions(), &batch);
573 if (!status.ok()) { 573 if (!status.ok()) {
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 919
920 void SandboxDirectoryDatabase::HandleError( 920 void SandboxDirectoryDatabase::HandleError(
921 const tracked_objects::Location& from_here, 921 const tracked_objects::Location& from_here,
922 const leveldb::Status& status) { 922 const leveldb::Status& status) {
923 LOG(ERROR) << "SandboxDirectoryDatabase failed at: " 923 LOG(ERROR) << "SandboxDirectoryDatabase failed at: "
924 << from_here.ToString() << " with error: " << status.ToString(); 924 << from_here.ToString() << " with error: " << status.ToString();
925 db_.reset(); 925 db_.reset();
926 } 926 }
927 927
928 } // namespace fileapi 928 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/browser/fileapi/sandbox_directory_database.h ('k') | webkit/browser/fileapi/sandbox_directory_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698