diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-09 06:59:16 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-09 06:59:16 +0000 |
commit | 6c20697e6da610f40947526bbd65dbda0579445c (patch) | |
tree | 97989a6b4e28a59038e7656c79d0502ba14b8bdd | |
parent | cc9c9d751953abd0230d7ae22ac2be27b2d9b632 (diff) | |
download | chromium_src-6c20697e6da610f40947526bbd65dbda0579445c.zip chromium_src-6c20697e6da610f40947526bbd65dbda0579445c.tar.gz chromium_src-6c20697e6da610f40947526bbd65dbda0579445c.tar.bz2 |
FileSystem code cleanup 1st cut - does some class renaming.
Renamed FileSystemQuota to FileSystemQuotaManager.
Removed PlatFormErrorToFileError in simple_file_system.cc (in favor of webkit_flue::PlatformErrorToFileError)
BUG=60243
TEST=none
Review URL: http://codereview.chromium.org/4017007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65506 0039d316-1c4b-4281-b951-d872f2087c98
24 files changed, 199 insertions, 201 deletions
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index 4227333..f58f5da 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -1243,8 +1243,8 @@ void ExtensionsService::GrantUnlimitedStorage(const Extension* extension) { BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, NewRunnableMethod( - profile_->GetFileSystemHostContext(), - &FileSystemHostContext::SetOriginQuotaUnlimited, + profile_->GetFileSystemContext(), + &BrowserFileSystemContext::SetOriginQuotaUnlimited, origin)); } } @@ -1278,8 +1278,8 @@ void ExtensionsService::RevokeUnlimitedStorage(const Extension* extension) { BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, NewRunnableMethod( - profile_->GetFileSystemHostContext(), - &FileSystemHostContext::ResetOriginQuotaUnlimited, + profile_->GetFileSystemContext(), + &BrowserFileSystemContext::ResetOriginQuotaUnlimited, origin)); } } diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc index fa8f341..2e7e675 100644 --- a/chrome/browser/extensions/extensions_service_unittest.cc +++ b/chrome/browser/extensions/extensions_service_unittest.cc @@ -23,7 +23,7 @@ #include "base/version.h" #include "chrome/browser/appcache/chrome_appcache_service.h" #include "chrome/browser/browser_thread.h" -#include "chrome/browser/file_system/file_system_host_context.h" +#include "chrome/browser/file_system/browser_file_system_context.h" #include "chrome/browser/extensions/crx_installer.h" #include "chrome/browser/extensions/extension_creator.h" #include "chrome/browser/extensions/extension_error_reporter.h" @@ -297,17 +297,17 @@ class ExtensionTestingProfile : public TestingProfile { return appcache_service_; } - virtual FileSystemHostContext* GetFileSystemHostContext() { - if (!file_system_host_context_) - file_system_host_context_ = new FileSystemHostContext( + virtual BrowserFileSystemContext* GetFileSystemContext() { + if (!browser_file_system_context_) + browser_file_system_context_ = new BrowserFileSystemContext( GetPath(), IsOffTheRecord()); - return file_system_host_context_; + return browser_file_system_context_; } private: ExtensionsService* service_; scoped_refptr<ChromeAppCacheService> appcache_service_; - scoped_refptr<FileSystemHostContext> file_system_host_context_; + scoped_refptr<BrowserFileSystemContext> browser_file_system_context_; }; // Our message loop may be used in tests which require it to be an IO loop. diff --git a/chrome/browser/file_system/browser_file_system_context.cc b/chrome/browser/file_system/browser_file_system_context.cc new file mode 100644 index 0000000..26428cb --- /dev/null +++ b/chrome/browser/file_system/browser_file_system_context.cc @@ -0,0 +1,47 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/file_system/browser_file_system_context.h" + +#include "base/file_path.h" +#include "base/command_line.h" +#include "chrome/common/chrome_switches.h" +#include "webkit/fileapi/file_system_path_manager.h" +#include "webkit/fileapi/file_system_quota_manager.h" + +static inline bool GetAllowFileAccessFromFiles() { + return CommandLine::ForCurrentProcess()->HasSwitch( + switches::kAllowFileAccessFromFiles); +} + +BrowserFileSystemContext::BrowserFileSystemContext( + const FilePath& data_path, bool is_incognito) { + CommandLine* command_line = CommandLine::ForCurrentProcess(); + bool allow_file_access_from_files = + command_line->HasSwitch(switches::kAllowFileAccessFromFiles); + bool unlimited_quota = + command_line->HasSwitch(switches::kUnlimitedQuotaForFiles); + quota_manager_.reset(new fileapi::FileSystemQuotaManager( + allow_file_access_from_files, unlimited_quota)); + path_manager_.reset(new fileapi::FileSystemPathManager( + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), + data_path, is_incognito, allow_file_access_from_files)); +} + +bool BrowserFileSystemContext::CheckOriginQuota(const GURL& url, int64 growth) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + return quota_manager_->CheckOriginQuota(url, growth); +} + +void BrowserFileSystemContext::SetOriginQuotaUnlimited(const GURL& url) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + quota_manager_->SetOriginQuotaUnlimited(url); +} + +void BrowserFileSystemContext::ResetOriginQuotaUnlimited(const GURL& url) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + quota_manager_->ResetOriginQuotaUnlimited(url); +} + +BrowserFileSystemContext::~BrowserFileSystemContext() {} diff --git a/chrome/browser/file_system/file_system_host_context.h b/chrome/browser/file_system/browser_file_system_context.h index ddb0bf2..661c65f 100644 --- a/chrome/browser/file_system/file_system_host_context.h +++ b/chrome/browser/file_system/browser_file_system_context.h @@ -2,27 +2,29 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_FILE_SYSTEM_FILE_SYSTEM_HOST_CONTEXT_H_ -#define CHROME_BROWSER_FILE_SYSTEM_FILE_SYSTEM_HOST_CONTEXT_H_ +#ifndef CHROME_BROWSER_FILE_SYSTEM_BROWSER_FILE_SYSTEM_CONTEXT_H_ +#define CHROME_BROWSER_FILE_SYSTEM_BROWSER_FILE_SYSTEM_CONTEXT_H_ -#include "base/file_path.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" #include "chrome/browser/browser_thread.h" -#include "webkit/fileapi/file_system_types.h" -#include "webkit/fileapi/file_system_path_manager.h" -#include "webkit/fileapi/file_system_quota.h" +class FilePath; class GURL; +namespace fileapi { +class FileSystemPathManager; +class FileSystemQuotaManager; +} + // This is owned by profile and shared by all the FileSystemDispatcherHost // that shared by the same profile. -class FileSystemHostContext - : public base::RefCountedThreadSafe<FileSystemHostContext, +class BrowserFileSystemContext + : public base::RefCountedThreadSafe<BrowserFileSystemContext, BrowserThread::DeleteOnIOThread> { public: - FileSystemHostContext(const FilePath& data_path, bool is_incognito); - virtual ~FileSystemHostContext(); + BrowserFileSystemContext(const FilePath& data_path, bool is_incognito); + virtual ~BrowserFileSystemContext(); // Quota related methods. bool CheckOriginQuota(const GURL& url, int64 growth); @@ -32,13 +34,10 @@ class FileSystemHostContext fileapi::FileSystemPathManager* path_manager() { return path_manager_.get(); } private: - scoped_ptr<fileapi::FileSystemQuota> quota_manager_; + scoped_ptr<fileapi::FileSystemQuotaManager> quota_manager_; scoped_ptr<fileapi::FileSystemPathManager> path_manager_; - bool allow_file_access_from_files_; - bool unlimited_quota_; - - DISALLOW_IMPLICIT_CONSTRUCTORS(FileSystemHostContext); + DISALLOW_IMPLICIT_CONSTRUCTORS(BrowserFileSystemContext); }; -#endif // CHROME_BROWSER_FILE_SYSTEM_FILE_SYSTEM_HOST_CONTEXT_H_ +#endif // CHROME_BROWSER_FILE_SYSTEM_BROWSER_FILE_SYSTEM_CONTEXT_H_ diff --git a/chrome/browser/file_system/file_system_dispatcher_host.cc b/chrome/browser/file_system/file_system_dispatcher_host.cc index cb13bd0..3ebda7b 100644 --- a/chrome/browser/file_system/file_system_dispatcher_host.cc +++ b/chrome/browser/file_system/file_system_dispatcher_host.cc @@ -10,7 +10,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/browser_thread.h" #include "chrome/browser/file_system/browser_file_system_callback_dispatcher.h" -#include "chrome/browser/file_system/file_system_host_context.h" +#include "chrome/browser/file_system/browser_file_system_context.h" #include "chrome/browser/host_content_settings_map.h" #include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/browser/profile.h" @@ -21,9 +21,9 @@ #include "googleurl/src/gurl.h" #include "net/url_request/url_request_context.h" #include "webkit/fileapi/file_system_path_manager.h" -#include "webkit/fileapi/file_system_quota.h" +#include "webkit/fileapi/file_system_quota_manager.h" -using fileapi::FileSystemQuota; +using fileapi::FileSystemQuotaManager; class FileSystemDispatcherHost::OpenFileSystemTask { public: @@ -78,7 +78,7 @@ FileSystemDispatcherHost::FileSystemDispatcherHost( : message_sender_(sender), process_handle_(0), shutdown_(false), - context_(profile->GetFileSystemHostContext()), + context_(profile->GetFileSystemContext()), host_content_settings_map_(profile->GetHostContentSettingsMap()), request_context_getter_(profile->GetRequestContext()) { DCHECK(message_sender_); @@ -89,7 +89,7 @@ FileSystemDispatcherHost::FileSystemDispatcherHost( : message_sender_(sender), process_handle_(0), shutdown_(false), - context_(context->file_system_host_context()), + context_(context->browser_file_system_context()), host_content_settings_map_(context->host_content_settings_map()), request_context_(context) { DCHECK(message_sender_); @@ -163,7 +163,7 @@ void FileSystemDispatcherHost::OnMove( int request_id, const FilePath& src_path, const FilePath& dest_path) { if (!VerifyFileSystemPathForRead(src_path, request_id) || !VerifyFileSystemPathForWrite(dest_path, request_id, true /* create */, - FileSystemQuota::kUnknownSize)) + FileSystemQuotaManager::kUnknownSize)) return; GetNewOperation(request_id)->Move(src_path, dest_path); @@ -173,7 +173,7 @@ void FileSystemDispatcherHost::OnCopy( int request_id, const FilePath& src_path, const FilePath& dest_path) { if (!VerifyFileSystemPathForRead(src_path, request_id) || !VerifyFileSystemPathForWrite(dest_path, request_id, true /* create */, - FileSystemQuota::kUnknownSize)) + FileSystemQuotaManager::kUnknownSize)) return; GetNewOperation(request_id)->Copy(src_path, dest_path); @@ -227,7 +227,7 @@ void FileSystemDispatcherHost::OnWrite( const GURL& blob_url, int64 offset) { if (!VerifyFileSystemPathForWrite(path, request_id, true /* create */, - FileSystemQuota::kUnknownSize)) + FileSystemQuotaManager::kUnknownSize)) return; GetNewOperation(request_id)->Write( request_context_, path, blob_url, offset); diff --git a/chrome/browser/file_system/file_system_dispatcher_host.h b/chrome/browser/file_system/file_system_dispatcher_host.h index f51e7f2..fd7b8ba 100644 --- a/chrome/browser/file_system/file_system_dispatcher_host.h +++ b/chrome/browser/file_system/file_system_dispatcher_host.h @@ -22,7 +22,7 @@ class Time; } class ChromeURLRequestContext; -class FileSystemHostContext; +class BrowserFileSystemContext; class GURL; class HostContentSettingsMap; class Profile; @@ -119,7 +119,7 @@ class FileSystemDispatcherHost bool shutdown_; - scoped_refptr<FileSystemHostContext> context_; + scoped_refptr<BrowserFileSystemContext> context_; // Used to look up permissions. scoped_refptr<HostContentSettingsMap> host_content_settings_map_; diff --git a/chrome/browser/file_system/file_system_host_context.cc b/chrome/browser/file_system/file_system_host_context.cc deleted file mode 100644 index 34698db..0000000 --- a/chrome/browser/file_system/file_system_host_context.cc +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/file_system/file_system_host_context.h" - -#include "base/command_line.h" -#include "base/file_util.h" -#include "base/logging.h" -#include "base/string_util.h" -#include "base/utf_string_conversions.h" -#include "chrome/common/chrome_switches.h" -#include "googleurl/src/gurl.h" -#include "webkit/glue/webkit_glue.h" - -FileSystemHostContext::FileSystemHostContext( - const FilePath& data_path, bool is_incognito) - : quota_manager_(new fileapi::FileSystemQuota()) { - CommandLine* command_line = CommandLine::ForCurrentProcess(); - allow_file_access_from_files_ = - command_line->HasSwitch(switches::kAllowFileAccessFromFiles); - unlimited_quota_ = - command_line->HasSwitch(switches::kUnlimitedQuotaForFiles); - path_manager_.reset(new fileapi::FileSystemPathManager( - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), - data_path, is_incognito, allow_file_access_from_files_)); -} - -bool FileSystemHostContext::CheckOriginQuota(const GURL& url, int64 growth) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - // If allow-file-access-from-files flag is explicitly given and the scheme - // is file, or if unlimited quota for this process was explicitly requested, - // return true. - if (unlimited_quota_ || - (url.SchemeIsFile() && allow_file_access_from_files_)) - return true; - return quota_manager_->CheckOriginQuota(url, growth); -} - -void FileSystemHostContext::SetOriginQuotaUnlimited(const GURL& url) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - quota_manager_->SetOriginQuotaUnlimited(url); -} - -void FileSystemHostContext::ResetOriginQuotaUnlimited(const GURL& url) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - quota_manager_->ResetOriginQuotaUnlimited(url); -} - -FileSystemHostContext::~FileSystemHostContext() {} diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index a40e548e..159c674 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -834,7 +834,7 @@ ChromeURLRequestContext::ChromeURLRequestContext( is_media_ = other->is_media_; is_off_the_record_ = other->is_off_the_record_; blob_storage_context_ = other->blob_storage_context_; - file_system_host_context_ = other->file_system_host_context_; + browser_file_system_context_ = other->browser_file_system_context_; extension_info_map_ = other->extension_info_map_; } @@ -902,7 +902,7 @@ ChromeURLRequestContextFactory::ChromeURLRequestContextFactory(Profile* profile) appcache_service_ = profile->GetAppCacheService(); database_tracker_ = profile->GetDatabaseTracker(); blob_storage_context_ = profile->GetBlobStorageContext(); - file_system_host_context_ = profile->GetFileSystemHostContext(); + browser_file_system_context_ = profile->GetFileSystemContext(); extension_info_map_ = profile->GetExtensionInfoMap(); } @@ -928,7 +928,7 @@ void ChromeURLRequestContextFactory::ApplyProfileParametersToContext( context->set_appcache_service(appcache_service_); context->set_database_tracker(database_tracker_); context->set_blob_storage_context(blob_storage_context_); - context->set_file_system_host_context(file_system_host_context_); + context->set_browser_file_system_context(browser_file_system_context_); context->set_extension_info_map(extension_info_map_); } diff --git a/chrome/browser/net/chrome_url_request_context.h b/chrome/browser/net/chrome_url_request_context.h index 51d9246..72a31af 100644 --- a/chrome/browser/net/chrome_url_request_context.h +++ b/chrome/browser/net/chrome_url_request_context.h @@ -13,7 +13,7 @@ #include "chrome/browser/appcache/chrome_appcache_service.h" #include "chrome/browser/chrome_blob_storage_context.h" #include "chrome/browser/extensions/extension_info_map.h" -#include "chrome/browser/file_system/file_system_host_context.h" +#include "chrome/browser/file_system/browser_file_system_context.h" #include "chrome/browser/host_content_settings_map.h" #include "chrome/browser/host_zoom_map.h" #include "chrome/browser/io_thread.h" @@ -71,8 +71,8 @@ class ChromeURLRequestContext : public URLRequestContext { } // Gets the file system host context with this context's profile. - FileSystemHostContext* file_system_host_context() const { - return file_system_host_context_.get(); + BrowserFileSystemContext* browser_file_system_context() const { + return browser_file_system_context_.get(); } bool is_off_the_record() const { @@ -174,8 +174,8 @@ class ChromeURLRequestContext : public URLRequestContext { void set_blob_storage_context(ChromeBlobStorageContext* context) { blob_storage_context_ = context; } - void set_file_system_host_context(FileSystemHostContext* context) { - file_system_host_context_ = context; + void set_browser_file_system_context(BrowserFileSystemContext* context) { + browser_file_system_context_ = context; } void set_extension_info_map(ExtensionInfoMap* map) { extension_info_map_ = map; @@ -204,7 +204,7 @@ class ChromeURLRequestContext : public URLRequestContext { scoped_refptr<HostContentSettingsMap> host_content_settings_map_; scoped_refptr<HostZoomMap> host_zoom_map_; scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; - scoped_refptr<FileSystemHostContext> file_system_host_context_; + scoped_refptr<BrowserFileSystemContext> browser_file_system_context_; scoped_refptr<ExtensionInfoMap> extension_info_map_; bool is_media_; @@ -373,7 +373,7 @@ class ChromeURLRequestContextFactory { scoped_refptr<net::SSLConfigService> ssl_config_service_; scoped_refptr<net::CookieMonster::Delegate> cookie_monster_delegate_; scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; - scoped_refptr<FileSystemHostContext> file_system_host_context_; + scoped_refptr<BrowserFileSystemContext> browser_file_system_context_; scoped_refptr<ExtensionInfoMap> extension_info_map_; FilePath profile_dir_path_; diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc index bc5ba44..4b11fadb 100644 --- a/chrome/browser/profile.cc +++ b/chrome/browser/profile.cc @@ -17,9 +17,9 @@ #include "chrome/browser/browser_thread.h" #include "chrome/browser/chrome_blob_storage_context.h" #include "chrome/browser/download/download_manager.h" -#include "chrome/browser/file_system/file_system_host_context.h" #include "chrome/browser/extensions/extension_message_service.h" #include "chrome/browser/extensions/extension_process_manager.h" +#include "chrome/browser/file_system/browser_file_system_context.h" #include "chrome/browser/find_bar_state.h" #include "chrome/browser/in_process_webkit/webkit_context.h" #include "chrome/browser/net/chrome_url_request_context.h" @@ -323,12 +323,12 @@ class OffTheRecordProfileImpl : public Profile, return NULL; } - virtual FileSystemHostContext* GetFileSystemHostContext() { - if (!file_system_host_context_) - file_system_host_context_ = new FileSystemHostContext( + virtual BrowserFileSystemContext* GetFileSystemContext() { + if (!browser_file_system_context_) + browser_file_system_context_ = new BrowserFileSystemContext( GetPath(), IsOffTheRecord()); - DCHECK(file_system_host_context_.get()); - return file_system_host_context_.get(); + DCHECK(browser_file_system_context_.get()); + return browser_file_system_context_.get(); } virtual void InitThemes() { @@ -632,7 +632,7 @@ class OffTheRecordProfileImpl : public Profile, scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; // The file_system context for this profile. - scoped_refptr<FileSystemHostContext> file_system_host_context_; + scoped_refptr<BrowserFileSystemContext> browser_file_system_context_; DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl); }; diff --git a/chrome/browser/profile.h b/chrome/browser/profile.h index aac3f02..9c958e0 100644 --- a/chrome/browser/profile.h +++ b/chrome/browser/profile.h @@ -54,7 +54,7 @@ class ExtensionProcessManager; class ExtensionsService; class FaviconService; class FilePath; -class FileSystemHostContext; +class BrowserFileSystemContext; class FindBarState; class GeolocationContentSettingsMap; class GeolocationPermissionContext; @@ -287,8 +287,10 @@ class Profile { // Returns the PersonalDataManager associated with this profile. virtual PersonalDataManager* GetPersonalDataManager() = 0; - // Returns the HTML5 FileSystemHostContext assigned to this profile. - virtual FileSystemHostContext* GetFileSystemHostContext() = 0; + // Returns the FileSystemContext associated to this profile. The context + // is lazily created the first time this method is called. This is owned + // by the profile. + virtual BrowserFileSystemContext* GetFileSystemContext() = 0; // Returns the BrowserSignin object assigned to this profile. virtual BrowserSignin* GetBrowserSignin() = 0; diff --git a/chrome/browser/profile_impl.cc b/chrome/browser/profile_impl.cc index 649ef1c..28ee7d1 100644 --- a/chrome/browser/profile_impl.cc +++ b/chrome/browser/profile_impl.cc @@ -38,7 +38,7 @@ #include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/extensions/user_script_master.h" #include "chrome/browser/favicon_service.h" -#include "chrome/browser/file_system/file_system_host_context.h" +#include "chrome/browser/file_system/browser_file_system_context.h" #include "chrome/browser/find_bar_state.h" #include "chrome/browser/geolocation/geolocation_content_settings_map.h" #include "chrome/browser/geolocation/geolocation_permission_context.h" @@ -1010,12 +1010,12 @@ PersonalDataManager* ProfileImpl::GetPersonalDataManager() { return personal_data_manager_.get(); } -FileSystemHostContext* ProfileImpl::GetFileSystemHostContext() { - if (!file_system_host_context_.get()) - file_system_host_context_ = new FileSystemHostContext( +BrowserFileSystemContext* ProfileImpl::GetFileSystemContext() { + if (!browser_file_system_context_.get()) + browser_file_system_context_ = new BrowserFileSystemContext( GetPath(), IsOffTheRecord()); - DCHECK(file_system_host_context_.get()); - return file_system_host_context_.get(); + DCHECK(browser_file_system_context_.get()); + return browser_file_system_context_.get(); } void ProfileImpl::InitThemes() { diff --git a/chrome/browser/profile_impl.h b/chrome/browser/profile_impl.h index 9834fc1..5b0906c 100644 --- a/chrome/browser/profile_impl.h +++ b/chrome/browser/profile_impl.h @@ -70,7 +70,7 @@ class ProfileImpl : public Profile, virtual TemplateURLFetcher* GetTemplateURLFetcher(); virtual DownloadManager* GetDownloadManager(); virtual PersonalDataManager* GetPersonalDataManager(); - virtual FileSystemHostContext* GetFileSystemHostContext(); + virtual BrowserFileSystemContext* GetFileSystemContext(); virtual void InitThemes(); virtual void SetTheme(const Extension* extension); virtual void SetNativeTheme(); @@ -221,7 +221,7 @@ class ProfileImpl : public Profile, scoped_ptr<StatusTray> status_tray_; scoped_refptr<PersonalDataManager> personal_data_manager_; scoped_ptr<PinnedTabService> pinned_tab_service_; - scoped_refptr<FileSystemHostContext> file_system_host_context_; + scoped_refptr<BrowserFileSystemContext> browser_file_system_context_; scoped_ptr<BrowserSignin> browser_signin_; bool history_service_created_; bool favicon_service_created_; diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc index fc8cc12..13a9246 100644 --- a/chrome/browser/renderer_host/resource_message_filter.cc +++ b/chrome/browser/renderer_host/resource_message_filter.cc @@ -24,7 +24,6 @@ #include "chrome/browser/download/download_types.h" #include "chrome/browser/extensions/extension_message_service.h" #include "chrome/browser/file_system/file_system_dispatcher_host.h" -#include "chrome/browser/file_system/file_system_host_context.h" #include "chrome/browser/geolocation/geolocation_dispatcher_host_old.h" #include "chrome/browser/geolocation/geolocation_permission_context.h" #include "chrome/browser/gpu_process_host.h" diff --git a/chrome/browser/worker_host/worker_process_host.cc b/chrome/browser/worker_host/worker_process_host.cc index 713e6db..6f9e2432 100644 --- a/chrome/browser/worker_host/worker_process_host.cc +++ b/chrome/browser/worker_host/worker_process_host.cc @@ -192,7 +192,7 @@ bool WorkerProcessHost::Init() { // requests them. ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( id(), - request_context_->file_system_host_context()-> + request_context_->browser_file_system_context()-> path_manager()->base_path(), base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_CREATE | diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 1e1f6a1..88e1448 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1642,10 +1642,10 @@ 'browser/file_select_helper.h', 'browser/file_system/browser_file_system_callback_dispatcher.cc', 'browser/file_system/browser_file_system_callback_dispatcher.h', + 'browser/file_system/browser_file_system_context.cc', + 'browser/file_system/browser_file_system_context.h', 'browser/file_system/file_system_dispatcher_host.cc', 'browser/file_system/file_system_dispatcher_host.h', - 'browser/file_system/file_system_host_context.cc', - 'browser/file_system/file_system_host_context.h', 'browser/find_bar.h', 'browser/find_bar_controller.cc', 'browser/find_bar_controller.h', diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h index 5604b15..7afcf01 100644 --- a/chrome/test/testing_profile.h +++ b/chrome/test/testing_profile.h @@ -197,7 +197,7 @@ class TestingProfile : public Profile { } virtual DownloadManager* GetDownloadManager() { return NULL; } virtual PersonalDataManager* GetPersonalDataManager() { return NULL; } - virtual FileSystemHostContext* GetFileSystemHostContext() { return NULL; } + virtual BrowserFileSystemContext* GetFileSystemContext() { return NULL; } virtual BrowserSignin* GetBrowserSignin() { return NULL; } virtual bool HasCreatedDownloadManager() const { return false; } virtual void InitThemes(); diff --git a/webkit/fileapi/file_system_quota.cc b/webkit/fileapi/file_system_quota.cc deleted file mode 100644 index 7133082..0000000 --- a/webkit/fileapi/file_system_quota.cc +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "webkit/fileapi/file_system_quota.h" - -#include "base/file_path.h" -#include "base/file_util_proxy.h" -#include "base/ref_counted.h" -#include "base/scoped_callback_factory.h" - -namespace fileapi { - -const int64 FileSystemQuota::kUnknownSize = -1; - -FileSystemQuota::FileSystemQuota() {} - -FileSystemQuota::~FileSystemQuota() {} - -bool FileSystemQuota::CheckOriginQuota(const GURL& origin, int64) { - return CheckIfOriginGrantedUnlimitedQuota(origin); -} - -void FileSystemQuota::SetOriginQuotaUnlimited(const GURL& origin) { - DCHECK(origin == origin.GetOrigin()); - unlimited_quota_origins_.insert(origin); -} - -void FileSystemQuota::ResetOriginQuotaUnlimited(const GURL& origin) { - DCHECK(origin == origin.GetOrigin()); - unlimited_quota_origins_.erase(origin); -} - -bool FileSystemQuota::CheckIfOriginGrantedUnlimitedQuota(const GURL& origin) { - std::set<GURL>::const_iterator found = unlimited_quota_origins_.find(origin); - return (found != unlimited_quota_origins_.end()); -} - -} // namespace fileapi diff --git a/webkit/fileapi/file_system_quota_manager.cc b/webkit/fileapi/file_system_quota_manager.cc new file mode 100644 index 0000000..13a33f6 --- /dev/null +++ b/webkit/fileapi/file_system_quota_manager.cc @@ -0,0 +1,51 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "webkit/fileapi/file_system_quota_manager.h" + +#include "base/file_path.h" +#include "base/file_util_proxy.h" +#include "base/ref_counted.h" +#include "base/scoped_callback_factory.h" + +namespace fileapi { + +const int64 FileSystemQuotaManager::kUnknownSize = -1; + +FileSystemQuotaManager::FileSystemQuotaManager( + bool allow_file_access_from_files, + bool unlimited_quota) + : allow_file_access_from_files_(allow_file_access_from_files), + unlimited_quota_(unlimited_quota) { +} + +FileSystemQuotaManager::~FileSystemQuotaManager() {} + +bool FileSystemQuotaManager::CheckOriginQuota(const GURL& origin, int64) { + // If allow-file-access-from-files flag is explicitly given and the scheme + // is file, or if unlimited quota for this process was explicitly requested, + // return true. + if (unlimited_quota_ || + (origin.SchemeIsFile() && allow_file_access_from_files_)) + return true; + return CheckIfOriginGrantedUnlimitedQuota(origin); +} + +void FileSystemQuotaManager::SetOriginQuotaUnlimited(const GURL& origin) { + DCHECK(origin == origin.GetOrigin()); + unlimited_quota_origins_.insert(origin); +} + +void FileSystemQuotaManager::ResetOriginQuotaUnlimited(const GURL& origin) { + DCHECK(origin == origin.GetOrigin()); + unlimited_quota_origins_.erase(origin); +} + +bool FileSystemQuotaManager::CheckIfOriginGrantedUnlimitedQuota( + const GURL& origin) { + std::set<GURL>::const_iterator found = unlimited_quota_origins_.find(origin); + return (found != unlimited_quota_origins_.end()); +} + +} // namespace fileapi diff --git a/webkit/fileapi/file_system_quota.h b/webkit/fileapi/file_system_quota_manager.h index 9b77c9b..f1c94e1 100644 --- a/webkit/fileapi/file_system_quota.h +++ b/webkit/fileapi/file_system_quota_manager.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef WEBKIT_FILEAPI_FILE_SYSTEM_QUOTA_H_ -#define WEBKIT_FILEAPI_FILE_SYSTEM_QUOTA_H_ +#ifndef WEBKIT_FILEAPI_FILE_SYSTEM_QUOTA_MANAGER_H_ +#define WEBKIT_FILEAPI_FILE_SYSTEM_QUOTA_MANAGER_H_ #include <set> @@ -14,12 +14,17 @@ namespace fileapi { // A quota manager for FileSystem. For now it has little implementation // and just allows unlimited quota for apps. -class FileSystemQuota { +class FileSystemQuotaManager { public: static const int64 kUnknownSize; - FileSystemQuota(); - ~FileSystemQuota(); + // If |allow_file_access_from_files| is true, unlimited access is granted + // for file:/// URLs. + // If |unlimited_quota| is true, unlimited access is granted for every + // origin. This flag must be used only for testing. + FileSystemQuotaManager(bool allow_file_access_from_files, + bool unlimited_quota); + ~FileSystemQuotaManager(); // Checks if the origin can grow its usage by |growth| bytes. // This only performs in-memory check and returns immediately. @@ -36,9 +41,12 @@ class FileSystemQuota { // For some extensions/apps we allow unlimited quota. std::set<GURL> unlimited_quota_origins_; - DISALLOW_COPY_AND_ASSIGN(FileSystemQuota); + const bool allow_file_access_from_files_; + const bool unlimited_quota_; + + DISALLOW_COPY_AND_ASSIGN(FileSystemQuotaManager); }; } // namespace fileapi -#endif // WEBKIT_FILEAPI_FILE_SYSTEM_QUOTA_H_ +#endif // WEBKIT_FILEAPI_FILE_SYSTEM_QUOTA_MANAGER_H_ diff --git a/webkit/fileapi/file_system_quota_unittest.cc b/webkit/fileapi/file_system_quota_manager_unittest.cc index ff0d733..3bc7ac3 100644 --- a/webkit/fileapi/file_system_quota_unittest.cc +++ b/webkit/fileapi/file_system_quota_manager_unittest.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "webkit/fileapi/file_system_quota.h" +#include "webkit/fileapi/file_system_quota_manager.h" #include "base/basictypes.h" #include "base/logging.h" @@ -12,19 +12,19 @@ using namespace fileapi; -class FileSystemQuotaTest : public testing::Test { +class FileSystemQuotaManagerTest : public testing::Test { public: - FileSystemQuotaTest() { } + FileSystemQuotaManagerTest() { } void SetUp() { - quota_.reset(new FileSystemQuota); + quota_.reset(new FileSystemQuotaManager(false, false)); } - FileSystemQuota* quota() const { return quota_.get(); } + FileSystemQuotaManager* quota() const { return quota_.get(); } protected: - scoped_ptr<FileSystemQuota> quota_; - DISALLOW_COPY_AND_ASSIGN(FileSystemQuotaTest); + scoped_ptr<FileSystemQuotaManager> quota_; + DISALLOW_COPY_AND_ASSIGN(FileSystemQuotaManagerTest); }; namespace { @@ -38,7 +38,7 @@ static const char* const kTestOrigins[] = { } // anonymous namespace -TEST_F(FileSystemQuotaTest, CheckOriginQuotaNotAllowed) { +TEST_F(FileSystemQuotaManagerTest, CheckOriginQuotaNotAllowed) { for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) { SCOPED_TRACE(testing::Message() << "CheckOriginQuotaNotAllowed #" << i << " " << kTestOrigins[i]); @@ -49,7 +49,7 @@ TEST_F(FileSystemQuotaTest, CheckOriginQuotaNotAllowed) { } } -TEST_F(FileSystemQuotaTest, CheckOriginQuotaUnlimited) { +TEST_F(FileSystemQuotaManagerTest, CheckOriginQuotaUnlimited) { // Tests if SetOriginQuotaUnlimited and ResetOriginQuotaUnlimited // are working as expected. for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) { @@ -73,7 +73,7 @@ TEST_F(FileSystemQuotaTest, CheckOriginQuotaUnlimited) { } } -TEST_F(FileSystemQuotaTest, CheckOriginQuotaWithMixedSet) { +TEST_F(FileSystemQuotaManagerTest, CheckOriginQuotaWithMixedSet) { // Tests setting unlimited quota for some urls doesn't affect // other urls. GURL test_url1("http://foo.bar.com/"); @@ -90,7 +90,7 @@ TEST_F(FileSystemQuotaTest, CheckOriginQuotaWithMixedSet) { } } -TEST_F(FileSystemQuotaTest, CheckOriginQuotaMixedWithDifferentScheme) { +TEST_F(FileSystemQuotaManagerTest, CheckOriginQuotaMixedWithDifferentScheme) { // Tests setting unlimited quota for urls doesn't affect // pages in the same hosts but with different scheme. for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) { @@ -119,7 +119,7 @@ TEST_F(FileSystemQuotaTest, CheckOriginQuotaMixedWithDifferentScheme) { } } -TEST_F(FileSystemQuotaTest, CheckOriginQuotaMixedWithDifferentPort) { +TEST_F(FileSystemQuotaManagerTest, CheckOriginQuotaMixedWithDifferentPort) { // Tests setting unlimited quota for urls doesn't affect // pages in the same scheme/hosts but with different port number. for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) { diff --git a/webkit/fileapi/webkit_fileapi.gypi b/webkit/fileapi/webkit_fileapi.gypi index 73d49838..de9e612 100644 --- a/webkit/fileapi/webkit_fileapi.gypi +++ b/webkit/fileapi/webkit_fileapi.gypi @@ -19,8 +19,8 @@ 'file_system_operation.h', 'file_system_path_manager.cc', 'file_system_path_manager.h', - 'file_system_quota.cc', - 'file_system_quota.h', + 'file_system_quota_manager.cc', + 'file_system_quota_manager.h', 'file_system_types.h', 'file_writer_delegate.cc', 'file_writer_delegate.h', diff --git a/webkit/tools/test_shell/simple_file_system.cc b/webkit/tools/test_shell/simple_file_system.cc index 563ff34..520f709 100644 --- a/webkit/tools/test_shell/simple_file_system.cc +++ b/webkit/tools/test_shell/simple_file_system.cc @@ -24,26 +24,6 @@ using WebKit::WebVector; namespace { -WebKit::WebFileError PlatformFileErrorToWebFileError( - base::PlatformFileError error_code) { - switch (error_code) { - case base::PLATFORM_FILE_ERROR_NOT_FOUND: - return WebKit::WebFileErrorNotFound; - case base::PLATFORM_FILE_ERROR_INVALID_OPERATION: - case base::PLATFORM_FILE_ERROR_EXISTS: - case base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY: - return WebKit::WebFileErrorInvalidModification; - case base::PLATFORM_FILE_ERROR_ACCESS_DENIED: - return WebKit::WebFileErrorNoModificationAllowed; - case base::PLATFORM_FILE_ERROR_FAILED: - return WebKit::WebFileErrorInvalidState; - case base::PLATFORM_FILE_ERROR_ABORT: - return WebKit::WebFileErrorAbort; - default: - return WebKit::WebFileErrorInvalidModification; - } -} - class TestShellFileSystemCallbackDispatcher : public fileapi::FileSystemCallbackDispatcher { public: @@ -94,7 +74,8 @@ class TestShellFileSystemCallbackDispatcher } virtual void DidFail(base::PlatformFileError error_code) { - callbacks_->didFail(PlatformFileErrorToWebFileError(error_code)); + callbacks_->didFail( + webkit_glue::PlatformFileErrorToWebFileError(error_code)); file_system_->RemoveCompletedOperation(request_id_); } diff --git a/webkit/tools/test_shell/test_shell.gypi b/webkit/tools/test_shell/test_shell.gypi index 901f6fc..6bb3bbb 100644 --- a/webkit/tools/test_shell/test_shell.gypi +++ b/webkit/tools/test_shell/test_shell.gypi @@ -389,7 +389,7 @@ '../../database/quota_table_unittest.cc', '../../fileapi/file_system_operation_unittest.cc', '../../fileapi/file_system_path_manager_unittest.cc', - '../../fileapi/file_system_quota_unittest.cc', + '../../fileapi/file_system_quota_manager_unittest.cc', '../../fileapi/webfilewriter_base_unittest.cc', '../../glue/bookmarklet_unittest.cc', '../../glue/context_menu_unittest.cc', |