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

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

Issue 492873002: Collapse fileapi, webkit_blob, webkit_database, quota, and webkit_common namespaces into single sto… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix chromeos build Created 6 years, 4 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 25 matching lines...) Expand all
36 36
37 // Example of various paths: 37 // Example of various paths:
38 // void ObfuscatedFileUtil::DoSomething(const FileSystemURL& url) { 38 // void ObfuscatedFileUtil::DoSomething(const FileSystemURL& url) {
39 // base::FilePath virtual_path = url.path(); 39 // base::FilePath virtual_path = url.path();
40 // base::FilePath local_path = GetLocalFilePath(url); 40 // base::FilePath local_path = GetLocalFilePath(url);
41 // 41 //
42 // NativeFileUtil::DoSomething(local_path); 42 // NativeFileUtil::DoSomething(local_path);
43 // file_util::DoAnother(local_path); 43 // file_util::DoAnother(local_path);
44 // } 44 // }
45 45
46 namespace fileapi { 46 namespace storage {
47 47
48 namespace { 48 namespace {
49 49
50 typedef SandboxDirectoryDatabase::FileId FileId; 50 typedef SandboxDirectoryDatabase::FileId FileId;
51 typedef SandboxDirectoryDatabase::FileInfo FileInfo; 51 typedef SandboxDirectoryDatabase::FileInfo FileInfo;
52 52
53 void InitFileInfo( 53 void InitFileInfo(
54 SandboxDirectoryDatabase::FileInfo* file_info, 54 SandboxDirectoryDatabase::FileInfo* file_info,
55 SandboxDirectoryDatabase::FileId parent_id, 55 SandboxDirectoryDatabase::FileId parent_id,
56 const base::FilePath::StringType& file_name) { 56 const base::FilePath::StringType& file_name) {
57 DCHECK(file_info); 57 DCHECK(file_info);
58 file_info->parent_id = parent_id; 58 file_info->parent_id = parent_id;
59 file_info->name = file_name; 59 file_info->name = file_name;
60 } 60 }
61 61
62 // Costs computed as per crbug.com/86114, based on the LevelDB implementation of 62 // Costs computed as per crbug.com/86114, based on the LevelDB implementation of
63 // path storage under Linux. It's not clear if that will differ on Windows, on 63 // path storage under Linux. It's not clear if that will differ on Windows, on
64 // which base::FilePath uses wide chars [since they're converted to UTF-8 for 64 // which base::FilePath uses wide chars [since they're converted to UTF-8 for
65 // storage anyway], but as long as the cost is high enough that one can't cheat 65 // storage anyway], but as long as the cost is high enough that one can't cheat
66 // on quota by storing data in paths, it doesn't need to be all that accurate. 66 // on quota by storing data in paths, it doesn't need to be all that accurate.
67 const int64 kPathCreationQuotaCost = 146; // Bytes per inode, basically. 67 const int64 kPathCreationQuotaCost = 146; // Bytes per inode, basically.
68 const int64 kPathByteQuotaCost = 2; // Bytes per byte of path length in UTF-8. 68 const int64 kPathByteQuotaCost = 2; // Bytes per byte of path length in UTF-8.
69 69
70 int64 UsageForPath(size_t length) { 70 int64 UsageForPath(size_t length) {
71 return kPathCreationQuotaCost + 71 return kPathCreationQuotaCost +
72 static_cast<int64>(length) * kPathByteQuotaCost; 72 static_cast<int64>(length) * kPathByteQuotaCost;
73 } 73 }
74 74
75 bool AllocateQuota(FileSystemOperationContext* context, int64 growth) { 75 bool AllocateQuota(FileSystemOperationContext* context, int64 growth) {
76 if (context->allowed_bytes_growth() == quota::QuotaManager::kNoLimit) 76 if (context->allowed_bytes_growth() == storage::QuotaManager::kNoLimit)
77 return true; 77 return true;
78 78
79 int64 new_quota = context->allowed_bytes_growth() - growth; 79 int64 new_quota = context->allowed_bytes_growth() - growth;
80 if (growth > 0 && new_quota < 0) 80 if (growth > 0 && new_quota < 0)
81 return false; 81 return false;
82 context->set_allowed_bytes_growth(new_quota); 82 context->set_allowed_bytes_growth(new_quota);
83 return true; 83 return true;
84 } 84 }
85 85
86 void UpdateUsage( 86 void UpdateUsage(
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 virtual ~ObfuscatedOriginEnumerator() {} 220 virtual ~ObfuscatedOriginEnumerator() {}
221 221
222 // Returns the next origin. Returns empty if there are no more origins. 222 // Returns the next origin. Returns empty if there are no more origins.
223 virtual GURL Next() OVERRIDE { 223 virtual GURL Next() OVERRIDE {
224 OriginRecord record; 224 OriginRecord record;
225 if (!origins_.empty()) { 225 if (!origins_.empty()) {
226 record = origins_.back(); 226 record = origins_.back();
227 origins_.pop_back(); 227 origins_.pop_back();
228 } 228 }
229 current_ = record; 229 current_ = record;
230 return webkit_database::GetOriginFromIdentifier(record.origin); 230 return storage::GetOriginFromIdentifier(record.origin);
231 } 231 }
232 232
233 // Returns the current origin's information. 233 // Returns the current origin's information.
234 virtual bool HasTypeDirectory(const std::string& type_string) const OVERRIDE { 234 virtual bool HasTypeDirectory(const std::string& type_string) const OVERRIDE {
235 if (current_.path.empty()) 235 if (current_.path.empty())
236 return false; 236 return false;
237 if (type_string.empty()) { 237 if (type_string.empty()) {
238 NOTREACHED(); 238 NOTREACHED();
239 return false; 239 return false;
240 } 240 }
241 base::FilePath path = 241 base::FilePath path =
242 base_file_path_.Append(current_.path).AppendASCII(type_string); 242 base_file_path_.Append(current_.path).AppendASCII(type_string);
243 return base::DirectoryExists(path); 243 return base::DirectoryExists(path);
244 } 244 }
245 245
246 private: 246 private:
247 std::vector<OriginRecord> origins_; 247 std::vector<OriginRecord> origins_;
248 OriginRecord current_; 248 OriginRecord current_;
249 base::FilePath base_file_path_; 249 base::FilePath base_file_path_;
250 }; 250 };
251 251
252 ObfuscatedFileUtil::ObfuscatedFileUtil( 252 ObfuscatedFileUtil::ObfuscatedFileUtil(
253 quota::SpecialStoragePolicy* special_storage_policy, 253 storage::SpecialStoragePolicy* special_storage_policy,
254 const base::FilePath& file_system_directory, 254 const base::FilePath& file_system_directory,
255 leveldb::Env* env_override, 255 leveldb::Env* env_override,
256 base::SequencedTaskRunner* file_task_runner, 256 base::SequencedTaskRunner* file_task_runner,
257 const GetTypeStringForURLCallback& get_type_string_for_url, 257 const GetTypeStringForURLCallback& get_type_string_for_url,
258 const std::set<std::string>& known_type_strings, 258 const std::set<std::string>& known_type_strings,
259 SandboxFileSystemBackendDelegate* sandbox_delegate) 259 SandboxFileSystemBackendDelegate* sandbox_delegate)
260 : special_storage_policy_(special_storage_policy), 260 : special_storage_policy_(special_storage_policy),
261 file_system_directory_(file_system_directory), 261 file_system_directory_(file_system_directory),
262 env_override_(env_override), 262 env_override_(env_override),
263 db_flush_delay_seconds_(10 * 60), // 10 mins. 263 db_flush_delay_seconds_(10 * 60), // 10 mins.
264 file_task_runner_(file_task_runner), 264 file_task_runner_(file_task_runner),
265 get_type_string_for_url_(get_type_string_for_url), 265 get_type_string_for_url_(get_type_string_for_url),
266 known_type_strings_(known_type_strings), 266 known_type_strings_(known_type_strings),
267 sandbox_delegate_(sandbox_delegate) { 267 sandbox_delegate_(sandbox_delegate) {
268 } 268 }
269 269
270 ObfuscatedFileUtil::~ObfuscatedFileUtil() { 270 ObfuscatedFileUtil::~ObfuscatedFileUtil() {
271 DropDatabases(); 271 DropDatabases();
272 } 272 }
273 273
274 base::File ObfuscatedFileUtil::CreateOrOpen( 274 base::File ObfuscatedFileUtil::CreateOrOpen(
275 FileSystemOperationContext* context, 275 FileSystemOperationContext* context,
276 const FileSystemURL& url, int file_flags) { 276 const FileSystemURL& url, int file_flags) {
277 base::File file = CreateOrOpenInternal(context, url, file_flags); 277 base::File file = CreateOrOpenInternal(context, url, file_flags);
278 if (file.IsValid() && file_flags & base::File::FLAG_WRITE && 278 if (file.IsValid() && file_flags & base::File::FLAG_WRITE &&
279 context->quota_limit_type() == quota::kQuotaLimitTypeUnlimited && 279 context->quota_limit_type() == storage::kQuotaLimitTypeUnlimited &&
280 sandbox_delegate_) { 280 sandbox_delegate_) {
281 sandbox_delegate_->StickyInvalidateUsageCache(url.origin(), url.type()); 281 sandbox_delegate_->StickyInvalidateUsageCache(url.origin(), url.type());
282 } 282 }
283 return file.Pass(); 283 return file.Pass();
284 } 284 }
285 285
286 base::File::Error ObfuscatedFileUtil::EnsureFileExists( 286 base::File::Error ObfuscatedFileUtil::EnsureFileExists(
287 FileSystemOperationContext* context, 287 FileSystemOperationContext* context,
288 const FileSystemURL& url, 288 const FileSystemURL& url,
289 bool* created) { 289 bool* created) {
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 * Move-without-overwrite 572 * Move-without-overwrite
573 * Just update metadata 573 * Just update metadata
574 */ 574 */
575 error = base::File::FILE_ERROR_FAILED; 575 error = base::File::FILE_ERROR_FAILED;
576 if (copy) { 576 if (copy) {
577 if (overwrite) { 577 if (overwrite) {
578 error = NativeFileUtil::CopyOrMoveFile( 578 error = NativeFileUtil::CopyOrMoveFile(
579 src_local_path, 579 src_local_path,
580 dest_local_path, 580 dest_local_path,
581 option, 581 option,
582 fileapi::NativeFileUtil::CopyOrMoveModeForDestination( 582 storage::NativeFileUtil::CopyOrMoveModeForDestination(
583 dest_url, true /* copy */)); 583 dest_url, true /* copy */));
584 } else { // non-overwrite 584 } else { // non-overwrite
585 error = CreateFile(context, src_local_path, dest_url, &dest_file_info); 585 error = CreateFile(context, src_local_path, dest_url, &dest_file_info);
586 } 586 }
587 } else { 587 } else {
588 if (overwrite) { 588 if (overwrite) {
589 if (db->OverwritingMoveFile(src_file_id, dest_file_id)) { 589 if (db->OverwritingMoveFile(src_file_id, dest_file_id)) {
590 if (base::File::FILE_OK != 590 if (base::File::FILE_OK !=
591 NativeFileUtil::DeleteFile(dest_local_path)) 591 NativeFileUtil::DeleteFile(dest_local_path))
592 LOG(WARNING) << "Leaked a backing file."; 592 LOG(WARNING) << "Leaked a backing file.";
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 else 675 else
676 growth += UsageForPath(dest_file_info.name.size()); 676 growth += UsageForPath(dest_file_info.name.size());
677 if (!AllocateQuota(context, growth)) 677 if (!AllocateQuota(context, growth))
678 return base::File::FILE_ERROR_NO_SPACE; 678 return base::File::FILE_ERROR_NO_SPACE;
679 679
680 base::File::Error error; 680 base::File::Error error;
681 if (overwrite) { 681 if (overwrite) {
682 base::FilePath dest_local_path = 682 base::FilePath dest_local_path =
683 DataPathToLocalPath(dest_url, dest_file_info.data_path); 683 DataPathToLocalPath(dest_url, dest_file_info.data_path);
684 error = NativeFileUtil::CopyOrMoveFile( 684 error = NativeFileUtil::CopyOrMoveFile(
685 src_file_path, dest_local_path, 685 src_file_path,
686 dest_local_path,
686 FileSystemOperation::OPTION_NONE, 687 FileSystemOperation::OPTION_NONE,
687 fileapi::NativeFileUtil::CopyOrMoveModeForDestination(dest_url, 688 storage::NativeFileUtil::CopyOrMoveModeForDestination(dest_url,
688 true /* copy */)); 689 true /* copy */));
689 } else { 690 } else {
690 error = CreateFile(context, src_file_path, dest_url, &dest_file_info); 691 error = CreateFile(context, src_file_path, dest_url, &dest_file_info);
691 } 692 }
692 693
693 if (error != base::File::FILE_OK) 694 if (error != base::File::FILE_OK)
694 return error; 695 return error;
695 696
696 if (overwrite) { 697 if (overwrite) {
697 context->change_observers()->Notify( 698 context->change_observers()->Notify(
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 return base::File::FILE_ERROR_NOT_EMPTY; 771 return base::File::FILE_ERROR_NOT_EMPTY;
771 int64 growth = -UsageForPath(file_info.name.size()); 772 int64 growth = -UsageForPath(file_info.name.size());
772 AllocateQuota(context, growth); 773 AllocateQuota(context, growth);
773 UpdateUsage(context, url, growth); 774 UpdateUsage(context, url, growth);
774 TouchDirectory(db, file_info.parent_id); 775 TouchDirectory(db, file_info.parent_id);
775 context->change_observers()->Notify( 776 context->change_observers()->Notify(
776 &FileChangeObserver::OnRemoveDirectory, MakeTuple(url)); 777 &FileChangeObserver::OnRemoveDirectory, MakeTuple(url));
777 return base::File::FILE_OK; 778 return base::File::FILE_OK;
778 } 779 }
779 780
780 webkit_blob::ScopedFile ObfuscatedFileUtil::CreateSnapshotFile( 781 storage::ScopedFile ObfuscatedFileUtil::CreateSnapshotFile(
781 FileSystemOperationContext* context, 782 FileSystemOperationContext* context,
782 const FileSystemURL& url, 783 const FileSystemURL& url,
783 base::File::Error* error, 784 base::File::Error* error,
784 base::File::Info* file_info, 785 base::File::Info* file_info,
785 base::FilePath* platform_path) { 786 base::FilePath* platform_path) {
786 // We're just returning the local file information. 787 // We're just returning the local file information.
787 *error = GetFileInfo(context, url, file_info, platform_path); 788 *error = GetFileInfo(context, url, file_info, platform_path);
788 if (*error == base::File::FILE_OK && file_info->is_directory) { 789 if (*error == base::File::FILE_OK && file_info->is_directory) {
789 *file_info = base::File::Info(); 790 *file_info = base::File::Info();
790 *error = base::File::FILE_ERROR_NOT_A_FILE; 791 *error = base::File::FILE_ERROR_NOT_A_FILE;
791 } 792 }
792 return webkit_blob::ScopedFile(); 793 return storage::ScopedFile();
793 } 794 }
794 795
795 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> 796 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator>
796 ObfuscatedFileUtil::CreateFileEnumerator( 797 ObfuscatedFileUtil::CreateFileEnumerator(
797 FileSystemOperationContext* context, 798 FileSystemOperationContext* context,
798 const FileSystemURL& root_url, 799 const FileSystemURL& root_url,
799 bool recursive) { 800 bool recursive) {
800 SandboxDirectoryDatabase* db = GetDirectoryDatabase(root_url, false); 801 SandboxDirectoryDatabase* db = GetDirectoryDatabase(root_url, false);
801 if (!db) { 802 if (!db) {
802 return scoped_ptr<AbstractFileEnumerator>(new EmptyFileEnumerator()); 803 return scoped_ptr<AbstractFileEnumerator>(new EmptyFileEnumerator());
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 // Other type's directory exists; just return true here. 891 // Other type's directory exists; just return true here.
891 return true; 892 return true;
892 } 893 }
893 } 894 }
894 } 895 }
895 896
896 // No other directories seem exist. Try deleting the entire origin directory. 897 // No other directories seem exist. Try deleting the entire origin directory.
897 InitOriginDatabase(origin, false); 898 InitOriginDatabase(origin, false);
898 if (origin_database_) { 899 if (origin_database_) {
899 origin_database_->RemovePathForOrigin( 900 origin_database_->RemovePathForOrigin(
900 webkit_database::GetIdentifierFromOrigin(origin)); 901 storage::GetIdentifierFromOrigin(origin));
901 } 902 }
902 if (!base::DeleteFile(origin_path, true /* recursive */)) 903 if (!base::DeleteFile(origin_path, true /* recursive */))
903 return false; 904 return false;
904 905
905 return true; 906 return true;
906 } 907 }
907 908
908 ObfuscatedFileUtil::AbstractOriginEnumerator* 909 ObfuscatedFileUtil::AbstractOriginEnumerator*
909 ObfuscatedFileUtil::CreateOriginEnumerator() { 910 ObfuscatedFileUtil::CreateOriginEnumerator() {
910 std::vector<SandboxOriginDatabase::OriginRecord> origins; 911 std::vector<SandboxOriginDatabase::OriginRecord> origins;
(...skipping 29 matching lines...) Expand all
940 return UsageForPath(VirtualPath::BaseName(path).value().size()); 941 return UsageForPath(VirtualPath::BaseName(path).value().size());
941 } 942 }
942 943
943 void ObfuscatedFileUtil::MaybePrepopulateDatabase( 944 void ObfuscatedFileUtil::MaybePrepopulateDatabase(
944 const std::vector<std::string>& type_strings_to_prepopulate) { 945 const std::vector<std::string>& type_strings_to_prepopulate) {
945 SandboxPrioritizedOriginDatabase database(file_system_directory_, 946 SandboxPrioritizedOriginDatabase database(file_system_directory_,
946 env_override_); 947 env_override_);
947 std::string origin_string = database.GetPrimaryOrigin(); 948 std::string origin_string = database.GetPrimaryOrigin();
948 if (origin_string.empty() || !database.HasOriginPath(origin_string)) 949 if (origin_string.empty() || !database.HasOriginPath(origin_string))
949 return; 950 return;
950 const GURL origin = webkit_database::GetOriginFromIdentifier(origin_string); 951 const GURL origin = storage::GetOriginFromIdentifier(origin_string);
951 952
952 // Prepopulate the directory database(s) if and only if this instance 953 // Prepopulate the directory database(s) if and only if this instance
953 // has primary origin and the directory database is already there. 954 // has primary origin and the directory database is already there.
954 for (size_t i = 0; i < type_strings_to_prepopulate.size(); ++i) { 955 for (size_t i = 0; i < type_strings_to_prepopulate.size(); ++i) {
955 const std::string type_string = type_strings_to_prepopulate[i]; 956 const std::string type_string = type_strings_to_prepopulate[i];
956 // Only handles known types. 957 // Only handles known types.
957 if (!ContainsKey(known_type_strings_, type_string)) 958 if (!ContainsKey(known_type_strings_, type_string))
958 continue; 959 continue;
959 base::File::Error error = base::File::FILE_ERROR_FAILED; 960 base::File::Error error = base::File::FILE_ERROR_FAILED;
960 base::FilePath path = GetDirectoryForOriginAndType( 961 base::FilePath path = GetDirectoryForOriginAndType(
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 if (base::PathExists(dest_local_path)) { 1093 if (base::PathExists(dest_local_path)) {
1093 if (!base::DeleteFile(dest_local_path, true /* recursive */)) 1094 if (!base::DeleteFile(dest_local_path, true /* recursive */))
1094 return base::File::FILE_ERROR_FAILED; 1095 return base::File::FILE_ERROR_FAILED;
1095 LOG(WARNING) << "A stray file detected"; 1096 LOG(WARNING) << "A stray file detected";
1096 InvalidateUsageCache(context, dest_url.origin(), dest_url.type()); 1097 InvalidateUsageCache(context, dest_url.origin(), dest_url.type());
1097 } 1098 }
1098 1099
1099 error = NativeFileUtil::EnsureFileExists(dest_local_path, &created); 1100 error = NativeFileUtil::EnsureFileExists(dest_local_path, &created);
1100 } else { 1101 } else {
1101 error = NativeFileUtil::CopyOrMoveFile( 1102 error = NativeFileUtil::CopyOrMoveFile(
1102 src_file_path, dest_local_path, 1103 src_file_path,
1104 dest_local_path,
1103 FileSystemOperation::OPTION_NONE, 1105 FileSystemOperation::OPTION_NONE,
1104 fileapi::NativeFileUtil::CopyOrMoveModeForDestination(dest_url, 1106 storage::NativeFileUtil::CopyOrMoveModeForDestination(dest_url,
1105 true /* copy */)); 1107 true /* copy */));
1106 created = true; 1108 created = true;
1107 } 1109 }
1108 if (error != base::File::FILE_OK) 1110 if (error != base::File::FILE_OK)
1109 return error; 1111 return error;
1110 if (!created) 1112 if (!created)
1111 return base::File::FILE_ERROR_FAILED; 1113 return base::File::FILE_ERROR_FAILED;
1112 1114
1113 return CommitCreateFile(root, dest_local_path, db, dest_file_info); 1115 return CommitCreateFile(root, dest_local_path, db, dest_file_info);
1114 } 1116 }
(...skipping 26 matching lines...) Expand all
1141 return root.Append(data_path); 1143 return root.Append(data_path);
1142 } 1144 }
1143 1145
1144 std::string ObfuscatedFileUtil::GetDirectoryDatabaseKey( 1146 std::string ObfuscatedFileUtil::GetDirectoryDatabaseKey(
1145 const GURL& origin, const std::string& type_string) { 1147 const GURL& origin, const std::string& type_string) {
1146 if (type_string.empty()) { 1148 if (type_string.empty()) {
1147 LOG(WARNING) << "Unknown filesystem type requested:" << type_string; 1149 LOG(WARNING) << "Unknown filesystem type requested:" << type_string;
1148 return std::string(); 1150 return std::string();
1149 } 1151 }
1150 // For isolated origin we just use a type string as a key. 1152 // For isolated origin we just use a type string as a key.
1151 return webkit_database::GetIdentifierFromOrigin(origin) + 1153 return storage::GetIdentifierFromOrigin(origin) + type_string;
1152 type_string;
1153 } 1154 }
1154 1155
1155 // TODO(ericu): How to do the whole validation-without-creation thing? 1156 // TODO(ericu): How to do the whole validation-without-creation thing?
1156 // We may not have quota even to create the database. 1157 // We may not have quota even to create the database.
1157 // Ah, in that case don't even get here? 1158 // Ah, in that case don't even get here?
1158 // Still doesn't answer the quota issue, though. 1159 // Still doesn't answer the quota issue, though.
1159 SandboxDirectoryDatabase* ObfuscatedFileUtil::GetDirectoryDatabase( 1160 SandboxDirectoryDatabase* ObfuscatedFileUtil::GetDirectoryDatabase(
1160 const FileSystemURL& url, bool create) { 1161 const FileSystemURL& url, bool create) {
1161 std::string key = GetDirectoryDatabaseKey( 1162 std::string key = GetDirectoryDatabaseKey(
1162 url.origin(), CallGetTypeStringForURL(url)); 1163 url.origin(), CallGetTypeStringForURL(url));
(...skipping 24 matching lines...) Expand all
1187 const GURL& origin, bool create, base::File::Error* error_code) { 1188 const GURL& origin, bool create, base::File::Error* error_code) {
1188 if (!InitOriginDatabase(origin, create)) { 1189 if (!InitOriginDatabase(origin, create)) {
1189 if (error_code) { 1190 if (error_code) {
1190 *error_code = create ? 1191 *error_code = create ?
1191 base::File::FILE_ERROR_FAILED : 1192 base::File::FILE_ERROR_FAILED :
1192 base::File::FILE_ERROR_NOT_FOUND; 1193 base::File::FILE_ERROR_NOT_FOUND;
1193 } 1194 }
1194 return base::FilePath(); 1195 return base::FilePath();
1195 } 1196 }
1196 base::FilePath directory_name; 1197 base::FilePath directory_name;
1197 std::string id = webkit_database::GetIdentifierFromOrigin(origin); 1198 std::string id = storage::GetIdentifierFromOrigin(origin);
1198 1199
1199 bool exists_in_db = origin_database_->HasOriginPath(id); 1200 bool exists_in_db = origin_database_->HasOriginPath(id);
1200 if (!exists_in_db && !create) { 1201 if (!exists_in_db && !create) {
1201 if (error_code) 1202 if (error_code)
1202 *error_code = base::File::FILE_ERROR_NOT_FOUND; 1203 *error_code = base::File::FILE_ERROR_NOT_FOUND;
1203 return base::FilePath(); 1204 return base::FilePath();
1204 } 1205 }
1205 if (!origin_database_->GetPathForOrigin(id, &directory_name)) { 1206 if (!origin_database_->GetPathForOrigin(id, &directory_name)) {
1206 if (error_code) 1207 if (error_code)
1207 *error_code = base::File::FILE_ERROR_FAILED; 1208 *error_code = base::File::FILE_ERROR_FAILED;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 1281
1281 SandboxPrioritizedOriginDatabase* prioritized_origin_database = 1282 SandboxPrioritizedOriginDatabase* prioritized_origin_database =
1282 new SandboxPrioritizedOriginDatabase(file_system_directory_, 1283 new SandboxPrioritizedOriginDatabase(file_system_directory_,
1283 env_override_); 1284 env_override_);
1284 origin_database_.reset(prioritized_origin_database); 1285 origin_database_.reset(prioritized_origin_database);
1285 1286
1286 if (origin_hint.is_empty() || !HasIsolatedStorage(origin_hint)) 1287 if (origin_hint.is_empty() || !HasIsolatedStorage(origin_hint))
1287 return true; 1288 return true;
1288 1289
1289 const std::string isolated_origin_string = 1290 const std::string isolated_origin_string =
1290 webkit_database::GetIdentifierFromOrigin(origin_hint); 1291 storage::GetIdentifierFromOrigin(origin_hint);
1291 1292
1292 // TODO(kinuko): Deprecate this after a few release cycles, e.g. around M33. 1293 // TODO(kinuko): Deprecate this after a few release cycles, e.g. around M33.
1293 base::FilePath isolated_origin_dir = file_system_directory_.Append( 1294 base::FilePath isolated_origin_dir = file_system_directory_.Append(
1294 SandboxIsolatedOriginDatabase::kObsoleteOriginDirectory); 1295 SandboxIsolatedOriginDatabase::kObsoleteOriginDirectory);
1295 if (base::DirectoryExists(isolated_origin_dir) && 1296 if (base::DirectoryExists(isolated_origin_dir) &&
1296 prioritized_origin_database->GetSandboxOriginDatabase()) { 1297 prioritized_origin_database->GetSandboxOriginDatabase()) {
1297 SandboxIsolatedOriginDatabase::MigrateBackFromObsoleteOriginDatabase( 1298 SandboxIsolatedOriginDatabase::MigrateBackFromObsoleteOriginDatabase(
1298 isolated_origin_string, 1299 isolated_origin_string,
1299 file_system_directory_, 1300 file_system_directory_,
1300 prioritized_origin_database->GetSandboxOriginDatabase()); 1301 prioritized_origin_database->GetSandboxOriginDatabase());
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1413 &FileChangeObserver::OnModifyFile, MakeTuple(url)); 1414 &FileChangeObserver::OnModifyFile, MakeTuple(url));
1414 } 1415 }
1415 return file.Pass(); 1416 return file.Pass();
1416 } 1417 }
1417 1418
1418 bool ObfuscatedFileUtil::HasIsolatedStorage(const GURL& origin) { 1419 bool ObfuscatedFileUtil::HasIsolatedStorage(const GURL& origin) {
1419 return special_storage_policy_.get() && 1420 return special_storage_policy_.get() &&
1420 special_storage_policy_->HasIsolatedStorage(origin); 1421 special_storage_policy_->HasIsolatedStorage(origin);
1421 } 1422 }
1422 1423
1423 } // namespace fileapi 1424 } // namespace storage
OLDNEW
« no previous file with comments | « webkit/browser/fileapi/obfuscated_file_util.h ('k') | webkit/browser/fileapi/open_file_system_mode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698