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

Side by Side Diff: webkit/browser/fileapi/obfuscated_file_util.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/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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 247
248 private: 248 private:
249 std::vector<OriginRecord> origins_; 249 std::vector<OriginRecord> origins_;
250 OriginRecord current_; 250 OriginRecord current_;
251 base::FilePath base_file_path_; 251 base::FilePath base_file_path_;
252 }; 252 };
253 253
254 ObfuscatedFileUtil::ObfuscatedFileUtil( 254 ObfuscatedFileUtil::ObfuscatedFileUtil(
255 quota::SpecialStoragePolicy* special_storage_policy, 255 quota::SpecialStoragePolicy* special_storage_policy,
256 const base::FilePath& file_system_directory, 256 const base::FilePath& file_system_directory,
257 leveldb::Env* env_override,
257 base::SequencedTaskRunner* file_task_runner, 258 base::SequencedTaskRunner* file_task_runner,
258 const GetTypeStringForURLCallback& get_type_string_for_url, 259 const GetTypeStringForURLCallback& get_type_string_for_url,
259 const std::set<std::string>& known_type_strings, 260 const std::set<std::string>& known_type_strings,
260 SandboxFileSystemBackendDelegate* sandbox_delegate) 261 SandboxFileSystemBackendDelegate* sandbox_delegate)
261 : special_storage_policy_(special_storage_policy), 262 : special_storage_policy_(special_storage_policy),
262 file_system_directory_(file_system_directory), 263 file_system_directory_(file_system_directory),
264 env_override_(env_override),
263 db_flush_delay_seconds_(10 * 60), // 10 mins. 265 db_flush_delay_seconds_(10 * 60), // 10 mins.
264 file_task_runner_(file_task_runner), 266 file_task_runner_(file_task_runner),
265 get_type_string_for_url_(get_type_string_for_url), 267 get_type_string_for_url_(get_type_string_for_url),
266 known_type_strings_(known_type_strings), 268 known_type_strings_(known_type_strings),
267 sandbox_delegate_(sandbox_delegate) { 269 sandbox_delegate_(sandbox_delegate) {
268 } 270 }
269 271
270 ObfuscatedFileUtil::~ObfuscatedFileUtil() { 272 ObfuscatedFileUtil::~ObfuscatedFileUtil() {
271 DropDatabases(); 273 DropDatabases();
272 } 274 }
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 SandboxDirectoryDatabase* database = iter->second; 939 SandboxDirectoryDatabase* database = iter->second;
938 directories_.erase(iter); 940 directories_.erase(iter);
939 delete database; 941 delete database;
940 } 942 }
941 943
942 base::File::Error error = base::File::FILE_OK; 944 base::File::Error error = base::File::FILE_OK;
943 base::FilePath path = GetDirectoryForOriginAndType( 945 base::FilePath path = GetDirectoryForOriginAndType(
944 origin, type_string, false, &error); 946 origin, type_string, false, &error);
945 if (path.empty() || error == base::File::FILE_ERROR_NOT_FOUND) 947 if (path.empty() || error == base::File::FILE_ERROR_NOT_FOUND)
946 return true; 948 return true;
947 return SandboxDirectoryDatabase::DestroyDatabase(path); 949 return SandboxDirectoryDatabase::DestroyDatabase(path, env_override_);
948 } 950 }
949 951
950 // static 952 // static
951 int64 ObfuscatedFileUtil::ComputeFilePathCost(const base::FilePath& path) { 953 int64 ObfuscatedFileUtil::ComputeFilePathCost(const base::FilePath& path) {
952 return UsageForPath(VirtualPath::BaseName(path).value().size()); 954 return UsageForPath(VirtualPath::BaseName(path).value().size());
953 } 955 }
954 956
955 void ObfuscatedFileUtil::MaybePrepopulateDatabase( 957 void ObfuscatedFileUtil::MaybePrepopulateDatabase(
956 const std::vector<std::string>& type_strings_to_prepopulate) { 958 const std::vector<std::string>& type_strings_to_prepopulate) {
957 SandboxPrioritizedOriginDatabase database(file_system_directory_); 959 SandboxPrioritizedOriginDatabase database(file_system_directory_,
960 env_override_);
958 std::string origin_string = database.GetPrimaryOrigin(); 961 std::string origin_string = database.GetPrimaryOrigin();
959 if (origin_string.empty() || !database.HasOriginPath(origin_string)) 962 if (origin_string.empty() || !database.HasOriginPath(origin_string))
960 return; 963 return;
961 const GURL origin = webkit_database::GetOriginFromIdentifier(origin_string); 964 const GURL origin = webkit_database::GetOriginFromIdentifier(origin_string);
962 965
963 // Prepopulate the directory database(s) if and only if this instance 966 // Prepopulate the directory database(s) if and only if this instance
964 // has primary origin and the directory database is already there. 967 // has primary origin and the directory database is already there.
965 for (size_t i = 0; i < type_strings_to_prepopulate.size(); ++i) { 968 for (size_t i = 0; i < type_strings_to_prepopulate.size(); ++i) {
966 const std::string type_string = type_strings_to_prepopulate[i]; 969 const std::string type_string = type_strings_to_prepopulate[i];
967 // Only handles known types. 970 // Only handles known types.
968 if (!ContainsKey(known_type_strings_, type_string)) 971 if (!ContainsKey(known_type_strings_, type_string))
969 continue; 972 continue;
970 base::File::Error error = base::File::FILE_ERROR_FAILED; 973 base::File::Error error = base::File::FILE_ERROR_FAILED;
971 base::FilePath path = GetDirectoryForOriginAndType( 974 base::FilePath path = GetDirectoryForOriginAndType(
972 origin, type_string, false, &error); 975 origin, type_string, false, &error);
973 if (error != base::File::FILE_OK) 976 if (error != base::File::FILE_OK)
974 continue; 977 continue;
975 scoped_ptr<SandboxDirectoryDatabase> db(new SandboxDirectoryDatabase(path)); 978 scoped_ptr<SandboxDirectoryDatabase> db(
979 new SandboxDirectoryDatabase(path, env_override_));
976 if (db->Init(SandboxDirectoryDatabase::FAIL_ON_CORRUPTION)) { 980 if (db->Init(SandboxDirectoryDatabase::FAIL_ON_CORRUPTION)) {
977 directories_[GetDirectoryDatabaseKey(origin, type_string)] = db.release(); 981 directories_[GetDirectoryDatabaseKey(origin, type_string)] = db.release();
978 MarkUsed(); 982 MarkUsed();
979 // Don't populate more than one database, as it may rather hurt 983 // Don't populate more than one database, as it may rather hurt
980 // performance. 984 // performance.
981 break; 985 break;
982 } 986 }
983 } 987 }
984 } 988 }
985 989
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 } 1170 }
1167 1171
1168 base::File::Error error = base::File::FILE_OK; 1172 base::File::Error error = base::File::FILE_OK;
1169 base::FilePath path = GetDirectoryForURL(url, create, &error); 1173 base::FilePath path = GetDirectoryForURL(url, create, &error);
1170 if (error != base::File::FILE_OK) { 1174 if (error != base::File::FILE_OK) {
1171 LOG(WARNING) << "Failed to get origin+type directory: " 1175 LOG(WARNING) << "Failed to get origin+type directory: "
1172 << url.DebugString() << " error:" << error; 1176 << url.DebugString() << " error:" << error;
1173 return NULL; 1177 return NULL;
1174 } 1178 }
1175 MarkUsed(); 1179 MarkUsed();
1176 SandboxDirectoryDatabase* database = new SandboxDirectoryDatabase(path); 1180 SandboxDirectoryDatabase* database =
1181 new SandboxDirectoryDatabase(path, env_override_);
1177 directories_[key] = database; 1182 directories_[key] = database;
1178 return database; 1183 return database;
1179 } 1184 }
1180 1185
1181 base::FilePath ObfuscatedFileUtil::GetDirectoryForOrigin( 1186 base::FilePath ObfuscatedFileUtil::GetDirectoryForOrigin(
1182 const GURL& origin, bool create, base::File::Error* error_code) { 1187 const GURL& origin, bool create, base::File::Error* error_code) {
1183 if (!InitOriginDatabase(origin, create)) { 1188 if (!InitOriginDatabase(origin, create)) {
1184 if (error_code) { 1189 if (error_code) {
1185 *error_code = create ? 1190 *error_code = create ?
1186 base::File::FILE_ERROR_FAILED : 1191 base::File::FILE_ERROR_FAILED :
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 1272
1268 if (!create && !base::DirectoryExists(file_system_directory_)) 1273 if (!create && !base::DirectoryExists(file_system_directory_))
1269 return false; 1274 return false;
1270 if (!base::CreateDirectory(file_system_directory_)) { 1275 if (!base::CreateDirectory(file_system_directory_)) {
1271 LOG(WARNING) << "Failed to create FileSystem directory: " << 1276 LOG(WARNING) << "Failed to create FileSystem directory: " <<
1272 file_system_directory_.value(); 1277 file_system_directory_.value();
1273 return false; 1278 return false;
1274 } 1279 }
1275 1280
1276 SandboxPrioritizedOriginDatabase* prioritized_origin_database = 1281 SandboxPrioritizedOriginDatabase* prioritized_origin_database =
1277 new SandboxPrioritizedOriginDatabase(file_system_directory_); 1282 new SandboxPrioritizedOriginDatabase(file_system_directory_,
1283 env_override_);
1278 origin_database_.reset(prioritized_origin_database); 1284 origin_database_.reset(prioritized_origin_database);
1279 1285
1280 if (origin_hint.is_empty() || !HasIsolatedStorage(origin_hint)) 1286 if (origin_hint.is_empty() || !HasIsolatedStorage(origin_hint))
1281 return true; 1287 return true;
1282 1288
1283 const std::string isolated_origin_string = 1289 const std::string isolated_origin_string =
1284 webkit_database::GetIdentifierFromOrigin(origin_hint); 1290 webkit_database::GetIdentifierFromOrigin(origin_hint);
1285 1291
1286 // TODO(kinuko): Deprecate this after a few release cycles, e.g. around M33. 1292 // TODO(kinuko): Deprecate this after a few release cycles, e.g. around M33.
1287 base::FilePath isolated_origin_dir = file_system_directory_.Append( 1293 base::FilePath isolated_origin_dir = file_system_directory_.Append(
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 } 1414 }
1409 return error; 1415 return error;
1410 } 1416 }
1411 1417
1412 bool ObfuscatedFileUtil::HasIsolatedStorage(const GURL& origin) { 1418 bool ObfuscatedFileUtil::HasIsolatedStorage(const GURL& origin) {
1413 return special_storage_policy_.get() && 1419 return special_storage_policy_.get() &&
1414 special_storage_policy_->HasIsolatedStorage(origin); 1420 special_storage_policy_->HasIsolatedStorage(origin);
1415 } 1421 }
1416 1422
1417 } // namespace fileapi 1423 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/browser/fileapi/obfuscated_file_util.h ('k') | webkit/browser/fileapi/plugin_private_file_system_backend.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698