diff options
81 files changed, 570 insertions, 805 deletions
diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS index 3a41149..2202077 100644 --- a/chrome/browser/DEPS +++ b/chrome/browser/DEPS @@ -52,7 +52,6 @@ include_rules = [ "+content/browser/download/drag_download_util.h", "+content/browser/download/interrupt_reasons.h", "+content/browser/download/mhtml_generation_manager.h", - "+content/browser/file_system/browser_file_system_helper.h", "+content/browser/find_pasteboard.h", "+content/browser/font_list_async.h", "+content/browser/geolocation/wifi_data_provider_common.h", diff --git a/chrome/browser/browsing_data_appcache_helper.cc b/chrome/browser/browsing_data_appcache_helper.cc index 135b015..148fa85 100644 --- a/chrome/browser/browsing_data_appcache_helper.cc +++ b/chrome/browser/browsing_data_appcache_helper.cc @@ -13,11 +13,12 @@ #include "webkit/appcache/appcache_storage.h" using appcache::AppCacheDatabase; +using content::BrowserContext; using content::BrowserThread; BrowsingDataAppCacheHelper::BrowsingDataAppCacheHelper(Profile* profile) : is_fetching_(false), - appcache_service_(profile->GetAppCacheService()) { + appcache_service_(BrowserContext::GetAppCacheService(profile)) { } void BrowsingDataAppCacheHelper::StartFetching(const base::Closure& callback) { diff --git a/chrome/browser/browsing_data_database_helper.cc b/chrome/browser/browsing_data_database_helper.cc index b34fa44..ccb5615 100644 --- a/chrome/browser/browsing_data_database_helper.cc +++ b/chrome/browser/browsing_data_database_helper.cc @@ -17,6 +17,7 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" +using content::BrowserContext; using content::BrowserThread; using WebKit::WebSecurityOrigin; @@ -51,7 +52,7 @@ bool BrowsingDataDatabaseHelper::DatabaseInfo::IsFileSchemeData() { BrowsingDataDatabaseHelper::BrowsingDataDatabaseHelper(Profile* profile) : is_fetching_(false), - tracker_(profile->GetDatabaseTracker()) { + tracker_(BrowserContext::GetDatabaseTracker(profile)) { } BrowsingDataDatabaseHelper::~BrowsingDataDatabaseHelper() { diff --git a/chrome/browser/browsing_data_database_helper_browsertest.cc b/chrome/browser/browsing_data_database_helper_browsertest.cc index 3889077..e234267 100644 --- a/chrome/browser/browsing_data_database_helper_browsertest.cc +++ b/chrome/browser/browsing_data_database_helper_browsertest.cc @@ -14,6 +14,7 @@ #include "chrome/test/base/ui_test_utils.h" #include "content/test/test_browser_thread.h" +using content::BrowserContext; using content::BrowserThread; namespace { @@ -29,7 +30,7 @@ class BrowsingDataDatabaseHelperTest : public InProcessBrowserTest { public: virtual void CreateDatabases() { webkit_database::DatabaseTracker* db_tracker = - browser()->profile()->GetDatabaseTracker(); + BrowserContext::GetDatabaseTracker(browser()->profile()); string16 db_name = ASCIIToUTF16("db"); string16 description = ASCIIToUTF16("db_description"); int64 size; diff --git a/chrome/browser/browsing_data_file_system_helper.cc b/chrome/browser/browsing_data_file_system_helper.cc index 859b32e..9cde505 100644 --- a/chrome/browser/browsing_data_file_system_helper.cc +++ b/chrome/browser/browsing_data_file_system_helper.cc @@ -18,6 +18,7 @@ #include "webkit/fileapi/file_system_types.h" #include "webkit/fileapi/sandbox_mount_point_provider.h" +using content::BrowserContext; using content::BrowserThread; namespace { @@ -113,13 +114,14 @@ void BrowsingDataFileSystemHelperImpl::DeleteFileSystemOrigin( void BrowsingDataFileSystemHelperImpl::FetchFileSystemInfoInFileThread() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); scoped_ptr<fileapi::SandboxMountPointProvider::OriginEnumerator> - origin_enumerator(profile_->GetFileSystemContext()-> + origin_enumerator(BrowserContext::GetFileSystemContext(profile_)-> sandbox_provider()->CreateOriginEnumerator()); // We don't own this pointer; it's a magic singleton generated by the // profile's FileSystemContext. Deleting it would be a bad idea. - fileapi::FileSystemQuotaUtil* quota_util = profile_-> - GetFileSystemContext()->GetQuotaUtil(fileapi::kFileSystemTypeTemporary); + fileapi::FileSystemQuotaUtil* quota_util = + BrowserContext::GetFileSystemContext(profile_)->GetQuotaUtil( + fileapi::kFileSystemTypeTemporary); GURL current; while (!(current = origin_enumerator->Next()).is_empty()) { @@ -164,7 +166,8 @@ void BrowsingDataFileSystemHelperImpl::NotifyOnUIThread() { void BrowsingDataFileSystemHelperImpl::DeleteFileSystemOriginInFileThread( const GURL& origin) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); - profile_->GetFileSystemContext()->DeleteDataForOriginOnFileThread(origin); + BrowserContext::GetFileSystemContext(profile_)-> + DeleteDataForOriginOnFileThread(origin); } } // namespace diff --git a/chrome/browser/browsing_data_file_system_helper_unittest.cc b/chrome/browser/browsing_data_file_system_helper_unittest.cc index 5e05dfc..8ed961b 100644 --- a/chrome/browser/browsing_data_file_system_helper_unittest.cc +++ b/chrome/browser/browsing_data_file_system_helper_unittest.cc @@ -18,6 +18,7 @@ #include "webkit/fileapi/file_system_usage_cache.h" #include "webkit/fileapi/sandbox_mount_point_provider.h" +using content::BrowserContext; using content::BrowserThread; namespace { @@ -54,16 +55,25 @@ typedef scoped_ptr<FileSystemInfoList> ScopedFileSystemInfoList; class BrowsingDataFileSystemHelperTest : public testing::Test { public: BrowsingDataFileSystemHelperTest() - : helper_(BrowsingDataFileSystemHelper::Create(&profile_)), - canned_helper_(new CannedBrowsingDataFileSystemHelper(&profile_)), - ui_thread_(BrowserThread::UI, &message_loop_), + : ui_thread_(BrowserThread::UI, &message_loop_), + db_thread_(BrowserThread::DB, &message_loop_), + webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &message_loop_), file_thread_(BrowserThread::FILE, &message_loop_), + file_user_blocking_thread_( + BrowserThread::FILE_USER_BLOCKING, &message_loop_), io_thread_(BrowserThread::IO, &message_loop_) { + profile_.reset(new TestingProfile()); + helper_ = BrowsingDataFileSystemHelper::Create(profile_.get()); + canned_helper_ = new CannedBrowsingDataFileSystemHelper(profile_.get()); + } + virtual ~BrowsingDataFileSystemHelperTest() { + // Avoid memory leaks. + profile_.reset(); + message_loop_.RunAllPending(); } - virtual ~BrowsingDataFileSystemHelperTest() {} TestingProfile* GetProfile() { - return &profile_; + return profile_.get(); } // Blocks on the current MessageLoop until Notify() is called. @@ -131,7 +141,8 @@ class BrowsingDataFileSystemHelperTest : public testing::Test { // Sets up kOrigin1 with a temporary file system, kOrigin2 with a persistent // file system, and kOrigin3 with both. virtual void PopulateTestFileSystemData() { - sandbox_ = profile_.GetFileSystemContext()->sandbox_provider(); + sandbox_ = BrowserContext::GetFileSystemContext(profile_.get())-> + sandbox_provider(); CreateDirectoryForOriginAndType(kOrigin1, kTemporary); CreateDirectoryForOriginAndType(kOrigin2, kPersistent); @@ -175,9 +186,12 @@ class BrowsingDataFileSystemHelperTest : public testing::Test { // defined in the order they're listed here. Oh how I love C++. MessageLoopForUI message_loop_; content::TestBrowserThread ui_thread_; + content::TestBrowserThread db_thread_; + content::TestBrowserThread webkit_thread_; content::TestBrowserThread file_thread_; + content::TestBrowserThread file_user_blocking_thread_; content::TestBrowserThread io_thread_; - TestingProfile profile_; + scoped_ptr<TestingProfile> profile_; // We don't own this pointer: don't delete it. fileapi::SandboxMountPointProvider* sandbox_; diff --git a/chrome/browser/browsing_data_indexed_db_helper.cc b/chrome/browser/browsing_data_indexed_db_helper.cc index e749be3..a26207c 100644 --- a/chrome/browser/browsing_data_indexed_db_helper.cc +++ b/chrome/browser/browsing_data_indexed_db_helper.cc @@ -18,6 +18,7 @@ #include "webkit/database/database_util.h" #include "webkit/glue/webkit_glue.h" +using content::BrowserContext; using content::BrowserThread; using webkit_database::DatabaseUtil; @@ -62,7 +63,8 @@ class BrowsingDataIndexedDBHelperImpl : public BrowsingDataIndexedDBHelper { BrowsingDataIndexedDBHelperImpl::BrowsingDataIndexedDBHelperImpl( Profile* profile) - : indexed_db_context_(profile->GetWebKitContext()->indexed_db_context()), + : indexed_db_context_( + BrowserContext::GetWebKitContext(profile)->indexed_db_context()), is_fetching_(false) { DCHECK(indexed_db_context_.get()); } diff --git a/chrome/browser/browsing_data_local_storage_helper.cc b/chrome/browser/browsing_data_local_storage_helper.cc index ec5daeb..57ccd360 100644 --- a/chrome/browser/browsing_data_local_storage_helper.cc +++ b/chrome/browser/browsing_data_local_storage_helper.cc @@ -17,6 +17,7 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" #include "webkit/glue/webkit_glue.h" +using content::BrowserContext; using content::BrowserThread; using WebKit::WebSecurityOrigin; @@ -89,7 +90,7 @@ void BrowsingDataLocalStorageHelper::DeleteLocalStorageFile( void BrowsingDataLocalStorageHelper::FetchLocalStorageInfoInWebKitThread() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); file_util::FileEnumerator file_enumerator( - profile_->GetWebKitContext()->data_path().Append( + BrowserContext::GetWebKitContext(profile_)->data_path().Append( DOMStorageContext::kLocalStorageDirectory), false, file_util::FileEnumerator::FILES); for (FilePath file_path = file_enumerator.Next(); !file_path.empty(); @@ -139,8 +140,8 @@ void BrowsingDataLocalStorageHelper::NotifyInUIThread() { void BrowsingDataLocalStorageHelper::DeleteLocalStorageFileInWebKitThread( const FilePath& file_path) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); - profile_->GetWebKitContext()->dom_storage_context()->DeleteLocalStorageFile( - file_path); + BrowserContext::GetWebKitContext(profile_)->dom_storage_context()-> + DeleteLocalStorageFile(file_path); } CannedBrowsingDataLocalStorageHelper::CannedBrowsingDataLocalStorageHelper( @@ -221,7 +222,7 @@ void CannedBrowsingDataLocalStorageHelper::ConvertPendingInfoInWebKitThread() { web_security_origin.port(), web_security_origin.databaseIdentifier().utf8(), security_origin, - profile_->GetWebKitContext()->dom_storage_context()-> + BrowserContext::GetWebKitContext(profile_)->dom_storage_context()-> GetLocalStorageFilePath(web_security_origin.databaseIdentifier()), 0, base::Time())); diff --git a/chrome/browser/browsing_data_quota_helper_impl.cc b/chrome/browser/browsing_data_quota_helper_impl.cc index b198068..435afb0 100644 --- a/chrome/browser/browsing_data_quota_helper_impl.cc +++ b/chrome/browser/browsing_data_quota_helper_impl.cc @@ -19,7 +19,7 @@ BrowsingDataQuotaHelper* BrowsingDataQuotaHelper::Create(Profile* profile) { return new BrowsingDataQuotaHelperImpl( BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), - profile->GetQuotaManager()); + content::BrowserContext::GetQuotaManager(profile)); } void BrowsingDataQuotaHelperImpl::StartFetching( diff --git a/chrome/browser/browsing_data_remover.cc b/chrome/browser/browsing_data_remover.cc index 1d4394e..9130f87 100644 --- a/chrome/browser/browsing_data_remover.cc +++ b/chrome/browser/browsing_data_remover.cc @@ -58,6 +58,7 @@ #include "webkit/quota/quota_manager.h" #include "webkit/quota/quota_types.h" +using content::BrowserContext; using content::BrowserThread; using content::DownloadManager; using content::UserMetricsAction; @@ -283,20 +284,20 @@ void BrowsingDataRemover::RemoveImpl(int remove_mask, // be removed if a WEBKIT thread exists, so check that first: if (BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT_DEPRECATED)) { // We assume the end time is now. - profile_->GetWebKitContext()->DeleteDataModifiedSince(delete_begin_); + BrowserContext::GetWebKitContext(profile_)-> + DeleteDataModifiedSince(delete_begin_); } } if (remove_mask & REMOVE_INDEXEDDB || remove_mask & REMOVE_WEBSQL || remove_mask & REMOVE_APPCACHE || remove_mask & REMOVE_FILE_SYSTEMS) { - quota_manager_ = profile_->GetQuotaManager(); - if (quota_manager_) { - waiting_for_clear_quota_managed_data_ = true; - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&BrowsingDataRemover::ClearQuotaManagedDataOnIOThread, - base::Unretained(this))); - } + if (!quota_manager_) + quota_manager_ = content::BrowserContext::GetQuotaManager(profile_); + waiting_for_clear_quota_managed_data_ = true; + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + base::Bind(&BrowsingDataRemover::ClearQuotaManagedDataOnIOThread, + base::Unretained(this))); } if (remove_mask & REMOVE_PLUGIN_DATA) { @@ -382,6 +383,11 @@ void BrowsingDataRemover::OnHistoryDeletionDone() { NotifyAndDeleteIfDone(); } +void BrowsingDataRemover::OverrideQuotaManagerForTesting( + quota::QuotaManager* quota_manager) { + quota_manager_ = quota_manager; +} + base::Time BrowsingDataRemover::CalculateBeginDeleteTime( TimePeriod time_period) { base::TimeDelta diff; @@ -566,7 +572,7 @@ void BrowsingDataRemover::ClearQuotaManagedDataOnIOThread() { // all origins with persistent quota modified within the user-specified // timeframe, and deal with the resulting set in // OnGotPersistentQuotaManagedOrigins. - profile_->GetQuotaManager()->GetOriginsModifiedSince( + quota_manager_->GetOriginsModifiedSince( quota::kStorageTypePersistent, delete_begin_, base::Bind(&BrowsingDataRemover::OnGotQuotaManagedOrigins, base::Unretained(this))); @@ -577,7 +583,7 @@ void BrowsingDataRemover::ClearQuotaManagedDataOnIOThread() { // Do the same for temporary quota, regardless, passing the resulting set into // OnGotTemporaryQuotaManagedOrigins. - profile_->GetQuotaManager()->GetOriginsModifiedSince( + quota_manager_->GetOriginsModifiedSince( quota::kStorageTypeTemporary, delete_begin_, base::Bind(&BrowsingDataRemover::OnGotQuotaManagedOrigins, base::Unretained(this))); diff --git a/chrome/browser/browsing_data_remover.h b/chrome/browser/browsing_data_remover.h index 33f3515..40b3c25 100644 --- a/chrome/browser/browsing_data_remover.h +++ b/chrome/browser/browsing_data_remover.h @@ -130,6 +130,9 @@ class BrowsingDataRemover : public content::NotificationObserver, // BrowsingDataRemover uses. This method generates that mask. static int GenerateQuotaClientMask(int remove_mask); + // Used for testing. + void OverrideQuotaManagerForTesting(quota::QuotaManager* quota_manager); + static bool is_removing() { return removing_; } private: diff --git a/chrome/browser/browsing_data_remover_unittest.cc b/chrome/browser/browsing_data_remover_unittest.cc index ab25812..b19f338 100644 --- a/chrome/browser/browsing_data_remover_unittest.cc +++ b/chrome/browser/browsing_data_remover_unittest.cc @@ -292,6 +292,8 @@ class BrowsingDataRemoverTest : public testing::Test, db_thread_(BrowserThread::DB, &message_loop_), webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &message_loop_), file_thread_(BrowserThread::FILE, &message_loop_), + file_user_blocking_thread_( + BrowserThread::FILE_USER_BLOCKING, &message_loop_), io_thread_(BrowserThread::IO, &message_loop_), profile_(new TestingProfile()) { registrar_.Add(this, chrome::NOTIFICATION_BROWSING_DATA_REMOVED, @@ -317,6 +319,7 @@ class BrowsingDataRemoverTest : public testing::Test, BrowsingDataRemover* remover = new BrowsingDataRemover( profile_.get(), period, base::Time::Now() + base::TimeDelta::FromMilliseconds(10)); + remover->OverrideQuotaManagerForTesting(GetMockManager()); remover->AddObserver(tester); called_with_details_.reset(new BrowsingDataRemover::NotificationDetails()); @@ -333,6 +336,7 @@ class BrowsingDataRemoverTest : public testing::Test, BrowsingDataRemover* remover = new BrowsingDataRemover( profile_.get(), period, base::Time::Now() + base::TimeDelta::FromMilliseconds(10)); + remover->OverrideQuotaManagerForTesting(GetMockManager()); remover->AddObserver(tester); called_with_details_.reset(new BrowsingDataRemover::NotificationDetails()); @@ -355,15 +359,15 @@ class BrowsingDataRemoverTest : public testing::Test, } quota::MockQuotaManager* GetMockManager() { - if (profile_->GetQuotaManager() == NULL) { - profile_->SetQuotaManager(new quota::MockQuotaManager( + if (!quota_manager_) { + quota_manager_ = new quota::MockQuotaManager( profile_->IsOffTheRecord(), profile_->GetPath(), BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), - profile_->GetExtensionSpecialStoragePolicy())); + profile_->GetExtensionSpecialStoragePolicy()); } - return (quota::MockQuotaManager*) profile_->GetQuotaManager(); + return quota_manager_; } // content::NotificationObserver implementation. @@ -392,8 +396,10 @@ class BrowsingDataRemoverTest : public testing::Test, content::TestBrowserThread db_thread_; content::TestBrowserThread webkit_thread_; content::TestBrowserThread file_thread_; + content::TestBrowserThread file_user_blocking_thread_; content::TestBrowserThread io_thread_; scoped_ptr<TestingProfile> profile_; + scoped_refptr<quota::MockQuotaManager> quota_manager_; DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest); }; diff --git a/chrome/browser/chromeos/offline/offline_load_page_unittest.cc b/chrome/browser/chromeos/offline/offline_load_page_unittest.cc index 9b6fe98..b307cd1 100644 --- a/chrome/browser/chromeos/offline/offline_load_page_unittest.cc +++ b/chrome/browser/chromeos/offline/offline_load_page_unittest.cc @@ -50,6 +50,8 @@ class OfflineLoadPageTest : public ChromeRenderViewHostTestHarness { OfflineLoadPageTest() : ui_thread_(BrowserThread::UI, MessageLoop::current()), + file_user_blocking_thread_( + BrowserThread::FILE_USER_BLOCKING, MessageLoop::current()), io_thread_(BrowserThread::IO, MessageLoop::current()) { } @@ -86,6 +88,7 @@ class OfflineLoadPageTest : public ChromeRenderViewHostTestHarness { private: UserResponse user_response_; content::TestBrowserThread ui_thread_; + content::TestBrowserThread file_user_blocking_thread_; content::TestBrowserThread io_thread_; // Initializes / shuts down a stub CrosLibrary. diff --git a/chrome/browser/cookies_tree_model_unittest.cc b/chrome/browser/cookies_tree_model_unittest.cc index 6dde8ea..d98f041 100644 --- a/chrome/browser/cookies_tree_model_unittest.cc +++ b/chrome/browser/cookies_tree_model_unittest.cc @@ -34,11 +34,16 @@ namespace { class CookiesTreeModelTest : public testing::Test { public: - CookiesTreeModelTest() : ui_thread_(BrowserThread::UI, &message_loop_), - io_thread_(BrowserThread::IO, &message_loop_) { + CookiesTreeModelTest() + : ui_thread_(BrowserThread::UI, &message_loop_), + file_user_blocking_(BrowserThread::FILE_USER_BLOCKING, &message_loop_), + io_thread_(BrowserThread::IO, &message_loop_) { } virtual ~CookiesTreeModelTest() { + // Avoid memory leaks. + profile_.reset(); + message_loop_.RunAllPending(); } virtual void SetUp() OVERRIDE { @@ -276,6 +281,7 @@ class CookiesTreeModelTest : public testing::Test { protected: MessageLoop message_loop_; content::TestBrowserThread ui_thread_; + content::TestBrowserThread file_user_blocking_; content::TestBrowserThread io_thread_; scoped_ptr<TestingProfile> profile_; diff --git a/chrome/browser/diagnostics/sqlite_diagnostics.cc b/chrome/browser/diagnostics/sqlite_diagnostics.cc index 4074b73..3fba29e 100644 --- a/chrome/browser/diagnostics/sqlite_diagnostics.cc +++ b/chrome/browser/diagnostics/sqlite_diagnostics.cc @@ -13,6 +13,7 @@ #include "base/utf_string_conversions.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" +#include "content/public/common/content_constants.h" #include "sql/connection.h" #include "sql/diagnostic_error_delegate.h" #include "sql/statement.h" @@ -152,7 +153,7 @@ DiagnosticTest* MakeSqliteThumbnailsDbTest() { } DiagnosticTest* MakeSqliteAppCacheDbTest() { - FilePath appcache_dir(chrome::kAppCacheDirname); + FilePath appcache_dir(content::kAppCacheDirname); FilePath appcache_db = appcache_dir.Append(appcache::kAppCacheDatabaseName); return new SqliteIntegrityTest(false, ASCIIToUTF16("AppCache DB"), appcache_db); diff --git a/chrome/browser/download/download_request_limiter_unittest.cc b/chrome/browser/download/download_request_limiter_unittest.cc index 614fe07..fff7d64 100644 --- a/chrome/browser/download/download_request_limiter_unittest.cc +++ b/chrome/browser/download/download_request_limiter_unittest.cc @@ -16,6 +16,8 @@ class DownloadRequestLimiterTest : public TabContentsWrapperTestHarness { public: DownloadRequestLimiterTest() : ui_thread_(BrowserThread::UI, &message_loop_), + file_user_blocking_thread_( + BrowserThread::FILE_USER_BLOCKING, &message_loop_), io_thread_(BrowserThread::IO, &message_loop_) { } @@ -90,6 +92,7 @@ class DownloadRequestLimiterTest : public TabContentsWrapperTestHarness { int ask_allow_count_; content::TestBrowserThread ui_thread_; + content::TestBrowserThread file_user_blocking_thread_; content::TestBrowserThread io_thread_; }; diff --git a/chrome/browser/extensions/extension_data_deleter.cc b/chrome/browser/extensions/extension_data_deleter.cc index d314ffd..da69e21 100644 --- a/chrome/browser/extensions/extension_data_deleter.cc +++ b/chrome/browser/extensions/extension_data_deleter.cc @@ -23,6 +23,7 @@ #include "webkit/database/database_util.h" #include "webkit/fileapi/file_system_context.h" +using content::BrowserContext; using content::BrowserThread; // static @@ -77,9 +78,9 @@ ExtensionDataDeleter::ExtensionDataDeleter( const GURL& storage_origin, bool is_storage_isolated) : extension_id_(extension_id) { - appcache_service_ = profile->GetAppCacheService(); - webkit_context_ = profile->GetWebKitContext(); - database_tracker_ = profile->GetDatabaseTracker(); + appcache_service_ = BrowserContext::GetAppCacheService(profile); + webkit_context_ = BrowserContext::GetWebKitContext(profile); + database_tracker_ = BrowserContext::GetDatabaseTracker(profile); // Pick the right request context depending on whether it's an extension, // isolated app, or regular app. if (storage_origin.SchemeIs(chrome::kExtensionScheme)) { @@ -92,7 +93,7 @@ ExtensionDataDeleter::ExtensionDataDeleter( } else { extension_request_context_ = profile->GetRequestContext(); } - file_system_context_ = profile->GetFileSystemContext(); + file_system_context_ = BrowserContext::GetFileSystemContext(profile); storage_origin_ = storage_origin; origin_id_ = webkit_database::DatabaseUtil::GetOriginIdentifier(storage_origin_); diff --git a/chrome/browser/extensions/extension_file_browser_private_api.cc b/chrome/browser/extensions/extension_file_browser_private_api.cc index 75a2c83..039265a 100644 --- a/chrome/browser/extensions/extension_file_browser_private_api.cc +++ b/chrome/browser/extensions/extension_file_browser_private_api.cc @@ -54,6 +54,7 @@ #endif using chromeos::disks::DiskMountManager; +using content::BrowserContext; using content::BrowserThread; using content::ChildProcessSecurityPolicy; using content::SiteInstance; @@ -389,7 +390,7 @@ class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher { } fileapi::ExternalFileSystemMountPointProvider* provider = - profile_->GetFileSystemContext()->external_provider(); + BrowserContext::GetFileSystemContext(profile_)->external_provider(); if (!provider) return false; @@ -420,7 +421,7 @@ class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher { void RequestLocalFileSystemFunction::RequestOnFileThread( const GURL& source_url, int child_id) { GURL origin_url = source_url.GetOrigin(); - profile()->GetFileSystemContext()->OpenFileSystem( + BrowserContext::GetFileSystemContext(profile())->OpenFileSystem( origin_url, fileapi::kFileSystemTypeExternal, false, // create LocalFileSystemCallbackDispatcher::CreateCallback( this, @@ -473,8 +474,8 @@ bool FileWatchBrowserFunctionBase::GetLocalFilePath( if (type != fileapi::kFileSystemTypeExternal) return false; - FilePath root_path = profile_->GetFileSystemContext()->external_provider()-> - GetFileSystemRootPathOnFileThread( + FilePath root_path = BrowserContext::GetFileSystemContext(profile_)-> + external_provider()->GetFileSystemRootPathOnFileThread( file_origin_url, fileapi::kFileSystemTypeExternal, *virtual_path, @@ -744,7 +745,7 @@ class return false; fileapi::ExternalFileSystemMountPointProvider* external_provider = - profile_->GetFileSystemContext()->external_provider(); + BrowserContext::GetFileSystemContext(profile_)->external_provider(); if (!external_provider) return false; @@ -871,7 +872,7 @@ void ExecuteTasksFileBrowserFunction::RequestFileEntryOnFileThread( const std::vector<GURL>& file_urls) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); GURL origin_url = source_url.GetOrigin(); - profile()->GetFileSystemContext()->OpenFileSystem( + BrowserContext::GetFileSystemContext(profile())->OpenFileSystem( origin_url, fileapi::kFileSystemTypeExternal, false, // create ExecuteTasksFileSystemCallbackDispatcher::CreateCallback( this, @@ -1005,7 +1006,7 @@ void FileBrowserFunction::GetLocalPathsOnFileThread( // FilePath(virtual_path) doesn't work on win, so limit this to ChromeOS. #if defined(OS_CHROMEOS) fileapi::ExternalFileSystemMountPointProvider* provider = - profile_->GetFileSystemContext()->external_provider(); + BrowserContext::GetFileSystemContext(profile_)->external_provider(); if (!provider) { LOG(WARNING) << "External provider is not available"; BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, diff --git a/chrome/browser/extensions/extension_file_browser_private_apitest.cc b/chrome/browser/extensions/extension_file_browser_private_apitest.cc index 417cc1f..7f42438 100644 --- a/chrome/browser/extensions/extension_file_browser_private_apitest.cc +++ b/chrome/browser/extensions/extension_file_browser_private_apitest.cc @@ -17,6 +17,7 @@ using ::testing::_; using ::testing::ReturnRef; using ::testing::StrEq; +using content::BrowserContext; class ExtensionFileBrowserPrivateApiTest : public ExtensionApiTest { public: @@ -51,7 +52,8 @@ class ExtensionFileBrowserPrivateApiTest : public ExtensionApiTest { void AddTmpMountPoint() { fileapi::ExternalFileSystemMountPointProvider* provider = - browser()->profile()->GetFileSystemContext()->external_provider(); + BrowserContext::GetFileSystemContext(browser()->profile())-> + external_provider(); provider->AddMountPoint(test_mount_point_); } diff --git a/chrome/browser/extensions/extension_local_filesystem_apitest.cc b/chrome/browser/extensions/extension_local_filesystem_apitest.cc index d8e8ce8..76502c2 100644 --- a/chrome/browser/extensions/extension_local_filesystem_apitest.cc +++ b/chrome/browser/extensions/extension_local_filesystem_apitest.cc @@ -8,6 +8,8 @@ #include "webkit/fileapi/file_system_context.h" #include "webkit/fileapi/file_system_mount_point_provider.h" +using content::BrowserContext; + #if defined(OS_CHROMEOS) class FileSystemExtensionApiTest : public ExtensionApiTest { @@ -21,7 +23,8 @@ class FileSystemExtensionApiTest : public ExtensionApiTest { void AddTmpMountPoint() { // Add tmp mount point. fileapi::ExternalFileSystemMountPointProvider* provider = - browser()->profile()->GetFileSystemContext()->external_provider(); + BrowserContext::GetFileSystemContext(browser()->profile())-> + external_provider(); provider->AddMountPoint(test_mount_point_); } diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc index 81a6a2f3..3b0902c 100644 --- a/chrome/browser/extensions/extension_service.cc +++ b/chrome/browser/extensions/extension_service.cc @@ -120,6 +120,7 @@ #endif using base::Time; +using content::BrowserContext; using content::BrowserThread; using content::DevToolsAgentHost; using content::DevToolsAgentHostRegistry; @@ -1136,9 +1137,9 @@ void ExtensionService::NotifyExtensionUnloaded( #if defined(OS_CHROMEOS) // Revoke external file access to - if (profile_->GetFileSystemContext() && - profile_->GetFileSystemContext()->external_provider()) { - profile_->GetFileSystemContext()->external_provider()-> + if (BrowserContext::GetFileSystemContext(profile_) && + BrowserContext::GetFileSystemContext(profile_)->external_provider()) { + BrowserContext::GetFileSystemContext(profile_)->external_provider()-> RevokeAccessForExtension(extension->id()); } diff --git a/chrome/browser/extensions/extension_service_unittest.cc b/chrome/browser/extensions/extension_service_unittest.cc index 5c4cc56..d18a3202 100644 --- a/chrome/browser/extensions/extension_service_unittest.cc +++ b/chrome/browser/extensions/extension_service_unittest.cc @@ -61,12 +61,12 @@ #include "chrome/common/url_constants.h" #include "chrome/test/base/testing_profile.h" #include "content/browser/appcache/chrome_appcache_service.h" -#include "content/browser/file_system/browser_file_system_helper.h" #include "content/browser/in_process_webkit/dom_storage_context.h" #include "content/browser/in_process_webkit/webkit_context.h" #include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/plugin_service.h" +#include "content/public/common/content_constants.h" #include "content/test/test_browser_thread.h" #include "googleurl/src/gurl.h" #include "grit/browser_resources.h" @@ -81,6 +81,7 @@ #include "webkit/plugins/npapi/mock_plugin_list.h" #include "webkit/quota/quota_manager.h" +using content::BrowserContext; using content::BrowserThread; using content::PluginService; @@ -375,38 +376,8 @@ class ExtensionTestingProfile : public TestingProfile { } virtual ExtensionService* GetExtensionService() { return service_; } - virtual ChromeAppCacheService* GetAppCacheService() { - if (!appcache_service_) { - appcache_service_ = new ChromeAppCacheService(NULL); - if (!BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind( - &ChromeAppCacheService::InitializeOnIOThread, - appcache_service_.get(), - IsOffTheRecord() - ? FilePath() : GetPath().Append(chrome::kAppCacheDirname), - GetResourceContext(), - make_scoped_refptr(GetExtensionSpecialStoragePolicy())))) - NOTREACHED(); - } - return appcache_service_; - } - - virtual fileapi::FileSystemContext* GetFileSystemContext() { - if (!file_system_context_) { - quota::QuotaManager* quota_manager = GetQuotaManager(); - file_system_context_ = CreateFileSystemContext( - GetPath(), IsOffTheRecord(), - GetExtensionSpecialStoragePolicy(), - quota_manager ? quota_manager->proxy() : NULL); - } - return file_system_context_; - } - private: ExtensionService* service_; - scoped_refptr<ChromeAppCacheService> appcache_service_; - scoped_refptr<fileapi::FileSystemContext> file_system_context_; }; // Our message loop may be used in tests which require it to be an IO loop. @@ -3104,7 +3075,8 @@ TEST_F(ExtensionServiceTest, ClearExtensionData) { EXPECT_EQ(1U, callback.list_.size()); // Open a database. - webkit_database::DatabaseTracker* db_tracker = profile_->GetDatabaseTracker(); + webkit_database::DatabaseTracker* db_tracker = + BrowserContext::GetDatabaseTracker(profile_.get()); string16 db_name = UTF8ToUTF16("db"); string16 description = UTF8ToUTF16("db_description"); int64 size; @@ -3118,7 +3090,7 @@ TEST_F(ExtensionServiceTest, ClearExtensionData) { // Create local storage. We only simulate this by creating the backing file // since webkit is not initialized. DOMStorageContext* context = - profile_->GetWebKitContext()->dom_storage_context(); + BrowserContext::GetWebKitContext(profile_.get())->dom_storage_context(); FilePath lso_path = context->GetLocalStorageFilePath(origin_id); EXPECT_TRUE(file_util::CreateDirectory(lso_path.DirName())); EXPECT_EQ(0, file_util::WriteFile(lso_path, NULL, 0)); @@ -3127,7 +3099,7 @@ TEST_F(ExtensionServiceTest, ClearExtensionData) { // Create indexed db. Similarly, it is enough to only simulate this by // creating the directory on the disk. IndexedDBContext* idb_context = - profile_->GetWebKitContext()->indexed_db_context(); + BrowserContext::GetWebKitContext(profile_.get())->indexed_db_context(); FilePath idb_path = idb_context->GetIndexedDBFilePath(origin_id); EXPECT_TRUE(file_util::CreateDirectory(idb_path)); EXPECT_TRUE(file_util::DirectoryExists(idb_path)); @@ -3213,7 +3185,8 @@ TEST_F(ExtensionServiceTest, ClearAppData) { EXPECT_EQ(1U, callback.list_.size()); // Open a database. - webkit_database::DatabaseTracker* db_tracker = profile_->GetDatabaseTracker(); + webkit_database::DatabaseTracker* db_tracker = + BrowserContext::GetDatabaseTracker(profile_.get()); string16 db_name = UTF8ToUTF16("db"); string16 description = UTF8ToUTF16("db_description"); int64 size; @@ -3227,7 +3200,7 @@ TEST_F(ExtensionServiceTest, ClearAppData) { // Create local storage. We only simulate this by creating the backing file // since webkit is not initialized. DOMStorageContext* context = - profile_->GetWebKitContext()->dom_storage_context(); + BrowserContext::GetWebKitContext(profile_.get())->dom_storage_context(); FilePath lso_path = context->GetLocalStorageFilePath(origin_id); EXPECT_TRUE(file_util::CreateDirectory(lso_path.DirName())); EXPECT_EQ(0, file_util::WriteFile(lso_path, NULL, 0)); @@ -3236,7 +3209,7 @@ TEST_F(ExtensionServiceTest, ClearAppData) { // Create indexed db. Similarly, it is enough to only simulate this by // creating the directory on the disk. IndexedDBContext* idb_context = - profile_->GetWebKitContext()->indexed_db_context(); + BrowserContext::GetWebKitContext(profile_.get())->indexed_db_context(); FilePath idb_path = idb_context->GetIndexedDBFilePath(origin_id); EXPECT_TRUE(file_util::CreateDirectory(idb_path)); EXPECT_TRUE(file_util::DirectoryExists(idb_path)); diff --git a/chrome/browser/extensions/file_manager_util.cc b/chrome/browser/extensions/file_manager_util.cc index 02ed921..5b96ac6 100644 --- a/chrome/browser/extensions/file_manager_util.cc +++ b/chrome/browser/extensions/file_manager_util.cc @@ -38,6 +38,7 @@ #include "chrome/browser/chromeos/media/media_player.h" #endif +using content::BrowserContext; using content::BrowserThread; using content::PluginService; using content::UserMetricsAction; @@ -216,7 +217,7 @@ bool ConvertFileToFileSystemUrl( bool ConvertFileToRelativeFileSystemPath( Profile* profile, const FilePath& full_file_path, FilePath* virtual_path) { fileapi::ExternalFileSystemMountPointProvider* provider = - profile->GetFileSystemContext()->external_provider(); + BrowserContext::GetFileSystemContext(profile)->external_provider(); if (!provider) return false; diff --git a/chrome/browser/memory_purger.cc b/chrome/browser/memory_purger.cc index a183855..7bf7c3a 100644 --- a/chrome/browser/memory_purger.cc +++ b/chrome/browser/memory_purger.cc @@ -25,6 +25,7 @@ #include "net/url_request/url_request_context_getter.h" #include "third_party/tcmalloc/chromium/src/google/malloc_extension.h" +using content::BrowserContext; using content::BrowserThread; // PurgeMemoryHelper ----------------------------------------------------------- @@ -118,7 +119,7 @@ void MemoryPurger::PurgeBrowser() { // Ask all WebKitContexts to purge memory (freeing memory used to cache // the LocalStorage sqlite DB). WebKitContext creation is basically free so // we don't bother with a "...WithoutCreating()" function. - profiles[i]->GetWebKitContext()->PurgeMemory(); + BrowserContext::GetWebKitContext(profiles[i])->PurgeMemory(); } BrowserThread::PostTask( diff --git a/chrome/browser/net/view_blob_internals_job_factory.cc b/chrome/browser/net/view_blob_internals_job_factory.cc index 246e618..ed9a109 100644 --- a/chrome/browser/net/view_blob_internals_job_factory.cc +++ b/chrome/browser/net/view_blob_internals_job_factory.cc @@ -8,7 +8,6 @@ #include "base/string_util.h" #include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/common/url_constants.h" -#include "content/browser/chrome_blob_storage_context.h" #include "net/url_request/url_request.h" #include "webkit/blob/view_blob_internals_job.h" diff --git a/chrome/browser/profiles/off_the_record_profile_impl.cc b/chrome/browser/profiles/off_the_record_profile_impl.cc index b206eec..49738b1 100644 --- a/chrome/browser/profiles/off_the_record_profile_impl.cc +++ b/chrome/browser/profiles/off_the_record_profile_impl.cc @@ -44,9 +44,6 @@ #include "chrome/common/json_pref_store.h" #include "chrome/common/pref_names.h" #include "chrome/common/render_messages.h" -#include "content/browser/appcache/chrome_appcache_service.h" -#include "content/browser/chrome_blob_storage_context.h" -#include "content/browser/file_system/browser_file_system_helper.h" #include "content/browser/in_process_webkit/webkit_context.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/host_zoom_map.h" @@ -55,7 +52,6 @@ #include "net/base/transport_security_state.h" #include "net/http/http_server_properties.h" #include "webkit/database/database_tracker.h" -#include "webkit/quota/quota_manager.h" #if defined(OS_CHROMEOS) #include "chrome/browser/chromeos/preferences.h" @@ -133,14 +129,6 @@ OffTheRecordProfileImpl::~OffTheRecordProfileImpl() { BrowserThread::IO, FROM_HERE, base::Bind(&NotifyOTRProfileDestroyedOnIOThread, profile_, this)); - // Clean up all DB files/directories - if (db_tracker_) { - BrowserThread::PostTask( - BrowserThread::FILE, FROM_HERE, - base::Bind(&webkit_database::DatabaseTracker::Shutdown, - db_tracker_.get())); - } - BrowserList::RemoveObserver(this); if (host_content_settings_map_) @@ -190,17 +178,6 @@ Profile* OffTheRecordProfileImpl::GetOriginalProfile() { return profile_; } -ChromeAppCacheService* OffTheRecordProfileImpl::GetAppCacheService() { - CreateQuotaManagerAndClients(); - return appcache_service_; -} - -webkit_database::DatabaseTracker* - OffTheRecordProfileImpl::GetDatabaseTracker() { - CreateQuotaManagerAndClients(); - return db_tracker_; -} - VisitedLinkMaster* OffTheRecordProfileImpl::GetVisitedLinkMaster() { // We don't provide access to the VisitedLinkMaster when we're OffTheRecord // because we don't want to leak the sites that the user has visited before. @@ -313,20 +290,10 @@ DownloadManager* OffTheRecordProfileImpl::GetDownloadManager() { return DownloadServiceFactory::GetForProfile(this)->GetDownloadManager(); } -fileapi::FileSystemContext* OffTheRecordProfileImpl::GetFileSystemContext() { - CreateQuotaManagerAndClients(); - return file_system_context_.get(); -} - net::URLRequestContextGetter* OffTheRecordProfileImpl::GetRequestContext() { return io_data_.GetMainRequestContextGetter(); } -quota::QuotaManager* OffTheRecordProfileImpl::GetQuotaManager() { - CreateQuotaManagerAndClients(); - return quota_manager_.get(); -} - net::URLRequestContextGetter* OffTheRecordProfileImpl::GetRequestContextForRenderProcess( int renderer_child_id) { @@ -409,6 +376,11 @@ bool OffTheRecordProfileImpl::DidLastSessionExitCleanly() { return profile_->DidLastSessionExitCleanly(); } +quota::SpecialStoragePolicy* + OffTheRecordProfileImpl::GetSpecialStoragePolicy() { + return GetExtensionSpecialStoragePolicy(); +} + BookmarkModel* OffTheRecordProfileImpl::GetBookmarkModel() { return profile_->GetBookmarkModel(); } @@ -429,11 +401,6 @@ Time OffTheRecordProfileImpl::GetStartTime() const { return start_time_; } -WebKitContext* OffTheRecordProfileImpl::GetWebKitContext() { - CreateQuotaManagerAndClients(); - return webkit_context_.get(); -} - history::TopSites* OffTheRecordProfileImpl::GetTopSitesWithoutCreating() { return NULL; } @@ -487,17 +454,6 @@ void OffTheRecordProfileImpl::OnBrowserAdded(const Browser* browser) { void OffTheRecordProfileImpl::OnBrowserRemoved(const Browser* browser) { } -ChromeBlobStorageContext* OffTheRecordProfileImpl::GetBlobStorageContext() { - if (!blob_storage_context_) { - blob_storage_context_ = new ChromeBlobStorageContext(); - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&ChromeBlobStorageContext::InitializeOnIOThread, - blob_storage_context_.get())); - } - return blob_storage_context_; -} - ExtensionInfoMap* OffTheRecordProfileImpl::GetExtensionInfoMap() { return profile_->GetExtensionInfoMap(); } @@ -557,51 +513,6 @@ void OffTheRecordProfileImpl::Observe(int type, } } -void OffTheRecordProfileImpl::CreateQuotaManagerAndClients() { - if (quota_manager_.get()) { - DCHECK(file_system_context_.get()); - DCHECK(db_tracker_.get()); - DCHECK(webkit_context_.get()); - return; - } - - // All of the clients have to be created and registered with the - // QuotaManager prior to the QuotaManger being used. So we do them - // all together here prior to handing out a reference to anything - // that utlizes the QuotaManager. - quota_manager_ = new quota::QuotaManager( - IsOffTheRecord(), - GetPath(), - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), - GetExtensionSpecialStoragePolicy()); - - // Each consumer is responsible for registering its QuotaClient during - // its construction. - file_system_context_ = CreateFileSystemContext( - GetPath(), IsOffTheRecord(), - GetExtensionSpecialStoragePolicy(), - quota_manager_->proxy()); - db_tracker_ = new webkit_database::DatabaseTracker( - GetPath(), IsOffTheRecord(), false, GetExtensionSpecialStoragePolicy(), - quota_manager_->proxy(), - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); - webkit_context_ = new WebKitContext( - IsOffTheRecord(), GetPath(), GetExtensionSpecialStoragePolicy(), - false, quota_manager_->proxy(), - BrowserThread::GetMessageLoopProxyForThread( - BrowserThread::WEBKIT_DEPRECATED)); - appcache_service_ = new ChromeAppCacheService(quota_manager_->proxy()); - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&ChromeAppCacheService::InitializeOnIOThread, - appcache_service_.get(), - IsOffTheRecord() - ? FilePath() : GetPath().Append(chrome::kAppCacheDirname), - io_data_.GetResourceContextNoInit(), - make_scoped_refptr(GetExtensionSpecialStoragePolicy()))); -} - #if defined(OS_CHROMEOS) // Special case of the OffTheRecordProfileImpl which is used while Guest // session in CrOS. diff --git a/chrome/browser/profiles/off_the_record_profile_impl.h b/chrome/browser/profiles/off_the_record_profile_impl.h index d22887d..e22e9d4 100644 --- a/chrome/browser/profiles/off_the_record_profile_impl.h +++ b/chrome/browser/profiles/off_the_record_profile_impl.h @@ -35,14 +35,10 @@ class OffTheRecordProfileImpl : public Profile, // Profile implementation. virtual std::string GetProfileName() OVERRIDE; - virtual FilePath GetPath() OVERRIDE; - virtual bool IsOffTheRecord() OVERRIDE; virtual Profile* GetOffTheRecordProfile() OVERRIDE; virtual void DestroyOffTheRecordProfile() OVERRIDE; virtual bool HasOffTheRecordProfile() OVERRIDE; virtual Profile* GetOriginalProfile() OVERRIDE; - virtual ChromeAppCacheService* GetAppCacheService() OVERRIDE; - virtual webkit_database::DatabaseTracker* GetDatabaseTracker() OVERRIDE; virtual VisitedLinkMaster* GetVisitedLinkMaster() OVERRIDE; virtual ExtensionService* GetExtensionService() OVERRIDE; virtual UserScriptMaster* GetUserScriptMaster() OVERRIDE; @@ -64,32 +60,18 @@ class OffTheRecordProfileImpl : public Profile, virtual PrefService* GetPrefs() OVERRIDE; virtual PrefService* GetOffTheRecordPrefs() OVERRIDE; virtual TemplateURLFetcher* GetTemplateURLFetcher() OVERRIDE; - virtual content::DownloadManager* GetDownloadManager() OVERRIDE; - virtual fileapi::FileSystemContext* GetFileSystemContext() OVERRIDE; - virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; - virtual quota::QuotaManager* GetQuotaManager() OVERRIDE; - virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess( - int renderer_child_id) OVERRIDE; - virtual net::URLRequestContextGetter* GetRequestContextForMedia() OVERRIDE; virtual net::URLRequestContextGetter* GetRequestContextForExtensions() OVERRIDE; virtual net::URLRequestContextGetter* GetRequestContextForIsolatedApp( const std::string& app_id) OVERRIDE; - virtual content::ResourceContext* GetResourceContext() OVERRIDE; virtual net::SSLConfigService* GetSSLConfigService() OVERRIDE; virtual HostContentSettingsMap* GetHostContentSettingsMap() OVERRIDE; - virtual content::HostZoomMap* GetHostZoomMap() OVERRIDE; - virtual content::GeolocationPermissionContext* - GetGeolocationPermissionContext() OVERRIDE; - virtual content::SpeechInputPreferences* GetSpeechInputPreferences() OVERRIDE; virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() OVERRIDE; - virtual bool DidLastSessionExitCleanly() OVERRIDE; virtual BookmarkModel* GetBookmarkModel() OVERRIDE; virtual ProtocolHandlerRegistry* GetProtocolHandlerRegistry() OVERRIDE; virtual TokenService* GetTokenService() OVERRIDE; virtual bool IsSameProfile(Profile* profile) OVERRIDE; virtual Time GetStartTime() const OVERRIDE; - virtual WebKitContext* GetWebKitContext() OVERRIDE; virtual history::TopSites* GetTopSitesWithoutCreating() OVERRIDE; virtual history::TopSites* GetTopSites() OVERRIDE; virtual void MarkAsCleanShutdown() OVERRIDE; @@ -106,7 +88,6 @@ class OffTheRecordProfileImpl : public Profile, virtual void OnBrowserAdded(const Browser* browser) OVERRIDE; virtual void OnBrowserRemoved(const Browser* browser) OVERRIDE; - virtual ChromeBlobStorageContext* GetBlobStorageContext() OVERRIDE; virtual ExtensionInfoMap* GetExtensionInfoMap() OVERRIDE; virtual ChromeURLDataManager* GetChromeURLDataManager() OVERRIDE; virtual PromoCounter* GetInstantPromoCounter() OVERRIDE; @@ -123,14 +104,28 @@ class OffTheRecordProfileImpl : public Profile, virtual void ClearNetworkingHistorySince(base::Time time) OVERRIDE; virtual GURL GetHomePage() OVERRIDE; + // content::BrowserContext implementation: + virtual FilePath GetPath() OVERRIDE; + virtual bool IsOffTheRecord() OVERRIDE; + virtual content::DownloadManager* GetDownloadManager() OVERRIDE; + virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; + virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess( + int renderer_child_id) OVERRIDE; + virtual net::URLRequestContextGetter* GetRequestContextForMedia() OVERRIDE; + virtual content::ResourceContext* GetResourceContext() OVERRIDE; + virtual content::HostZoomMap* GetHostZoomMap() OVERRIDE; + virtual content::GeolocationPermissionContext* + GetGeolocationPermissionContext() OVERRIDE; + virtual content::SpeechInputPreferences* GetSpeechInputPreferences() OVERRIDE; + virtual bool DidLastSessionExitCleanly() OVERRIDE; + virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE; + // content::NotificationObserver implementation. virtual void Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; private: - void CreateQuotaManagerAndClients(); - content::NotificationRegistrar registrar_; // The real underlying profile. @@ -152,31 +147,15 @@ class OffTheRecordProfileImpl : public Profile, // Use a separate zoom map for OTR. scoped_refptr<content::HostZoomMap> host_zoom_map_; - // Use a special WebKit context for OTR browsing. - scoped_refptr<WebKitContext> webkit_context_; - // Time we were started. Time start_time_; - scoped_refptr<ChromeAppCacheService> appcache_service_; - - // The main database tracker for this profile. - // Should be used only on the file thread. - scoped_refptr<webkit_database::DatabaseTracker> db_tracker_; - FilePath last_selected_directory_; - scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; - - // The file_system context for this profile. - scoped_refptr<fileapi::FileSystemContext> file_system_context_; - scoped_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_; scoped_ptr<ChromeURLDataManager> chrome_url_data_manager_; - scoped_refptr<quota::QuotaManager> quota_manager_; - DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl); }; diff --git a/chrome/browser/profiles/off_the_record_profile_io_data.cc b/chrome/browser/profiles/off_the_record_profile_io_data.cc index a77beec..3f8a01b 100644 --- a/chrome/browser/profiles/off_the_record_profile_io_data.cc +++ b/chrome/browser/profiles/off_the_record_profile_io_data.cc @@ -130,6 +130,9 @@ OffTheRecordProfileIOData::Handle::GetIsolatedAppRequestContextGetter( void OffTheRecordProfileIOData::Handle::LazyInitialize() const { if (!initialized_) { + // Set initialized_ to true at the beginning in case any of the objects + // below try to get the ResourceContext pointer. + initialized_ = true; io_data_->InitializeOnUIThread(profile_); ChromeNetworkDelegate::InitializeReferrersEnabled( io_data_->enable_referrers(), profile_->GetPrefs()); @@ -138,7 +141,6 @@ void OffTheRecordProfileIOData::Handle::LazyInitialize() const { profile_->GetPrefs(), NULL); io_data_->safe_browsing_enabled()->MoveToThread(BrowserThread::IO); #endif - initialized_ = true; } } diff --git a/chrome/browser/profiles/profile.cc b/chrome/browser/profiles/profile.cc index c238068..4390994 100644 --- a/chrome/browser/profiles/profile.cc +++ b/chrome/browser/profiles/profile.cc @@ -44,17 +44,12 @@ #include "chrome/common/json_pref_store.h" #include "chrome/common/pref_names.h" #include "chrome/common/render_messages.h" -#include "content/browser/appcache/chrome_appcache_service.h" -#include "content/browser/chrome_blob_storage_context.h" -#include "content/browser/file_system/browser_file_system_helper.h" #include "content/browser/in_process_webkit/webkit_context.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/download_manager.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_ui.h" #include "ui/base/resource/resource_bundle.h" -#include "webkit/database/database_tracker.h" -#include "webkit/quota/quota_manager.h" #if defined(TOOLKIT_USES_GTK) #include "chrome/browser/ui/gtk/gtk_theme_service.h" diff --git a/chrome/browser/profiles/profile.h b/chrome/browser/profiles/profile.h index 286af37..3f6f5f4 100644 --- a/chrome/browser/profiles/profile.h +++ b/chrome/browser/profiles/profile.h @@ -182,26 +182,6 @@ class Profile : public content::BrowserContext { // content::BrowserContext implementation ------------------------------------ - virtual FilePath GetPath() = 0; - virtual content::DownloadManager* GetDownloadManager() = 0; - virtual net::URLRequestContextGetter* GetRequestContext() = 0; - virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess( - int renderer_child_id) = 0; - virtual net::URLRequestContextGetter* GetRequestContextForMedia() = 0; - virtual content::ResourceContext* GetResourceContext() = 0; - virtual content::HostZoomMap* GetHostZoomMap() = 0; - virtual content::GeolocationPermissionContext* - GetGeolocationPermissionContext() = 0; - virtual content::SpeechInputPreferences* GetSpeechInputPreferences() = 0; - virtual quota::QuotaManager* GetQuotaManager() = 0; - virtual webkit_database::DatabaseTracker* GetDatabaseTracker() = 0; - virtual WebKitContext* GetWebKitContext() = 0; - virtual ChromeAppCacheService* GetAppCacheService() = 0; - virtual ChromeBlobStorageContext* GetBlobStorageContext() = 0; - virtual fileapi::FileSystemContext* GetFileSystemContext() = 0; - - // content::BrowserContext implementation ------------------------------------ - // Typesafe upcast. virtual TestingProfile* AsTestingProfile(); @@ -378,9 +358,6 @@ class Profile : public content::BrowserContext { // Returns the user style sheet watcher. virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() = 0; - // Returns true if the last time this profile was open it was exited cleanly. - virtual bool DidLastSessionExitCleanly() = 0; - // Returns the BookmarkModel, creating if not yet created. virtual BookmarkModel* GetBookmarkModel() = 0; diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index 1c95a71..b166fc0 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -92,9 +92,6 @@ #include "chrome/common/json_pref_store.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" -#include "content/browser/appcache/chrome_appcache_service.h" -#include "content/browser/chrome_blob_storage_context.h" -#include "content/browser/file_system/browser_file_system_helper.h" #include "content/browser/in_process_webkit/webkit_context.h" #include "content/browser/speech/speech_input_manager.h" #include "content/public/browser/browser_thread.h" @@ -105,7 +102,6 @@ #include "net/base/transport_security_state.h" #include "net/http/http_server_properties.h" #include "webkit/database/database_tracker.h" -#include "webkit/quota/quota_manager.h" #if defined(OS_WIN) #include "chrome/browser/instant/promo_counter.h" @@ -549,13 +545,15 @@ ProfileImpl::~ProfileImpl() { // Save the session state if we're going to restore the session during the // next startup. SessionStartupPref pref = SessionStartupPref::GetStartupPref(this); - if (pref.type == SessionStartupPref::LAST) + if (pref.type == SessionStartupPref::LAST) { SaveSessionState(); - else if (appcache_service_ && clear_local_state_on_exit_) { + } else if (clear_local_state_on_exit_) { BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, base::Bind(&appcache::AppCacheService::set_clear_local_state_on_exit, - appcache_service_.get(), true)); + BrowserContext::GetAppCacheService(this), true)); + BrowserContext::GetWebKitContext(this)->set_clear_local_state_on_exit(true); + BrowserContext::GetDatabaseTracker(this)->SetClearLocalStateOnExit(true); } StopCreateSessionServiceTimer(); @@ -576,13 +574,6 @@ ProfileImpl::~ProfileImpl() { ProfileDependencyManager::GetInstance()->DestroyProfileServices(this); - if (db_tracker_) { - BrowserThread::PostTask( - BrowserThread::FILE, FROM_HERE, - base::Bind(&webkit_database::DatabaseTracker::Shutdown, - db_tracker_.get())); - } - // Password store uses WebDB, shut it down before the WebDB has been shutdown. if (password_store_.get()) password_store_->Shutdown(); @@ -680,16 +671,6 @@ Profile* ProfileImpl::GetOriginalProfile() { return this; } -ChromeAppCacheService* ProfileImpl::GetAppCacheService() { - CreateQuotaManagerAndClients(); - return appcache_service_; -} - -webkit_database::DatabaseTracker* ProfileImpl::GetDatabaseTracker() { - CreateQuotaManagerAndClients(); - return db_tracker_; -} - VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() { if (!visited_link_master_.get()) { scoped_ptr<VisitedLinkMaster> visited_links( @@ -1136,16 +1117,6 @@ DownloadManager* ProfileImpl::GetDownloadManager() { return DownloadServiceFactory::GetForProfile(this)->GetDownloadManager(); } -fileapi::FileSystemContext* ProfileImpl::GetFileSystemContext() { - CreateQuotaManagerAndClients(); - return file_system_context_.get(); -} - -quota::QuotaManager* ProfileImpl::GetQuotaManager() { - CreateQuotaManagerAndClients(); - return quota_manager_.get(); -} - bool ProfileImpl::DidLastSessionExitCleanly() { // last_session_exited_cleanly_ is set when the preferences are loaded. Force // it to be set by asking for the prefs. @@ -1153,6 +1124,10 @@ bool ProfileImpl::DidLastSessionExitCleanly() { return last_session_exited_cleanly_; } +quota::SpecialStoragePolicy* ProfileImpl::GetSpecialStoragePolicy() { + return GetExtensionSpecialStoragePolicy(); +} + BookmarkModel* ProfileImpl::GetBookmarkModel() { if (!bookmark_bar_model_.get()) { bookmark_bar_model_.reset(new BookmarkModel(this)); @@ -1194,57 +1169,6 @@ ExtensionPrefValueMap* ProfileImpl::GetExtensionPrefValueMap() { return extension_pref_value_map_.get(); } -void ProfileImpl::CreateQuotaManagerAndClients() { - if (quota_manager_.get()) { - DCHECK(file_system_context_.get()); - DCHECK(db_tracker_.get()); - DCHECK(webkit_context_.get()); - return; - } - - // All of the clients have to be created and registered with the - // QuotaManager prior to the QuotaManger being used. So we do them - // all together here prior to handing out a reference to anything - // that utlizes the QuotaManager. - quota_manager_ = new quota::QuotaManager( - IsOffTheRecord(), - GetPath(), - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), - GetExtensionSpecialStoragePolicy()); - - // Each consumer is responsible for registering its QuotaClient during - // its construction. - file_system_context_ = CreateFileSystemContext( - GetPath(), IsOffTheRecord(), - GetExtensionSpecialStoragePolicy(), - quota_manager_->proxy()); - db_tracker_ = new webkit_database::DatabaseTracker( - GetPath(), IsOffTheRecord(), clear_local_state_on_exit_, - GetExtensionSpecialStoragePolicy(), - quota_manager_->proxy(), - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); - webkit_context_ = new WebKitContext( - IsOffTheRecord(), GetPath(), GetExtensionSpecialStoragePolicy(), - clear_local_state_on_exit_, quota_manager_->proxy(), - BrowserThread::GetMessageLoopProxyForThread( - BrowserThread::WEBKIT_DEPRECATED)); - appcache_service_ = new ChromeAppCacheService(quota_manager_->proxy()); - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&ChromeAppCacheService::InitializeOnIOThread, - appcache_service_.get(), - IsOffTheRecord() - ? FilePath() : GetPath().Append(chrome::kAppCacheDirname), - io_data_.GetResourceContextNoInit(), - make_scoped_refptr(GetExtensionSpecialStoragePolicy()))); -} - -WebKitContext* ProfileImpl::GetWebKitContext() { - CreateQuotaManagerAndClients(); - return webkit_context_.get(); -} - void ProfileImpl::MarkAsCleanShutdown() { if (prefs_.get()) { // The session cleanly exited, set kSessionExitedCleanly appropriately. @@ -1280,14 +1204,6 @@ void ProfileImpl::Observe(int type, } else if (*pref_name_in == prefs::kClearSiteDataOnExit) { clear_local_state_on_exit_ = prefs->GetBoolean(prefs::kClearSiteDataOnExit); - if (webkit_context_) { - webkit_context_->set_clear_local_state_on_exit( - clear_local_state_on_exit_); - } - if (db_tracker_) { - db_tracker_->SetClearLocalStateOnExit( - clear_local_state_on_exit_); - } } else if (*pref_name_in == prefs::kGoogleServicesUsername) { UpdateProfileUserNameCache(); } else if (*pref_name_in == prefs::kProfileAvatarIndex) { @@ -1342,17 +1258,6 @@ TokenService* ProfileImpl::GetTokenService() { return token_service_.get(); } -ChromeBlobStorageContext* ProfileImpl::GetBlobStorageContext() { - if (!blob_storage_context_) { - blob_storage_context_ = new ChromeBlobStorageContext(); - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&ChromeBlobStorageContext::InitializeOnIOThread, - blob_storage_context_.get())); - } - return blob_storage_context_; -} - ExtensionInfoMap* ProfileImpl::GetExtensionInfoMap() { return extension_info_map_.get(); } @@ -1526,16 +1431,14 @@ GURL ProfileImpl::GetHomePage() { void ProfileImpl::SaveSessionState() { if (!session_restore_enabled_) return; - if (webkit_context_.get()) - webkit_context_->SaveSessionState(); - if (db_tracker_.get()) - db_tracker_->SaveSessionState(); + BrowserContext::GetWebKitContext(this)->SaveSessionState(); + BrowserContext::GetDatabaseTracker(this)->SaveSessionState(); BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, base::Bind(&SaveSessionStateOnIOThread, make_scoped_refptr(GetRequestContext()), - make_scoped_refptr(appcache_service_.get()))); + make_scoped_refptr(BrowserContext::GetAppCacheService(this)))); } void ProfileImpl::UpdateProfileUserNameCache() { diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h index f7884b1..b82f1a7 100644 --- a/chrome/browser/profiles/profile_impl.h +++ b/chrome/browser/profiles/profile_impl.h @@ -61,12 +61,8 @@ class ProfileImpl : public Profile, virtual content::GeolocationPermissionContext* GetGeolocationPermissionContext() OVERRIDE; virtual content::SpeechInputPreferences* GetSpeechInputPreferences() OVERRIDE; - virtual quota::QuotaManager* GetQuotaManager() OVERRIDE; - virtual webkit_database::DatabaseTracker* GetDatabaseTracker() OVERRIDE; - virtual WebKitContext* GetWebKitContext() OVERRIDE; - virtual ChromeAppCacheService* GetAppCacheService() OVERRIDE; - virtual ChromeBlobStorageContext* GetBlobStorageContext() OVERRIDE; - virtual fileapi::FileSystemContext* GetFileSystemContext() OVERRIDE; + virtual bool DidLastSessionExitCleanly() OVERRIDE; + virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE; // Profile implementation: virtual std::string GetProfileName() OVERRIDE; @@ -110,7 +106,6 @@ class ProfileImpl : public Profile, virtual net::SSLConfigService* GetSSLConfigService() OVERRIDE; virtual HostContentSettingsMap* GetHostContentSettingsMap() OVERRIDE; virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() OVERRIDE; - virtual bool DidLastSessionExitCleanly() OVERRIDE; virtual BookmarkModel* GetBookmarkModel() OVERRIDE; virtual ProtocolHandlerRegistry* GetProtocolHandlerRegistry() OVERRIDE; virtual bool IsSameProfile(Profile* profile) OVERRIDE; @@ -176,8 +171,6 @@ class ProfileImpl : public Profile, ExtensionPrefValueMap* GetExtensionPrefValueMap(); - void CreateQuotaManagerAndClients(); - void UpdateProfileUserNameCache(); @@ -251,9 +244,6 @@ class ProfileImpl : public Profile, scoped_refptr<history::ShortcutsBackend> shortcuts_backend_; scoped_refptr<WebDataService> web_data_service_; scoped_refptr<PasswordStore> password_store_; - scoped_refptr<WebKitContext> webkit_context_; - scoped_refptr<fileapi::FileSystemContext> file_system_context_; - scoped_refptr<quota::QuotaManager> quota_manager_; bool history_service_created_; bool favicon_service_created_; bool created_web_data_service_; @@ -274,18 +264,8 @@ class ProfileImpl : public Profile, scoped_ptr<PromoCounter> instant_promo_counter_; #endif - // The AppCacheService for this profile, shared by all requests contexts - // associated with this profile. Should only be used on the IO thread. - scoped_refptr<ChromeAppCacheService> appcache_service_; - - // The main database tracker for this profile. - // Should be used only on the file thread. - scoped_refptr<webkit_database::DatabaseTracker> db_tracker_; - scoped_refptr<history::TopSites> top_sites_; // For history and thumbnails. - scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; - #if defined(OS_CHROMEOS) scoped_ptr<chromeos::Preferences> chromeos_preferences_; diff --git a/chrome/browser/profiles/profile_impl_io_data.cc b/chrome/browser/profiles/profile_impl_io_data.cc index 3481fda..0b01f29 100644 --- a/chrome/browser/profiles/profile_impl_io_data.cc +++ b/chrome/browser/profiles/profile_impl_io_data.cc @@ -223,6 +223,9 @@ void ProfileImplIOData::Handle::ClearNetworkingHistorySince( void ProfileImplIOData::Handle::LazyInitialize() const { if (!initialized_) { + // Set initialized_ to true at the beginning in case any of the objects + // below try to get the ResourceContext pointer. + initialized_ = true; io_data_->InitializeOnUIThread(profile_); PrefService* pref_service = profile_->GetPrefs(); io_data_->http_server_properties_manager_.reset( @@ -240,7 +243,6 @@ void ProfileImplIOData::Handle::LazyInitialize() const { pref_service, NULL); io_data_->safe_browsing_enabled()->MoveToThread(BrowserThread::IO); #endif - initialized_ = true; } } diff --git a/chrome/browser/profiles/profile_io_data.cc b/chrome/browser/profiles/profile_io_data.cc index 5e761a1..c0b0e13 100644 --- a/chrome/browser/profiles/profile_io_data.cc +++ b/chrome/browser/profiles/profile_io_data.cc @@ -70,6 +70,7 @@ #include "chrome/browser/chromeos/proxy_config_service_impl.h" #endif // defined(OS_CHROMEOS) +using content::BrowserContext; using content::BrowserThread; namespace { @@ -195,7 +196,7 @@ void ProfileIOData::InitializeOnUIThread(Profile* profile) { params->clear_local_state_on_exit = pref_service->GetBoolean(prefs::kClearSiteDataOnExit); - params->appcache_service = profile->GetAppCacheService(); + params->appcache_service = BrowserContext::GetAppCacheService(profile); // Set up Accept-Language and Accept-Charset header values params->accept_language = net::HttpUtil::GenerateAcceptLanguageHeader( @@ -231,12 +232,12 @@ void ProfileIOData::InitializeOnUIThread(Profile* profile) { profile); params->cookie_monster_delegate = new ChromeCookieMonsterDelegate(profile_getter); - params->database_tracker = profile->GetDatabaseTracker(); - params->appcache_service = profile->GetAppCacheService(); - params->blob_storage_context = profile->GetBlobStorageContext(); - params->file_system_context = profile->GetFileSystemContext(); - params->webkit_context = profile->GetWebKitContext(); - params->quota_manager = profile->GetQuotaManager(); + params->database_tracker = BrowserContext::GetDatabaseTracker(profile); + params->appcache_service = BrowserContext::GetAppCacheService(profile); + params->blob_storage_context = BrowserContext::GetBlobStorageContext(profile); + params->file_system_context = BrowserContext::GetFileSystemContext(profile); + params->webkit_context = BrowserContext::GetWebKitContext(profile); + params->quota_manager = BrowserContext::GetQuotaManager(profile); params->extension_info_map = profile->GetExtensionInfoMap(); params->notification_service = DesktopNotificationServiceFactory::GetForProfile(profile); diff --git a/chrome/browser/safe_browsing/client_side_detection_host_unittest.cc b/chrome/browser/safe_browsing/client_side_detection_host_unittest.cc index ff85fac..0b101f8 100644 --- a/chrome/browser/safe_browsing/client_side_detection_host_unittest.cc +++ b/chrome/browser/safe_browsing/client_side_detection_host_unittest.cc @@ -5,6 +5,7 @@ #include "base/file_path.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" +#include "base/synchronization/waitable_event.h" #include "chrome/browser/safe_browsing/browser_feature_extractor.h" #include "chrome/browser/safe_browsing/client_side_detection_host.h" #include "chrome/browser/safe_browsing/client_side_detection_service.h" @@ -159,6 +160,9 @@ class ClientSideDetectionHostTest : public TabContentsWrapperTestHarness { ui_thread_.reset(new content::TestBrowserThread(BrowserThread::UI, &message_loop_)); + file_user_blocking_thread_.reset( + new content::TestBrowserThread(BrowserThread::FILE_USER_BLOCKING, + &message_loop_)); // Note: we're starting a real IO thread to make sure our DCHECKs that // verify which thread is running are actually tested. io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO)); @@ -178,6 +182,11 @@ class ClientSideDetectionHostTest : public TabContentsWrapperTestHarness { csd_host_->browse_info_.reset(new BrowseInfo); } + static void RunAllPendingOnIO(base::WaitableEvent* event) { + MessageLoop::current()->RunAllPending(); + event->Signal(); + } + virtual void TearDown() { // Delete the host object on the UI thread and release the // SafeBrowsingService. @@ -186,7 +195,15 @@ class ClientSideDetectionHostTest : public TabContentsWrapperTestHarness { sb_service_ = NULL; message_loop_.RunAllPending(); TabContentsWrapperTestHarness::TearDown(); + + // Let the tasks on the IO thread run to avoid memory leaks. + base::WaitableEvent done(false, false); + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, + base::Bind(RunAllPendingOnIO, &done)); + done.Wait(); io_thread_.reset(); + message_loop_.RunAllPending(); + file_user_blocking_thread_.reset(); ui_thread_.reset(); } @@ -290,6 +307,7 @@ class ClientSideDetectionHostTest : public TabContentsWrapperTestHarness { private: scoped_ptr<content::TestBrowserThread> ui_thread_; + scoped_ptr<content::TestBrowserThread> file_user_blocking_thread_; scoped_ptr<content::TestBrowserThread> io_thread_; }; diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc index 139a643..7a366bc 100644 --- a/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc +++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc @@ -82,6 +82,8 @@ class SafeBrowsingBlockingPageTest : public ChromeRenderViewHostTestHarness { SafeBrowsingBlockingPageTest() : ui_thread_(BrowserThread::UI, MessageLoop::current()), + file_user_blocking_thread_( + BrowserThread::FILE_USER_BLOCKING, MessageLoop::current()), io_thread_(BrowserThread::IO, MessageLoop::current()) { ResetUserResponse(); service_ = new TestSafeBrowsingService(); @@ -189,6 +191,7 @@ class SafeBrowsingBlockingPageTest : public ChromeRenderViewHostTestHarness { UserResponse user_response_; TestSafeBrowsingBlockingPageFactory factory_; content::TestBrowserThread ui_thread_; + content::TestBrowserThread file_user_blocking_thread_; content::TestBrowserThread io_thread_; }; diff --git a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc index 60c44b3..bb872fd 100644 --- a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc @@ -380,10 +380,6 @@ class ProfileSyncServiceAutofillTest : public AbstractProfileSyncServiceTest { WillRepeatedly(Return(web_data_service_.get())); personal_data_manager_->Init(&profile_); - notification_service_ = new ThreadNotificationService( - db_thread_.DeprecatedGetThreadObject()); - notification_service_->Init(); - // Note: This must be called *after* the notification service is created. web_data_service_->StartSyncableService(); } @@ -392,7 +388,6 @@ class ProfileSyncServiceAutofillTest : public AbstractProfileSyncServiceTest { // Note: The tear down order is important. service_.reset(); web_data_service_->ShutdownSyncableService(); - notification_service_->TearDown(); profile_.ResetRequestContext(); AbstractProfileSyncServiceTest::TearDown(); } @@ -572,8 +567,6 @@ class ProfileSyncServiceAutofillTest : public AbstractProfileSyncServiceTest { friend class AddAutofillHelper<AutofillProfile>; friend class FakeServerUpdater; - scoped_refptr<ThreadNotificationService> notification_service_; - ProfileMock profile_; AutofillTableMock autofill_table_; scoped_ptr<WebDatabaseFake> web_database_; diff --git a/chrome/browser/sync/profile_sync_service_password_unittest.cc b/chrome/browser/sync/profile_sync_service_password_unittest.cc index d8d481d..49a453a 100644 --- a/chrome/browser/sync/profile_sync_service_password_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_password_unittest.cc @@ -181,9 +181,6 @@ class ProfileSyncServicePasswordTest : public AbstractProfileSyncServiceTest { profile_.CreateRequestContext(); password_store_ = new MockPasswordStore(); - notification_service_ = new ThreadNotificationService( - db_thread_.DeprecatedGetThreadObject()); - notification_service_->Init(); registrar_.Add(&observer_, chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, content::NotificationService::AllSources()); @@ -195,7 +192,6 @@ class ProfileSyncServicePasswordTest : public AbstractProfileSyncServiceTest { virtual void TearDown() { password_store_->Shutdown(); service_.reset(); - notification_service_->TearDown(); profile_.ResetRequestContext(); AbstractProfileSyncServiceTest::TearDown(); } @@ -315,7 +311,6 @@ class ProfileSyncServicePasswordTest : public AbstractProfileSyncServiceTest { EXPECT_CALL(*password_store_, RemoveLoginImpl(_)).Times(0); } - scoped_refptr<ThreadNotificationService> notification_service_; content::NotificationObserverMock observer_; ProfileMock profile_; scoped_refptr<MockPasswordStore> password_store_; diff --git a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc index 251dcd7..6db9cf2 100644 --- a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc @@ -164,17 +164,12 @@ class ProfileSyncServiceTypedUrlTest : public AbstractProfileSyncServiceTest { .WillRepeatedly(RunTaskOnDBThread(&history_thread_, history_backend_.get())); history_thread_.Start(); - - notification_service_ = - new ThreadNotificationService(&history_thread_); - notification_service_->Init(); } virtual void TearDown() { history_backend_ = NULL; history_service_ = NULL; service_.reset(); - notification_service_->TearDown(); history_thread_.Stop(); profile_.ResetRequestContext(); AbstractProfileSyncServiceTest::TearDown(); @@ -297,7 +292,6 @@ class ProfileSyncServiceTypedUrlTest : public AbstractProfileSyncServiceTest { } Thread history_thread_; - scoped_refptr<ThreadNotificationService> notification_service_; ProfileMock profile_; scoped_refptr<HistoryBackendMock> history_backend_; diff --git a/chrome/browser/sync/profile_sync_test_util.cc b/chrome/browser/sync/profile_sync_test_util.cc index 2211aa1..951acd3 100644 --- a/chrome/browser/sync/profile_sync_test_util.cc +++ b/chrome/browser/sync/profile_sync_test_util.cc @@ -13,39 +13,6 @@ ProfileSyncServiceObserverMock::ProfileSyncServiceObserverMock() {} ProfileSyncServiceObserverMock::~ProfileSyncServiceObserverMock() {} -ThreadNotificationService::ThreadNotificationService( - base::Thread* notification_thread) - : done_event_(false, false), - notification_thread_(notification_thread) {} - -void ThreadNotificationService::Init() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - notification_thread_->message_loop()->PostTask( - FROM_HERE, - base::Bind(&ThreadNotificationService::InitTask, this)); - done_event_.Wait(); -} - -void ThreadNotificationService::TearDown() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - notification_thread_->message_loop()->PostTask( - FROM_HERE, - base::Bind(&ThreadNotificationService::TearDownTask, this)); - done_event_.Wait(); -} - -ThreadNotificationService::~ThreadNotificationService() {} - -void ThreadNotificationService::InitTask() { - service_.reset(content::NotificationService::Create()); - done_event_.Signal(); -} - -void ThreadNotificationService::TearDownTask() { - service_.reset(NULL); - done_event_.Signal(); -} - ThreadNotifier::ThreadNotifier(base::Thread* notify_thread) : done_event_(false, false), notify_thread_(notify_thread) {} diff --git a/chrome/browser/sync/profile_sync_test_util.h b/chrome/browser/sync/profile_sync_test_util.h index c99134e..de41505 100644 --- a/chrome/browser/sync/profile_sync_test_util.h +++ b/chrome/browser/sync/profile_sync_test_util.h @@ -43,26 +43,6 @@ class ProfileSyncServiceObserverMock : public ProfileSyncServiceObserver { MOCK_METHOD0(OnStateChanged, void()); }; -class ThreadNotificationService - : public base::RefCountedThreadSafe<ThreadNotificationService> { - public: - explicit ThreadNotificationService(base::Thread* notification_thread); - - void Init(); - void TearDown(); - - private: - friend class base::RefCountedThreadSafe<ThreadNotificationService>; - virtual ~ThreadNotificationService(); - - void InitTask(); - void TearDownTask(); - - base::WaitableEvent done_event_; - base::Thread* notification_thread_; - scoped_ptr<content::NotificationService> service_; -}; - class ThreadNotifier : // NOLINT public base::RefCountedThreadSafe<ThreadNotifier> { public: diff --git a/chrome/browser/ui/cocoa/cocoa_profile_test.h b/chrome/browser/ui/cocoa/cocoa_profile_test.h index 968acc6..331cf21 100644 --- a/chrome/browser/ui/cocoa/cocoa_profile_test.h +++ b/chrome/browser/ui/cocoa/cocoa_profile_test.h @@ -65,6 +65,7 @@ class CocoaProfileTest : public CocoaTest { TestingProfile* profile_; // Weak; owned by profile_manager_. scoped_ptr<Browser> browser_; + scoped_ptr<content::TestBrowserThread> file_user_blocking_thread_; scoped_ptr<content::TestBrowserThread> file_thread_; scoped_ptr<content::TestBrowserThread> io_thread_; }; diff --git a/chrome/browser/ui/cocoa/cocoa_profile_test.mm b/chrome/browser/ui/cocoa/cocoa_profile_test.mm index a0f07e0..abdacb3 100644 --- a/chrome/browser/ui/cocoa/cocoa_profile_test.mm +++ b/chrome/browser/ui/cocoa/cocoa_profile_test.mm @@ -14,6 +14,8 @@ CocoaProfileTest::CocoaProfileTest() : ui_thread_(BrowserThread::UI, &message_loop_), profile_manager_(static_cast<TestingBrowserProcess*>(g_browser_process)), profile_(NULL), + file_user_blocking_thread_(new content::TestBrowserThread( + BrowserThread::FILE_USER_BLOCKING, &message_loop_)), file_thread_(new content::TestBrowserThread(BrowserThread::FILE, &message_loop_)), io_thread_(new content::TestBrowserThread(BrowserThread::IO, @@ -38,6 +40,7 @@ CocoaProfileTest::~CocoaProfileTest() { // Drop any new tasks for the IO and FILE threads. io_thread_.reset(); file_thread_.reset(); + file_user_blocking_thread_.reset(); message_loop_.RunAllPending(); } diff --git a/chrome/browser/ui/cocoa/notifications/balloon_controller_unittest.mm b/chrome/browser/ui/cocoa/notifications/balloon_controller_unittest.mm index 8f3edcf..cd9a421 100644 --- a/chrome/browser/ui/cocoa/notifications/balloon_controller_unittest.mm +++ b/chrome/browser/ui/cocoa/notifications/balloon_controller_unittest.mm @@ -52,6 +52,8 @@ class BalloonControllerTest : public ChromeRenderViewHostTestHarness { public: BalloonControllerTest() : ui_thread_(BrowserThread::UI, MessageLoop::current()), + file_user_blocking_thread_( + BrowserThread::FILE_USER_BLOCKING, MessageLoop::current()), io_thread_(BrowserThread::IO, MessageLoop::current()) { } @@ -72,6 +74,7 @@ class BalloonControllerTest : public ChromeRenderViewHostTestHarness { protected: content::TestBrowserThread ui_thread_; + content::TestBrowserThread file_user_blocking_thread_; content::TestBrowserThread io_thread_; scoped_ptr<Browser> browser_; scoped_ptr<BalloonCollection> collection_; diff --git a/chrome/browser/ui/views/select_file_dialog_extension_browsertest.cc b/chrome/browser/ui/views/select_file_dialog_extension_browsertest.cc index 43f3d1b..41f1686 100644 --- a/chrome/browser/ui/views/select_file_dialog_extension_browsertest.cc +++ b/chrome/browser/ui/views/select_file_dialog_extension_browsertest.cc @@ -27,6 +27,8 @@ #include "webkit/fileapi/file_system_context.h" #include "webkit/fileapi/file_system_mount_point_provider.h" +using content::BrowserContext; + // Mock listener used by test below. class MockSelectFileDialogListener : public SelectFileDialog::Listener { public: @@ -101,7 +103,8 @@ class SelectFileDialogExtensionBrowserTest : public ExtensionBrowserTest { // Creates a file system mount point for a directory. void AddMountPoint(const FilePath& path) { fileapi::ExternalFileSystemMountPointProvider* provider = - browser()->profile()->GetFileSystemContext()->external_provider(); + BrowserContext::GetFileSystemContext(browser()->profile())-> + external_provider(); provider->AddMountPoint(path); } diff --git a/chrome/browser/ui/webui/quota_internals_handler.cc b/chrome/browser/ui/webui/quota_internals_handler.cc index b56e47a..877c25f 100644 --- a/chrome/browser/ui/webui/quota_internals_handler.cc +++ b/chrome/browser/ui/webui/quota_internals_handler.cc @@ -15,6 +15,8 @@ #include "content/public/browser/web_ui.h" #include "net/base/net_util.h" +using content::BrowserContext; + namespace quota_internals { QuotaInternalsHandler::QuotaInternalsHandler() {} @@ -84,7 +86,8 @@ void QuotaInternalsHandler::SendMessage(const std::string& message, void QuotaInternalsHandler::OnRequestInfo(const base::ListValue*) { if (!proxy_) proxy_ = new QuotaInternalsProxy(this); - proxy_->RequestInfo(Profile::FromWebUI(web_ui())->GetQuotaManager()); + proxy_->RequestInfo( + content::BrowserContext::GetQuotaManager(Profile::FromWebUI(web_ui()))); } } // namespace quota_internals diff --git a/chrome/common/chrome_constants.cc b/chrome/common/chrome_constants.cc index 1b4a1c5..62f68d7 100644 --- a/chrome/common/chrome_constants.cc +++ b/chrome/common/chrome_constants.cc @@ -129,7 +129,6 @@ const FilePath::CharType kCRLSetFilename[] = const FilePath::CharType kMediaCacheDirname[] = FPL("Media Cache"); const FilePath::CharType kOffTheRecordMediaCacheDirname[] = FPL("Incognito Media Cache"); -const FilePath::CharType kAppCacheDirname[] = FPL("Application Cache"); const FilePath::CharType kThemePackFilename[] = FPL("Cached Theme.pak"); const FilePath::CharType kCookieFilename[] = FPL("Cookies"); const FilePath::CharType kOBCertFilename[] = FPL("Origin Bound Certs"); diff --git a/chrome/common/chrome_constants.h b/chrome/common/chrome_constants.h index cdc7e1a..99f9f16 100644 --- a/chrome/common/chrome_constants.h +++ b/chrome/common/chrome_constants.h @@ -57,7 +57,6 @@ extern const FilePath::CharType kCacheDirname[]; extern const FilePath::CharType kCRLSetFilename[]; extern const FilePath::CharType kMediaCacheDirname[]; extern const FilePath::CharType kOffTheRecordMediaCacheDirname[]; -extern const FilePath::CharType kAppCacheDirname[]; extern const FilePath::CharType kThemePackFilename[]; extern const FilePath::CharType kCookieFilename[]; extern const FilePath::CharType kOBCertFilename[]; diff --git a/chrome/test/base/browser_with_test_window_test.cc b/chrome/test/base/browser_with_test_window_test.cc index 2106b4d..47be6d8 100644 --- a/chrome/test/base/browser_with_test_window_test.cc +++ b/chrome/test/base/browser_with_test_window_test.cc @@ -25,6 +25,8 @@ using content::WebContents; BrowserWithTestWindowTest::BrowserWithTestWindowTest() : ui_thread_(BrowserThread::UI, message_loop()), file_thread_(BrowserThread::FILE, message_loop()), + file_user_blocking_thread_( + BrowserThread::FILE_USER_BLOCKING, message_loop()), rph_factory_(), rvh_factory_(&rph_factory_) { #if defined(OS_WIN) diff --git a/chrome/test/base/browser_with_test_window_test.h b/chrome/test/base/browser_with_test_window_test.h index 029cc76..ab88c6a 100644 --- a/chrome/test/base/browser_with_test_window_test.h +++ b/chrome/test/base/browser_with_test_window_test.h @@ -116,6 +116,7 @@ class BrowserWithTestWindowTest : public testing::Test { MessageLoopForUI ui_loop_; content::TestBrowserThread ui_thread_; content::TestBrowserThread file_thread_; + content::TestBrowserThread file_user_blocking_thread_; scoped_ptr<TestingProfile> profile_; scoped_ptr<TestBrowserWindow> window_; diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc index 0ff506c..30f6b39 100644 --- a/chrome/test/base/testing_profile.cc +++ b/chrome/test/base/testing_profile.cc @@ -127,14 +127,6 @@ ProfileKeyedBase* CreateTestDesktopNotificationService(Profile* profile) { return new DesktopNotificationService(profile, NULL); } -fileapi::FileSystemOptions CreateTestingFileSystemOptions(bool is_incognito) { - return fileapi::FileSystemOptions( - is_incognito - ? fileapi::FileSystemOptions::PROFILE_MODE_INCOGNITO - : fileapi::FileSystemOptions::PROFILE_MODE_NORMAL, - std::vector<std::string>()); -} - } // namespace TestingProfile::TestingProfile() @@ -244,9 +236,6 @@ TestingProfile::~TestingProfile() { if (pref_proxy_config_tracker_.get()) pref_proxy_config_tracker_->DetachFromPrefService(); - - // Close the handles so that proper cleanup can be done. - db_tracker_ = NULL; } void TestingProfile::CreateFaviconService() { @@ -474,24 +463,6 @@ Profile* TestingProfile::GetOriginalProfile() { return this; } -void TestingProfile::SetAppCacheService( - ChromeAppCacheService* appcache_service) { - appcache_service_ = appcache_service; -} - -ChromeAppCacheService* TestingProfile::GetAppCacheService() { - return appcache_service_.get(); -} - -webkit_database::DatabaseTracker* TestingProfile::GetDatabaseTracker() { - if (!db_tracker_) { - db_tracker_ = new webkit_database::DatabaseTracker( - GetPath(), false, false, GetExtensionSpecialStoragePolicy(), - NULL, NULL); - } - return db_tracker_; -} - VisitedLinkMaster* TestingProfile::GetVisitedLinkMaster() { return NULL; } @@ -606,27 +577,6 @@ DownloadManager* TestingProfile::GetDownloadManager() { return NULL; } -fileapi::FileSystemContext* TestingProfile::GetFileSystemContext() { - if (!file_system_context_) { - file_system_context_ = new fileapi::FileSystemContext( - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), - GetExtensionSpecialStoragePolicy(), - NULL, - GetPath(), - CreateTestingFileSystemOptions(IsOffTheRecord())); - } - return file_system_context_.get(); -} - -void TestingProfile::SetQuotaManager(quota::QuotaManager* manager) { - quota_manager_ = manager; -} - -quota::QuotaManager* TestingProfile::GetQuotaManager() { - return quota_manager_.get(); -} - net::URLRequestContextGetter* TestingProfile::GetRequestContext() { return request_context_.get(); } @@ -740,16 +690,6 @@ ProtocolHandlerRegistry* TestingProfile::GetProtocolHandlerRegistry() { return protocol_handler_registry_.get(); } -WebKitContext* TestingProfile::GetWebKitContext() { - if (webkit_context_ == NULL) { - webkit_context_ = new WebKitContext( - IsOffTheRecord(), GetPath(), - GetExtensionSpecialStoragePolicy(), - false, NULL, NULL); - } - return webkit_context_; -} - WebKitContext* TestingProfile::GetOffTheRecordWebKitContext() { return NULL; } @@ -786,10 +726,6 @@ TokenService* TestingProfile::GetTokenService() { return token_service_.get(); } -ChromeBlobStorageContext* TestingProfile::GetBlobStorageContext() { - return NULL; -} - ExtensionInfoMap* TestingProfile::GetExtensionInfoMap() { return NULL; } diff --git a/chrome/test/base/testing_profile.h b/chrome/test/base/testing_profile.h index 7e3a2f6..d39f3a2 100644 --- a/chrome/test/base/testing_profile.h +++ b/chrome/test/base/testing_profile.h @@ -147,11 +147,32 @@ class TestingProfile : public Profile { TestingPrefService* GetTestingPrefService(); + // content::BrowserContext + virtual FilePath GetPath() OVERRIDE; + virtual bool IsOffTheRecord() OVERRIDE; + virtual content::DownloadManager* GetDownloadManager() OVERRIDE; + // Returns a testing ContextGetter (if one has been created via + // CreateRequestContext) or NULL. This is not done on-demand for two reasons: + // (1) Some tests depend on GetRequestContext() returning NULL. (2) Because + // of the special memory management considerations for the + // TestURLRequestContextGetter class, many tests would find themseleves + // leaking if they called this method without the necessary IO thread. This + // getter is currently only capable of returning a Context that helps test + // the CookieMonster. See implementation comments for more details. + virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; + virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess( + int renderer_child_id) OVERRIDE; + virtual content::ResourceContext* GetResourceContext() OVERRIDE; + virtual content::HostZoomMap* GetHostZoomMap() OVERRIDE; + virtual content::GeolocationPermissionContext* + GetGeolocationPermissionContext() OVERRIDE; + virtual content::SpeechInputPreferences* GetSpeechInputPreferences() OVERRIDE; + virtual bool DidLastSessionExitCleanly() OVERRIDE; + virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE; + virtual TestingProfile* AsTestingProfile() OVERRIDE; virtual std::string GetProfileName() OVERRIDE; - virtual FilePath GetPath() OVERRIDE; void set_incognito(bool incognito) { incognito_ = incognito; } - virtual bool IsOffTheRecord() OVERRIDE; // Assumes ownership. virtual void SetOffTheRecordProfile(Profile* profile); virtual Profile* GetOffTheRecordProfile() OVERRIDE; @@ -159,9 +180,6 @@ class TestingProfile : public Profile { virtual GAIAInfoUpdateService* GetGAIAInfoUpdateService() OVERRIDE; virtual bool HasOffTheRecordProfile() OVERRIDE; virtual Profile* GetOriginalProfile() OVERRIDE; - void SetAppCacheService(ChromeAppCacheService* appcache_service); - virtual ChromeAppCacheService* GetAppCacheService() OVERRIDE; - virtual webkit_database::DatabaseTracker* GetDatabaseTracker() OVERRIDE; virtual VisitedLinkMaster* GetVisitedLinkMaster() OVERRIDE; virtual ExtensionService* GetExtensionService() OVERRIDE; virtual UserScriptMaster* GetUserScriptMaster() OVERRIDE; @@ -194,22 +212,7 @@ class TestingProfile : public Profile { virtual TemplateURLFetcher* GetTemplateURLFetcher() OVERRIDE; virtual history::TopSites* GetTopSites() OVERRIDE; virtual history::TopSites* GetTopSitesWithoutCreating() OVERRIDE; - virtual content::DownloadManager* GetDownloadManager() OVERRIDE; - virtual fileapi::FileSystemContext* GetFileSystemContext() OVERRIDE; - virtual void SetQuotaManager(quota::QuotaManager* manager); - virtual quota::QuotaManager* GetQuotaManager() OVERRIDE; - // Returns a testing ContextGetter (if one has been created via - // CreateRequestContext) or NULL. This is not done on-demand for two reasons: - // (1) Some tests depend on GetRequestContext() returning NULL. (2) Because - // of the special memory management considerations for the - // TestURLRequestContextGetter class, many tests would find themseleves - // leaking if they called this method without the necessary IO thread. This - // getter is currently only capable of returning a Context that helps test - // the CookieMonster. See implementation comments for more details. - virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; - virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess( - int renderer_child_id) OVERRIDE; void CreateRequestContext(); // Clears out the created request context (which must be done before shutting // down the IO thread to avoid leaks). @@ -220,16 +223,9 @@ class TestingProfile : public Profile { GetRequestContextForExtensions() OVERRIDE; virtual net::URLRequestContextGetter* GetRequestContextForIsolatedApp( const std::string& app_id) OVERRIDE; - - virtual content::ResourceContext* GetResourceContext() OVERRIDE; - virtual net::SSLConfigService* GetSSLConfigService() OVERRIDE; virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() OVERRIDE; virtual HostContentSettingsMap* GetHostContentSettingsMap() OVERRIDE; - virtual content::GeolocationPermissionContext* - GetGeolocationPermissionContext() OVERRIDE; - virtual content::SpeechInputPreferences* GetSpeechInputPreferences() OVERRIDE; - virtual content::HostZoomMap* GetHostZoomMap() OVERRIDE; virtual std::wstring GetName(); virtual void SetName(const std::wstring& name) {} virtual std::wstring GetID(); @@ -237,7 +233,6 @@ class TestingProfile : public Profile { void set_last_session_exited_cleanly(bool value) { last_session_exited_cleanly_ = value; } - virtual bool DidLastSessionExitCleanly() OVERRIDE; virtual void MergeResourceString(int message_id, std::wstring* output_string) {} virtual void MergeResourceInteger(int message_id, int* output_value) {} @@ -246,7 +241,6 @@ class TestingProfile : public Profile { virtual bool IsSameProfile(Profile *p) OVERRIDE; virtual base::Time GetStartTime() const OVERRIDE; virtual ProtocolHandlerRegistry* GetProtocolHandlerRegistry() OVERRIDE; - virtual WebKitContext* GetWebKitContext() OVERRIDE; virtual WebKitContext* GetOffTheRecordWebKitContext(); virtual void MarkAsCleanShutdown() OVERRIDE {} virtual void InitExtensions(bool extensions_enabled) OVERRIDE {} @@ -275,7 +269,6 @@ class TestingProfile : public Profile { void BlockUntilHistoryProcessesPendingRequests(); virtual TokenService* GetTokenService() OVERRIDE; - virtual ChromeBlobStorageContext* GetBlobStorageContext() OVERRIDE; virtual ExtensionInfoMap* GetExtensionInfoMap() OVERRIDE; virtual PromoCounter* GetInstantPromoCounter() OVERRIDE; virtual ChromeURLDataManager* GetChromeURLDataManager() OVERRIDE; @@ -285,11 +278,6 @@ class TestingProfile : public Profile { virtual PrefService* GetOffTheRecordPrefs() OVERRIDE; - // TODO(jam): remove me once webkit_context_unittest.cc doesn't use Profile - // and gets the quota::SpecialStoragePolicy* from whatever ends up replacing - // it in the content module. - quota::SpecialStoragePolicy* GetSpecialStoragePolicy(); - protected: base::Time start_time_; scoped_ptr<PrefService> prefs_; @@ -356,16 +344,6 @@ class TestingProfile : public Profile { // Did the last session exit cleanly? Default is true. bool last_session_exited_cleanly_; - // FileSystemContext. Created lazily by GetFileSystemContext(). - scoped_refptr<fileapi::FileSystemContext> file_system_context_; - - // WebKitContext, lazily initialized by GetWebKitContext(). - scoped_refptr<WebKitContext> webkit_context_; - - // The main database tracker for this profile. - // Should be used only on the file thread. - scoped_refptr<webkit_database::DatabaseTracker> db_tracker_; - scoped_refptr<HostContentSettingsMap> host_content_settings_map_; scoped_refptr<content::GeolocationPermissionContext> geolocation_permission_context_; @@ -406,11 +384,6 @@ class TestingProfile : public Profile { // testing. ProfileDependencyManager* profile_dependency_manager_; - scoped_refptr<ChromeAppCacheService> appcache_service_; - - // The QuotaManager, only available if set explicitly via SetQuotaManager. - scoped_refptr<quota::QuotaManager> quota_manager_; - // Weak pointer to a delegate for indicating that a profile was created. Delegate* delegate_; }; diff --git a/content/browser/appcache/chrome_appcache_service.cc b/content/browser/appcache/chrome_appcache_service.cc index 2dbf2c8..9be6b05 100644 --- a/content/browser/appcache/chrome_appcache_service.cc +++ b/content/browser/appcache/chrome_appcache_service.cc @@ -45,6 +45,15 @@ void ChromeAppCacheService::InitializeOnIOThread( ChromeAppCacheService::~ChromeAppCacheService() { } +void ChromeAppCacheService::DeleteOnCorrectThread() const { + if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) && + !BrowserThread::CurrentlyOn(BrowserThread::IO)) { + BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this); + return; + } + delete this; +} + bool ChromeAppCacheService::CanLoadAppCache(const GURL& manifest_url, const GURL& first_party) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); diff --git a/content/browser/appcache/chrome_appcache_service.h b/content/browser/appcache/chrome_appcache_service.h index 8ba1430..c1bf134 100644 --- a/content/browser/appcache/chrome_appcache_service.h +++ b/content/browser/appcache/chrome_appcache_service.h @@ -23,6 +23,8 @@ namespace content { class ResourceContext; } +struct ChromeAppCacheServiceDeleter; + // An AppCacheService subclass used by the chrome. There is an instance // associated with each BrowserContext. This derivation adds refcounting // semantics since a browser context has multiple URLRequestContexts which refer @@ -36,12 +38,13 @@ class ResourceContext; // to worry about clients calling AppCacheService methods. class CONTENT_EXPORT ChromeAppCacheService : public base::RefCountedThreadSafe< - ChromeAppCacheService, content::BrowserThread::DeleteOnIOThread>, + ChromeAppCacheService, ChromeAppCacheServiceDeleter>, NON_EXPORTED_BASE(public appcache::AppCacheService), NON_EXPORTED_BASE(public appcache::AppCachePolicy), public content::NotificationObserver { public: explicit ChromeAppCacheService(quota::QuotaManagerProxy* proxy); + virtual ~ChromeAppCacheService(); void InitializeOnIOThread( const FilePath& cache_path, // may be empty to use in-memory structures @@ -49,13 +52,9 @@ class CONTENT_EXPORT ChromeAppCacheService scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy); private: - friend class base::RefCountedThreadSafe< - ChromeAppCacheService, - content::BrowserThread::DeleteOnIOThread>; - friend class content::BrowserThread; - friend class base::DeleteHelper<ChromeAppCacheService>; + friend struct ChromeAppCacheServiceDeleter; - virtual ~ChromeAppCacheService(); + void DeleteOnCorrectThread() const; // AppCachePolicy overrides virtual bool CanLoadAppCache(const GURL& manifest_url, @@ -75,4 +74,10 @@ class CONTENT_EXPORT ChromeAppCacheService DISALLOW_COPY_AND_ASSIGN(ChromeAppCacheService); }; +struct ChromeAppCacheServiceDeleter { + static void Destruct(const ChromeAppCacheService* service) { + service->DeleteOnCorrectThread(); + } +}; + #endif // CONTENT_BROWSER_APPCACHE_CHROME_APPCACHE_SERVICE_H_ diff --git a/content/browser/browser_context.cc b/content/browser/browser_context.cc new file mode 100644 index 0000000..1461b14 --- /dev/null +++ b/content/browser/browser_context.cc @@ -0,0 +1,168 @@ +// Copyright (c) 2012 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 "content/public/browser/browser_context.h" + +#include "content/browser/appcache/chrome_appcache_service.h" +#include "content/browser/chrome_blob_storage_context.h" +#include "content/browser/file_system/browser_file_system_helper.h" +#include "content/browser/in_process_webkit/webkit_context.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/common/content_constants.h" +#include "webkit/database/database_tracker.h" +#include "webkit/quota/quota_manager.h" + +using content::BrowserThread; +using fileapi::FileSystemContext; +using quota::QuotaManager; +using webkit_database::DatabaseTracker; + +static const char* kAppCacheServicKeyName = "content_appcache_service_tracker"; +static const char* kBlobStorageContextKeyName = "content_blob_storage_context"; +static const char* kDatabaseTrackerKeyName = "content_database_tracker"; +static const char* kFileSystemContextKeyName = "content_file_system_context"; +static const char* kQuotaManagerKeyName = "content_quota_manager"; +static const char* kWebKitContextKeyName = "content_webkit_context"; + +namespace content { + +// Adapter class that releases a refcounted object when the +// SupportsUserData::Data object is deleted. +template <typename T> +class UserDataAdapter : public base::SupportsUserData::Data { + public: + static T* Get(BrowserContext* context, const char* key) { + UserDataAdapter* data = + static_cast<UserDataAdapter*>(context->GetUserData(key)); + return static_cast<T*>(data->object_.get()); + } + + UserDataAdapter(T* object) : object_(object) {} + + private: + scoped_refptr<T> object_; + + DISALLOW_COPY_AND_ASSIGN(UserDataAdapter); +}; + +void CreateQuotaManagerAndClients(BrowserContext* context) { + if (context->GetUserData(kQuotaManagerKeyName)) { + DCHECK(context->GetUserData(kDatabaseTrackerKeyName)); + DCHECK(context->GetUserData(kFileSystemContextKeyName)); + DCHECK(context->GetUserData(kWebKitContextKeyName)); + return; + } + + // All of the clients have to be created and registered with the + // QuotaManager prior to the QuotaManger being used. So we do them + // all together here prior to handing out a reference to anything + // that utlizes the QuotaManager. + scoped_refptr<QuotaManager> quota_manager = new quota::QuotaManager( + context->IsOffTheRecord(), context->GetPath(), + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), + context->GetSpecialStoragePolicy()); + context->SetUserData(kQuotaManagerKeyName, + new UserDataAdapter<QuotaManager>(quota_manager)); + + // Each consumer is responsible for registering its QuotaClient during + // its construction. + scoped_refptr<FileSystemContext> filesystem_context = CreateFileSystemContext( + context->GetPath(), context->IsOffTheRecord(), + context->GetSpecialStoragePolicy(), quota_manager->proxy()); + context->SetUserData( + kFileSystemContextKeyName, + new UserDataAdapter<FileSystemContext>(filesystem_context)); + + scoped_refptr<DatabaseTracker> db_tracker = new DatabaseTracker( + context->GetPath(), context->IsOffTheRecord(), false, + context->GetSpecialStoragePolicy(), quota_manager->proxy(), + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); + context->SetUserData(kDatabaseTrackerKeyName, + new UserDataAdapter<DatabaseTracker>(db_tracker)); + + scoped_refptr<WebKitContext> webkit_context = new WebKitContext( + context->IsOffTheRecord(), context->GetPath(), + context->GetSpecialStoragePolicy(), false, quota_manager->proxy(), + BrowserThread::GetMessageLoopProxyForThread( + BrowserThread::WEBKIT_DEPRECATED)); + context->SetUserData(kWebKitContextKeyName, + new UserDataAdapter<WebKitContext>(webkit_context)); + + scoped_refptr<ChromeAppCacheService> appcache_service = + new ChromeAppCacheService(quota_manager->proxy()); + context->SetUserData( + kAppCacheServicKeyName, + new UserDataAdapter<ChromeAppCacheService>(appcache_service)); + + // Check first to avoid memory leak in unittests. + if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + base::Bind(&ChromeAppCacheService::InitializeOnIOThread, + appcache_service, + context->IsOffTheRecord() ? FilePath() : + context->GetPath().Append(content::kAppCacheDirname), + context->GetResourceContext(), + make_scoped_refptr(context->GetSpecialStoragePolicy()))); + } +} + +QuotaManager* BrowserContext::GetQuotaManager(BrowserContext* context) { + CreateQuotaManagerAndClients(context); + return UserDataAdapter<QuotaManager>::Get(context, kQuotaManagerKeyName); +} + +WebKitContext* BrowserContext::GetWebKitContext(BrowserContext* context) { + CreateQuotaManagerAndClients(context); + return UserDataAdapter<WebKitContext>::Get(context, kWebKitContextKeyName); +} + +DatabaseTracker* BrowserContext::GetDatabaseTracker(BrowserContext* context) { + CreateQuotaManagerAndClients(context); + return UserDataAdapter<DatabaseTracker>::Get( + context, kDatabaseTrackerKeyName); +} + +ChromeAppCacheService* BrowserContext::GetAppCacheService( + BrowserContext* browser_context) { + CreateQuotaManagerAndClients(browser_context); + return UserDataAdapter<ChromeAppCacheService>::Get( + browser_context, kAppCacheServicKeyName); +} + +FileSystemContext* BrowserContext::GetFileSystemContext( + BrowserContext* browser_context) { + CreateQuotaManagerAndClients(browser_context); + return UserDataAdapter<FileSystemContext>::Get( + browser_context, kFileSystemContextKeyName); +} + +ChromeBlobStorageContext* BrowserContext::GetBlobStorageContext( + BrowserContext* context) { + if (!context->GetUserData(kBlobStorageContextKeyName)) { + scoped_refptr<ChromeBlobStorageContext> blob = + new ChromeBlobStorageContext(); + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + base::Bind(&ChromeBlobStorageContext::InitializeOnIOThread, blob)); + context->SetUserData(kBlobStorageContextKeyName, + new UserDataAdapter<ChromeBlobStorageContext>(blob)); + } + + return UserDataAdapter<ChromeBlobStorageContext>::Get( + context, kBlobStorageContextKeyName); +} + +BrowserContext::~BrowserContext() { + if (GetUserData(kDatabaseTrackerKeyName) && + BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) { + BrowserThread::PostTask( + BrowserThread::FILE, FROM_HERE, + base::Bind(&webkit_database::DatabaseTracker::Shutdown, + GetDatabaseTracker(this))); + } +} + +} // namespace content diff --git a/content/browser/browser_context.h b/content/browser/browser_context.h deleted file mode 100644 index 8bdb181..0000000 --- a/content/browser/browser_context.h +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) 2011 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. - -#ifndef CONTENT_BROWSER_BROWSER_CONTEXT_H_ -#define CONTENT_BROWSER_BROWSER_CONTEXT_H_ -#pragma once - -// Deprecated header. -// TODO(joi): Remove in a follow-up change. -#include "content/public/browser/browser_context.h" - -#endif // CONTENT_BROWSER_BROWSER_CONTEXT_H_ diff --git a/content/browser/file_system/file_system_browsertest.cc b/content/browser/file_system/file_system_browsertest.cc index 582cd08..edd7cc9 100644 --- a/content/browser/file_system/file_system_browsertest.cc +++ b/content/browser/file_system/file_system_browsertest.cc @@ -58,7 +58,8 @@ class FileSystemBrowserTestWithLowQuota : public FileSystemBrowserTest { const int kTemporaryStorageQuotaMaxSize = kInitialQuotaKilobytes * 1024 * QuotaManager::kPerHostTemporaryPortion; SetTempQuota( - kTemporaryStorageQuotaMaxSize, browser()->profile()->GetQuotaManager()); + kTemporaryStorageQuotaMaxSize, + content::BrowserContext::GetQuotaManager(browser()->profile())); } static void SetTempQuota(int64 bytes, scoped_refptr<QuotaManager> qm) { diff --git a/content/browser/in_process_webkit/dom_storage_browsertest.cc b/content/browser/in_process_webkit/dom_storage_browsertest.cc index 2456399..cdd4d55 100644 --- a/content/browser/in_process_webkit/dom_storage_browsertest.cc +++ b/content/browser/in_process_webkit/dom_storage_browsertest.cc @@ -11,6 +11,7 @@ #include "content/browser/in_process_webkit/dom_storage_context.h" #include "content/browser/in_process_webkit/webkit_context.h" +using content::BrowserContext; using content::BrowserThread; typedef InProcessBrowserTest DOMStorageBrowserTest; @@ -39,7 +40,7 @@ IN_PROC_BROWSER_TEST_F(DOMStorageBrowserTest, ClearLocalState) { // context which should trigger the clean up. { TestingProfile profile; - WebKitContext *webkit_context = profile.GetWebKitContext(); + WebKitContext* webkit_context = BrowserContext::GetWebKitContext(&profile); webkit_context->dom_storage_context()-> set_data_path_for_testing(temp_dir.path()); webkit_context->set_clear_local_state_on_exit(true); diff --git a/content/browser/in_process_webkit/dom_storage_context.cc b/content/browser/in_process_webkit/dom_storage_context.cc index c276d76..7828d74 100644 --- a/content/browser/in_process_webkit/dom_storage_context.cc +++ b/content/browser/in_process_webkit/dom_storage_context.cc @@ -141,7 +141,8 @@ DOMStorageArea* DOMStorageContext::GetStorageArea(int64 id) { } void DOMStorageContext::DeleteSessionStorageNamespace(int64 namespace_id) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED) || + !BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT_DEPRECATED)); StorageNamespaceMap::iterator iter = storage_namespace_map_.find(namespace_id); if (iter == storage_namespace_map_.end()) diff --git a/content/browser/in_process_webkit/dom_storage_unittest.cc b/content/browser/in_process_webkit/dom_storage_unittest.cc index 355871e..049fbb3 100644 --- a/content/browser/in_process_webkit/dom_storage_unittest.cc +++ b/content/browser/in_process_webkit/dom_storage_unittest.cc @@ -10,6 +10,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "webkit/quota/mock_special_storage_policy.h" +using content::BrowserContext; using content::BrowserThread; using content::BrowserThreadImpl; @@ -33,10 +34,10 @@ TEST_F(DOMStorageTest, SessionOnly) { new quota::MockSpecialStoragePolicy; special_storage_policy->AddSessionOnly(session_only_origin); - TestBrowserContext browser_context; + scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext); // Create databases for permanent and session-only origins. - FilePath domstorage_dir = browser_context.GetPath().Append( + FilePath domstorage_dir = browser_context->GetPath().Append( DOMStorageContext::kLocalStorageDirectory); FilePath::StringType session_only_database( FILE_PATH_LITERAL("http_www.sessiononly.com_0")); @@ -55,12 +56,14 @@ TEST_F(DOMStorageTest, SessionOnly) { ASSERT_EQ(1, file_util::WriteFile(permanent_database_path, ".", 1)); // Inject MockSpecialStoragePolicy into DOMStorageContext. - browser_context.GetWebKitContext()->dom_storage_context()-> - special_storage_policy_ = special_storage_policy; + BrowserContext::GetWebKitContext(browser_context.get())-> + dom_storage_context()->special_storage_policy_ = special_storage_policy; - // Delete the WebKitContext before destroying TestBrowserContext. This way the + // Delete the TestBrowserContext but own the temp dir. This way the // temporary data directory stays alive long enough to conduct the test. - browser_context.webkit_context_ = NULL; + ScopedTempDir temp_dir; + ignore_result(temp_dir.Set(browser_context->TakePath())); + browser_context.reset(); // Run the message loop to ensure that DOMStorageContext gets destroyed. message_loop_.RunAllPending(); @@ -76,10 +79,10 @@ TEST_F(DOMStorageTest, SaveSessionState) { new quota::MockSpecialStoragePolicy; special_storage_policy->AddSessionOnly(session_only_origin); - TestBrowserContext browser_context; + scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext); // Create databases for permanent and session-only origins. - FilePath domstorage_dir = browser_context.GetPath().Append( + FilePath domstorage_dir = browser_context->GetPath().Append( DOMStorageContext::kLocalStorageDirectory); FilePath::StringType session_only_database( FILE_PATH_LITERAL("http_www.sessiononly.com_0")); @@ -99,7 +102,8 @@ TEST_F(DOMStorageTest, SaveSessionState) { // Inject MockSpecialStoragePolicy into DOMStorageContext. DOMStorageContext* dom_storage_context = - browser_context.GetWebKitContext()->dom_storage_context(); + BrowserContext::GetWebKitContext(browser_context.get())-> + dom_storage_context(); dom_storage_context->special_storage_policy_ = special_storage_policy; dom_storage_context->set_clear_local_state_on_exit_(true); @@ -107,9 +111,11 @@ TEST_F(DOMStorageTest, SaveSessionState) { // Save session state. This should bypass the destruction-time deletion. dom_storage_context->SaveSessionState(); - // Delete the WebKitContext before destroying TestBrowserContext. This way the + // Delete the TestBrowserContext but own the temp dir. This way the // temporary data directory stays alive long enough to conduct the test. - browser_context.webkit_context_ = NULL; + ScopedTempDir temp_dir; + ignore_result(temp_dir.Set(browser_context->TakePath())); + browser_context.reset(); // Run the message loop to ensure that DOMStorageContext gets destroyed. message_loop_.RunAllPending(); diff --git a/content/browser/in_process_webkit/indexed_db_browsertest.cc b/content/browser/in_process_webkit/indexed_db_browsertest.cc index 003d4b5..d1fcb5a 100644 --- a/content/browser/in_process_webkit/indexed_db_browsertest.cc +++ b/content/browser/in_process_webkit/indexed_db_browsertest.cc @@ -23,6 +23,7 @@ #include "webkit/quota/quota_manager.h" #include "webkit/quota/special_storage_policy.h" +using content::BrowserContext; using content::BrowserThread; using quota::QuotaManager; using webkit_database::DatabaseUtil; @@ -153,7 +154,7 @@ IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, ClearLocalState) { // Create some indexedDB paths. // With the levelDB backend, these are directories. - WebKitContext *webkit_context = profile.GetWebKitContext(); + WebKitContext* webkit_context = BrowserContext::GetWebKitContext(&profile); IndexedDBContext* idb_context = webkit_context->indexed_db_context(); idb_context->set_data_path_for_testing(temp_dir.path()); protected_path = idb_context->GetIndexedDBFilePath( @@ -168,11 +169,15 @@ IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, ClearLocalState) { } // Make sure we wait until the destructor has run. - scoped_refptr<base::ThreadTestHelper> helper( + scoped_refptr<base::ThreadTestHelper> helper_io( + new base::ThreadTestHelper( + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); + ASSERT_TRUE(helper_io->Run()); + scoped_refptr<base::ThreadTestHelper> helper_webkit( new base::ThreadTestHelper( BrowserThread::GetMessageLoopProxyForThread( BrowserThread::WEBKIT_DEPRECATED))); - ASSERT_TRUE(helper->Run()); + ASSERT_TRUE(helper_webkit->Run()); ASSERT_TRUE(file_util::DirectoryExists(protected_path)); ASSERT_FALSE(file_util::DirectoryExists(unprotected_path)); @@ -200,7 +205,7 @@ IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, ClearSessionOnlyDatabases) { // Create some indexedDB paths. // With the levelDB backend, these are directories. - WebKitContext *webkit_context = profile.GetWebKitContext(); + WebKitContext* webkit_context = BrowserContext::GetWebKitContext(&profile); IndexedDBContext* idb_context = webkit_context->indexed_db_context(); // Override the storage policy with our own. @@ -215,12 +220,15 @@ IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, ClearSessionOnlyDatabases) { ASSERT_TRUE(file_util::CreateDirectory(session_only_path)); } - // Make sure we wait until the destructor has run. - scoped_refptr<base::ThreadTestHelper> helper( + scoped_refptr<base::ThreadTestHelper> helper_io( + new base::ThreadTestHelper( + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); + ASSERT_TRUE(helper_io->Run()); + scoped_refptr<base::ThreadTestHelper> helper_webkit( new base::ThreadTestHelper( BrowserThread::GetMessageLoopProxyForThread( BrowserThread::WEBKIT_DEPRECATED))); - ASSERT_TRUE(helper->Run()); + ASSERT_TRUE(helper_webkit->Run()); EXPECT_TRUE(file_util::DirectoryExists(normal_path)); EXPECT_FALSE(file_util::DirectoryExists(session_only_path)); @@ -246,7 +254,7 @@ IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, SaveSessionState) { // Create some indexedDB paths. // With the levelDB backend, these are directories. - WebKitContext *webkit_context = profile.GetWebKitContext(); + WebKitContext* webkit_context = BrowserContext::GetWebKitContext(&profile); IndexedDBContext* idb_context = webkit_context->indexed_db_context(); // Override the storage policy with our own. @@ -284,7 +292,8 @@ class IndexedDBBrowserTestWithLowQuota : public IndexedDBBrowserTest { const int kTemporaryStorageQuotaMaxSize = kInitialQuotaKilobytes * 1024 * QuotaManager::kPerHostTemporaryPortion; SetTempQuota( - kTemporaryStorageQuotaMaxSize, browser()->profile()->GetQuotaManager()); + kTemporaryStorageQuotaMaxSize, + content::BrowserContext::GetQuotaManager(browser()->profile())); } static void SetTempQuota(int64 bytes, scoped_refptr<QuotaManager> qm) { diff --git a/content/browser/in_process_webkit/indexed_db_quota_client_unittest.cc b/content/browser/in_process_webkit/indexed_db_quota_client_unittest.cc index 04e7041..0689eeb 100644 --- a/content/browser/in_process_webkit/indexed_db_quota_client_unittest.cc +++ b/content/browser/in_process_webkit/indexed_db_quota_client_unittest.cc @@ -18,6 +18,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "webkit/database/database_util.h" +using content::BrowserContext; using content::BrowserThread; // Declared to shorten the line lengths. @@ -42,9 +43,11 @@ class IndexedDBQuotaClientTest : public testing::Test { weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), message_loop_(MessageLoop::TYPE_IO), webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &message_loop_), + file_thread_(BrowserThread::FILE_USER_BLOCKING, &message_loop_), io_thread_(BrowserThread::IO, &message_loop_) { TestBrowserContext browser_context; - idb_context_ = browser_context.GetWebKitContext()->indexed_db_context(); + idb_context_ = BrowserContext::GetWebKitContext(&browser_context)-> + indexed_db_context(); setup_temp_dir(); } void setup_temp_dir() { @@ -158,6 +161,7 @@ class IndexedDBQuotaClientTest : public testing::Test { base::WeakPtrFactory<IndexedDBQuotaClientTest> weak_factory_; MessageLoop message_loop_; BrowserThreadImpl webkit_thread_; + BrowserThreadImpl file_thread_; BrowserThreadImpl io_thread_; quota::QuotaStatusCode delete_status_; }; diff --git a/content/browser/in_process_webkit/webkit_context.cc b/content/browser/in_process_webkit/webkit_context.cc index f1cb1da..b2700da 100644 --- a/content/browser/in_process_webkit/webkit_context.cc +++ b/content/browser/in_process_webkit/webkit_context.cc @@ -70,11 +70,11 @@ void WebKitContext::DeleteDataModifiedSince(const base::Time& cutoff) { void WebKitContext::DeleteSessionStorageNamespace( int64 session_storage_namespace_id) { - if (!BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)) { - BrowserThread::PostTask( - BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, - base::Bind(&WebKitContext::DeleteSessionStorageNamespace, this, - session_storage_namespace_id)); + if (!BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED) && + BrowserThread::PostTask( + BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, + base::Bind(&WebKitContext::DeleteSessionStorageNamespace, this, + session_storage_namespace_id))) { return; } diff --git a/content/browser/renderer_host/render_message_filter.cc b/content/browser/renderer_host/render_message_filter.cc index dde71d0..a05771e 100644 --- a/content/browser/renderer_host/render_message_filter.cc +++ b/content/browser/renderer_host/render_message_filter.cc @@ -67,6 +67,7 @@ #include "base/file_descriptor_posix.h" #endif +using content::BrowserContext; using content::BrowserMessageFilter; using content::BrowserThread; using content::ChildProcessHostImpl; @@ -273,7 +274,7 @@ RenderMessageFilter::RenderMessageFilter( resource_context_(browser_context->GetResourceContext()), render_widget_helper_(render_widget_helper), incognito_(browser_context->IsOffTheRecord()), - webkit_context_(browser_context->GetWebKitContext()), + webkit_context_(BrowserContext::GetWebKitContext(browser_context)), render_process_id_(render_process_id), cpu_usage_(0) { DCHECK(request_context_); diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index d6084ffe..0174d49 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -114,6 +114,7 @@ #include "third_party/skia/include/core/SkBitmap.h" +using content::BrowserContext; using content::BrowserMessageFilter; using content::BrowserThread; using content::ChildProcessHost; @@ -460,12 +461,12 @@ void RenderProcessHostImpl::CreateMessageFilters() { channel_->AddFilter(new AudioRendererHost(resource_context)); channel_->AddFilter(new VideoCaptureHost(resource_context)); channel_->AddFilter(new AppCacheDispatcherHost( - browser_context->GetAppCacheService(), GetID())); + BrowserContext::GetAppCacheService(browser_context), GetID())); channel_->AddFilter(new ClipboardMessageFilter()); channel_->AddFilter(new DOMStorageMessageFilter(GetID(), - browser_context->GetWebKitContext())); + BrowserContext::GetWebKitContext(browser_context))); channel_->AddFilter(new IndexedDBDispatcherHost(GetID(), - browser_context->GetWebKitContext())); + BrowserContext::GetWebKitContext(browser_context))); channel_->AddFilter(GeolocationDispatcherHost::New( GetID(), browser_context->GetGeolocationPermissionContext())); channel_->AddFilter(new GpuMessageFilter(GetID(), widget_helper_.get())); @@ -479,14 +480,14 @@ void RenderProcessHostImpl::CreateMessageFilters() { browser_context->GetSpeechInputPreferences(), resource_context)); channel_->AddFilter(new FileSystemDispatcherHost( browser_context->GetRequestContext(), - browser_context->GetFileSystemContext())); + BrowserContext::GetFileSystemContext(browser_context))); channel_->AddFilter(new device_orientation::MessageFilter()); channel_->AddFilter(new BlobMessageFilter(GetID(), - browser_context->GetBlobStorageContext())); + BrowserContext::GetBlobStorageContext(browser_context))); channel_->AddFilter(new FileUtilitiesMessageFilter(GetID())); channel_->AddFilter(new MimeRegistryMessageFilter()); channel_->AddFilter(new DatabaseMessageFilter( - browser_context->GetDatabaseTracker())); + BrowserContext::GetDatabaseTracker(browser_context))); #if defined(OS_MACOSX) channel_->AddFilter(new TextInputClientMessageFilter(GetID())); #elif defined(OS_WIN) @@ -510,8 +511,9 @@ void RenderProcessHostImpl::CreateMessageFilters() { channel_->AddFilter(new TraceMessageFilter()); channel_->AddFilter(new ResolveProxyMsgHelper( browser_context->GetRequestContextForRenderProcess(GetID()))); - channel_->AddFilter(new QuotaDispatcherHost(GetID(), - browser_context->GetQuotaManager(), + channel_->AddFilter(new QuotaDispatcherHost( + GetID(), + content::BrowserContext::GetQuotaManager(browser_context), content::GetContentClient()->browser()->CreateQuotaPermissionContext())); channel_->AddFilter(new content::GamepadBrowserMessageFilter(this)); channel_->AddFilter(new ProfilerMessageFilter()); diff --git a/content/browser/renderer_host/render_view_host.cc b/content/browser/renderer_host/render_view_host.cc index 2b1a29a..fcd112c 100644 --- a/content/browser/renderer_host/render_view_host.cc +++ b/content/browser/renderer_host/render_view_host.cc @@ -59,6 +59,7 @@ #include "webkit/glue/webdropdata.h" using base::TimeDelta; +using content::BrowserContext; using content::BrowserMessageFilter; using content::BrowserThread; using content::DomOperationNotificationDetails; @@ -136,7 +137,7 @@ RenderViewHost::RenderViewHost(SiteInstance* instance, render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING) { if (!session_storage_namespace_) { session_storage_namespace_ = new SessionStorageNamespace( - process()->GetBrowserContext()->GetWebKitContext()); + BrowserContext::GetWebKitContext(process()->GetBrowserContext())); } DCHECK(instance_); diff --git a/content/browser/tab_contents/navigation_controller_impl.cc b/content/browser/tab_contents/navigation_controller_impl.cc index e72fc89..0e893bd 100644 --- a/content/browser/tab_contents/navigation_controller_impl.cc +++ b/content/browser/tab_contents/navigation_controller_impl.cc @@ -183,7 +183,7 @@ NavigationControllerImpl::NavigationControllerImpl( DCHECK(browser_context_); if (!session_storage_namespace_) { session_storage_namespace_ = new SessionStorageNamespace( - browser_context_->GetWebKitContext()); + BrowserContext::GetWebKitContext(browser_context_)); } } diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 9f1e3f2..ebcf8ed 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -150,6 +150,7 @@ 'browser/appcache/chrome_appcache_service.h', 'browser/browser_child_process_host_impl.cc', 'browser/browser_child_process_host_impl.h', + 'browser/browser_context.cc', 'browser/browser_main.cc', 'browser/browser_main.h', 'browser/browser_main_loop.cc', diff --git a/content/public/browser/browser_context.cc b/content/public/browser/browser_context.cc deleted file mode 100644 index b8f540f..0000000 --- a/content/public/browser/browser_context.cc +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) 2012 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 "content/public/browser/browser_context.h" - -namespace content { - - -} // namespace content diff --git a/content/public/browser/browser_context.h b/content/public/browser/browser_context.h index 9618315..dd00b4a 100644 --- a/content/public/browser/browser_context.h +++ b/content/public/browser/browser_context.h @@ -20,6 +20,7 @@ class URLRequestContextGetter; namespace quota { class QuotaManager; +class SpecialStoragePolicy; } namespace webkit_database { @@ -43,7 +44,19 @@ class SpeechInputPreferences; // It lives on the UI thread. class CONTENT_EXPORT BrowserContext : public base::SupportsUserData { public: - virtual ~BrowserContext() {} + // Getter for the QuotaManager associated with the given BrowserContext. + static quota::QuotaManager* GetQuotaManager(BrowserContext* browser_context); + static WebKitContext* GetWebKitContext(BrowserContext* browser_context); + static webkit_database::DatabaseTracker* GetDatabaseTracker( + BrowserContext* browser_context); + static ChromeAppCacheService* GetAppCacheService( + BrowserContext* browser_context); + static fileapi::FileSystemContext* GetFileSystemContext( + BrowserContext* browser_context); + static ChromeBlobStorageContext* GetBlobStorageContext( + BrowserContext* browser_context); + + virtual ~BrowserContext(); // Returns the path of the directory where this context's data is stored. virtual FilePath GetPath() = 0; @@ -90,14 +103,8 @@ class CONTENT_EXPORT BrowserContext : public base::SupportsUserData { // This doesn't belong here; http://crbug.com/90737 virtual bool DidLastSessionExitCleanly() = 0; - // The following getters return references to various storage related - // contexts associated with this browser context. - virtual quota::QuotaManager* GetQuotaManager() = 0; - virtual WebKitContext* GetWebKitContext() = 0; - virtual webkit_database::DatabaseTracker* GetDatabaseTracker() = 0; - virtual ChromeBlobStorageContext* GetBlobStorageContext() = 0; - virtual ChromeAppCacheService* GetAppCacheService() = 0; - virtual fileapi::FileSystemContext* GetFileSystemContext() = 0; + // Returns a special storage policy implementation, or NULL. + virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() = 0; }; } // namespace content diff --git a/content/public/common/content_constants.cc b/content/public/common/content_constants.cc index 743622d5e..b0e3b58 100644 --- a/content/public/common/content_constants.cc +++ b/content/public/common/content_constants.cc @@ -3,9 +3,11 @@ // found in the LICENSE file. #include "content/public/common/content_constants.h" - namespace content { +const FilePath::CharType kAppCacheDirname[] = + FILE_PATH_LITERAL("Application Cache"); + // This number used to be limited to 32 in the past (see b/535234). const size_t kMaxRendererProcessCount = 82; const int kMaxSessionHistoryEntries = 50; diff --git a/content/public/common/content_constants.h b/content/public/common/content_constants.h index a5e2c53..0df8b8b 100644 --- a/content/public/common/content_constants.h +++ b/content/public/common/content_constants.h @@ -10,10 +10,15 @@ #include <stddef.h> // For size_t +#include "base/file_path.h" #include "content/common/content_export.h" namespace content { +// The name of the directory under BrowserContext::GetPath where the AppCache is +// put. +CONTENT_EXPORT extern const FilePath::CharType kAppCacheDirname[]; + CONTENT_EXPORT extern const size_t kMaxRendererProcessCount; // The maximum number of session history entries per tab. diff --git a/content/shell/shell_browser_context.cc b/content/shell/shell_browser_context.cc index cd47383..b118413 100644 --- a/content/shell/shell_browser_context.cc +++ b/content/shell/shell_browser_context.cc @@ -10,10 +10,7 @@ #include "base/logging.h" #include "base/path_service.h" #include "base/threading/thread.h" -#include "content/browser/appcache/chrome_appcache_service.h" -#include "content/browser/chrome_blob_storage_context.h" #include "content/browser/download/download_manager_impl.h" -#include "content/browser/file_system/browser_file_system_helper.h" #include "content/browser/host_zoom_map_impl.h" #include "content/browser/in_process_webkit/webkit_context.h" #include "content/public/browser/browser_thread.h" @@ -23,8 +20,6 @@ #include "content/shell/shell_download_manager_delegate.h" #include "content/shell/shell_resource_context.h" #include "content/shell/shell_url_request_context_getter.h" -#include "webkit/database/database_tracker.h" -#include "webkit/quota/quota_manager.h" #if defined(OS_WIN) #include "base/base_paths_win.h" @@ -164,7 +159,7 @@ ResourceContext* ShellBrowserContext::GetResourceContext() { if (!resource_context_.get()) { resource_context_.reset(new ShellResourceContext( static_cast<ShellURLRequestContextGetter*>(GetRequestContext()), - GetBlobStorageContext())); + BrowserContext::GetBlobStorageContext(this))); } return resource_context_.get(); } @@ -194,73 +189,8 @@ bool ShellBrowserContext::DidLastSessionExitCleanly() { return true; } -quota::QuotaManager* ShellBrowserContext::GetQuotaManager() { - CreateQuotaManagerAndClients(); - return quota_manager_.get(); -} - -WebKitContext* ShellBrowserContext::GetWebKitContext() { - CreateQuotaManagerAndClients(); - return webkit_context_.get(); -} - -webkit_database::DatabaseTracker* ShellBrowserContext::GetDatabaseTracker() { - CreateQuotaManagerAndClients(); - return db_tracker_; -} - -ChromeBlobStorageContext* ShellBrowserContext::GetBlobStorageContext() { - if (!blob_storage_context_) { - blob_storage_context_ = new ChromeBlobStorageContext(); - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind( - &ChromeBlobStorageContext::InitializeOnIOThread, - blob_storage_context_.get())); - } - return blob_storage_context_; -} - -ChromeAppCacheService* ShellBrowserContext::GetAppCacheService() { - CreateQuotaManagerAndClients(); - return appcache_service_; -} - -fileapi::FileSystemContext* ShellBrowserContext::GetFileSystemContext() { - CreateQuotaManagerAndClients(); - return file_system_context_.get(); -} - -void ShellBrowserContext::CreateQuotaManagerAndClients() { - if (quota_manager_.get()) - return; - quota_manager_ = new quota::QuotaManager( - IsOffTheRecord(), - GetPath(), - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), - NULL); - - file_system_context_ = CreateFileSystemContext( - GetPath(), IsOffTheRecord(), NULL, quota_manager_->proxy()); - db_tracker_ = new webkit_database::DatabaseTracker( - GetPath(), IsOffTheRecord(), false, NULL, quota_manager_->proxy(), - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); - webkit_context_ = new WebKitContext( - IsOffTheRecord(), GetPath(), NULL, false, quota_manager_->proxy(), - BrowserThread::GetMessageLoopProxyForThread( - BrowserThread::WEBKIT_DEPRECATED)); - appcache_service_ = new ChromeAppCacheService(quota_manager_->proxy()); - scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy; - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind( - &ChromeAppCacheService::InitializeOnIOThread, - appcache_service_.get(), - IsOffTheRecord() - ? FilePath() : GetPath().Append(FILE_PATH_LITERAL("AppCache")), - GetResourceContext(), - special_storage_policy)); +quota::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() { + return NULL; } } // namespace content diff --git a/content/shell/shell_browser_context.h b/content/shell/shell_browser_context.h index 84d29b8..3def4fd 100644 --- a/content/shell/shell_browser_context.h +++ b/content/shell/shell_browser_context.h @@ -40,15 +40,9 @@ class ShellBrowserContext : public BrowserContext { GetGeolocationPermissionContext() OVERRIDE; virtual SpeechInputPreferences* GetSpeechInputPreferences() OVERRIDE; virtual bool DidLastSessionExitCleanly() OVERRIDE; - virtual quota::QuotaManager* GetQuotaManager() OVERRIDE; - virtual WebKitContext* GetWebKitContext() OVERRIDE; - virtual webkit_database::DatabaseTracker* GetDatabaseTracker() OVERRIDE; - virtual ChromeBlobStorageContext* GetBlobStorageContext() OVERRIDE; - virtual ChromeAppCacheService* GetAppCacheService() OVERRIDE; - virtual fileapi::FileSystemContext* GetFileSystemContext() OVERRIDE; + virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE; private: - void CreateQuotaManagerAndClients(); FilePath path_; scoped_ptr<ResourceContext> resource_context_; @@ -58,12 +52,6 @@ class ShellBrowserContext : public BrowserContext { scoped_refptr<HostZoomMap> host_zoom_map_; scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_; scoped_refptr<SpeechInputPreferences> speech_input_preferences_; - scoped_refptr<WebKitContext> webkit_context_; - scoped_refptr<ChromeAppCacheService> appcache_service_; - scoped_refptr<webkit_database::DatabaseTracker> db_tracker_; - scoped_refptr<fileapi::FileSystemContext> file_system_context_; - scoped_refptr<quota::QuotaManager> quota_manager_; - scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; ShellBrowserMainParts* shell_main_parts_; diff --git a/content/test/test_browser_context.cc b/content/test/test_browser_context.cc index bc8a3ee..df3934e 100644 --- a/content/test/test_browser_context.cc +++ b/content/test/test_browser_context.cc @@ -19,6 +19,10 @@ TestBrowserContext::TestBrowserContext() { TestBrowserContext::~TestBrowserContext() { } +FilePath TestBrowserContext::TakePath() { + return browser_context_dir_.Take(); +} + FilePath TestBrowserContext::GetPath() { return browser_context_dir_.path(); } @@ -67,31 +71,6 @@ bool TestBrowserContext::DidLastSessionExitCleanly() { return true; } -quota::QuotaManager* TestBrowserContext::GetQuotaManager() { - return NULL; -} - -WebKitContext* TestBrowserContext::GetWebKitContext() { - if (webkit_context_ == NULL) { - webkit_context_ = new WebKitContext( - IsOffTheRecord(), GetPath(), - NULL, false, NULL, NULL); - } - return webkit_context_; -} - -webkit_database::DatabaseTracker* TestBrowserContext::GetDatabaseTracker() { - return NULL; -} - -ChromeBlobStorageContext* TestBrowserContext::GetBlobStorageContext() { - return NULL; -} - -ChromeAppCacheService* TestBrowserContext::GetAppCacheService() { - return NULL; -} - -fileapi::FileSystemContext* TestBrowserContext::GetFileSystemContext() { +quota::SpecialStoragePolicy* TestBrowserContext::GetSpecialStoragePolicy() { return NULL; } diff --git a/content/test/test_browser_context.h b/content/test/test_browser_context.h index ee5acf6..c0873c0 100644 --- a/content/test/test_browser_context.h +++ b/content/test/test_browser_context.h @@ -20,6 +20,10 @@ class TestBrowserContext : public content::BrowserContext { TestBrowserContext(); virtual ~TestBrowserContext(); + // Takes ownership of the temporary directory so that it's not deleted when + // this object is destructed. + FilePath TakePath(); + virtual FilePath GetPath() OVERRIDE; virtual bool IsOffTheRecord() OVERRIDE; virtual content::DownloadManager* GetDownloadManager() OVERRIDE; @@ -33,20 +37,12 @@ class TestBrowserContext : public content::BrowserContext { GetGeolocationPermissionContext() OVERRIDE; virtual content::SpeechInputPreferences* GetSpeechInputPreferences() OVERRIDE; virtual bool DidLastSessionExitCleanly() OVERRIDE; - virtual quota::QuotaManager* GetQuotaManager() OVERRIDE; - virtual WebKitContext* GetWebKitContext() OVERRIDE; - virtual webkit_database::DatabaseTracker* GetDatabaseTracker() OVERRIDE; - virtual ChromeBlobStorageContext* GetBlobStorageContext() OVERRIDE; - virtual ChromeAppCacheService* GetAppCacheService() OVERRIDE; - virtual fileapi::FileSystemContext* GetFileSystemContext() OVERRIDE; + virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE; private: FRIEND_TEST_ALL_PREFIXES(DOMStorageTest, SessionOnly); FRIEND_TEST_ALL_PREFIXES(DOMStorageTest, SaveSessionState); - // WebKitContext, lazily initialized by GetWebKitContext(). - scoped_refptr<WebKitContext> webkit_context_; - ScopedTempDir browser_context_dir_; DISALLOW_COPY_AND_ASSIGN(TestBrowserContext); diff --git a/content/test/test_browser_thread.cc b/content/test/test_browser_thread.cc index 9224726..353b5ea 100644 --- a/content/test/test_browser_thread.cc +++ b/content/test/test_browser_thread.cc @@ -7,6 +7,7 @@ #include "base/message_loop.h" #include "base/threading/thread.h" #include "content/browser/browser_thread_impl.h" +#include "content/browser/notification_service_impl.h" namespace content { @@ -14,12 +15,14 @@ namespace content { class TestBrowserThreadImpl : public BrowserThreadImpl { public: explicit TestBrowserThreadImpl(BrowserThread::ID identifier) - : BrowserThreadImpl(identifier) { + : BrowserThreadImpl(identifier), + notification_service_(NULL) { } TestBrowserThreadImpl(BrowserThread::ID identifier, MessageLoop* message_loop) - : BrowserThreadImpl(identifier, message_loop) { + : BrowserThreadImpl(identifier, message_loop), + notification_service_(NULL) { } virtual ~TestBrowserThreadImpl() { @@ -30,7 +33,19 @@ class TestBrowserThreadImpl : public BrowserThreadImpl { Thread::set_message_loop(loop); } + virtual void Init() OVERRIDE { + notification_service_ = new NotificationServiceImpl; + BrowserThreadImpl::Init(); + } + + virtual void CleanUp() OVERRIDE { + delete notification_service_; + notification_service_ = NULL; + BrowserThreadImpl::CleanUp(); + } + private: + NotificationService* notification_service_; DISALLOW_COPY_AND_ASSIGN(TestBrowserThreadImpl); }; diff --git a/webkit/appcache/appcache_storage_impl.cc b/webkit/appcache/appcache_storage_impl.cc index e68cf27..99f731e 100644 --- a/webkit/appcache/appcache_storage_impl.cc +++ b/webkit/appcache/appcache_storage_impl.cc @@ -1221,13 +1221,14 @@ AppCacheStorageImpl::~AppCacheStorageImpl() { scheduled_database_tasks_.end(), std::mem_fun(&DatabaseTask::CancelCompletion)); - if (database_) { - db_thread_->PostTask( - FROM_HERE, - base::Bind(&CleanUpOnDatabaseThread, database_, - make_scoped_refptr(service_->special_storage_policy()), - service()->clear_local_state_on_exit(), - service()->save_session_state())); + if (database_ && + !db_thread_->PostTask( + FROM_HERE, + base::Bind(&CleanUpOnDatabaseThread, database_, + make_scoped_refptr(service_->special_storage_policy()), + service()->clear_local_state_on_exit(), + service()->save_session_state()))) { + delete database_; } } diff --git a/webkit/fileapi/file_system_context.cc b/webkit/fileapi/file_system_context.cc index 2bee4f3..600518e 100644 --- a/webkit/fileapi/file_system_context.cc +++ b/webkit/fileapi/file_system_context.cc @@ -141,8 +141,8 @@ FileSystemContext::external_provider() const { } void FileSystemContext::DeleteOnCorrectThread() const { - if (!io_message_loop_->BelongsToCurrentThread()) { - io_message_loop_->DeleteSoon(FROM_HERE, this); + if (!io_message_loop_->BelongsToCurrentThread() && + io_message_loop_->DeleteSoon(FROM_HERE, this)) { return; } delete this; diff --git a/webkit/fileapi/sandbox_mount_point_provider.cc b/webkit/fileapi/sandbox_mount_point_provider.cc index e79624e..cbcda1d 100644 --- a/webkit/fileapi/sandbox_mount_point_provider.cc +++ b/webkit/fileapi/sandbox_mount_point_provider.cc @@ -316,8 +316,11 @@ SandboxMountPointProvider::SandboxMountPointProvider( } SandboxMountPointProvider::~SandboxMountPointProvider() { - if (!file_message_loop_->BelongsToCurrentThread()) - file_message_loop_->ReleaseSoon(FROM_HERE, sandbox_file_util_.release()); + if (!file_message_loop_->BelongsToCurrentThread()) { + ObfuscatedFileUtil* sandbox_file_util = sandbox_file_util_.release(); + if (!file_message_loop_->ReleaseSoon(FROM_HERE, sandbox_file_util)) + sandbox_file_util->Release(); + } } void SandboxMountPointProvider::ValidateFileSystemRoot( diff --git a/webkit/quota/quota_manager.cc b/webkit/quota/quota_manager.cc index edc6ee6..640de20 100644 --- a/webkit/quota/quota_manager.cc +++ b/webkit/quota/quota_manager.cc @@ -1137,7 +1137,6 @@ QuotaManager::QuotaManager(bool is_incognito, } QuotaManager::~QuotaManager() { - DCHECK(io_thread_->BelongsToCurrentThread()); proxy_->manager_ = NULL; std::for_each(clients_.begin(), clients_.end(), std::mem_fun(&QuotaClient::OnQuotaManagerDestroyed)); @@ -1297,7 +1296,6 @@ void QuotaManager::LazyInitialize() { } void QuotaManager::RegisterClient(QuotaClient* client) { - DCHECK(io_thread_->BelongsToCurrentThread()); DCHECK(!database_.get()); clients_.push_back(client); } @@ -1674,8 +1672,8 @@ void QuotaManager::DidGetDatabaseLRUOrigin(const GURL& origin) { } void QuotaManager::DeleteOnCorrectThread() const { - if (!io_thread_->BelongsToCurrentThread()) { - io_thread_->DeleteSoon(FROM_HERE, this); + if (!io_thread_->BelongsToCurrentThread() && + io_thread_->DeleteSoon(FROM_HERE, this)) { return; } delete this; @@ -1684,10 +1682,10 @@ void QuotaManager::DeleteOnCorrectThread() const { // QuotaManagerProxy ---------------------------------------------------------- void QuotaManagerProxy::RegisterClient(QuotaClient* client) { - if (!io_thread_->BelongsToCurrentThread()) { - io_thread_->PostTask( - FROM_HERE, - base::Bind(&QuotaManagerProxy::RegisterClient, this, client)); + if (!io_thread_->BelongsToCurrentThread() && + io_thread_->PostTask( + FROM_HERE, + base::Bind(&QuotaManagerProxy::RegisterClient, this, client))) { return; } |