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

Side by Side Diff: webkit/browser/fileapi/sandbox_origin_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_origin_database.h" 5 #include "webkit/browser/fileapi/sandbox_origin_database.h"
6 6
7 #include <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 const char* LastPathKey() { 52 const char* LastPathKey() {
53 return kLastPathKey; 53 return kLastPathKey;
54 } 54 }
55 55
56 } // namespace 56 } // namespace
57 57
58 namespace fileapi { 58 namespace fileapi {
59 59
60 SandboxOriginDatabase::SandboxOriginDatabase( 60 SandboxOriginDatabase::SandboxOriginDatabase(
61 const base::FilePath& file_system_directory) 61 const base::FilePath& file_system_directory,
62 : file_system_directory_(file_system_directory) { 62 leveldb::Env* env_override)
63 : file_system_directory_(file_system_directory),
64 env_override_(env_override) {
63 } 65 }
64 66
65 SandboxOriginDatabase::~SandboxOriginDatabase() { 67 SandboxOriginDatabase::~SandboxOriginDatabase() {
66 } 68 }
67 69
68 bool SandboxOriginDatabase::Init(InitOption init_option, 70 bool SandboxOriginDatabase::Init(InitOption init_option,
69 RecoveryOption recovery_option) { 71 RecoveryOption recovery_option) {
70 if (db_) 72 if (db_)
71 return true; 73 return true;
72 74
73 base::FilePath db_path = GetDatabasePath(); 75 base::FilePath db_path = GetDatabasePath();
74 if (init_option == FAIL_IF_NONEXISTENT && !base::PathExists(db_path)) 76 if (init_option == FAIL_IF_NONEXISTENT && !base::PathExists(db_path))
75 return false; 77 return false;
76 78
77 std::string path = FilePathToString(db_path); 79 std::string path = FilePathToString(db_path);
78 leveldb::Options options; 80 leveldb::Options options;
79 options.max_open_files = 0; // Use minimum. 81 options.max_open_files = 0; // Use minimum.
80 options.create_if_missing = true; 82 options.create_if_missing = true;
83 if (env_override_)
84 options.env = env_override_;
81 leveldb::DB* db; 85 leveldb::DB* db;
82 leveldb::Status status = leveldb::DB::Open(options, path, &db); 86 leveldb::Status status = leveldb::DB::Open(options, path, &db);
83 ReportInitStatus(status); 87 ReportInitStatus(status);
84 if (status.ok()) { 88 if (status.ok()) {
85 db_.reset(db); 89 db_.reset(db);
86 return true; 90 return true;
87 } 91 }
88 HandleError(FROM_HERE, status); 92 HandleError(FROM_HERE, status);
89 93
90 // Corruption due to missing necessary MANIFEST-* file causes IOError instead 94 // Corruption due to missing necessary MANIFEST-* file causes IOError instead
(...skipping 25 matching lines...) Expand all
116 return Init(init_option, FAIL_ON_CORRUPTION); 120 return Init(init_option, FAIL_ON_CORRUPTION);
117 } 121 }
118 NOTREACHED(); 122 NOTREACHED();
119 return false; 123 return false;
120 } 124 }
121 125
122 bool SandboxOriginDatabase::RepairDatabase(const std::string& db_path) { 126 bool SandboxOriginDatabase::RepairDatabase(const std::string& db_path) {
123 DCHECK(!db_.get()); 127 DCHECK(!db_.get());
124 leveldb::Options options; 128 leveldb::Options options;
125 options.max_open_files = 0; // Use minimum. 129 options.max_open_files = 0; // Use minimum.
130 if (env_override_)
131 options.env = env_override_;
126 if (!leveldb::RepairDB(db_path, options).ok() || 132 if (!leveldb::RepairDB(db_path, options).ok() ||
127 !Init(FAIL_IF_NONEXISTENT, FAIL_ON_CORRUPTION)) { 133 !Init(FAIL_IF_NONEXISTENT, FAIL_ON_CORRUPTION)) {
128 LOG(WARNING) << "Failed to repair SandboxOriginDatabase."; 134 LOG(WARNING) << "Failed to repair SandboxOriginDatabase.";
129 return false; 135 return false;
130 } 136 }
131 137
132 // See if the repaired entries match with what we have on disk. 138 // See if the repaired entries match with what we have on disk.
133 std::set<base::FilePath> directories; 139 std::set<base::FilePath> directories;
134 base::FileEnumerator file_enum(file_system_directory_, 140 base::FileEnumerator file_enum(file_system_directory_,
135 false /* recursive */, 141 false /* recursive */,
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 db_->Put(leveldb::WriteOptions(), LastPathKey(), std::string("-1")); 338 db_->Put(leveldb::WriteOptions(), LastPathKey(), std::string("-1"));
333 if (!status.ok()) { 339 if (!status.ok()) {
334 HandleError(FROM_HERE, status); 340 HandleError(FROM_HERE, status);
335 return false; 341 return false;
336 } 342 }
337 *number = -1; 343 *number = -1;
338 return true; 344 return true;
339 } 345 }
340 346
341 } // namespace fileapi 347 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/browser/fileapi/sandbox_origin_database.h ('k') | webkit/browser/fileapi/sandbox_origin_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698