diff options
4 files changed, 73 insertions, 75 deletions
diff --git a/chrome/browser/sync_file_system/local/sync_file_system_backend.cc b/chrome/browser/sync_file_system/local/sync_file_system_backend.cc index 199c233..f85aaa8 100644 --- a/chrome/browser/sync_file_system/local/sync_file_system_backend.cc +++ b/chrome/browser/sync_file_system/local/sync_file_system_backend.cc @@ -18,7 +18,6 @@ #include "webkit/browser/fileapi/file_stream_writer.h" #include "webkit/browser/fileapi/file_system_context.h" #include "webkit/browser/fileapi/file_system_operation.h" -#include "webkit/browser/fileapi/sandbox_quota_observer.h" #include "webkit/common/fileapi/file_system_util.h" using content::BrowserThread; @@ -106,14 +105,9 @@ void SyncFileSystemBackend::Initialize(fileapi::FileSystemContext* context) { context_ = context; fileapi::SandboxFileSystemBackendDelegate* delegate = GetDelegate(); - delegate->AddFileUpdateObserver( - fileapi::kFileSystemTypeSyncable, - delegate->quota_observer(), - delegate->file_task_runner()); - delegate->AddFileUpdateObserver( - fileapi::kFileSystemTypeSyncableForInternalSync, - delegate->quota_observer(), - delegate->file_task_runner()); + delegate->RegisterQuotaUpdateObserver(fileapi::kFileSystemTypeSyncable); + delegate->RegisterQuotaUpdateObserver( + fileapi::kFileSystemTypeSyncableForInternalSync); } void SyncFileSystemBackend::OpenFileSystem( diff --git a/webkit/browser/fileapi/sandbox_file_system_backend.cc b/webkit/browser/fileapi/sandbox_file_system_backend.cc index a5adc63..cc02278 100644 --- a/webkit/browser/fileapi/sandbox_file_system_backend.cc +++ b/webkit/browser/fileapi/sandbox_file_system_backend.cc @@ -49,18 +49,12 @@ void SandboxFileSystemBackend::Initialize(FileSystemContext* context) { DCHECK(delegate_); // Set quota observers. - delegate_->AddFileUpdateObserver( - fileapi::kFileSystemTypeTemporary, - delegate_->quota_observer(), - delegate_->file_task_runner()); + delegate_->RegisterQuotaUpdateObserver(fileapi::kFileSystemTypeTemporary); delegate_->AddFileAccessObserver( fileapi::kFileSystemTypeTemporary, delegate_->quota_observer(), NULL); - delegate_->AddFileUpdateObserver( - fileapi::kFileSystemTypePersistent, - delegate_->quota_observer(), - delegate_->file_task_runner()); + delegate_->RegisterQuotaUpdateObserver(fileapi::kFileSystemTypePersistent); delegate_->AddFileAccessObserver( fileapi::kFileSystemTypePersistent, delegate_->quota_observer(), NULL); diff --git a/webkit/browser/fileapi/sandbox_file_system_backend_delegate.cc b/webkit/browser/fileapi/sandbox_file_system_backend_delegate.cc index 1cb61bb..dc3b298 100644 --- a/webkit/browser/fileapi/sandbox_file_system_backend_delegate.cc +++ b/webkit/browser/fileapi/sandbox_file_system_backend_delegate.cc @@ -153,56 +153,6 @@ SandboxFileSystemBackendDelegate::~SandboxFileSystemBackendDelegate() { } } -bool SandboxFileSystemBackendDelegate::IsAccessValid( - const FileSystemURL& url) const { - if (!IsAllowedScheme(url.origin())) - return false; - - if (url.path().ReferencesParent()) - return false; - - // Return earlier if the path is '/', because VirtualPath::BaseName() - // returns '/' for '/' and we fail the "basename != '/'" check below. - // (We exclude '.' because it's disallowed by spec.) - if (VirtualPath::IsRootPath(url.path()) && - url.path() != base::FilePath(base::FilePath::kCurrentDirectory)) - return true; - - // Restricted names specified in - // http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#naming-restrictions - base::FilePath filename = VirtualPath::BaseName(url.path()); - // See if the name is allowed to create. - for (size_t i = 0; i < arraysize(kRestrictedNames); ++i) { - if (filename.value() == kRestrictedNames[i]) - return false; - } - for (size_t i = 0; i < arraysize(kRestrictedChars); ++i) { - if (filename.value().find(kRestrictedChars[i]) != - base::FilePath::StringType::npos) - return false; - } - - return true; -} - -bool SandboxFileSystemBackendDelegate::IsAllowedScheme(const GURL& url) const { - // Basically we only accept http or https. We allow file:// URLs - // only if --allow-file-access-from-files flag is given. - if (url.SchemeIsHTTPOrHTTPS()) - return true; - if (url.SchemeIsFileSystem()) - return url.inner_url() && IsAllowedScheme(*url.inner_url()); - - for (size_t i = 0; - i < file_system_options_.additional_allowed_schemes().size(); - ++i) { - if (url.SchemeIs( - file_system_options_.additional_allowed_schemes()[i].c_str())) - return true; - } - return false; -} - SandboxFileSystemBackendDelegate::OriginEnumerator* SandboxFileSystemBackendDelegate::CreateOriginEnumerator() { return new ObfuscatedOriginEnumerator(obfuscated_file_util()); @@ -449,6 +399,11 @@ const AccessObserverList* SandboxFileSystemBackendDelegate::GetAccessObservers( return &iter->second; } +void SandboxFileSystemBackendDelegate::RegisterQuotaUpdateObserver( + FileSystemType type) { + AddFileUpdateObserver(type, quota_observer_.get(), file_task_runner_.get()); +} + void SandboxFileSystemBackendDelegate::InvalidateUsageCache( const GURL& origin, FileSystemType type) { @@ -472,6 +427,56 @@ FileSystemFileUtil* SandboxFileSystemBackendDelegate::sync_file_util() { return static_cast<AsyncFileUtilAdapter*>(file_util())->sync_file_util(); } +bool SandboxFileSystemBackendDelegate::IsAccessValid( + const FileSystemURL& url) const { + if (!IsAllowedScheme(url.origin())) + return false; + + if (url.path().ReferencesParent()) + return false; + + // Return earlier if the path is '/', because VirtualPath::BaseName() + // returns '/' for '/' and we fail the "basename != '/'" check below. + // (We exclude '.' because it's disallowed by spec.) + if (VirtualPath::IsRootPath(url.path()) && + url.path() != base::FilePath(base::FilePath::kCurrentDirectory)) + return true; + + // Restricted names specified in + // http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#naming-restrictions + base::FilePath filename = VirtualPath::BaseName(url.path()); + // See if the name is allowed to create. + for (size_t i = 0; i < arraysize(kRestrictedNames); ++i) { + if (filename.value() == kRestrictedNames[i]) + return false; + } + for (size_t i = 0; i < arraysize(kRestrictedChars); ++i) { + if (filename.value().find(kRestrictedChars[i]) != + base::FilePath::StringType::npos) + return false; + } + + return true; +} + +bool SandboxFileSystemBackendDelegate::IsAllowedScheme(const GURL& url) const { + // Basically we only accept http or https. We allow file:// URLs + // only if --allow-file-access-from-files flag is given. + if (url.SchemeIsHTTPOrHTTPS()) + return true; + if (url.SchemeIsFileSystem()) + return url.inner_url() && IsAllowedScheme(*url.inner_url()); + + for (size_t i = 0; + i < file_system_options_.additional_allowed_schemes().size(); + ++i) { + if (url.SchemeIs( + file_system_options_.additional_allowed_schemes()[i].c_str())) + return true; + } + return false; +} + base::FilePath SandboxFileSystemBackendDelegate::GetUsageCachePathForOriginAndType( const GURL& origin_url, diff --git a/webkit/browser/fileapi/sandbox_file_system_backend_delegate.h b/webkit/browser/fileapi/sandbox_file_system_backend_delegate.h index 33d791e..d08c9a6 100644 --- a/webkit/browser/fileapi/sandbox_file_system_backend_delegate.h +++ b/webkit/browser/fileapi/sandbox_file_system_backend_delegate.h @@ -11,6 +11,7 @@ #include <utility> #include "base/files/file_path.h" +#include "base/gtest_prod_util.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" @@ -79,14 +80,6 @@ class WEBKIT_STORAGE_BROWSER_EXPORT SandboxFileSystemBackendDelegate virtual ~SandboxFileSystemBackendDelegate(); - // Performs API-specific validity checks on the given path |url|. - // Returns true if access to |url| is valid in this filesystem. - bool IsAccessValid(const FileSystemURL& url) const; - - // Returns true if the given |url|'s scheme is allowed to access - // filesystem. - bool IsAllowedScheme(const GURL& url) const; - // Returns an origin enumerator of sandbox filesystem. // This method can only be called on the file thread. OriginEnumerator* CreateOriginEnumerator(); @@ -160,6 +153,9 @@ class WEBKIT_STORAGE_BROWSER_EXPORT SandboxFileSystemBackendDelegate virtual const AccessObserverList* GetAccessObservers( FileSystemType type) const OVERRIDE; + // Registers quota observer for file updates on filesystem of |type|. + void RegisterQuotaUpdateObserver(FileSystemType type); + void InvalidateUsageCache(const GURL& origin_url, FileSystemType type); void StickyInvalidateUsageCache(const GURL& origin_url, @@ -188,6 +184,15 @@ class WEBKIT_STORAGE_BROWSER_EXPORT SandboxFileSystemBackendDelegate private: friend class SandboxQuotaObserver; friend class SandboxFileSystemTestHelper; + FRIEND_TEST_ALL_PREFIXES(SandboxFileSystemBackendDelegateTest, IsAccessValid); + + // Performs API-specific validity checks on the given path |url|. + // Returns true if access to |url| is valid in this filesystem. + bool IsAccessValid(const FileSystemURL& url) const; + + // Returns true if the given |url|'s scheme is allowed to access + // filesystem. + bool IsAllowedScheme(const GURL& url) const; // Returns a path to the usage cache file. base::FilePath GetUsageCachePathForOriginAndType( |