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

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

Issue 145693005: [FileAPI] Replace default leveldb::Env with leveldb::MemEnv in tests. (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 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 403
404 namespace fileapi { 404 namespace fileapi {
405 405
406 SandboxDirectoryDatabase::FileInfo::FileInfo() : parent_id(0) { 406 SandboxDirectoryDatabase::FileInfo::FileInfo() : parent_id(0) {
407 } 407 }
408 408
409 SandboxDirectoryDatabase::FileInfo::~FileInfo() { 409 SandboxDirectoryDatabase::FileInfo::~FileInfo() {
410 } 410 }
411 411
412 SandboxDirectoryDatabase::SandboxDirectoryDatabase( 412 SandboxDirectoryDatabase::SandboxDirectoryDatabase(
413 const base::FilePath& filesystem_data_directory) 413 const base::FilePath& filesystem_data_directory,
414 : filesystem_data_directory_(filesystem_data_directory) { 414 leveldb::Env* env_override)
415 : filesystem_data_directory_(filesystem_data_directory),
416 env_override_(env_override) {
415 } 417 }
416 418
417 SandboxDirectoryDatabase::~SandboxDirectoryDatabase() { 419 SandboxDirectoryDatabase::~SandboxDirectoryDatabase() {
418 } 420 }
419 421
420 bool SandboxDirectoryDatabase::GetChildWithName( 422 bool SandboxDirectoryDatabase::GetChildWithName(
421 FileId parent_id, 423 FileId parent_id,
422 const base::FilePath::StringType& name, 424 const base::FilePath::StringType& name,
423 FileId* child_id) { 425 FileId* child_id) {
424 if (!Init(REPAIR_ON_CORRUPTION)) 426 if (!Init(REPAIR_ON_CORRUPTION))
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 return false; 694 return false;
693 } 695 }
694 // The database must not yet exist; initialize it. 696 // The database must not yet exist; initialize it.
695 if (!StoreDefaultValues()) 697 if (!StoreDefaultValues())
696 return false; 698 return false;
697 699
698 return GetNextInteger(next); 700 return GetNextInteger(next);
699 } 701 }
700 702
701 // static 703 // static
702 bool SandboxDirectoryDatabase::DestroyDatabase(const base::FilePath& path) { 704 bool SandboxDirectoryDatabase::DestroyDatabase(const base::FilePath& path,
705 leveldb::Env* env_override) {
703 std::string name = FilePathToString(path.Append(kDirectoryDatabaseName)); 706 std::string name = FilePathToString(path.Append(kDirectoryDatabaseName));
704 leveldb::Status status = leveldb::DestroyDB(name, leveldb::Options()); 707 leveldb::Options options;
708 if (env_override)
709 options.env = env_override;
710 leveldb::Status status = leveldb::DestroyDB(name, options);
705 if (status.ok()) 711 if (status.ok())
706 return true; 712 return true;
707 LOG(WARNING) << "Failed to destroy a database with status " << 713 LOG(WARNING) << "Failed to destroy a database with status " <<
708 status.ToString(); 714 status.ToString();
709 return false; 715 return false;
710 } 716 }
711 717
712 bool SandboxDirectoryDatabase::Init(RecoveryOption recovery_option) { 718 bool SandboxDirectoryDatabase::Init(RecoveryOption recovery_option) {
713 if (db_) 719 if (db_)
714 return true; 720 return true;
715 721
716 std::string path = 722 std::string path =
717 FilePathToString(filesystem_data_directory_.Append( 723 FilePathToString(filesystem_data_directory_.Append(
718 kDirectoryDatabaseName)); 724 kDirectoryDatabaseName));
719 leveldb::Options options; 725 leveldb::Options options;
720 options.max_open_files = 0; // Use minimum. 726 options.max_open_files = 0; // Use minimum.
721 options.create_if_missing = true; 727 options.create_if_missing = true;
728 if (env_override_)
729 options.env = env_override_;
722 leveldb::DB* db; 730 leveldb::DB* db;
723 leveldb::Status status = leveldb::DB::Open(options, path, &db); 731 leveldb::Status status = leveldb::DB::Open(options, path, &db);
724 ReportInitStatus(status); 732 ReportInitStatus(status);
725 if (status.ok()) { 733 if (status.ok()) {
726 db_.reset(db); 734 db_.reset(db);
727 return true; 735 return true;
728 } 736 }
729 HandleError(FROM_HERE, status); 737 HandleError(FROM_HERE, status);
730 738
731 // Corruption due to missing necessary MANIFEST-* file causes IOError instead 739 // Corruption due to missing necessary MANIFEST-* file causes IOError instead
(...skipping 27 matching lines...) Expand all
759 } 767 }
760 768
761 NOTREACHED(); 769 NOTREACHED();
762 return false; 770 return false;
763 } 771 }
764 772
765 bool SandboxDirectoryDatabase::RepairDatabase(const std::string& db_path) { 773 bool SandboxDirectoryDatabase::RepairDatabase(const std::string& db_path) {
766 DCHECK(!db_.get()); 774 DCHECK(!db_.get());
767 leveldb::Options options; 775 leveldb::Options options;
768 options.max_open_files = 0; // Use minimum. 776 options.max_open_files = 0; // Use minimum.
777 if (env_override_)
778 options.env = env_override_;
769 if (!leveldb::RepairDB(db_path, options).ok()) 779 if (!leveldb::RepairDB(db_path, options).ok())
770 return false; 780 return false;
771 if (!Init(FAIL_ON_CORRUPTION)) 781 if (!Init(FAIL_ON_CORRUPTION))
772 return false; 782 return false;
773 if (IsFileSystemConsistent()) 783 if (IsFileSystemConsistent())
774 return true; 784 return true;
775 db_.reset(); 785 db_.reset();
776 return false; 786 return false;
777 } 787 }
778 788
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 929
920 void SandboxDirectoryDatabase::HandleError( 930 void SandboxDirectoryDatabase::HandleError(
921 const tracked_objects::Location& from_here, 931 const tracked_objects::Location& from_here,
922 const leveldb::Status& status) { 932 const leveldb::Status& status) {
923 LOG(ERROR) << "SandboxDirectoryDatabase failed at: " 933 LOG(ERROR) << "SandboxDirectoryDatabase failed at: "
924 << from_here.ToString() << " with error: " << status.ToString(); 934 << from_here.ToString() << " with error: " << status.ToString();
925 db_.reset(); 935 db_.reset();
926 } 936 }
927 937
928 } // namespace fileapi 938 } // 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