summaryrefslogtreecommitdiffstats
path: root/webkit/browser
diff options
context:
space:
mode:
authornhiroki@chromium.org <nhiroki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-01 08:16:53 +0000
committernhiroki@chromium.org <nhiroki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-01 08:16:53 +0000
commit54043cdf14d102f9bc99cd517da37bd2b109121c (patch)
treeabb7868115340081d9d4f609329d2c9a374acead /webkit/browser
parent1fa4f68a637d5001032ab94f7109c2830ad6c361 (diff)
downloadchromium_src-54043cdf14d102f9bc99cd517da37bd2b109121c.zip
chromium_src-54043cdf14d102f9bc99cd517da37bd2b109121c.tar.gz
chromium_src-54043cdf14d102f9bc99cd517da37bd2b109121c.tar.bz2
FileAPI: Move OpenFileSystem into SandboxContext
This moves SandboxFileSystemBackend::OpenFileSystem to SandboxContext so that the backend can share the function with SyncFileSystemBackend which will be introduced in the following CL. BUG=242422 TEST=content_unittests R=kinuko@chromium.org, tzik@chromium.org Review URL: https://codereview.chromium.org/21305005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@214991 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/browser')
-rw-r--r--webkit/browser/fileapi/sandbox_context.cc113
-rw-r--r--webkit/browser/fileapi/sandbox_context.h18
-rw-r--r--webkit/browser/fileapi/sandbox_file_system_backend.cc110
-rw-r--r--webkit/browser/fileapi/sandbox_file_system_backend.h7
4 files changed, 135 insertions, 113 deletions
diff --git a/webkit/browser/fileapi/sandbox_context.cc b/webkit/browser/fileapi/sandbox_context.cc
index 006c867..d8b7293 100644
--- a/webkit/browser/fileapi/sandbox_context.cc
+++ b/webkit/browser/fileapi/sandbox_context.cc
@@ -6,6 +6,7 @@
#include "base/command_line.h"
#include "base/file_util.h"
+#include "base/metrics/histogram.h"
#include "base/stl_util.h"
#include "base/task_runner_util.h"
#include "net/base/net_util.h"
@@ -15,6 +16,7 @@
#include "webkit/browser/fileapi/file_system_url.h"
#include "webkit/browser/fileapi/file_system_usage_cache.h"
#include "webkit/browser/fileapi/obfuscated_file_util.h"
+#include "webkit/browser/fileapi/sandbox_file_system_backend.h"
#include "webkit/browser/fileapi/sandbox_quota_observer.h"
#include "webkit/browser/quota/quota_manager.h"
#include "webkit/common/fileapi/file_system_util.h"
@@ -23,6 +25,22 @@ namespace fileapi {
namespace {
+const char kOpenFileSystemLabel[] = "FileSystem.OpenFileSystem";
+const char kOpenFileSystemDetailLabel[] = "FileSystem.OpenFileSystemDetail";
+const char kOpenFileSystemDetailNonThrottledLabel[] =
+ "FileSystem.OpenFileSystemDetailNonthrottled";
+int64 kMinimumStatsCollectionIntervalHours = 1;
+
+enum FileSystemError {
+ kOK = 0,
+ kIncognito,
+ kInvalidSchemeError,
+ kCreateDirectoryError,
+ kNotFound,
+ kUnknownError,
+ kFileSystemErrorMax,
+};
+
// Restricted names.
// http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#naming-restrictions
const base::FilePath::CharType* const kRestrictedNames[] = {
@@ -54,6 +72,36 @@ class ObfuscatedOriginEnumerator
scoped_ptr<ObfuscatedFileUtil::AbstractOriginEnumerator> enum_;
};
+void OpenFileSystemOnFileThread(
+ ObfuscatedFileUtil* file_util,
+ const GURL& origin_url,
+ FileSystemType type,
+ OpenFileSystemMode mode,
+ 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);
+ if (*error_ptr != base::PLATFORM_FILE_OK) {
+ UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel,
+ kCreateDirectoryError,
+ kFileSystemErrorMax);
+ } else {
+ UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel, kOK, kFileSystemErrorMax);
+ }
+ // The reference of file_util will be derefed on the FILE thread
+ // when the storage of this callback gets deleted regardless of whether
+ // this method is called or not.
+}
+
+void DidOpenFileSystem(
+ base::WeakPtr<SandboxContext> sandbox_context,
+ const base::Callback<void(base::PlatformFileError error)>& callback,
+ base::PlatformFileError* error) {
+ if (sandbox_context.get())
+ sandbox_context.get()->CollectOpenFileSystemMetrics(*error);
+ callback.Run(*error);
+}
+
} // namespace
const base::FilePath::CharType
@@ -78,7 +126,8 @@ SandboxContext::SandboxContext(
sync_file_util(),
usage_cache())),
special_storage_policy_(special_storage_policy),
- file_system_options_(file_system_options) {
+ file_system_options_(file_system_options),
+ weak_factory_(this) {
}
SandboxContext::~SandboxContext() {
@@ -159,6 +208,31 @@ base::FilePath SandboxContext::GetBaseDirectoryForOriginAndType(
return path;
}
+void SandboxContext::OpenFileSystem(
+ const GURL& origin_url,
+ fileapi::FileSystemType type,
+ OpenFileSystemMode mode,
+ const OpenFileSystemCallback& callback,
+ const GURL& root_url) {
+ if (!IsAllowedScheme(origin_url)) {
+ callback.Run(GURL(), std::string(), base::PLATFORM_FILE_ERROR_SECURITY);
+ return;
+ }
+
+ std::string name = GetFileSystemName(origin_url, type);
+
+ base::PlatformFileError* error_ptr = new base::PlatformFileError;
+ file_task_runner_->PostTaskAndReply(
+ FROM_HERE,
+ base::Bind(&OpenFileSystemOnFileThread,
+ sync_file_util(), origin_url, type, mode,
+ base::Unretained(error_ptr)),
+ base::Bind(&DidOpenFileSystem,
+ weak_factory_.GetWeakPtr(),
+ base::Bind(callback, root_url, name),
+ base::Owned(error_ptr)));
+}
+
base::PlatformFileError SandboxContext::DeleteOriginDataOnFileThread(
FileSystemContext* file_system_context,
quota::QuotaManagerProxy* proxy,
@@ -309,6 +383,43 @@ int64 SandboxContext::RecalculateUsage(FileSystemContext* context,
return usage;
}
+void SandboxContext::CollectOpenFileSystemMetrics(
+ base::PlatformFileError error_code) {
+ base::Time now = base::Time::Now();
+ bool throttled = now < next_release_time_for_open_filesystem_stat_;
+ if (!throttled) {
+ next_release_time_for_open_filesystem_stat_ =
+ now + base::TimeDelta::FromHours(kMinimumStatsCollectionIntervalHours);
+ }
+
+#define REPORT(report_value) \
+ UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemDetailLabel, \
+ (report_value), \
+ kFileSystemErrorMax); \
+ if (!throttled) { \
+ UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemDetailNonThrottledLabel, \
+ (report_value), \
+ kFileSystemErrorMax); \
+ }
+
+ switch (error_code) {
+ case base::PLATFORM_FILE_OK:
+ REPORT(kOK);
+ break;
+ case base::PLATFORM_FILE_ERROR_INVALID_URL:
+ REPORT(kInvalidSchemeError);
+ break;
+ case base::PLATFORM_FILE_ERROR_NOT_FOUND:
+ REPORT(kNotFound);
+ break;
+ case base::PLATFORM_FILE_ERROR_FAILED:
+ default:
+ REPORT(kUnknownError);
+ break;
+ }
+#undef REPORT
+}
+
ObfuscatedFileUtil* SandboxContext::sync_file_util() {
return static_cast<ObfuscatedFileUtil*>(file_util()->sync_file_util());
}
diff --git a/webkit/browser/fileapi/sandbox_context.h b/webkit/browser/fileapi/sandbox_context.h
index 98a1b21..c765077 100644
--- a/webkit/browser/fileapi/sandbox_context.h
+++ b/webkit/browser/fileapi/sandbox_context.h
@@ -12,6 +12,8 @@
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "base/time/time.h"
#include "webkit/browser/fileapi/file_system_backend.h"
#include "webkit/browser/fileapi/file_system_options.h"
#include "webkit/browser/fileapi/file_system_quota_util.h"
@@ -40,6 +42,8 @@ class SandboxQuotaObserver;
// An instance of this class is created and owned by FileSystemContext.
class WEBKIT_STORAGE_BROWSER_EXPORT SandboxContext {
public:
+ typedef FileSystemBackend::OpenFileSystemCallback OpenFileSystemCallback;
+
// The FileSystem directory name.
static const base::FilePath::CharType kFileSystemDirectory[];
@@ -88,6 +92,14 @@ class WEBKIT_STORAGE_BROWSER_EXPORT SandboxContext {
FileSystemType type,
bool create);
+ // FileSystemBackend helpers.
+ void OpenFileSystem(
+ const GURL& origin_url,
+ FileSystemType type,
+ OpenFileSystemMode mode,
+ const OpenFileSystemCallback& callback,
+ const GURL& root_url);
+
// FileSystemQuotaUtil helpers.
base::PlatformFileError DeleteOriginDataOnFileThread(
FileSystemContext* context,
@@ -112,6 +124,8 @@ class WEBKIT_STORAGE_BROWSER_EXPORT SandboxContext {
const GURL& origin_url,
FileSystemType type);
+ void CollectOpenFileSystemMetrics(base::PlatformFileError error_code);
+
base::SequencedTaskRunner* file_task_runner() {
return file_task_runner_.get();
}
@@ -163,6 +177,10 @@ class WEBKIT_STORAGE_BROWSER_EXPORT SandboxContext {
std::set<std::pair<GURL, FileSystemType> > sticky_dirty_origins_;
+ base::Time next_release_time_for_open_filesystem_stat_;
+
+ base::WeakPtrFactory<SandboxContext> weak_factory_;
+
DISALLOW_COPY_AND_ASSIGN(SandboxContext);
};
diff --git a/webkit/browser/fileapi/sandbox_file_system_backend.cc b/webkit/browser/fileapi/sandbox_file_system_backend.cc
index 0399ab6..5251681 100644
--- a/webkit/browser/fileapi/sandbox_file_system_backend.cc
+++ b/webkit/browser/fileapi/sandbox_file_system_backend.cc
@@ -35,62 +35,15 @@ namespace fileapi {
namespace {
-const char kOpenFileSystemLabel[] = "FileSystem.OpenFileSystem";
-const char kOpenFileSystemDetailLabel[] = "FileSystem.OpenFileSystemDetail";
-const char kOpenFileSystemDetailNonThrottledLabel[] =
- "FileSystem.OpenFileSystemDetailNonthrottled";
-int64 kMinimumStatsCollectionIntervalHours = 1;
-
-enum FileSystemError {
- kOK = 0,
- kIncognito,
- kInvalidSchemeError,
- kCreateDirectoryError,
- kNotFound,
- kUnknownError,
- kFileSystemErrorMax,
-};
-
const char kTemporaryOriginsCountLabel[] = "FileSystem.TemporaryOriginsCount";
const char kPersistentOriginsCountLabel[] = "FileSystem.PersistentOriginsCount";
-void DidOpenFileSystem(
- base::WeakPtr<SandboxFileSystemBackend> sandbox_backend,
- const base::Callback<void(base::PlatformFileError error)>& callback,
- base::PlatformFileError* error) {
- if (sandbox_backend.get())
- sandbox_backend.get()->CollectOpenFileSystemMetrics(*error);
- callback.Run(*error);
-}
-
-void OpenFileSystemOnFileThread(
- ObfuscatedFileUtil* file_util,
- const GURL& origin_url,
- FileSystemType type,
- OpenFileSystemMode mode,
- 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);
- if (*error_ptr != base::PLATFORM_FILE_OK) {
- UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel,
- kCreateDirectoryError,
- kFileSystemErrorMax);
- } else {
- UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel, kOK, kFileSystemErrorMax);
- }
- // The reference of file_util will be derefed on the FILE thread
- // when the storage of this callback gets deleted regardless of whether
- // this method is called or not.
-}
-
} // anonymous namespace
SandboxFileSystemBackend::SandboxFileSystemBackend(
SandboxContext* sandbox_context)
: sandbox_context_(sandbox_context),
- enable_temporary_file_system_in_incognito_(false),
- weak_factory_(this) {
+ enable_temporary_file_system_in_incognito_(false) {
}
SandboxFileSystemBackend::~SandboxFileSystemBackend() {
@@ -138,34 +91,18 @@ void SandboxFileSystemBackend::OpenFileSystem(
return;
}
- if (!sandbox_context_->IsAllowedScheme(origin_url)) {
- callback.Run(GURL(), std::string(), base::PLATFORM_FILE_ERROR_SECURITY);
- return;
- }
-
// TODO(nhiroki): Factor out SyncFS related code to SyncFileSystemBackend we
// plan to introduce. (http://crbug.com/242422/)
GURL root_url = (type == kFileSystemTypeSyncable)
? sync_file_system::GetSyncableFileSystemRootURI(origin_url)
: GetFileSystemRootURI(origin_url, type);
- std::string name = GetFileSystemName(origin_url, type);
-
- base::PlatformFileError* error_ptr = new base::PlatformFileError;
- sandbox_context_->file_task_runner()->PostTaskAndReply(
- FROM_HERE,
- base::Bind(&OpenFileSystemOnFileThread,
- sandbox_context_->sync_file_util(),
- origin_url, type, mode,
- base::Unretained(error_ptr)),
- base::Bind(&DidOpenFileSystem,
- weak_factory_.GetWeakPtr(),
- base::Bind(callback, root_url, name),
- base::Owned(error_ptr)));
-};
+
+ sandbox_context_->OpenFileSystem(
+ origin_url, type, mode, callback, root_url);
+}
FileSystemFileUtil* SandboxFileSystemBackend::GetFileUtil(
FileSystemType type) {
- DCHECK(sandbox_context_);
return sandbox_context_->sync_file_util();
}
@@ -372,41 +309,4 @@ const AccessObserverList* SandboxFileSystemBackend::GetAccessObservers(
return &access_observers_;
}
-void SandboxFileSystemBackend::CollectOpenFileSystemMetrics(
- base::PlatformFileError error_code) {
- base::Time now = base::Time::Now();
- bool throttled = now < next_release_time_for_open_filesystem_stat_;
- if (!throttled) {
- next_release_time_for_open_filesystem_stat_ =
- now + base::TimeDelta::FromHours(kMinimumStatsCollectionIntervalHours);
- }
-
-#define REPORT(report_value) \
- UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemDetailLabel, \
- (report_value), \
- kFileSystemErrorMax); \
- if (!throttled) { \
- UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemDetailNonThrottledLabel, \
- (report_value), \
- kFileSystemErrorMax); \
- }
-
- switch (error_code) {
- case base::PLATFORM_FILE_OK:
- REPORT(kOK);
- break;
- case base::PLATFORM_FILE_ERROR_INVALID_URL:
- REPORT(kInvalidSchemeError);
- break;
- case base::PLATFORM_FILE_ERROR_NOT_FOUND:
- REPORT(kNotFound);
- break;
- case base::PLATFORM_FILE_ERROR_FAILED:
- default:
- REPORT(kUnknownError);
- break;
- }
-#undef REPORT
-}
-
} // namespace fileapi
diff --git a/webkit/browser/fileapi/sandbox_file_system_backend.h b/webkit/browser/fileapi/sandbox_file_system_backend.h
index 77f6ae5..2a88f76 100644
--- a/webkit/browser/fileapi/sandbox_file_system_backend.h
+++ b/webkit/browser/fileapi/sandbox_file_system_backend.h
@@ -12,7 +12,6 @@
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
-#include "base/memory/weak_ptr.h"
#include "webkit/browser/fileapi/file_system_backend.h"
#include "webkit/browser/fileapi/file_system_quota_util.h"
#include "webkit/browser/fileapi/sandbox_context.h"
@@ -108,8 +107,6 @@ class WEBKIT_STORAGE_BROWSER_EXPORT SandboxFileSystemBackend
virtual const AccessObserverList* GetAccessObservers(
FileSystemType type) const OVERRIDE;
- void CollectOpenFileSystemMetrics(base::PlatformFileError error_code);
-
void set_enable_temporary_file_system_in_incognito(bool enable) {
enable_temporary_file_system_in_incognito_ = enable;
}
@@ -128,10 +125,6 @@ class WEBKIT_STORAGE_BROWSER_EXPORT SandboxFileSystemBackend
UpdateObserverList syncable_update_observers_;
ChangeObserverList syncable_change_observers_;
- base::Time next_release_time_for_open_filesystem_stat_;
-
- base::WeakPtrFactory<SandboxFileSystemBackend> weak_factory_;
-
DISALLOW_COPY_AND_ASSIGN(SandboxFileSystemBackend);
};