OLD | NEW |
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 |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
18 #include "base/strings/sys_string_conversions.h" | 18 #include "base/strings/sys_string_conversions.h" |
19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
20 #include "base/time.h" | 20 #include "base/time.h" |
21 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
22 #include "webkit/base/origin_url_conversions.h" | |
23 #include "webkit/browser/fileapi/file_observers.h" | 22 #include "webkit/browser/fileapi/file_observers.h" |
24 #include "webkit/browser/fileapi/file_system_context.h" | 23 #include "webkit/browser/fileapi/file_system_context.h" |
25 #include "webkit/browser/fileapi/file_system_operation_context.h" | 24 #include "webkit/browser/fileapi/file_system_operation_context.h" |
26 #include "webkit/browser/fileapi/file_system_url.h" | 25 #include "webkit/browser/fileapi/file_system_url.h" |
27 #include "webkit/browser/fileapi/native_file_util.h" | 26 #include "webkit/browser/fileapi/native_file_util.h" |
28 #include "webkit/browser/fileapi/sandbox_isolated_origin_database.h" | 27 #include "webkit/browser/fileapi/sandbox_isolated_origin_database.h" |
29 #include "webkit/browser/fileapi/sandbox_mount_point_provider.h" | 28 #include "webkit/browser/fileapi/sandbox_mount_point_provider.h" |
30 #include "webkit/browser/fileapi/sandbox_origin_database.h" | 29 #include "webkit/browser/fileapi/sandbox_origin_database.h" |
31 #include "webkit/browser/fileapi/syncable/syncable_file_system_util.h" | 30 #include "webkit/browser/fileapi/syncable/syncable_file_system_util.h" |
32 #include "webkit/browser/fileapi/timed_task_helper.h" | 31 #include "webkit/browser/fileapi/timed_task_helper.h" |
33 #include "webkit/browser/quota/quota_manager.h" | 32 #include "webkit/browser/quota/quota_manager.h" |
| 33 #include "webkit/common/database/database_identifier.h" |
34 #include "webkit/common/fileapi/file_system_util.h" | 34 #include "webkit/common/fileapi/file_system_util.h" |
35 | 35 |
36 // Example of various paths: | 36 // Example of various paths: |
37 // void ObfuscatedFileUtil::DoSomething(const FileSystemURL& url) { | 37 // void ObfuscatedFileUtil::DoSomething(const FileSystemURL& url) { |
38 // base::FilePath virtual_path = url.path(); | 38 // base::FilePath virtual_path = url.path(); |
39 // base::FilePath local_path = GetLocalFilePath(url); | 39 // base::FilePath local_path = GetLocalFilePath(url); |
40 // | 40 // |
41 // NativeFileUtil::DoSomething(local_path); | 41 // NativeFileUtil::DoSomething(local_path); |
42 // file_util::DoAnother(local_path); | 42 // file_util::DoAnother(local_path); |
43 // } | 43 // } |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 virtual ~ObfuscatedOriginEnumerator() {} | 222 virtual ~ObfuscatedOriginEnumerator() {} |
223 | 223 |
224 // Returns the next origin. Returns empty if there are no more origins. | 224 // Returns the next origin. Returns empty if there are no more origins. |
225 virtual GURL Next() OVERRIDE { | 225 virtual GURL Next() OVERRIDE { |
226 OriginRecord record; | 226 OriginRecord record; |
227 if (!origins_.empty()) { | 227 if (!origins_.empty()) { |
228 record = origins_.back(); | 228 record = origins_.back(); |
229 origins_.pop_back(); | 229 origins_.pop_back(); |
230 } | 230 } |
231 current_ = record; | 231 current_ = record; |
232 return webkit_base::GetOriginURLFromIdentifier(record.origin); | 232 return webkit_database::GetOriginFromIdentifier(record.origin); |
233 } | 233 } |
234 | 234 |
235 // Returns the current origin's information. | 235 // Returns the current origin's information. |
236 virtual bool HasFileSystemType(FileSystemType type) const OVERRIDE { | 236 virtual bool HasFileSystemType(FileSystemType type) const OVERRIDE { |
237 if (current_.path.empty()) | 237 if (current_.path.empty()) |
238 return false; | 238 return false; |
239 base::FilePath::StringType type_string = | 239 base::FilePath::StringType type_string = |
240 ObfuscatedFileUtil::GetDirectoryNameForType(type); | 240 ObfuscatedFileUtil::GetDirectoryNameForType(type); |
241 if (type_string.empty()) { | 241 if (type_string.empty()) { |
242 NOTREACHED(); | 242 NOTREACHED(); |
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
926 origin_path.Append(GetDirectoryNameForType(other_types[i])))) { | 926 origin_path.Append(GetDirectoryNameForType(other_types[i])))) { |
927 // Other type's directory exists; just return true here. | 927 // Other type's directory exists; just return true here. |
928 return true; | 928 return true; |
929 } | 929 } |
930 } | 930 } |
931 | 931 |
932 // No other directories seem exist. Try deleting the entire origin directory. | 932 // No other directories seem exist. Try deleting the entire origin directory. |
933 InitOriginDatabase(false); | 933 InitOriginDatabase(false); |
934 if (origin_database_) { | 934 if (origin_database_) { |
935 origin_database_->RemovePathForOrigin( | 935 origin_database_->RemovePathForOrigin( |
936 webkit_base::GetOriginIdentifierFromURL(origin)); | 936 webkit_database::GetIdentifierFromOrigin(origin)); |
937 } | 937 } |
938 if (!file_util::Delete(origin_path, true /* recursive */)) | 938 if (!file_util::Delete(origin_path, true /* recursive */)) |
939 return false; | 939 return false; |
940 | 940 |
941 return true; | 941 return true; |
942 } | 942 } |
943 | 943 |
944 // static | 944 // static |
945 base::FilePath::StringType ObfuscatedFileUtil::GetDirectoryNameForType( | 945 base::FilePath::StringType ObfuscatedFileUtil::GetDirectoryNameForType( |
946 FileSystemType type) { | 946 FileSystemType type) { |
(...skipping 21 matching lines...) Expand all Loading... |
968 } | 968 } |
969 | 969 |
970 bool ObfuscatedFileUtil::DestroyDirectoryDatabase( | 970 bool ObfuscatedFileUtil::DestroyDirectoryDatabase( |
971 const GURL& origin, FileSystemType type) { | 971 const GURL& origin, FileSystemType type) { |
972 std::string type_string = GetFileSystemTypeString(type); | 972 std::string type_string = GetFileSystemTypeString(type); |
973 if (type_string.empty()) { | 973 if (type_string.empty()) { |
974 LOG(WARNING) << "Unknown filesystem type requested:" << type; | 974 LOG(WARNING) << "Unknown filesystem type requested:" << type; |
975 return true; | 975 return true; |
976 } | 976 } |
977 std::string key = | 977 std::string key = |
978 webkit_base::GetOriginIdentifierFromURL(origin) + | 978 webkit_database::GetIdentifierFromOrigin(origin) + |
979 type_string; | 979 type_string; |
980 DirectoryMap::iterator iter = directories_.find(key); | 980 DirectoryMap::iterator iter = directories_.find(key); |
981 if (iter != directories_.end()) { | 981 if (iter != directories_.end()) { |
982 SandboxDirectoryDatabase* database = iter->second; | 982 SandboxDirectoryDatabase* database = iter->second; |
983 directories_.erase(iter); | 983 directories_.erase(iter); |
984 delete database; | 984 delete database; |
985 } | 985 } |
986 | 986 |
987 PlatformFileError error = base::PLATFORM_FILE_OK; | 987 PlatformFileError error = base::PLATFORM_FILE_OK; |
988 base::FilePath path = GetDirectoryForOriginAndType( | 988 base::FilePath path = GetDirectoryForOriginAndType( |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1173 std::string type_string = GetFileSystemTypeString(type); | 1173 std::string type_string = GetFileSystemTypeString(type); |
1174 if (type_string.empty()) { | 1174 if (type_string.empty()) { |
1175 LOG(WARNING) << "Unknown filesystem type requested:" << type; | 1175 LOG(WARNING) << "Unknown filesystem type requested:" << type; |
1176 return std::string(); | 1176 return std::string(); |
1177 } | 1177 } |
1178 // For isolated origin we just use a type string as a key. | 1178 // For isolated origin we just use a type string as a key. |
1179 if (special_storage_policy_.get() && | 1179 if (special_storage_policy_.get() && |
1180 special_storage_policy_->HasIsolatedStorage(origin)) { | 1180 special_storage_policy_->HasIsolatedStorage(origin)) { |
1181 return type_string; | 1181 return type_string; |
1182 } | 1182 } |
1183 return webkit_base::GetOriginIdentifierFromURL(origin) + | 1183 return webkit_database::GetIdentifierFromOrigin(origin) + |
1184 type_string; | 1184 type_string; |
1185 } | 1185 } |
1186 | 1186 |
1187 // TODO(ericu): How to do the whole validation-without-creation thing? | 1187 // TODO(ericu): How to do the whole validation-without-creation thing? |
1188 // We may not have quota even to create the database. | 1188 // We may not have quota even to create the database. |
1189 // Ah, in that case don't even get here? | 1189 // Ah, in that case don't even get here? |
1190 // Still doesn't answer the quota issue, though. | 1190 // Still doesn't answer the quota issue, though. |
1191 SandboxDirectoryDatabase* ObfuscatedFileUtil::GetDirectoryDatabase( | 1191 SandboxDirectoryDatabase* ObfuscatedFileUtil::GetDirectoryDatabase( |
1192 const GURL& origin, FileSystemType type, bool create) { | 1192 const GURL& origin, FileSystemType type, bool create) { |
1193 std::string key = GetDirectoryDatabaseKey(origin, type); | 1193 std::string key = GetDirectoryDatabaseKey(origin, type); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1225 | 1225 |
1226 if (!InitOriginDatabase(create)) { | 1226 if (!InitOriginDatabase(create)) { |
1227 if (error_code) { | 1227 if (error_code) { |
1228 *error_code = create ? | 1228 *error_code = create ? |
1229 base::PLATFORM_FILE_ERROR_FAILED : | 1229 base::PLATFORM_FILE_ERROR_FAILED : |
1230 base::PLATFORM_FILE_ERROR_NOT_FOUND; | 1230 base::PLATFORM_FILE_ERROR_NOT_FOUND; |
1231 } | 1231 } |
1232 return base::FilePath(); | 1232 return base::FilePath(); |
1233 } | 1233 } |
1234 base::FilePath directory_name; | 1234 base::FilePath directory_name; |
1235 std::string id = webkit_base::GetOriginIdentifierFromURL(origin); | 1235 std::string id = webkit_database::GetIdentifierFromOrigin(origin); |
1236 | 1236 |
1237 bool exists_in_db = origin_database_->HasOriginPath(id); | 1237 bool exists_in_db = origin_database_->HasOriginPath(id); |
1238 if (!exists_in_db && !create) { | 1238 if (!exists_in_db && !create) { |
1239 if (error_code) | 1239 if (error_code) |
1240 *error_code = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 1240 *error_code = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
1241 return base::FilePath(); | 1241 return base::FilePath(); |
1242 } | 1242 } |
1243 if (!origin_database_->GetPathForOrigin(id, &directory_name)) { | 1243 if (!origin_database_->GetPathForOrigin(id, &directory_name)) { |
1244 if (error_code) | 1244 if (error_code) |
1245 *error_code = base::PLATFORM_FILE_ERROR_FAILED; | 1245 *error_code = base::PLATFORM_FILE_ERROR_FAILED; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1312 if (!file_util::CreateDirectory(file_system_directory_)) { | 1312 if (!file_util::CreateDirectory(file_system_directory_)) { |
1313 LOG(WARNING) << "Failed to create FileSystem directory: " << | 1313 LOG(WARNING) << "Failed to create FileSystem directory: " << |
1314 file_system_directory_.value(); | 1314 file_system_directory_.value(); |
1315 return false; | 1315 return false; |
1316 } | 1316 } |
1317 | 1317 |
1318 if (!isolated_origin_.is_empty()) { | 1318 if (!isolated_origin_.is_empty()) { |
1319 DCHECK(special_storage_policy_->HasIsolatedStorage(isolated_origin_)); | 1319 DCHECK(special_storage_policy_->HasIsolatedStorage(isolated_origin_)); |
1320 origin_database_.reset( | 1320 origin_database_.reset( |
1321 new SandboxIsolatedOriginDatabase( | 1321 new SandboxIsolatedOriginDatabase( |
1322 webkit_base::GetOriginIdentifierFromURL(isolated_origin_), | 1322 webkit_database::GetIdentifierFromOrigin(isolated_origin_), |
1323 file_system_directory_)); | 1323 file_system_directory_)); |
1324 return true; | 1324 return true; |
1325 } | 1325 } |
1326 | 1326 |
1327 origin_database_.reset( | 1327 origin_database_.reset( |
1328 new SandboxOriginDatabase(file_system_directory_)); | 1328 new SandboxOriginDatabase(file_system_directory_)); |
1329 return true; | 1329 return true; |
1330 } | 1330 } |
1331 | 1331 |
1332 PlatformFileError ObfuscatedFileUtil::GenerateNewLocalPath( | 1332 PlatformFileError ObfuscatedFileUtil::GenerateNewLocalPath( |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1437 // If truncating we need to update the usage. | 1437 // If truncating we need to update the usage. |
1438 if (error == base::PLATFORM_FILE_OK && delta) { | 1438 if (error == base::PLATFORM_FILE_OK && delta) { |
1439 UpdateUsage(context, url, delta); | 1439 UpdateUsage(context, url, delta); |
1440 context->change_observers()->Notify( | 1440 context->change_observers()->Notify( |
1441 &FileChangeObserver::OnModifyFile, MakeTuple(url)); | 1441 &FileChangeObserver::OnModifyFile, MakeTuple(url)); |
1442 } | 1442 } |
1443 return error; | 1443 return error; |
1444 } | 1444 } |
1445 | 1445 |
1446 } // namespace fileapi | 1446 } // namespace fileapi |
OLD | NEW |