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

Side by Side Diff: webkit/fileapi/obfuscated_file_util.cc

Issue 9663021: Add database recovery for FileSystemOriginDatabase (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 9 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
« no previous file with comments | « webkit/fileapi/file_system_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/fileapi/obfuscated_file_util.h" 5 #include "webkit/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 13 matching lines...) Expand all
24 #include "webkit/fileapi/file_system_util.h" 24 #include "webkit/fileapi/file_system_util.h"
25 #include "webkit/fileapi/sandbox_mount_point_provider.h" 25 #include "webkit/fileapi/sandbox_mount_point_provider.h"
26 #include "webkit/quota/quota_manager.h" 26 #include "webkit/quota/quota_manager.h"
27 27
28 namespace fileapi { 28 namespace fileapi {
29 29
30 namespace { 30 namespace {
31 31
32 const int64 kFlushDelaySeconds = 10 * 60; // 10 minutes 32 const int64 kFlushDelaySeconds = 10 * 60; // 10 minutes
33 33
34 const char kOriginDatabaseName[] = "Origins";
35 const char kDirectoryDatabaseName[] = "Paths";
36
37 void InitFileInfo( 34 void InitFileInfo(
38 FileSystemDirectoryDatabase::FileInfo* file_info, 35 FileSystemDirectoryDatabase::FileInfo* file_info,
39 FileSystemDirectoryDatabase::FileId parent_id, 36 FileSystemDirectoryDatabase::FileId parent_id,
40 const FilePath::StringType& file_name) { 37 const FilePath::StringType& file_name) {
41 DCHECK(file_info); 38 DCHECK(file_info);
42 file_info->parent_id = parent_id; 39 file_info->parent_id = parent_id;
43 file_info->name = file_name; 40 file_info->name = file_name;
44 } 41 }
45 42
46 bool IsRootDirectory(const FileSystemPath& virtual_path) { 43 bool IsRootDirectory(const FileSystemPath& virtual_path) {
(...skipping 989 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 FileSystemDirectoryDatabase* database = iter->second; 1033 FileSystemDirectoryDatabase* database = iter->second;
1037 directories_.erase(iter); 1034 directories_.erase(iter);
1038 delete database; 1035 delete database;
1039 } 1036 }
1040 1037
1041 FilePath path = GetDirectoryForOriginAndType(origin, type, false); 1038 FilePath path = GetDirectoryForOriginAndType(origin, type, false);
1042 if (path.empty()) 1039 if (path.empty())
1043 return true; 1040 return true;
1044 if (!file_util::DirectoryExists(path)) 1041 if (!file_util::DirectoryExists(path))
1045 return true; 1042 return true;
1046 path = path.AppendASCII(kDirectoryDatabaseName);
1047 return FileSystemDirectoryDatabase::DestroyDatabase(path); 1043 return FileSystemDirectoryDatabase::DestroyDatabase(path);
1048 } 1044 }
1049 1045
1050 // static 1046 // static
1051 int64 ObfuscatedFileUtil::ComputeFilePathCost(const FilePath& path) { 1047 int64 ObfuscatedFileUtil::ComputeFilePathCost(const FilePath& path) {
1052 return GetPathQuotaUsage(1, VirtualPath::BaseName(path).value().size()); 1048 return GetPathQuotaUsage(1, VirtualPath::BaseName(path).value().size());
1053 } 1049 }
1054 1050
1055 PlatformFileError ObfuscatedFileUtil::GetFileInfoInternal( 1051 PlatformFileError ObfuscatedFileUtil::GetFileInfoInternal(
1056 FileSystemDirectoryDatabase* db, 1052 FileSystemDirectoryDatabase* db,
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 FilePath path = GetDirectoryForOriginAndType(origin, type, create); 1243 FilePath path = GetDirectoryForOriginAndType(origin, type, create);
1248 if (path.empty()) 1244 if (path.empty())
1249 return NULL; 1245 return NULL;
1250 if (!file_util::DirectoryExists(path)) { 1246 if (!file_util::DirectoryExists(path)) {
1251 if (!file_util::CreateDirectory(path)) { 1247 if (!file_util::CreateDirectory(path)) {
1252 LOG(WARNING) << "Failed to origin+type directory: " << path.value(); 1248 LOG(WARNING) << "Failed to origin+type directory: " << path.value();
1253 return NULL; 1249 return NULL;
1254 } 1250 }
1255 } 1251 }
1256 MarkUsed(); 1252 MarkUsed();
1257 path = path.AppendASCII(kDirectoryDatabaseName);
1258 FileSystemDirectoryDatabase* database = new FileSystemDirectoryDatabase(path); 1253 FileSystemDirectoryDatabase* database = new FileSystemDirectoryDatabase(path);
1259 directories_[key] = database; 1254 directories_[key] = database;
1260 return database; 1255 return database;
1261 } 1256 }
1262 1257
1263 FilePath ObfuscatedFileUtil::GetDirectoryForOrigin( 1258 FilePath ObfuscatedFileUtil::GetDirectoryForOrigin(
1264 const GURL& origin, bool create) { 1259 const GURL& origin, bool create) {
1265 if (!InitOriginDatabase(create)) 1260 if (!InitOriginDatabase(create))
1266 return FilePath(); 1261 return FilePath();
1267 FilePath directory_name; 1262 FilePath directory_name;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 bool ObfuscatedFileUtil::InitOriginDatabase(bool create) { 1302 bool ObfuscatedFileUtil::InitOriginDatabase(bool create) {
1308 if (!origin_database_.get()) { 1303 if (!origin_database_.get()) {
1309 if (!create && !file_util::DirectoryExists(file_system_directory_)) 1304 if (!create && !file_util::DirectoryExists(file_system_directory_))
1310 return false; 1305 return false;
1311 if (!file_util::CreateDirectory(file_system_directory_)) { 1306 if (!file_util::CreateDirectory(file_system_directory_)) {
1312 LOG(WARNING) << "Failed to create FileSystem directory: " << 1307 LOG(WARNING) << "Failed to create FileSystem directory: " <<
1313 file_system_directory_.value(); 1308 file_system_directory_.value();
1314 return false; 1309 return false;
1315 } 1310 }
1316 origin_database_.reset( 1311 origin_database_.reset(
1317 new FileSystemOriginDatabase( 1312 new FileSystemOriginDatabase(file_system_directory_));
1318 file_system_directory_.AppendASCII(kOriginDatabaseName)));
1319 } 1313 }
1320 return true; 1314 return true;
1321 } 1315 }
1322 1316
1323 } // namespace fileapi 1317 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698