summaryrefslogtreecommitdiffstats
path: root/webkit/browser
diff options
context:
space:
mode:
authorkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-19 18:15:10 +0000
committerkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-19 18:15:10 +0000
commitc19e2ff3cae12fb055ffed194b3a5a9c908cf996 (patch)
tree3f6f9bebaf88c0df74911110c8a504769b72f3b5 /webkit/browser
parent9f123a0fbd7d95a24a37b5e5069ee010124d3152 (diff)
downloadchromium_src-c19e2ff3cae12fb055ffed194b3a5a9c908cf996.zip
chromium_src-c19e2ff3cae12fb055ffed194b3a5a9c908cf996.tar.gz
chromium_src-c19e2ff3cae12fb055ffed194b3a5a9c908cf996.tar.bz2
Give type directory string for given URL from outside ObfuscatedFileUtil
This patch moves FileSystemType to type string map outside ObfuscatedFileUtil and let it take 'type string' from outside the ObfuscatedFileUtil (so that we can later utilize the 'type string' field for plugin/MIME-type private filesystem). Brief plausible plan: - Use separate ObfuscatedFileUtil in its own directory for plugin-private - Utilize type_string field for MIME type (this should be ok since we only store data for PluginPrivate type in this separate directory) - Record { filesystem_id: mime-type } pair for each OpenPrivateFileSystem() in PluginPrivateFileSystemBackend - GetTypeStringForURLCallback given in ctor can look up this table to get type_string - (We need to unregister filesystem_id when it's no longer needed) BUG=286240 TEST=content_unittests:ObfuscatedFileUtil*,Sandbox* Review URL: https://codereview.chromium.org/27168004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@229603 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/browser')
-rw-r--r--webkit/browser/fileapi/obfuscated_file_util.cc155
-rw-r--r--webkit/browser/fileapi/obfuscated_file_util.h80
-rw-r--r--webkit/browser/fileapi/sandbox_file_system_backend_delegate.cc67
-rw-r--r--webkit/browser/fileapi/sandbox_file_system_backend_delegate.h3
4 files changed, 173 insertions, 132 deletions
diff --git a/webkit/browser/fileapi/obfuscated_file_util.cc b/webkit/browser/fileapi/obfuscated_file_util.cc
index e025656..a87db0e 100644
--- a/webkit/browser/fileapi/obfuscated_file_util.cc
+++ b/webkit/browser/fileapi/obfuscated_file_util.cc
@@ -96,13 +96,6 @@ void TouchDirectory(SandboxDirectoryDatabase* db, FileId dir_id) {
NOTREACHED();
}
-const base::FilePath::CharType kTemporaryDirectoryName[] =
- FILE_PATH_LITERAL("t");
-const base::FilePath::CharType kPersistentDirectoryName[] =
- FILE_PATH_LITERAL("p");
-const base::FilePath::CharType kSyncableDirectoryName[] =
- FILE_PATH_LITERAL("s");
-
enum IsolatedOriginStatus {
kIsolatedOriginMatch,
kIsolatedOriginDontMatch,
@@ -240,17 +233,15 @@ class ObfuscatedOriginEnumerator
}
// Returns the current origin's information.
- virtual bool HasFileSystemType(FileSystemType type) const OVERRIDE {
+ virtual bool HasTypeDirectory(const std::string& type_string) const OVERRIDE {
if (current_.path.empty())
return false;
- base::FilePath::StringType type_string =
- ObfuscatedFileUtil::GetDirectoryNameForType(type);
if (type_string.empty()) {
NOTREACHED();
return false;
}
base::FilePath path =
- base_file_path_.Append(current_.path).Append(type_string);
+ base_file_path_.Append(current_.path).AppendASCII(type_string);
return base::DirectoryExists(path);
}
@@ -263,11 +254,15 @@ class ObfuscatedOriginEnumerator
ObfuscatedFileUtil::ObfuscatedFileUtil(
quota::SpecialStoragePolicy* special_storage_policy,
const base::FilePath& file_system_directory,
- base::SequencedTaskRunner* file_task_runner)
+ base::SequencedTaskRunner* file_task_runner,
+ const GetTypeStringForURLCallback& get_type_string_for_url,
+ const std::set<std::string>& known_type_strings)
: special_storage_policy_(special_storage_policy),
file_system_directory_(file_system_directory),
db_flush_delay_seconds_(10 * 60), // 10 mins.
- file_task_runner_(file_task_runner) {
+ file_task_runner_(file_task_runner),
+ get_type_string_for_url_(get_type_string_for_url),
+ known_type_strings_(known_type_strings) {
}
ObfuscatedFileUtil::~ObfuscatedFileUtil() {
@@ -841,24 +836,15 @@ bool ObfuscatedFileUtil::IsDirectoryEmpty(
base::FilePath ObfuscatedFileUtil::GetDirectoryForOriginAndType(
const GURL& origin,
- FileSystemType type,
+ const std::string& type_string,
bool create,
base::PlatformFileError* error_code) {
- // TODO(nhiroki): Add special handling for plugin-private filesystem
- // (http://crbug.com/286240).
-
base::FilePath origin_dir = GetDirectoryForOrigin(origin, create, error_code);
if (origin_dir.empty())
return base::FilePath();
- base::FilePath::StringType type_string = GetDirectoryNameForType(type);
- if (type_string.empty()) {
- LOG(WARNING) << "Unknown filesystem type requested:" << type;
-
- if (error_code)
- *error_code = base::PLATFORM_FILE_ERROR_INVALID_URL;
- return base::FilePath();
- }
- base::FilePath path = origin_dir.Append(type_string);
+ if (type_string.empty())
+ return origin_dir;
+ base::FilePath path = origin_dir.AppendASCII(type_string);
base::PlatformFileError error = base::PLATFORM_FILE_OK;
if (!base::DirectoryExists(path) &&
(!create || !file_util::CreateDirectory(path))) {
@@ -873,20 +859,21 @@ base::FilePath ObfuscatedFileUtil::GetDirectoryForOriginAndType(
}
bool ObfuscatedFileUtil::DeleteDirectoryForOriginAndType(
- const GURL& origin, FileSystemType type) {
+ const GURL& origin,
+ const std::string& type_string) {
base::PlatformFileError error = base::PLATFORM_FILE_OK;
base::FilePath origin_type_path = GetDirectoryForOriginAndType(
- origin, type, false, &error);
+ origin, type_string, false, &error);
if (origin_type_path.empty())
return true;
-
if (error != base::PLATFORM_FILE_ERROR_NOT_FOUND) {
// TODO(dmikurube): Consider the return value of DestroyDirectoryDatabase.
// We ignore its error now since 1) it doesn't matter the final result, and
// 2) it always returns false in Windows because of LevelDB's
// implementation.
// Information about failure would be useful for debugging.
- DestroyDirectoryDatabase(origin, type);
+ if (!type_string.empty())
+ DestroyDirectoryDatabase(origin, type_string);
if (!base::DeleteFile(origin_type_path, true /* recursive */))
return false;
}
@@ -895,23 +882,19 @@ bool ObfuscatedFileUtil::DeleteDirectoryForOriginAndType(
DCHECK_EQ(origin_path.value(),
GetDirectoryForOrigin(origin, false, NULL).value());
- // At this point we are sure we had successfully deleted the origin/type
- // directory (i.e. we're ready to just return true).
- // See if we have other directories in this origin directory.
- std::vector<FileSystemType> other_types;
- if (type != kFileSystemTypeTemporary)
- other_types.push_back(kFileSystemTypeTemporary);
- if (type != kFileSystemTypePersistent)
- other_types.push_back(kFileSystemTypePersistent);
- if (type != kFileSystemTypeSyncable)
- other_types.push_back(kFileSystemTypeSyncable);
- DCHECK(type != kFileSystemTypeSyncableForInternalSync);
-
- for (size_t i = 0; i < other_types.size(); ++i) {
- if (base::DirectoryExists(
- origin_path.Append(GetDirectoryNameForType(other_types[i])))) {
- // Other type's directory exists; just return true here.
- return true;
+ if (!type_string.empty()) {
+ // At this point we are sure we had successfully deleted the origin/type
+ // directory (i.e. we're ready to just return true).
+ // See if we have other directories in this origin directory.
+ for (std::set<std::string>::iterator iter = known_type_strings_.begin();
+ iter != known_type_strings_.end();
+ ++iter) {
+ if (*iter == type_string)
+ continue;
+ if (base::DirectoryExists(origin_path.AppendASCII(*iter))) {
+ // Other type's directory exists; just return true here.
+ return true;
+ }
}
}
@@ -927,23 +910,6 @@ bool ObfuscatedFileUtil::DeleteDirectoryForOriginAndType(
return true;
}
-// static
-base::FilePath::StringType ObfuscatedFileUtil::GetDirectoryNameForType(
- FileSystemType type) {
- switch (type) {
- case kFileSystemTypeTemporary:
- return kTemporaryDirectoryName;
- case kFileSystemTypePersistent:
- return kPersistentDirectoryName;
- case kFileSystemTypeSyncable:
- case kFileSystemTypeSyncableForInternalSync:
- return kSyncableDirectoryName;
- case kFileSystemTypeUnknown:
- default:
- return base::FilePath::StringType();
- }
-}
-
ObfuscatedFileUtil::AbstractOriginEnumerator*
ObfuscatedFileUtil::CreateOriginEnumerator() {
std::vector<SandboxOriginDatabase::OriginRecord> origins;
@@ -954,8 +920,9 @@ ObfuscatedFileUtil::CreateOriginEnumerator() {
}
bool ObfuscatedFileUtil::DestroyDirectoryDatabase(
- const GURL& origin, FileSystemType type) {
- std::string key = GetDirectoryDatabaseKey(origin, type);
+ const GURL& origin,
+ const std::string& type_string) {
+ std::string key = GetDirectoryDatabaseKey(origin, type_string);
if (key.empty())
return true;
DirectoryMap::iterator iter = directories_.find(key);
@@ -967,7 +934,7 @@ bool ObfuscatedFileUtil::DestroyDirectoryDatabase(
PlatformFileError error = base::PLATFORM_FILE_OK;
base::FilePath path = GetDirectoryForOriginAndType(
- origin, type, false, &error);
+ origin, type_string, false, &error);
if (path.empty() || error == base::PLATFORM_FILE_ERROR_NOT_FOUND)
return true;
return SandboxDirectoryDatabase::DestroyDatabase(path);
@@ -978,47 +945,18 @@ int64 ObfuscatedFileUtil::ComputeFilePathCost(const base::FilePath& path) {
return UsageForPath(VirtualPath::BaseName(path).value().size());
}
-void ObfuscatedFileUtil::MaybePrepopulateDatabase() {
- // Always disable this for now. crbug.com/264429
- return;
-
- base::FilePath isolated_origin_dir = file_system_directory_.Append(
- SandboxIsolatedOriginDatabase::kOriginDirectory);
- if (!base::DirectoryExists(isolated_origin_dir))
- return;
-
- const FileSystemType kPrepopulateTypes[] = {
- kFileSystemTypePersistent, kFileSystemTypeTemporary
- };
-
- // Prepulate the directory database(s) if and only if this instance is
- // initialized for isolated storage dedicated for a single origin.
- for (size_t i = 0; i < arraysize(kPrepopulateTypes); ++i) {
- const FileSystemType type = kPrepopulateTypes[i];
- base::FilePath::StringType type_string = GetDirectoryNameForType(type);
- DCHECK(!type_string.empty());
- base::FilePath path = isolated_origin_dir.Append(type_string);
- if (!base::DirectoryExists(path))
- continue;
- scoped_ptr<SandboxDirectoryDatabase> db(new SandboxDirectoryDatabase(path));
- if (db->Init(SandboxDirectoryDatabase::FAIL_ON_CORRUPTION)) {
- directories_[GetFileSystemTypeString(type)] = db.release();
- MarkUsed();
- // Don't populate more than one database, as it may rather hurt
- // performance.
- break;
- }
- }
-}
-
base::FilePath ObfuscatedFileUtil::GetDirectoryForURL(
const FileSystemURL& url,
bool create,
base::PlatformFileError* error_code) {
- // TODO(nhiroki): Add special handling for plugin-private filesystem
- // (http://crbug.com/286240).
return GetDirectoryForOriginAndType(
- url.origin(), url.type(), create, error_code);
+ url.origin(), CallGetTypeStringForURL(url), create, error_code);
+}
+
+std::string ObfuscatedFileUtil::CallGetTypeStringForURL(
+ const FileSystemURL& url) {
+ DCHECK(!get_type_string_for_url_.is_null());
+ return get_type_string_for_url_.Run(url);
}
PlatformFileError ObfuscatedFileUtil::GetFileInfoInternal(
@@ -1160,10 +1098,9 @@ base::FilePath ObfuscatedFileUtil::DataPathToLocalPath(
}
std::string ObfuscatedFileUtil::GetDirectoryDatabaseKey(
- const GURL& origin, FileSystemType type) {
- std::string type_string = GetFileSystemTypeString(type);
+ const GURL& origin, const std::string& type_string) {
if (type_string.empty()) {
- LOG(WARNING) << "Unknown filesystem type requested:" << type;
+ LOG(WARNING) << "Unknown filesystem type requested:" << type_string;
return std::string();
}
// For isolated origin we just use a type string as a key.
@@ -1181,10 +1118,8 @@ std::string ObfuscatedFileUtil::GetDirectoryDatabaseKey(
// Still doesn't answer the quota issue, though.
SandboxDirectoryDatabase* ObfuscatedFileUtil::GetDirectoryDatabase(
const FileSystemURL& url, bool create) {
- // TODO(nhiroki): Add special handling for plugin-private filesystem
- // (http://crbug.com/286240).
-
- std::string key = GetDirectoryDatabaseKey(url.origin(), url.type());
+ std::string key = GetDirectoryDatabaseKey(
+ url.origin(), CallGetTypeStringForURL(url));
if (key.empty())
return NULL;
diff --git a/webkit/browser/fileapi/obfuscated_file_util.h b/webkit/browser/fileapi/obfuscated_file_util.h
index 266939c0..c5ce737 100644
--- a/webkit/browser/fileapi/obfuscated_file_util.h
+++ b/webkit/browser/fileapi/obfuscated_file_util.h
@@ -6,8 +6,10 @@
#define WEBKIT_BROWSER_FILEAPI_OBFUSCATED_FILE_UTIL_H_
#include <map>
+#include <set>
#include <string>
+#include "base/callback_forward.h"
#include "base/files/file_path.h"
#include "base/files/file_util_proxy.h"
#include "base/gtest_prod_util.h"
@@ -37,6 +39,21 @@ class FileSystemOperationContext;
class SandboxOriginDatabaseInterface;
class TimedTaskHelper;
+// This file util stores directory information in LevelDB to obfuscate
+// and to neutralize virtual file paths given by arbitrary apps.
+// Files are stored with two-level isolation: per-origin and per-type.
+// The isolation is done by storing data in separate directory partitions.
+// For example, a file in Temporary file system for origin 'www.example.com'
+// is stored in a different partition for a file in Persistent file system
+// for the same origin, or for Temporary file system for another origin.
+//
+// * Per-origin directory name information is stored in a separate LevelDB,
+// which is maintained by SandboxOriginDatabase.
+// * Per-type directory name information is given by
+// GetTypeStringForURLCallback that is given in CTOR.
+// We use a small static mapping (e.g. 't' for Temporary type) for
+// regular sandbox filesystems.
+//
// The overall implementation philosophy of this class is that partial failures
// should leave us with an intact database; we'd prefer to leak the occasional
// backing file than have a database entry whose backing file is missing. When
@@ -58,13 +75,31 @@ class WEBKIT_STORAGE_BROWSER_EXPORT_PRIVATE ObfuscatedFileUtil
virtual GURL Next() = 0;
// Returns the current origin's information.
- virtual bool HasFileSystemType(FileSystemType type) const = 0;
+ // |type_string| must be ascii string.
+ virtual bool HasTypeDirectory(const std::string& type_string) const = 0;
};
+ typedef base::Callback<std::string(const FileSystemURL&)>
+ GetTypeStringForURLCallback;
+
+ // |get_type_string_for_url| is user-defined callback that should return
+ // a type string for the given FileSystemURL. The type string is used
+ // to provide per-type isolation in the sandboxed filesystem directory.
+ // Note that this method is called on file_task_runner.
+ //
+ // |known_type_strings| are known type string names that this file system
+ // should care about.
+ // This info is used to determine whether we could delete the entire
+ // origin directory or not in DeleteDirectoryForOriginAndType. If no directory
+ // for any known type exists the origin directory may get deleted when
+ // one origin/type pair is deleted.
+ //
ObfuscatedFileUtil(
quota::SpecialStoragePolicy* special_storage_policy,
const base::FilePath& file_system_directory,
- base::SequencedTaskRunner* file_task_runner);
+ base::SequencedTaskRunner* file_task_runner,
+ const GetTypeStringForURLCallback& get_type_string_for_url,
+ const std::set<std::string>& known_type_strings);
virtual ~ObfuscatedFileUtil();
// FileSystemFileUtil overrides.
@@ -143,26 +178,24 @@ class WEBKIT_STORAGE_BROWSER_EXPORT_PRIVATE ObfuscatedFileUtil
// Gets the topmost directory specific to this origin and type. This will
// contain both the directory database's files and all the backing file
// subdirectories.
- // Returns an empty path if the directory is undefined (e.g. because |type|
- // is invalid). If the directory is defined, it will be returned, even if
+ // Returns the topmost origin directory if |type_string| is empty.
+ // Returns an empty path if the directory is undefined.
+ // If the directory is defined, it will be returned, even if
// there is a file system error (e.g. the directory doesn't exist on disk and
// |create| is false). Callers should always check |error_code| to make sure
// the returned path is usable.
base::FilePath GetDirectoryForOriginAndType(
const GURL& origin,
- FileSystemType type,
+ const std::string& type_string,
bool create,
base::PlatformFileError* error_code);
// Deletes the topmost directory specific to this origin and type. This will
// delete its directory database.
- bool DeleteDirectoryForOriginAndType(const GURL& origin, FileSystemType type);
-
- // TODO(ericu): This doesn't really feel like it belongs in this class.
- // The previous version lives in FileSystemPathManager, but perhaps
- // SandboxFileSystemBackend would be better?
- static base::FilePath::StringType GetDirectoryNameForType(
- FileSystemType type);
+ // Deletes the topmost origin directory if |type_string| is empty.
+ bool DeleteDirectoryForOriginAndType(
+ const GURL& origin,
+ const std::string& type_string);
// This method and all methods of its returned class must be called only on
// the FILE thread. The caller is responsible for deleting the returned
@@ -171,7 +204,8 @@ class WEBKIT_STORAGE_BROWSER_EXPORT_PRIVATE ObfuscatedFileUtil
// Deletes a directory database from the database list in the ObfuscatedFSFU
// and destroys the database on the disk.
- bool DestroyDirectoryDatabase(const GURL& origin, FileSystemType type);
+ bool DestroyDirectoryDatabase(const GURL& origin,
+ const std::string& type_string);
// Computes a cost for storing a given file in the obfuscated FSFU.
// As the cost of a file is independent of the cost of its parent directories,
@@ -180,13 +214,12 @@ class WEBKIT_STORAGE_BROWSER_EXPORT_PRIVATE ObfuscatedFileUtil
// on each path segment and add the results.
static int64 ComputeFilePathCost(const base::FilePath& path);
- void MaybePrepopulateDatabase();
-
private:
typedef SandboxDirectoryDatabase::FileId FileId;
typedef SandboxDirectoryDatabase::FileInfo FileInfo;
friend class ObfuscatedFileEnumerator;
+ friend class ObfuscatedFileUtilTest;
FRIEND_TEST_ALL_PREFIXES(ObfuscatedFileUtilTest, MaybeDropDatabasesAliveCase);
FRIEND_TEST_ALL_PREFIXES(ObfuscatedFileUtilTest,
MaybeDropDatabasesAlreadyDeletedCase);
@@ -197,11 +230,22 @@ class WEBKIT_STORAGE_BROWSER_EXPORT_PRIVATE ObfuscatedFileUtil
FRIEND_TEST_ALL_PREFIXES(ObfuscatedFileUtilTest,
MigrationBackFromIsolated);
+ // Helper method to create an obfuscated file util for regular
+ // (temporary, persistent) file systems. Used only for testing.
+ // Note: this is implemented in sandbox_file_system_backend_delegate.cc.
+ static ObfuscatedFileUtil* CreateForTesting(
+ quota::SpecialStoragePolicy* special_storage_policy,
+ const base::FilePath& file_system_directory,
+ base::SequencedTaskRunner* file_task_runner);
+
base::FilePath GetDirectoryForURL(
const FileSystemURL& url,
bool create,
base::PlatformFileError* error_code);
+ // This just calls get_type_string_for_url_ callback that is given in ctor.
+ std::string CallGetTypeStringForURL(const FileSystemURL& url);
+
base::PlatformFileError GetFileInfoInternal(
SandboxDirectoryDatabase* db,
FileSystemOperationContext* context,
@@ -237,7 +281,8 @@ class WEBKIT_STORAGE_BROWSER_EXPORT_PRIVATE ObfuscatedFileUtil
const FileSystemURL& url,
const base::FilePath& data_file_path);
- std::string GetDirectoryDatabaseKey(const GURL& origin, FileSystemType type);
+ std::string GetDirectoryDatabaseKey(const GURL& origin,
+ const std::string& type_string);
// This returns NULL if |create| flag is false and a filesystem does not
// exist for the given |url|.
@@ -286,6 +331,9 @@ class WEBKIT_STORAGE_BROWSER_EXPORT_PRIVATE ObfuscatedFileUtil
scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
scoped_ptr<TimedTaskHelper> timer_;
+ GetTypeStringForURLCallback get_type_string_for_url_;
+ std::set<std::string> known_type_strings_;
+
// If this instance is initialized for an isolated partition, this should
// only see a single origin.
GURL isolated_origin_;
diff --git a/webkit/browser/fileapi/sandbox_file_system_backend_delegate.cc b/webkit/browser/fileapi/sandbox_file_system_backend_delegate.cc
index dc3b298..754c3b4 100644
--- a/webkit/browser/fileapi/sandbox_file_system_backend_delegate.cc
+++ b/webkit/browser/fileapi/sandbox_file_system_backend_delegate.cc
@@ -36,6 +36,13 @@ const char kOpenFileSystemDetailNonThrottledLabel[] =
"FileSystem.OpenFileSystemDetailNonthrottled";
int64 kMinimumStatsCollectionIntervalHours = 1;
+// For type directory names in ObfuscatedFileUtil.
+// TODO(kinuko,nhiroki): Each type string registration should be done
+// via its own backend.
+const char kTemporaryDirectoryName[] = "t";
+const char kPersistentDirectoryName[] = "p";
+const char kSyncableDirectoryName[] = "s";
+
enum FileSystemError {
kOK = 0,
kIncognito,
@@ -57,6 +64,18 @@ const base::FilePath::CharType kRestrictedChars[] = {
FILE_PATH_LITERAL('/'), FILE_PATH_LITERAL('\\'),
};
+std::string GetTypeStringForURL(const FileSystemURL& url) {
+ return SandboxFileSystemBackendDelegate::GetTypeString(url.type());
+}
+
+std::set<std::string> GetKnownTypeStrings() {
+ std::set<std::string> known_type_strings;
+ known_type_strings.insert(kTemporaryDirectoryName);
+ known_type_strings.insert(kPersistentDirectoryName);
+ known_type_strings.insert(kSyncableDirectoryName);
+ return known_type_strings;
+}
+
class ObfuscatedOriginEnumerator
: public SandboxFileSystemBackendDelegate::OriginEnumerator {
public:
@@ -70,7 +89,8 @@ class ObfuscatedOriginEnumerator
}
virtual bool HasFileSystemType(FileSystemType type) const OVERRIDE {
- return enum_->HasFileSystemType(type);
+ return enum_->HasTypeDirectory(
+ SandboxFileSystemBackendDelegate::GetTypeString(type));
}
private:
@@ -85,7 +105,9 @@ void OpenFileSystemOnFileThread(
base::PlatformFileError* error_ptr) {
DCHECK(error_ptr);
const bool create = (mode == OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT);
- file_util->GetDirectoryForOriginAndType(origin_url, type, create, error_ptr);
+ file_util->GetDirectoryForOriginAndType(
+ origin_url, SandboxFileSystemBackendDelegate::GetTypeString(type),
+ create, error_ptr);
if (*error_ptr != base::PLATFORM_FILE_OK) {
UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel,
kCreateDirectoryError,
@@ -113,6 +135,24 @@ const base::FilePath::CharType
SandboxFileSystemBackendDelegate::kFileSystemDirectory[] =
FILE_PATH_LITERAL("File System");
+// static
+std::string SandboxFileSystemBackendDelegate::GetTypeString(
+ FileSystemType type) {
+ switch (type) {
+ case kFileSystemTypeTemporary:
+ return kTemporaryDirectoryName;
+ case kFileSystemTypePersistent:
+ return kPersistentDirectoryName;
+ case kFileSystemTypeSyncable:
+ case kFileSystemTypeSyncableForInternalSync:
+ return kSyncableDirectoryName;
+ case kFileSystemTypeUnknown:
+ default:
+ NOTREACHED() << "Unknown filesystem type requested:" << type;
+ return std::string();
+ }
+}
+
SandboxFileSystemBackendDelegate::SandboxFileSystemBackendDelegate(
quota::QuotaManagerProxy* quota_manager_proxy,
base::SequencedTaskRunner* file_task_runner,
@@ -124,7 +164,9 @@ SandboxFileSystemBackendDelegate::SandboxFileSystemBackendDelegate(
new ObfuscatedFileUtil(
special_storage_policy,
profile_path.Append(kFileSystemDirectory),
- file_task_runner))),
+ file_task_runner,
+ base::Bind(&GetTypeStringForURL),
+ GetKnownTypeStrings()))),
file_system_usage_cache_(new FileSystemUsageCache(file_task_runner)),
quota_observer_(new SandboxQuotaObserver(
quota_manager_proxy,
@@ -165,7 +207,7 @@ SandboxFileSystemBackendDelegate::GetBaseDirectoryForOriginAndType(
bool create) {
base::PlatformFileError error = base::PLATFORM_FILE_OK;
base::FilePath path = obfuscated_file_util()->GetDirectoryForOriginAndType(
- origin_url, type, create, &error);
+ origin_url, GetTypeString(type), create, &error);
if (error != base::PLATFORM_FILE_OK)
return base::FilePath();
return path;
@@ -259,7 +301,7 @@ SandboxFileSystemBackendDelegate::DeleteOriginDataOnFileThread(
file_system_context, origin_url, type);
usage_cache()->CloseCacheFiles();
bool result = obfuscated_file_util()->DeleteDirectoryForOriginAndType(
- origin_url, type);
+ origin_url, GetTypeString(type));
if (result && proxy) {
proxy->NotifyStorageModified(
quota::QuotaClient::kFileSystem,
@@ -499,7 +541,7 @@ SandboxFileSystemBackendDelegate::GetUsageCachePathForOriginAndType(
DCHECK(error_out);
*error_out = base::PLATFORM_FILE_OK;
base::FilePath base_path = sandbox_file_util->GetDirectoryForOriginAndType(
- origin_url, type, false /* create */, error_out);
+ origin_url, GetTypeString(type), false /* create */, error_out);
if (*error_out != base::PLATFORM_FILE_OK)
return base::FilePath();
return base_path.Append(FileSystemUsageCache::kUsageFileName);
@@ -568,4 +610,17 @@ ObfuscatedFileUtil* SandboxFileSystemBackendDelegate::obfuscated_file_util() {
return static_cast<ObfuscatedFileUtil*>(sync_file_util());
}
+// Declared in obfuscated_file_util.h.
+// static
+ObfuscatedFileUtil* ObfuscatedFileUtil::CreateForTesting(
+ quota::SpecialStoragePolicy* special_storage_policy,
+ const base::FilePath& file_system_directory,
+ base::SequencedTaskRunner* file_task_runner) {
+ return new ObfuscatedFileUtil(special_storage_policy,
+ file_system_directory,
+ file_task_runner,
+ base::Bind(&GetTypeStringForURL),
+ GetKnownTypeStrings());
+}
+
} // namespace fileapi
diff --git a/webkit/browser/fileapi/sandbox_file_system_backend_delegate.h b/webkit/browser/fileapi/sandbox_file_system_backend_delegate.h
index d08c9a6..c011a48 100644
--- a/webkit/browser/fileapi/sandbox_file_system_backend_delegate.h
+++ b/webkit/browser/fileapi/sandbox_file_system_backend_delegate.h
@@ -71,6 +71,9 @@ class WEBKIT_STORAGE_BROWSER_EXPORT SandboxFileSystemBackendDelegate
virtual bool HasFileSystemType(FileSystemType type) const = 0;
};
+ // Returns the type directory name in sandbox directory for given |type|.
+ static std::string GetTypeString(FileSystemType type);
+
SandboxFileSystemBackendDelegate(
quota::QuotaManagerProxy* quota_manager_proxy,
base::SequencedTaskRunner* file_task_runner,