summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-21 03:57:42 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-21 03:57:42 +0000
commit314c3e2d86a4595db7b1ab02b2acd4decf21d65f (patch)
tree593431d4dad2fa3c944d8e8f97da3f6fc56140f6
parentc537090136d23d0064488c27de3bb2ba0f1ac120 (diff)
downloadchromium_src-314c3e2d86a4595db7b1ab02b2acd4decf21d65f.zip
chromium_src-314c3e2d86a4595db7b1ab02b2acd4decf21d65f.tar.gz
chromium_src-314c3e2d86a4595db7b1ab02b2acd4decf21d65f.tar.bz2
Remove getters for HTML5 related objects from the ResourceContext interface. Half of them weren't used by chrome, so they can be hidden from chrome. The rest were accessed by chrome, but we don't need every embedder to store this data on their ResourceContext implementation. Instead have content associate the data itself to simplify the work for embedders.
BUG=98716 Review URL: https://chromiumcodereview.appspot.com/9425026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@122790 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/supports_user_data.h20
-rw-r--r--chrome/browser/DEPS2
-rw-r--r--chrome/browser/browsing_data_appcache_helper.cc10
-rw-r--r--chrome/browser/browsing_data_appcache_helper.h8
-rw-r--r--chrome/browser/browsing_data_remover.h2
-rw-r--r--chrome/browser/extensions/extension_data_deleter.cc12
-rw-r--r--chrome/browser/extensions/extension_data_deleter.h13
-rw-r--r--chrome/browser/extensions/extension_service_unittest.cc4
-rw-r--r--chrome/browser/profiles/off_the_record_profile_io_data.cc23
-rw-r--r--chrome/browser/profiles/profile_impl.cc10
-rw-r--r--chrome/browser/profiles/profile_impl_io_data.cc41
-rw-r--r--chrome/browser/profiles/profile_io_data.cc80
-rw-r--r--chrome/browser/profiles/profile_io_data.h37
-rw-r--r--chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc2
-rw-r--r--chrome/browser/renderer_host/offline_resource_throttle.cc19
-rw-r--r--chrome/browser/renderer_host/offline_resource_throttle.h9
-rw-r--r--chrome/browser/ui/cocoa/content_settings/collected_cookies_mac.h1
-rw-r--r--chrome/browser/ui/webui/chrome_url_data_manager_backend.cc10
-rw-r--r--chrome/browser/ui/webui/chrome_url_data_manager_backend.h7
-rw-r--r--chrome/test/base/testing_profile.cc4
-rw-r--r--chrome/test/base/testing_profile.h3
-rw-r--r--content/browser/appcache/chrome_appcache_service.cc2
-rw-r--r--content/browser/appcache/chrome_appcache_service_unittest.cc7
-rw-r--r--content/browser/browser_context.cc61
-rw-r--r--content/browser/chrome_blob_storage_context.cc34
-rw-r--r--content/browser/chrome_blob_storage_context.h25
-rw-r--r--content/browser/in_process_webkit/indexed_db_quota_client_unittest.cc14
-rw-r--r--content/browser/mock_resource_context.cc24
-rw-r--r--content/browser/mock_resource_context.h6
-rw-r--r--content/browser/renderer_host/render_process_host_impl.cc8
-rw-r--r--content/browser/renderer_host/resource_dispatcher_host.cc7
-rw-r--r--content/browser/renderer_host/resource_dispatcher_host_unittest.cc40
-rw-r--r--content/browser/resource_context_impl.cc92
-rw-r--r--content/browser/resource_context_impl.h36
-rw-r--r--content/browser/worker_host/worker_process_host.cc34
-rw-r--r--content/content_browser.gypi2
-rw-r--r--content/public/browser/browser_context.h17
-rw-r--r--content/public/browser/resource_context.h44
-rw-r--r--content/shell/shell_browser_context.cc3
-rw-r--r--content/shell/shell_resource_context.cc32
-rw-r--r--content/shell/shell_resource_context.h11
-rw-r--r--content/test/test_browser_context.cc5
-rw-r--r--content/test/test_browser_context.h6
43 files changed, 460 insertions, 367 deletions
diff --git a/base/supports_user_data.h b/base/supports_user_data.h
index 0296a3e..1c90e01 100644
--- a/base/supports_user_data.h
+++ b/base/supports_user_data.h
@@ -9,6 +9,7 @@
#include "base/base_export.h"
#include "base/memory/linked_ptr.h"
+#include "base/memory/ref_counted.h"
namespace base {
@@ -42,6 +43,25 @@ class BASE_EXPORT SupportsUserData {
DISALLOW_COPY_AND_ASSIGN(SupportsUserData);
};
+// 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(SupportsUserData* supports_user_data, const char* key) {
+ UserDataAdapter* data =
+ static_cast<UserDataAdapter*>(supports_user_data->GetUserData(key));
+ return static_cast<T*>(data->object_.get());
+ }
+
+ UserDataAdapter(T* object) : object_(object) {}
+
+ private:
+ scoped_refptr<T> object_;
+
+ DISALLOW_COPY_AND_ASSIGN(UserDataAdapter);
+};
+
} // namespace base
#endif // BASE_SUPPORTS_USER_DATA_H_
diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS
index 2202077..8c62d46 100644
--- a/chrome/browser/DEPS
+++ b/chrome/browser/DEPS
@@ -35,10 +35,8 @@ include_rules = [
"+content/browser/accessibility/browser_accessibility_cocoa.h",
"+content/browser/accessibility/browser_accessibility_manager.h",
"+content/browser/accessibility/browser_accessibility_state.h",
- "+content/browser/appcache/chrome_appcache_service.h",
"+content/browser/browser_url_handler.h",
"+content/browser/cert_store.h",
- "+content/browser/chrome_blob_storage_context.h",
"+content/browser/disposition_utils.h",
"+content/browser/download/download_buffer.h",
"+content/browser/download/download_create_info.h",
diff --git a/chrome/browser/browsing_data_appcache_helper.cc b/chrome/browser/browsing_data_appcache_helper.cc
index 148fa85..153fa40 100644
--- a/chrome/browser/browsing_data_appcache_helper.cc
+++ b/chrome/browser/browsing_data_appcache_helper.cc
@@ -9,16 +9,18 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/resource_context.h"
#include "webkit/appcache/appcache_database.h"
#include "webkit/appcache/appcache_storage.h"
using appcache::AppCacheDatabase;
using content::BrowserContext;
using content::BrowserThread;
+using content::ResourceContext;
BrowsingDataAppCacheHelper::BrowsingDataAppCacheHelper(Profile* profile)
: is_fetching_(false),
- appcache_service_(BrowserContext::GetAppCacheService(profile)) {
+ resource_context_(profile->GetResourceContext()) {
}
void BrowsingDataAppCacheHelper::StartFetching(const base::Closure& callback) {
@@ -38,8 +40,8 @@ void BrowsingDataAppCacheHelper::StartFetching(const base::Closure& callback) {
appcache_info_callback_.Reset(
base::Bind(&BrowsingDataAppCacheHelper::OnFetchComplete,
base::Unretained(this)));
- appcache_service_->GetAllAppCacheInfo(info_collection_,
- appcache_info_callback_.callback());
+ ResourceContext::GetAppCacheService(resource_context_)->
+ GetAllAppCacheInfo(info_collection_, appcache_info_callback_.callback());
}
void BrowsingDataAppCacheHelper::CancelNotification() {
@@ -64,7 +66,7 @@ void BrowsingDataAppCacheHelper::DeleteAppCacheGroup(
return;
}
- appcache_service_->DeleteAppCacheGroup(
+ ResourceContext::GetAppCacheService(resource_context_)->DeleteAppCacheGroup(
manifest_url, net::CompletionCallback());
}
diff --git a/chrome/browser/browsing_data_appcache_helper.h b/chrome/browser/browsing_data_appcache_helper.h
index a5f703a..07c00c4 100644
--- a/chrome/browser/browsing_data_appcache_helper.h
+++ b/chrome/browser/browsing_data_appcache_helper.h
@@ -8,12 +8,16 @@
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
-#include "content/browser/appcache/chrome_appcache_service.h"
#include "net/base/completion_callback.h"
#include "googleurl/src/gurl.h"
+#include "webkit/appcache/appcache_service.h"
class Profile;
+namespace content {
+class ResourceContext;
+}
+
// This class fetches appcache information on behalf of a caller
// on the UI thread.
class BrowsingDataAppCacheHelper
@@ -41,7 +45,7 @@ class BrowsingDataAppCacheHelper
void OnFetchComplete(int rv);
bool is_fetching_;
- scoped_refptr<ChromeAppCacheService> appcache_service_;
+ content::ResourceContext* resource_context_;
net::CancelableCompletionCallback appcache_info_callback_;
DISALLOW_COPY_AND_ASSIGN(BrowsingDataAppCacheHelper);
diff --git a/chrome/browser/browsing_data_remover.h b/chrome/browser/browsing_data_remover.h
index 40b3c25..de973ba 100644
--- a/chrome/browser/browsing_data_remover.h
+++ b/chrome/browser/browsing_data_remover.h
@@ -15,9 +15,9 @@
#include "base/time.h"
#include "chrome/browser/cancelable_request.h"
#include "chrome/browser/prefs/pref_member.h"
-#include "content/browser/appcache/chrome_appcache_service.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
+#include "googleurl/src/gurl.h"
#include "webkit/quota/quota_types.h"
class ExtensionSpecialStoragePolicy;
diff --git a/chrome/browser/extensions/extension_data_deleter.cc b/chrome/browser/extensions/extension_data_deleter.cc
index da69e21..7e6c1be 100644
--- a/chrome/browser/extensions/extension_data_deleter.cc
+++ b/chrome/browser/extensions/extension_data_deleter.cc
@@ -12,19 +12,21 @@
#include "chrome/common/chrome_constants.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/url_constants.h"
-#include "content/browser/appcache/chrome_appcache_service.h"
#include "content/browser/in_process_webkit/webkit_context.h"
+#include "content/public/browser/resource_context.h"
#include "net/base/completion_callback.h"
#include "net/base/cookie_monster.h"
#include "net/base/net_errors.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
+#include "webkit/appcache/appcache_service.h"
#include "webkit/database/database_tracker.h"
#include "webkit/database/database_util.h"
#include "webkit/fileapi/file_system_context.h"
using content::BrowserContext;
using content::BrowserThread;
+using content::ResourceContext;
// static
void ExtensionDataDeleter::StartDeleting(
@@ -66,7 +68,8 @@ void ExtensionDataDeleter::StartDeleting(
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(
- &ExtensionDataDeleter::DeleteAppcachesOnIOThread, deleter));
+ &ExtensionDataDeleter::DeleteAppcachesOnIOThread, deleter,
+ profile->GetResourceContext()));
profile->GetExtensionService()->settings_frontend()->
DeleteStorageSoon(extension_id);
@@ -78,7 +81,6 @@ ExtensionDataDeleter::ExtensionDataDeleter(
const GURL& storage_origin,
bool is_storage_isolated)
: extension_id_(extension_id) {
- 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,
@@ -142,8 +144,8 @@ void ExtensionDataDeleter::DeleteFileSystemOnFileThread() {
file_util::Delete(isolated_app_path_, true);
}
-void ExtensionDataDeleter::DeleteAppcachesOnIOThread() {
+void ExtensionDataDeleter::DeleteAppcachesOnIOThread(ResourceContext* context) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- appcache_service_->DeleteAppCachesForOrigin(
+ ResourceContext::GetAppCacheService(context)->DeleteAppCachesForOrigin(
storage_origin_, net::CompletionCallback());
}
diff --git a/chrome/browser/extensions/extension_data_deleter.h b/chrome/browser/extensions/extension_data_deleter.h
index 851352c..ec9a77b 100644
--- a/chrome/browser/extensions/extension_data_deleter.h
+++ b/chrome/browser/extensions/extension_data_deleter.h
@@ -13,8 +13,8 @@
#include "content/public/browser/browser_thread.h"
#include "googleurl/src/gurl.h"
-namespace webkit_database {
-class DatabaseTracker;
+namespace content {
+class ResourceContext;
}
namespace fileapi {
@@ -25,7 +25,10 @@ namespace net {
class URLRequestContextGetter;
}
-class ChromeAppCacheService;
+namespace webkit_database {
+class DatabaseTracker;
+}
+
class Profile;
class WebKitContext;
@@ -80,7 +83,7 @@ class ExtensionDataDeleter
// Deletes appcache files for the extension. May only be called on the IO
// thread.
- void DeleteAppcachesOnIOThread();
+ void DeleteAppcachesOnIOThread(content::ResourceContext* resource_context);
// The ID of the extension being deleted.
const std::string extension_id_;
@@ -102,8 +105,6 @@ class ExtensionDataDeleter
scoped_refptr<fileapi::FileSystemContext> file_system_context_;
- scoped_refptr<ChromeAppCacheService> appcache_service_;
-
// If non-empty, the extension we're deleting is an isolated app, and this
// is its directory which we should delete.
FilePath isolated_app_path_;
diff --git a/chrome/browser/extensions/extension_service_unittest.cc b/chrome/browser/extensions/extension_service_unittest.cc
index d18a3202..37187c2 100644
--- a/chrome/browser/extensions/extension_service_unittest.cc
+++ b/chrome/browser/extensions/extension_service_unittest.cc
@@ -60,7 +60,6 @@
#include "chrome/common/string_ordinal.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/testing_profile.h"
-#include "content/browser/appcache/chrome_appcache_service.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"
@@ -404,6 +403,7 @@ ExtensionServiceTestBase::~ExtensionServiceTestBase() {
// can be destroyed while BrowserThreads and MessageLoop are still around
// (they are used in the destruction process).
service_ = NULL;
+ MessageLoop::current()->RunAllPending();
profile_.reset(NULL);
MessageLoop::current()->RunAllPending();
}
@@ -4323,6 +4323,7 @@ TEST_F(ExtensionServiceTest, ProcessSyncDataTerminatedExtension) {
TEST_F(ExtensionServiceTest, ProcessSyncDataVersionCheck) {
InitializeExtensionServiceWithUpdater();
+ InitializeRequestContext();
TestSyncProcessorStub processor;
service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(),
&processor);
@@ -4380,6 +4381,7 @@ TEST_F(ExtensionServiceTest, ProcessSyncDataVersionCheck) {
TEST_F(ExtensionServiceTest, ProcessSyncDataNotInstalled) {
InitializeExtensionServiceWithUpdater();
+ InitializeRequestContext();
TestSyncProcessorStub processor;
service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(),
&processor);
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 3f8a01b..c21cb73 100644
--- a/chrome/browser/profiles/off_the_record_profile_io_data.cc
+++ b/chrome/browser/profiles/off_the_record_profile_io_data.cc
@@ -129,19 +129,20 @@ 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());
+ if (initialized_)
+ return;
+
+ // Set initialized_ to true at the beginning in case any of the objects
+ // below try to get the ResourceContext pointer.
+ initialized_ = true;
+ ChromeNetworkDelegate::InitializeReferrersEnabled(
+ io_data_->enable_referrers(), profile_->GetPrefs());
#if defined(ENABLE_SAFE_BROWSING)
- io_data_->safe_browsing_enabled()->Init(prefs::kSafeBrowsingEnabled,
- profile_->GetPrefs(), NULL);
- io_data_->safe_browsing_enabled()->MoveToThread(BrowserThread::IO);
+ io_data_->safe_browsing_enabled()->Init(prefs::kSafeBrowsingEnabled,
+ profile_->GetPrefs(), NULL);
+ io_data_->safe_browsing_enabled()->MoveToThread(BrowserThread::IO);
#endif
- }
+ io_data_->InitializeOnUIThread(profile_);
}
OffTheRecordProfileIOData::OffTheRecordProfileIOData()
diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc
index b166fc0..e5d02e9 100644
--- a/chrome/browser/profiles/profile_impl.cc
+++ b/chrome/browser/profiles/profile_impl.cc
@@ -101,6 +101,7 @@
#include "grit/locale_settings.h"
#include "net/base/transport_security_state.h"
#include "net/http/http_server_properties.h"
+#include "webkit/appcache/appcache_service.h"
#include "webkit/database/database_tracker.h"
#if defined(OS_WIN)
@@ -174,12 +175,11 @@ FilePath GetMediaCachePath(const FilePath& base) {
void SaveSessionStateOnIOThread(
net::URLRequestContextGetter* url_request_context_getter,
- ChromeAppCacheService* appcache_service) {
+ appcache::AppCacheService* appcache_service) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
url_request_context_getter->GetURLRequestContext()->cookie_store()->
GetCookieMonster()->SaveSessionCookies();
- if (appcache_service)
- appcache_service->set_save_session_state(true);
+ appcache_service->set_save_session_state(true);
}
} // namespace
@@ -551,7 +551,7 @@ ProfileImpl::~ProfileImpl() {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&appcache::AppCacheService::set_clear_local_state_on_exit,
- BrowserContext::GetAppCacheService(this), true));
+ base::Unretained(BrowserContext::GetAppCacheService(this)), true));
BrowserContext::GetWebKitContext(this)->set_clear_local_state_on_exit(true);
BrowserContext::GetDatabaseTracker(this)->SetClearLocalStateOnExit(true);
}
@@ -1438,7 +1438,7 @@ void ProfileImpl::SaveSessionState() {
BrowserThread::IO, FROM_HERE,
base::Bind(&SaveSessionStateOnIOThread,
make_scoped_refptr(GetRequestContext()),
- make_scoped_refptr(BrowserContext::GetAppCacheService(this))));
+ BrowserContext::GetAppCacheService(this)));
}
void ProfileImpl::UpdateProfileUserNameCache() {
diff --git a/chrome/browser/profiles/profile_impl_io_data.cc b/chrome/browser/profiles/profile_impl_io_data.cc
index 0b01f29..2ea1c15 100644
--- a/chrome/browser/profiles/profile_impl_io_data.cc
+++ b/chrome/browser/profiles/profile_impl_io_data.cc
@@ -222,28 +222,29 @@ 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(
- new chrome_browser_net::HttpServerPropertiesManager(pref_service));
- ChromeNetworkDelegate::InitializeReferrersEnabled(
- io_data_->enable_referrers(), pref_service);
- io_data_->clear_local_state_on_exit()->Init(
- prefs::kClearSiteDataOnExit, pref_service, NULL);
- io_data_->clear_local_state_on_exit()->MoveToThread(BrowserThread::IO);
- io_data_->session_startup_pref()->Init(
- prefs::kRestoreOnStartup, pref_service, NULL);
- io_data_->session_startup_pref()->MoveToThread(BrowserThread::IO);
+ if (initialized_)
+ return;
+
+ // Set initialized_ to true at the beginning in case any of the objects
+ // below try to get the ResourceContext pointer.
+ initialized_ = true;
+ PrefService* pref_service = profile_->GetPrefs();
+ io_data_->http_server_properties_manager_.reset(
+ new chrome_browser_net::HttpServerPropertiesManager(pref_service));
+ ChromeNetworkDelegate::InitializeReferrersEnabled(
+ io_data_->enable_referrers(), pref_service);
+ io_data_->clear_local_state_on_exit()->Init(
+ prefs::kClearSiteDataOnExit, pref_service, NULL);
+ io_data_->clear_local_state_on_exit()->MoveToThread(BrowserThread::IO);
+ io_data_->session_startup_pref()->Init(
+ prefs::kRestoreOnStartup, pref_service, NULL);
+ io_data_->session_startup_pref()->MoveToThread(BrowserThread::IO);
#if defined(ENABLE_SAFE_BROWSING)
- io_data_->safe_browsing_enabled()->Init(prefs::kSafeBrowsingEnabled,
- pref_service, NULL);
- io_data_->safe_browsing_enabled()->MoveToThread(BrowserThread::IO);
+ io_data_->safe_browsing_enabled()->Init(prefs::kSafeBrowsingEnabled,
+ pref_service, NULL);
+ io_data_->safe_browsing_enabled()->MoveToThread(BrowserThread::IO);
#endif
- }
+ io_data_->InitializeOnUIThread(profile_);
}
ProfileImplIOData::LazyParams::LazyParams()
diff --git a/chrome/browser/profiles/profile_io_data.cc b/chrome/browser/profiles/profile_io_data.cc
index c0b0e13..0df44a9 100644
--- a/chrome/browser/profiles/profile_io_data.cc
+++ b/chrome/browser/profiles/profile_io_data.cc
@@ -14,6 +14,7 @@
#include "base/logging.h"
#include "base/stl_util.h"
#include "base/string_number_conversions.h"
+#include "base/string_util.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/content_settings/cookie_settings.h"
#include "chrome/browser/content_settings/host_content_settings_map.h"
@@ -40,8 +41,6 @@
#include "chrome/common/chrome_switches.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/in_process_webkit/webkit_context.h"
#include "content/browser/renderer_host/media/media_stream_manager.h"
#include "content/browser/renderer_host/resource_dispatcher_host.h"
@@ -60,10 +59,7 @@
#include "net/url_request/url_request.h"
#include "webkit/blob/blob_data.h"
#include "webkit/blob/blob_url_request_job_factory.h"
-#include "webkit/database/database_tracker.h"
-#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_url_request_job_factory.h"
-#include "webkit/quota/quota_manager.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/gview_request_interceptor.h"
@@ -72,6 +68,7 @@
using content::BrowserContext;
using content::BrowserThread;
+using content::ResourceContext;
namespace {
@@ -196,8 +193,6 @@ void ProfileIOData::InitializeOnUIThread(Profile* profile) {
params->clear_local_state_on_exit =
pref_service->GetBoolean(prefs::kClearSiteDataOnExit);
- params->appcache_service = BrowserContext::GetAppCacheService(profile);
-
// Set up Accept-Language and Accept-Charset header values
params->accept_language = net::HttpUtil::GenerateAcceptLanguageHeader(
pref_service->GetString(prefs::kAcceptLanguages));
@@ -232,12 +227,6 @@ void ProfileIOData::InitializeOnUIThread(Profile* profile) {
profile);
params->cookie_monster_delegate =
new ChromeCookieMonsterDelegate(profile_getter);
- 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);
@@ -261,6 +250,11 @@ void ProfileIOData::InitializeOnUIThread(Profile* profile) {
#endif
initialized_on_UI_thread_ = true;
+
+ // We need to make sure that content initializes its own data structures that
+ // are associated with each ResourceContext because we might post this
+ // object to the IO thread after this function.
+ BrowserContext::EnsureResourceContextInitialized(profile);
}
ProfileIOData::AppRequestContext::AppRequestContext() {}
@@ -419,44 +413,6 @@ net::URLRequestContext* ProfileIOData::ResourceContext::GetRequestContext() {
return request_context_;
}
-ChromeAppCacheService* ProfileIOData::ResourceContext::GetAppCacheService() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- EnsureInitialized();
- return appcache_service_;
-}
-
-webkit_database::DatabaseTracker*
- ProfileIOData::ResourceContext::GetDatabaseTracker() {
- EnsureInitialized();
- return database_tracker_;
-}
-
-fileapi::FileSystemContext*
- ProfileIOData::ResourceContext::GetFileSystemContext() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- EnsureInitialized();
- return file_system_context_;
-}
-
-WebKitContext* ProfileIOData::ResourceContext::GetWebKitContext() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- EnsureInitialized();
- return webkit_context_;
-}
-
-ChromeBlobStorageContext*
- ProfileIOData::ResourceContext::GetBlobStorageContext() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- EnsureInitialized();
- return blob_storage_context_;
-}
-
-quota::QuotaManager* ProfileIOData::ResourceContext::GetQuotaManager() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- EnsureInitialized();
- return quota_manager_;
-}
-
content::HostZoomMap* ProfileIOData::ResourceContext::GetHostZoomMap() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
EnsureInitialized();
@@ -501,8 +457,6 @@ void ProfileIOData::LazyInitialize() const {
main_request_context_ = new ChromeURLRequestContext;
extensions_request_context_ = new ChromeURLRequestContext;
- profile_params_->appcache_service->set_request_context(main_request_context_);
-
chrome_url_data_manager_backend_.reset(new ChromeURLDataManagerBackend);
network_delegate_.reset(new ChromeNetworkDelegate(
@@ -547,8 +501,8 @@ void ProfileIOData::LazyInitialize() const {
chrome::kChromeUIScheme,
ChromeURLDataManagerBackend::CreateProtocolHandler(
chrome_url_data_manager_backend_.get(),
- profile_params_->appcache_service,
- profile_params_->blob_storage_context->controller()));
+ ResourceContext::GetAppCacheService(&resource_context_),
+ ResourceContext::GetBlobStorageController(&resource_context_)));
DCHECK(set_protocol);
set_protocol = job_factory_->SetProtocolHandler(
chrome::kChromeDevToolsScheme,
@@ -557,13 +511,13 @@ void ProfileIOData::LazyInitialize() const {
set_protocol = job_factory_->SetProtocolHandler(
chrome::kBlobScheme,
new ChromeBlobProtocolHandler(
- profile_params_->blob_storage_context->controller(),
+ ResourceContext::GetBlobStorageController(&resource_context_),
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)));
DCHECK(set_protocol);
set_protocol = job_factory_->SetProtocolHandler(
chrome::kFileSystemScheme,
CreateFileSystemProtocolHandler(
- profile_params_->file_system_context,
+ ResourceContext::GetFileSystemContext(&resource_context_),
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)));
DCHECK(set_protocol);
#if defined(OS_CHROMEOS) && !defined(GOOGLE_CHROME_BUILD)
@@ -578,12 +532,6 @@ void ProfileIOData::LazyInitialize() const {
new media_stream::MediaStreamManager(profile_params_->audio_manager));
// Take ownership over these parameters.
- database_tracker_ = profile_params_->database_tracker;
- appcache_service_ = profile_params_->appcache_service;
- blob_storage_context_ = profile_params_->blob_storage_context;
- file_system_context_ = profile_params_->file_system_context;
- webkit_context_ = profile_params_->webkit_context;
- quota_manager_ = profile_params_->quota_manager;
host_zoom_map_ = profile_params_->host_zoom_map;
host_content_settings_map_ = profile_params_->host_content_settings_map;
cookie_settings_ = profile_params_->cookie_settings;
@@ -592,12 +540,6 @@ void ProfileIOData::LazyInitialize() const {
resource_context_.host_resolver_ = io_thread_globals->host_resolver.get();
resource_context_.request_context_ = main_request_context_;
- resource_context_.database_tracker_ = database_tracker_;
- resource_context_.appcache_service_ = appcache_service_;
- resource_context_.blob_storage_context_ = blob_storage_context_;
- resource_context_.file_system_context_ = file_system_context_;
- resource_context_.webkit_context_ = webkit_context_;
- resource_context_.quota_manager_ = quota_manager_;
resource_context_.host_zoom_map_ = host_zoom_map_;
resource_context_.media_observer_ =
io_thread_globals->media.media_internals.get();
diff --git a/chrome/browser/profiles/profile_io_data.h b/chrome/browser/profiles/profile_io_data.h
index ce970ee..a4d6f07 100644
--- a/chrome/browser/profiles/profile_io_data.h
+++ b/chrome/browser/profiles/profile_io_data.h
@@ -21,8 +21,6 @@
#include "net/base/cookie_monster.h"
class AudioManager;
-class ChromeAppCacheService;
-class ChromeBlobStorageContext;
class CookieSettings;
class DesktopNotificationService;
class ExtensionInfoMap;
@@ -33,10 +31,6 @@ class ProtocolHandlerRegistry;
class TransportSecurityPersister;
class WebKitContext;
-namespace fileapi {
-class FileSystemContext;
-} // namespace fileapi
-
namespace media_stream {
class MediaStreamManager;
} // namespace media_stream
@@ -56,14 +50,6 @@ namespace policy {
class URLBlacklistManager;
} // namespace policy
-namespace quota {
-class QuotaManager;
-}; // namespace quota
-
-namespace webkit_database {
-class DatabaseTracker;
-} // webkit_database
-
// Conceptually speaking, the ProfileIOData represents data that lives on the IO
// thread that is owned by a Profile, such as, but not limited to, network
// objects like CookieMonster, HttpTransactionFactory, etc. Profile owns
@@ -158,12 +144,7 @@ class ProfileIOData {
scoped_refptr<content::HostZoomMap> host_zoom_map;
scoped_refptr<net::SSLConfigService> ssl_config_service;
scoped_refptr<net::CookieMonster::Delegate> cookie_monster_delegate;
- scoped_refptr<webkit_database::DatabaseTracker> database_tracker;
- scoped_refptr<ChromeAppCacheService> appcache_service;
- scoped_refptr<ChromeBlobStorageContext> blob_storage_context;
- scoped_refptr<fileapi::FileSystemContext> file_system_context;
scoped_refptr<WebKitContext> webkit_context;
- scoped_refptr<quota::QuotaManager> quota_manager;
scoped_refptr<ExtensionInfoMap> extension_info_map;
DesktopNotificationService* notification_service;
scoped_refptr<ProtocolHandlerRegistry> protocol_handler_registry;
@@ -238,12 +219,6 @@ class ProfileIOData {
// ResourceContext implementation:
virtual net::HostResolver* GetHostResolver() OVERRIDE;
virtual net::URLRequestContext* GetRequestContext() OVERRIDE;
- virtual ChromeAppCacheService* GetAppCacheService() OVERRIDE;
- virtual webkit_database::DatabaseTracker* GetDatabaseTracker() OVERRIDE;
- virtual fileapi::FileSystemContext* GetFileSystemContext() OVERRIDE;
- virtual WebKitContext* GetWebKitContext() OVERRIDE;
- virtual ChromeBlobStorageContext* GetBlobStorageContext() OVERRIDE;
- virtual quota::QuotaManager* GetQuotaManager() OVERRIDE;
virtual content::HostZoomMap* GetHostZoomMap() OVERRIDE;
virtual MediaObserver* GetMediaObserver() OVERRIDE;
virtual media_stream::MediaStreamManager* GetMediaStreamManager() OVERRIDE;
@@ -255,12 +230,6 @@ class ProfileIOData {
net::HostResolver* host_resolver_;
net::URLRequestContext* request_context_;
- ChromeAppCacheService* appcache_service_;
- webkit_database::DatabaseTracker* database_tracker_;
- fileapi::FileSystemContext* file_system_context_;
- WebKitContext* webkit_context_;
- ChromeBlobStorageContext* blob_storage_context_;
- quota::QuotaManager* quota_manager_;
content::HostZoomMap* host_zoom_map_;
MediaObserver* media_observer_;
media_stream::MediaStreamManager* media_stream_manager_;
@@ -321,12 +290,6 @@ class ProfileIOData {
mutable scoped_ptr<net::URLRequestJobFactory> job_factory_;
// Pointed to by ResourceContext.
- mutable scoped_refptr<webkit_database::DatabaseTracker> database_tracker_;
- mutable scoped_refptr<ChromeAppCacheService> appcache_service_;
- mutable scoped_refptr<ChromeBlobStorageContext> blob_storage_context_;
- mutable scoped_refptr<fileapi::FileSystemContext> file_system_context_;
- mutable scoped_refptr<WebKitContext> webkit_context_;
- mutable scoped_refptr<quota::QuotaManager> quota_manager_;
mutable scoped_refptr<content::HostZoomMap> host_zoom_map_;
mutable scoped_ptr<media_stream::MediaStreamManager> media_stream_manager_;
diff --git a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
index 97db0c6..600ff21 100644
--- a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
+++ b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
@@ -156,7 +156,7 @@ void ChromeResourceDispatcherHostDelegate::RequestBeginning(
// We check offline first, then check safe browsing so that we still can
// block unsafe site after we remove offline page.
throttles->push_back(new OfflineResourceThrottle(
- child_id, route_id, request, resource_context->GetAppCacheService()));
+ child_id, route_id, request, resource_context));
#endif
throttles->push_back(
diff --git a/chrome/browser/renderer_host/offline_resource_throttle.cc b/chrome/browser/renderer_host/offline_resource_throttle.cc
index 53376de..20b5b30 100644
--- a/chrome/browser/renderer_host/offline_resource_throttle.cc
+++ b/chrome/browser/renderer_host/offline_resource_throttle.cc
@@ -14,19 +14,21 @@
#include "chrome/browser/chromeos/offline/offline_load_page.h"
#include "chrome/browser/net/chrome_url_request_context.h"
#include "chrome/common/url_constants.h"
-#include "content/browser/appcache/chrome_appcache_service.h"
#include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/renderer_host/resource_dispatcher_host.h"
#include "content/browser/renderer_host/resource_dispatcher_host_request_info.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_view_host_delegate.h"
+#include "content/public/browser/resource_context.h"
#include "content/public/browser/resource_throttle_controller.h"
#include "net/base/net_errors.h"
#include "net/base/network_change_notifier.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_context.h"
+#include "webkit/appcache/appcache_service.h"
using content::BrowserThread;
+using content::ResourceContext;
using content::WebContents;
namespace {
@@ -61,12 +63,12 @@ OfflineResourceThrottle::OfflineResourceThrottle(
int render_process_id,
int render_view_id,
net::URLRequest* request,
- ChromeAppCacheService* appcache_service)
+ content::ResourceContext* resource_context)
: render_process_id_(render_process_id),
render_view_id_(render_view_id),
request_(request),
- appcache_service_(appcache_service) {
- DCHECK(appcache_service_);
+ resource_context_(resource_context) {
+ DCHECK(resource_context);
}
OfflineResourceThrottle::~OfflineResourceThrottle() {
@@ -87,10 +89,11 @@ void OfflineResourceThrottle::WillStartRequest(bool* defer) {
appcache_completion_callback_.Reset(
base::Bind(&OfflineResourceThrottle::OnCanHandleOfflineComplete,
AsWeakPtr()));
- appcache_service_->CanHandleMainResourceOffline(
- request_->url(),
- request_->first_party_for_cookies(),
- appcache_completion_callback_.callback());
+ ResourceContext::GetAppCacheService(resource_context_)->
+ CanHandleMainResourceOffline(
+ request_->url(),
+ request_->first_party_for_cookies(),
+ appcache_completion_callback_.callback());
*defer = true;
}
diff --git a/chrome/browser/renderer_host/offline_resource_throttle.h b/chrome/browser/renderer_host/offline_resource_throttle.h
index 589e84b..1844860 100644
--- a/chrome/browser/renderer_host/offline_resource_throttle.h
+++ b/chrome/browser/renderer_host/offline_resource_throttle.h
@@ -17,6 +17,10 @@
class ChromeAppCacheService;
class ResourceDispatcherHost;
+namespace content {
+class ResourceContext;
+}
+
namespace net {
class URLRequest;
} // namespace net
@@ -29,7 +33,7 @@ class OfflineResourceThrottle
OfflineResourceThrottle(int render_process_id,
int render_view_id,
net::URLRequest* request,
- ChromeAppCacheService* appcache_service);
+ content::ResourceContext* resource_context);
virtual ~OfflineResourceThrottle();
// content::ResourceThrottle implementation:
@@ -52,7 +56,8 @@ class OfflineResourceThrottle
int render_process_id_;
int render_view_id_;
net::URLRequest* request_;
- ChromeAppCacheService* const appcache_service_;
+ // Safe to keep a pointer around since ResourceContext outlives all requests.
+ content::ResourceContext* resource_context_;
net::CancelableCompletionCallback appcache_completion_callback_;
DISALLOW_COPY_AND_ASSIGN(OfflineResourceThrottle);
diff --git a/chrome/browser/ui/cocoa/content_settings/collected_cookies_mac.h b/chrome/browser/ui/cocoa/content_settings/collected_cookies_mac.h
index 5a67fd2..5ae4682 100644
--- a/chrome/browser/ui/cocoa/content_settings/collected_cookies_mac.h
+++ b/chrome/browser/ui/cocoa/content_settings/collected_cookies_mac.h
@@ -10,6 +10,7 @@
#include "chrome/browser/cookies_tree_model.h"
#include "chrome/browser/ui/cocoa/constrained_window_mac.h"
#import "chrome/browser/ui/cocoa/content_settings/cookie_tree_node.h"
+#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
@class CollectedCookiesWindowController;
diff --git a/chrome/browser/ui/webui/chrome_url_data_manager_backend.cc b/chrome/browser/ui/webui/chrome_url_data_manager_backend.cc
index 9199e84..fe6bfa7 100644
--- a/chrome/browser/ui/webui/chrome_url_data_manager_backend.cc
+++ b/chrome/browser/ui/webui/chrome_url_data_manager_backend.cc
@@ -24,7 +24,6 @@
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/url_constants.h"
-#include "content/browser/appcache/chrome_appcache_service.h"
#include "content/public/browser/browser_thread.h"
#include "googleurl/src/url_util.h"
#include "grit/platform_locale_settings.h"
@@ -35,6 +34,7 @@
#include "net/url_request/url_request_file_job.h"
#include "net/url_request/url_request_job.h"
#include "net/url_request/url_request_job_factory.h"
+#include "webkit/appcache/appcache_service.h"
#include "webkit/appcache/view_appcache_internals_job.h"
using content::BrowserThread;
@@ -329,7 +329,7 @@ class ChromeProtocolHandler
public:
ChromeProtocolHandler(
ChromeURLDataManagerBackend* backend,
- ChromeAppCacheService* appcache_service,
+ appcache::AppCacheService* appcache_service,
webkit_blob::BlobStorageController* blob_storage_controller);
~ChromeProtocolHandler();
@@ -339,7 +339,7 @@ class ChromeProtocolHandler
private:
// These members are owned by ProfileIOData, which owns this ProtocolHandler.
ChromeURLDataManagerBackend* const backend_;
- ChromeAppCacheService* const appcache_service_;
+ appcache::AppCacheService* const appcache_service_;
webkit_blob::BlobStorageController* const blob_storage_controller_;
DISALLOW_COPY_AND_ASSIGN(ChromeProtocolHandler);
@@ -347,7 +347,7 @@ class ChromeProtocolHandler
ChromeProtocolHandler::ChromeProtocolHandler(
ChromeURLDataManagerBackend* backend,
- ChromeAppCacheService* appcache_service,
+ appcache::AppCacheService* appcache_service,
webkit_blob::BlobStorageController* blob_storage_controller)
: backend_(backend),
appcache_service_(appcache_service),
@@ -396,7 +396,7 @@ ChromeURLDataManagerBackend::~ChromeURLDataManagerBackend() {
net::URLRequestJobFactory::ProtocolHandler*
ChromeURLDataManagerBackend::CreateProtocolHandler(
ChromeURLDataManagerBackend* backend,
- ChromeAppCacheService* appcache_service,
+ appcache::AppCacheService* appcache_service,
webkit_blob::BlobStorageController* blob_storage_controller) {
DCHECK(appcache_service);
DCHECK(blob_storage_controller);
diff --git a/chrome/browser/ui/webui/chrome_url_data_manager_backend.h b/chrome/browser/ui/webui/chrome_url_data_manager_backend.h
index c9271de..073fdc1 100644
--- a/chrome/browser/ui/webui/chrome_url_data_manager_backend.h
+++ b/chrome/browser/ui/webui/chrome_url_data_manager_backend.h
@@ -15,12 +15,15 @@
#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
#include "net/url_request/url_request_job_factory.h"
-class ChromeAppCacheService;
class ChromeURLDataManagerBackend;
class GURL;
class RefCountedMemory;
class URLRequestChromeJob;
+namespace appcache {
+class AppCacheService;
+}
+
namespace net {
class URLRequest;
class URLRequestJob;
@@ -43,7 +46,7 @@ class ChromeURLDataManagerBackend {
// Invoked to create the protocol handler for chrome://.
static net::URLRequestJobFactory::ProtocolHandler* CreateProtocolHandler(
ChromeURLDataManagerBackend* backend,
- ChromeAppCacheService* appcache_service,
+ appcache::AppCacheService* appcache_service,
webkit_blob::BlobStorageController* blob_storage_controller);
// Adds a DataSource to the collection of data sources.
diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc
index 30f6b39..d2821e7 100644
--- a/chrome/test/base/testing_profile.cc
+++ b/chrome/test/base/testing_profile.cc
@@ -628,7 +628,9 @@ net::URLRequestContextGetter* TestingProfile::GetRequestContextForIsolatedApp(
}
content::ResourceContext* TestingProfile::GetResourceContext() {
- return content::MockResourceContext::GetInstance();
+ if (!resource_context_.get())
+ resource_context_.reset(new content::MockResourceContext());
+ return resource_context_.get();
}
HostContentSettingsMap* TestingProfile::GetHostContentSettingsMap() {
diff --git a/chrome/test/base/testing_profile.h b/chrome/test/base/testing_profile.h
index d39f3a2..f4db9ab 100644
--- a/chrome/test/base/testing_profile.h
+++ b/chrome/test/base/testing_profile.h
@@ -16,6 +16,7 @@
#include "content/browser/appcache/chrome_appcache_service.h"
namespace content {
+class MockResourceContext;
class SpeechInputPreferences;
}
@@ -384,6 +385,8 @@ class TestingProfile : public Profile {
// testing.
ProfileDependencyManager* profile_dependency_manager_;
+ scoped_ptr<content::MockResourceContext> resource_context_;
+
// 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 9be6b05..14e6ed2 100644
--- a/content/browser/appcache/chrome_appcache_service.cc
+++ b/content/browser/appcache/chrome_appcache_service.cc
@@ -9,6 +9,7 @@
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
+#include "content/public/browser/resource_context.h"
#include "net/base/net_errors.h"
#include "webkit/quota/quota_manager.h"
@@ -28,6 +29,7 @@ void ChromeAppCacheService::InitializeOnIOThread(
cache_path_ = cache_path;
resource_context_ = resource_context;
+ set_request_context(resource_context->GetRequestContext());
registrar_.Add(
this, content::NOTIFICATION_PURGE_MEMORY,
content::NotificationService::AllSources());
diff --git a/content/browser/appcache/chrome_appcache_service_unittest.cc b/content/browser/appcache/chrome_appcache_service_unittest.cc
index 7e59dcb..29b7956 100644
--- a/content/browser/appcache/chrome_appcache_service_unittest.cc
+++ b/content/browser/appcache/chrome_appcache_service_unittest.cc
@@ -9,6 +9,7 @@
#include "base/scoped_temp_dir.h"
#include "content/browser/browser_thread_impl.h"
#include "content/browser/appcache/chrome_appcache_service.h"
+#include "content/test/test_browser_context.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/appcache/appcache_database.h"
#include "webkit/appcache/appcache_storage_impl.h"
@@ -65,6 +66,7 @@ class ChromeAppCacheServiceTest : public testing::Test {
BrowserThreadImpl file_user_blocking_thread_;
BrowserThreadImpl cache_thread_;
BrowserThreadImpl io_thread_;
+ TestBrowserContext browser_context_;
};
scoped_refptr<ChromeAppCacheService>
@@ -73,7 +75,6 @@ ChromeAppCacheServiceTest::CreateAppCacheService(
bool init_storage) {
scoped_refptr<ChromeAppCacheService> appcache_service =
new ChromeAppCacheService(NULL);
- content::ResourceContext* resource_context = NULL;
scoped_refptr<quota::MockSpecialStoragePolicy> mock_policy =
new quota::MockSpecialStoragePolicy;
mock_policy->AddProtected(kProtectedManifestURL.GetOrigin());
@@ -81,8 +82,8 @@ ChromeAppCacheServiceTest::CreateAppCacheService(
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&ChromeAppCacheService::InitializeOnIOThread,
- appcache_service.get(), appcache_path, resource_context,
- mock_policy));
+ appcache_service.get(), appcache_path,
+ browser_context_.GetResourceContext(), mock_policy));
// Steps needed to initialize the storage of AppCache data.
message_loop_.RunAllPending();
if (init_storage) {
diff --git a/content/browser/browser_context.cc b/content/browser/browser_context.cc
index 1461b14..d56e797 100644
--- a/content/browser/browser_context.cc
+++ b/content/browser/browser_context.cc
@@ -5,21 +5,23 @@
#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/browser/resource_context_impl.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 appcache::AppCacheService;
+using base::UserDataAdapter;
using content::BrowserThread;
using fileapi::FileSystemContext;
using quota::QuotaManager;
using webkit_database::DatabaseTracker;
+// Key names on BrowserContext.
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";
@@ -27,25 +29,6 @@ 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));
@@ -96,16 +79,18 @@ void CreateQuotaManagerAndClients(BrowserContext* context) {
kAppCacheServicKeyName,
new UserDataAdapter<ChromeAppCacheService>(appcache_service));
+ InitializeResourceContext(context);
+
// 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())));
+ 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())));
}
}
@@ -125,7 +110,7 @@ DatabaseTracker* BrowserContext::GetDatabaseTracker(BrowserContext* context) {
context, kDatabaseTrackerKeyName);
}
-ChromeAppCacheService* BrowserContext::GetAppCacheService(
+AppCacheService* BrowserContext::GetAppCacheService(
BrowserContext* browser_context) {
CreateQuotaManagerAndClients(browser_context);
return UserDataAdapter<ChromeAppCacheService>::Get(
@@ -139,20 +124,10 @@ FileSystemContext* BrowserContext::GetFileSystemContext(
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);
+void BrowserContext::EnsureResourceContextInitialized(BrowserContext* context) {
+ if (context->GetResourceContext()->GetUserData(kWebKitContextKeyName))
+ return;
+ InitializeResourceContext(context);
}
BrowserContext::~BrowserContext() {
diff --git a/content/browser/chrome_blob_storage_context.cc b/content/browser/chrome_blob_storage_context.cc
index 85a706c..6f607f2 100644
--- a/content/browser/chrome_blob_storage_context.cc
+++ b/content/browser/chrome_blob_storage_context.cc
@@ -4,11 +4,36 @@
#include "content/browser/chrome_blob_storage_context.h"
+#include "base/bind.h"
+#include "content/public/browser/browser_context.h"
#include "webkit/blob/blob_storage_controller.h"
+using base::UserDataAdapter;
+using content::BrowserContext;
using content::BrowserThread;
using webkit_blob::BlobStorageController;
+static const char* kBlobStorageContextKeyName = "content_blob_storage_context";
+
+ChromeBlobStorageContext* ChromeBlobStorageContext::GetFor(
+ BrowserContext* context) {
+ if (!context->GetUserData(kBlobStorageContextKeyName)) {
+ scoped_refptr<ChromeBlobStorageContext> blob =
+ new ChromeBlobStorageContext();
+ context->SetUserData(kBlobStorageContextKeyName,
+ new UserDataAdapter<ChromeBlobStorageContext>(blob));
+ // Check first to avoid memory leak in unittests.
+ if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&ChromeBlobStorageContext::InitializeOnIOThread, blob));
+ }
+ }
+
+ return UserDataAdapter<ChromeBlobStorageContext>::Get(
+ context, kBlobStorageContextKeyName);
+}
+
ChromeBlobStorageContext::ChromeBlobStorageContext() {
}
@@ -20,3 +45,12 @@ void ChromeBlobStorageContext::InitializeOnIOThread() {
ChromeBlobStorageContext::~ChromeBlobStorageContext() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
}
+
+void ChromeBlobStorageContext::DeleteOnCorrectThread() const {
+ if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) &&
+ !BrowserThread::CurrentlyOn(BrowserThread::IO)) {
+ BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this);
+ return;
+ }
+ delete this;
+}
diff --git a/content/browser/chrome_blob_storage_context.h b/content/browser/chrome_blob_storage_context.h
index e83271c..0b5c820 100644
--- a/content/browser/chrome_blob_storage_context.h
+++ b/content/browser/chrome_blob_storage_context.h
@@ -12,10 +12,16 @@
#include "content/common/content_export.h"
#include "content/public/browser/browser_thread.h"
+namespace content {
+class BrowserContext;
+}
+
namespace webkit_blob {
class BlobStorageController;
}
+struct ChromeBlobStorageContextDeleter;
+
// A context class that keeps track of BlobStorageController used by the chrome.
// There is an instance associated with each BrowserContext. There could be
// multiple URLRequestContexts in the same browser context that refers to the
@@ -25,9 +31,13 @@ class BlobStorageController;
// the IO thread (unless specifically called out in doc comments).
class CONTENT_EXPORT ChromeBlobStorageContext
: public base::RefCountedThreadSafe<
- ChromeBlobStorageContext, content::BrowserThread::DeleteOnIOThread> {
+ ChromeBlobStorageContext, ChromeBlobStorageContextDeleter> {
public:
+ static ChromeBlobStorageContext* GetFor(
+ content::BrowserContext* browser_context);
+
ChromeBlobStorageContext();
+ virtual ~ChromeBlobStorageContext();
void InitializeOnIOThread();
@@ -36,14 +46,17 @@ class CONTENT_EXPORT ChromeBlobStorageContext
}
private:
- friend class base::RefCountedThreadSafe<
- ChromeBlobStorageContext, content::BrowserThread::DeleteOnIOThread>;
- friend class content::BrowserThread;
- friend class base::DeleteHelper<ChromeBlobStorageContext>;
+ friend struct ChromeBlobStorageContextDeleter;
- virtual ~ChromeBlobStorageContext();
+ void DeleteOnCorrectThread() const;
scoped_ptr<webkit_blob::BlobStorageController> controller_;
};
+struct ChromeBlobStorageContextDeleter {
+ static void Destruct(const ChromeBlobStorageContext* context) {
+ context->DeleteOnCorrectThread();
+ }
+};
+
#endif // CONTENT_BROWSER_CHROME_BLOB_STORAGE_CONTEXT_H_
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 0689eeb..c886c0d 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
@@ -42,12 +42,16 @@ class IndexedDBQuotaClientTest : public testing::Test {
usage_(0),
weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
message_loop_(MessageLoop::TYPE_IO),
+ db_thread_(BrowserThread::DB, &message_loop_),
webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &message_loop_),
- file_thread_(BrowserThread::FILE_USER_BLOCKING, &message_loop_),
+ file_thread_(BrowserThread::FILE, &message_loop_),
+ file_user_blocking_thread_(
+ BrowserThread::FILE_USER_BLOCKING, &message_loop_),
io_thread_(BrowserThread::IO, &message_loop_) {
- TestBrowserContext browser_context;
- idb_context_ = BrowserContext::GetWebKitContext(&browser_context)->
+ browser_context_.reset(new TestBrowserContext());
+ idb_context_ = BrowserContext::GetWebKitContext(browser_context_.get())->
indexed_db_context();
+ message_loop_.RunAllPending();
setup_temp_dir();
}
void setup_temp_dir() {
@@ -64,6 +68,7 @@ class IndexedDBQuotaClientTest : public testing::Test {
// class. Cause IndexedDBContext's destruction now to ensure that it
// doesn't outlive BrowserThread::WEBKIT_DEPRECATED.
idb_context_ = NULL;
+ browser_context_.reset();
MessageLoop::current()->RunAllPending();
}
@@ -160,9 +165,12 @@ class IndexedDBQuotaClientTest : public testing::Test {
scoped_refptr<IndexedDBContext> idb_context_;
base::WeakPtrFactory<IndexedDBQuotaClientTest> weak_factory_;
MessageLoop message_loop_;
+ BrowserThreadImpl db_thread_;
BrowserThreadImpl webkit_thread_;
BrowserThreadImpl file_thread_;
+ BrowserThreadImpl file_user_blocking_thread_;
BrowserThreadImpl io_thread_;
+ scoped_ptr<TestBrowserContext> browser_context_;
quota::QuotaStatusCode delete_status_;
};
diff --git a/content/browser/mock_resource_context.cc b/content/browser/mock_resource_context.cc
index 6baef2c..170b4e6 100644
--- a/content/browser/mock_resource_context.cc
+++ b/content/browser/mock_resource_context.cc
@@ -40,26 +40,6 @@ net::URLRequestContext* MockResourceContext::GetRequestContext() {
return test_request_context_;
}
-ChromeAppCacheService* MockResourceContext::GetAppCacheService() {
- return NULL;
-}
-
-webkit_database::DatabaseTracker* MockResourceContext::GetDatabaseTracker() {
- return NULL;
-}
-
-fileapi::FileSystemContext* MockResourceContext::GetFileSystemContext() {
- return NULL;
-}
-
-ChromeBlobStorageContext* MockResourceContext::GetBlobStorageContext() {
- return NULL;
-}
-
-quota::QuotaManager* MockResourceContext::GetQuotaManager() {
- return NULL;
-}
-
HostZoomMap* MockResourceContext::GetHostZoomMap() {
return NULL;
}
@@ -77,8 +57,4 @@ AudioManager* MockResourceContext::GetAudioManager() {
return audio_manager_;
}
-WebKitContext* MockResourceContext::GetWebKitContext() {
- return NULL;
-}
-
} // namespace content
diff --git a/content/browser/mock_resource_context.h b/content/browser/mock_resource_context.h
index 73be660..8841945 100644
--- a/content/browser/mock_resource_context.h
+++ b/content/browser/mock_resource_context.h
@@ -43,16 +43,10 @@ class MockResourceContext : public ResourceContext {
// ResourceContext implementation:
virtual net::HostResolver* GetHostResolver() OVERRIDE;
virtual net::URLRequestContext* GetRequestContext() OVERRIDE;
- virtual ChromeAppCacheService* GetAppCacheService() OVERRIDE;
- virtual webkit_database::DatabaseTracker* GetDatabaseTracker() OVERRIDE;
- virtual fileapi::FileSystemContext* GetFileSystemContext() OVERRIDE;
- virtual ChromeBlobStorageContext* GetBlobStorageContext() OVERRIDE;
- virtual quota::QuotaManager* GetQuotaManager() OVERRIDE;
virtual HostZoomMap* GetHostZoomMap() OVERRIDE;
virtual MediaObserver* GetMediaObserver() OVERRIDE;
virtual media_stream::MediaStreamManager* GetMediaStreamManager() OVERRIDE;
virtual AudioManager* GetAudioManager() OVERRIDE;
- virtual WebKitContext* GetWebKitContext() OVERRIDE;
private:
friend struct base::DefaultLazyInstanceTraits<MockResourceContext>;
diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc
index 0174d49..ef91b71 100644
--- a/content/browser/renderer_host/render_process_host_impl.cc
+++ b/content/browser/renderer_host/render_process_host_impl.cc
@@ -39,8 +39,10 @@
#include "base/threading/thread_restrictions.h"
#include "base/tracked_objects.h"
#include "content/browser/appcache/appcache_dispatcher_host.h"
+#include "content/browser/appcache/chrome_appcache_service.h"
#include "content/browser/browser_main.h"
#include "content/browser/child_process_security_policy_impl.h"
+#include "content/browser/chrome_blob_storage_context.h"
#include "content/browser/device_orientation/message_filter.h"
#include "content/browser/download/mhtml_generation_manager.h"
#include "content/browser/file_system/file_system_dispatcher_host.h"
@@ -461,7 +463,9 @@ void RenderProcessHostImpl::CreateMessageFilters() {
channel_->AddFilter(new AudioRendererHost(resource_context));
channel_->AddFilter(new VideoCaptureHost(resource_context));
channel_->AddFilter(new AppCacheDispatcherHost(
- BrowserContext::GetAppCacheService(browser_context), GetID()));
+ static_cast<ChromeAppCacheService*>(
+ BrowserContext::GetAppCacheService(browser_context)),
+ GetID()));
channel_->AddFilter(new ClipboardMessageFilter());
channel_->AddFilter(new DOMStorageMessageFilter(GetID(),
BrowserContext::GetWebKitContext(browser_context)));
@@ -483,7 +487,7 @@ void RenderProcessHostImpl::CreateMessageFilters() {
BrowserContext::GetFileSystemContext(browser_context)));
channel_->AddFilter(new device_orientation::MessageFilter());
channel_->AddFilter(new BlobMessageFilter(GetID(),
- BrowserContext::GetBlobStorageContext(browser_context)));
+ ChromeBlobStorageContext::GetFor(browser_context)));
channel_->AddFilter(new FileUtilitiesMessageFilter(GetID()));
channel_->AddFilter(new MimeRegistryMessageFilter());
channel_->AddFilter(new DatabaseMessageFilter(
diff --git a/content/browser/renderer_host/resource_dispatcher_host.cc b/content/browser/renderer_host/resource_dispatcher_host.cc
index 5b73ae8..dc1224e 100644
--- a/content/browser/renderer_host/resource_dispatcher_host.cc
+++ b/content/browser/renderer_host/resource_dispatcher_host.cc
@@ -90,6 +90,7 @@ using base::TimeDelta;
using base::TimeTicks;
using content::BrowserThread;
using content::GlobalRequestID;
+using content::ResourceContext;
using content::ResourceResponse;
using content::ResourceThrottle;
using content::ThrottlingResourceHandler;
@@ -541,7 +542,7 @@ void ResourceDispatcherHost::BeginRequest(
// Might need to resolve the blob references in the upload data.
if (request_data.upload_data) {
- resource_context->GetBlobStorageContext()->controller()->
+ ResourceContext::GetBlobStorageController(resource_context)->
ResolveBlobReferencesInUploadData(request_data.upload_data.get());
}
@@ -716,14 +717,14 @@ void ResourceDispatcherHost::BeginRequest(
// Hang on to a reference to ensure the blob is not released prior
// to the job being started.
webkit_blob::BlobStorageController* controller =
- resource_context->GetBlobStorageContext()->controller();
+ ResourceContext::GetBlobStorageController(resource_context);
extra_info->set_requested_blob_data(
controller->GetBlobDataFromUrl(request->url()));
}
// Have the appcache associate its extra info with the request.
appcache::AppCacheInterceptor::SetExtraRequestInfo(
- request, resource_context->GetAppCacheService(), child_id,
+ request, ResourceContext::GetAppCacheService(resource_context), child_id,
request_data.appcache_host_id, request_data.resource_type);
if (deferred_request) {
diff --git a/content/browser/renderer_host/resource_dispatcher_host_unittest.cc b/content/browser/renderer_host/resource_dispatcher_host_unittest.cc
index 3bf44bd..20d629a 100644
--- a/content/browser/renderer_host/resource_dispatcher_host_unittest.cc
+++ b/content/browser/renderer_host/resource_dispatcher_host_unittest.cc
@@ -26,6 +26,7 @@
#include "content/public/browser/resource_dispatcher_host_delegate.h"
#include "content/public/browser/resource_throttle.h"
#include "content/public/common/resource_response.h"
+#include "content/test/test_browser_context.h"
#include "net/base/net_errors.h"
#include "net/base/upload_data.h"
#include "net/http/http_util.h"
@@ -35,14 +36,10 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/appcache/appcache_interfaces.h"
-namespace content {
-class DownloadManager;
-} // namespace content
-
+using content::BrowserContext;
using content::BrowserThread;
using content::BrowserThreadImpl;
using content::ChildProcessHostImpl;
-using content::DownloadManager;
using content::GlobalRequestID;
// TODO(eroman): Write unit tests for SafeBrowsing that exercise
@@ -169,11 +166,12 @@ class MockURLRequestContextSelector
// messages to go to the same place, which is why this forwards.
class ForwardingFilter : public ResourceMessageFilter {
public:
- explicit ForwardingFilter(IPC::Message::Sender* dest)
+ explicit ForwardingFilter(IPC::Message::Sender* dest,
+ content::ResourceContext* resource_context)
: ResourceMessageFilter(
ChildProcessHostImpl::GenerateChildProcessUniqueId(),
content::PROCESS_TYPE_RENDERER,
- content::MockResourceContext::GetInstance(),
+ resource_context,
new MockURLRequestContextSelector(
content::MockResourceContext::GetInstance()->GetRequestContext())),
dest_(dest) {
@@ -334,10 +332,16 @@ class ResourceDispatcherHostTest : public testing::Test,
public:
ResourceDispatcherHostTest()
: ui_thread_(BrowserThread::UI, &message_loop_),
+ file_thread_(BrowserThread::FILE_USER_BLOCKING, &message_loop_),
+ cache_thread_(BrowserThread::CACHE, &message_loop_),
io_thread_(BrowserThread::IO, &message_loop_),
- ALLOW_THIS_IN_INITIALIZER_LIST(filter_(new ForwardingFilter(this))),
old_factory_(NULL),
resource_type_(ResourceType::SUB_RESOURCE) {
+ browser_context_.reset(new TestBrowserContext());
+ BrowserContext::EnsureResourceContextInitialized(browser_context_.get());
+ message_loop_.RunAllPending();
+ filter_ = new ForwardingFilter(
+ this, browser_context_->GetResourceContext());
}
// IPC::Message::Sender implementation
virtual bool Send(IPC::Message* msg) {
@@ -376,6 +380,7 @@ class ResourceDispatcherHostTest : public testing::Test,
ChildProcessSecurityPolicyImpl::GetInstance()->Remove(0);
// Flush the message loop to make application verifiers happy.
+ browser_context_.reset();
message_loop_.RunAllPending();
}
@@ -457,7 +462,10 @@ class ResourceDispatcherHostTest : public testing::Test,
MessageLoopForIO message_loop_;
BrowserThreadImpl ui_thread_;
+ BrowserThreadImpl file_thread_;
+ BrowserThreadImpl cache_thread_;
BrowserThreadImpl io_thread_;
+ scoped_ptr<TestBrowserContext> browser_context_;
scoped_refptr<ForwardingFilter> filter_;
ResourceDispatcherHost host_;
ResourceIPCAccumulator accum_;
@@ -698,8 +706,8 @@ TEST_F(ResourceDispatcherHostTest, PausedCancel) {
// pending and some canceled.
class TestFilter : public ForwardingFilter {
public:
- TestFilter()
- : ForwardingFilter(NULL),
+ explicit TestFilter(content::ResourceContext* resource_context)
+ : ForwardingFilter(NULL, resource_context),
has_canceled_(false),
received_after_canceled_(0) {
}
@@ -718,7 +726,8 @@ class TestFilter : public ForwardingFilter {
// Tests CancelRequestsForProcess
TEST_F(ResourceDispatcherHostTest, TestProcessCancel) {
- scoped_refptr<TestFilter> test_filter = new TestFilter();
+ scoped_refptr<TestFilter> test_filter = new TestFilter(
+ browser_context_->GetResourceContext());
// request 1 goes to the test delegate
ResourceHostMsg_Request request = CreateResourceRequest(
@@ -871,7 +880,8 @@ TEST_F(ResourceDispatcherHostTest, TestBlockingCancelingRequests) {
// Tests that blocked requests are canceled if their associated process dies.
TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsProcessDies) {
// This second filter is used to emulate a second process.
- scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter(this);
+ scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter(
+ this, browser_context_->GetResourceContext());
EXPECT_EQ(0, host_.GetOutstandingRequestsMemoryCost(filter_->child_id()));
EXPECT_EQ(0,
@@ -915,7 +925,8 @@ TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsProcessDies) {
// destructor to make sure the blocked requests are deleted.
TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsDontLeak) {
// This second filter is used to emulate a second process.
- scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter(this);
+ scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter(
+ this, browser_context_->GetResourceContext());
host_.BlockRequestsForRoute(filter_->child_id(), 1);
host_.BlockRequestsForRoute(filter_->child_id(), 2);
@@ -1006,7 +1017,8 @@ TEST_F(ResourceDispatcherHostTest, TooManyOutstandingRequests) {
size_t kMaxRequests = kMaxCostPerProcess / kMemoryCostOfTest2Req;
// This second filter is used to emulate a second process.
- scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter(this);
+ scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter(
+ this, browser_context_->GetResourceContext());
// Saturate the number of outstanding requests for our process.
for (size_t i = 0; i < kMaxRequests; ++i) {
diff --git a/content/browser/resource_context_impl.cc b/content/browser/resource_context_impl.cc
new file mode 100644
index 0000000..d7cbeab
--- /dev/null
+++ b/content/browser/resource_context_impl.cc
@@ -0,0 +1,92 @@
+// 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/browser/resource_context_impl.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_context.h"
+#include "content/public/browser/browser_thread.h"
+#include "webkit/database/database_tracker.h"
+
+// Key names on ResourceContext.
+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* kWebKitContextKeyName = "content_webkit_context";
+
+using appcache::AppCacheService;
+using base::UserDataAdapter;
+using content::BrowserThread;
+using fileapi::FileSystemContext;
+using webkit_blob::BlobStorageController;
+using webkit_database::DatabaseTracker;
+
+namespace content {
+
+AppCacheService* ResourceContext::GetAppCacheService(ResourceContext* context) {
+ return UserDataAdapter<ChromeAppCacheService>::Get(
+ context, kAppCacheServicKeyName);
+}
+
+FileSystemContext* ResourceContext::GetFileSystemContext(
+ ResourceContext* resource_context) {
+ return UserDataAdapter<FileSystemContext>::Get(
+ resource_context, kFileSystemContextKeyName);
+}
+
+BlobStorageController* ResourceContext::GetBlobStorageController(
+ ResourceContext* resource_context) {
+ return GetChromeBlobStorageContextForResourceContext(resource_context)->
+ controller();
+}
+
+DatabaseTracker* GetDatabaseTrackerForResourceContext(
+ ResourceContext* resource_context) {
+ return UserDataAdapter<DatabaseTracker>::Get(
+ resource_context, kDatabaseTrackerKeyName);
+}
+
+WebKitContext* GetWebKitContextForResourceContext(
+ ResourceContext* resource_context) {
+ return UserDataAdapter<WebKitContext>::Get(
+ resource_context, kWebKitContextKeyName);
+}
+
+ChromeBlobStorageContext* GetChromeBlobStorageContextForResourceContext(
+ ResourceContext* resource_context) {
+ return UserDataAdapter<ChromeBlobStorageContext>::Get(
+ resource_context, kBlobStorageContextKeyName);
+}
+
+void InitializeResourceContext(BrowserContext* browser_context) {
+ ResourceContext* resource_context = browser_context->GetResourceContext();
+ DCHECK(!resource_context->GetUserData(kWebKitContextKeyName));
+ resource_context->SetUserData(
+ kWebKitContextKeyName,
+ new UserDataAdapter<WebKitContext>(
+ BrowserContext::GetWebKitContext(browser_context)));
+ resource_context->SetUserData(
+ kDatabaseTrackerKeyName,
+ new UserDataAdapter<webkit_database::DatabaseTracker>(
+ BrowserContext::GetDatabaseTracker(browser_context)));
+ resource_context->SetUserData(
+ kAppCacheServicKeyName,
+ new UserDataAdapter<ChromeAppCacheService>(
+ static_cast<ChromeAppCacheService*>(
+ BrowserContext::GetAppCacheService(browser_context))));
+ resource_context->SetUserData(
+ kFileSystemContextKeyName,
+ new UserDataAdapter<FileSystemContext>(
+ BrowserContext::GetFileSystemContext(browser_context)));
+ resource_context->SetUserData(
+ kBlobStorageContextKeyName,
+ new UserDataAdapter<ChromeBlobStorageContext>(
+ ChromeBlobStorageContext::GetFor(browser_context)));
+}
+
+} // namespace content
diff --git a/content/browser/resource_context_impl.h b/content/browser/resource_context_impl.h
new file mode 100644
index 0000000..ba06635
--- /dev/null
+++ b/content/browser/resource_context_impl.h
@@ -0,0 +1,36 @@
+// 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.
+
+#ifndef CONTENT_BROWSER_RESOURCE_CONTEXT_IMPL_H_
+#define CONTENT_BROWSER_RESOURCE_CONTEXT_IMPL_H_
+
+#include "content/public/browser/resource_context.h"
+
+class ChromeBlobStorageContext;
+class WebKitContext;
+
+namespace webkit_database {
+class DatabaseTracker;
+}
+
+namespace content {
+
+class BrowserContext;
+
+// Getters for objects that are part of BrowserContext which are also used on
+// the IO thread. These are only accessed by content so they're not on the
+// public API.
+webkit_database::DatabaseTracker* GetDatabaseTrackerForResourceContext(
+ ResourceContext* resource_context);
+WebKitContext* GetWebKitContextForResourceContext(
+ ResourceContext* resource_context);
+ChromeBlobStorageContext* GetChromeBlobStorageContextForResourceContext(
+ ResourceContext* resource_context);
+
+// Initialize the above data on the ResourceContext from a given BrowserContext.
+void InitializeResourceContext(BrowserContext* browser_context);
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_RESOURCE_CONTEXT_IMPL_H_
diff --git a/content/browser/worker_host/worker_process_host.cc b/content/browser/worker_host/worker_process_host.cc
index f74f64f..c9d3757 100644
--- a/content/browser/worker_host/worker_process_host.cc
+++ b/content/browser/worker_host/worker_process_host.cc
@@ -16,6 +16,7 @@
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "content/browser/appcache/appcache_dispatcher_host.h"
+#include "content/browser/appcache/chrome_appcache_service.h"
#include "content/browser/browser_child_process_host_impl.h"
#include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/debugger/worker_devtools_manager.h"
@@ -28,6 +29,7 @@
#include "content/browser/renderer_host/file_utilities_message_filter.h"
#include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/renderer_host/socket_stream_dispatcher_host.h"
+#include "content/browser/resource_context_impl.h"
#include "content/browser/worker_host/message_port_service.h"
#include "content/browser/worker_host/worker_message_filter.h"
#include "content/browser/worker_host/worker_service_impl.h"
@@ -38,7 +40,6 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/render_view_host_delegate.h"
-#include "content/public/browser/resource_context.h"
#include "content/public/browser/user_metrics.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/result_codes.h"
@@ -53,6 +54,7 @@
using content::BrowserThread;
using content::ChildProcessData;
using content::ChildProcessHost;
+using content::ResourceContext;
using content::UserMetricsAction;
using content::WorkerDevToolsManager;
using content::WorkerServiceImpl;
@@ -194,6 +196,8 @@ bool WorkerProcessHost::Init(int render_process_id) {
#endif
cmd_line);
+ fileapi::FileSystemContext* file_system_context =
+ ResourceContext::GetFileSystemContext(resource_context_);
ChildProcessSecurityPolicyImpl::GetInstance()->AddWorker(
process_->GetData().id, render_process_id);
if (!CommandLine::ForCurrentProcess()->HasSwitch(
@@ -204,8 +208,8 @@ bool WorkerProcessHost::Init(int render_process_id) {
// requests them.
// This is for the filesystem sandbox.
ChildProcessSecurityPolicyImpl::GetInstance()->GrantPermissionsForFile(
- process_->GetData().id, resource_context_->GetFileSystemContext()->
- sandbox_provider()->new_base_path(),
+ process_->GetData().id,
+ file_system_context->sandbox_provider()->new_base_path(),
base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_CREATE |
base::PLATFORM_FILE_OPEN_ALWAYS |
@@ -221,16 +225,16 @@ bool WorkerProcessHost::Init(int render_process_id) {
// This is so that we can read and move stuff out of the old filesystem
// sandbox.
ChildProcessSecurityPolicyImpl::GetInstance()->GrantPermissionsForFile(
- process_->GetData().id, resource_context_->GetFileSystemContext()->
- sandbox_provider()->old_base_path(),
+ process_->GetData().id,
+ file_system_context->sandbox_provider()->old_base_path(),
base::PLATFORM_FILE_READ | base::PLATFORM_FILE_WRITE |
base::PLATFORM_FILE_WRITE_ATTRIBUTES |
base::PLATFORM_FILE_ENUMERATE);
// This is so that we can rename the old sandbox out of the way so that
// we know we've taken care of it.
ChildProcessSecurityPolicyImpl::GetInstance()->GrantPermissionsForFile(
- process_->GetData().id, resource_context_->GetFileSystemContext()->
- sandbox_provider()->renamed_old_base_path(),
+ process_->GetData().id,
+ file_system_context->sandbox_provider()->renamed_old_base_path(),
base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_CREATE_ALWAYS |
base::PLATFORM_FILE_WRITE);
}
@@ -255,16 +259,21 @@ void WorkerProcessHost::CreateMessageFilters(int render_process_id) {
base::Unretained(WorkerServiceImpl::GetInstance())));
process_->GetHost()->AddFilter(worker_message_filter_);
process_->GetHost()->AddFilter(new AppCacheDispatcherHost(
- resource_context_->GetAppCacheService(), process_->GetData().id));
+ static_cast<ChromeAppCacheService*>(
+ ResourceContext::GetAppCacheService(resource_context_)),
+ process_->GetData().id));
process_->GetHost()->AddFilter(new FileSystemDispatcherHost(
- request_context, resource_context_->GetFileSystemContext()));
+ request_context,
+ ResourceContext::GetFileSystemContext(resource_context_)));
process_->GetHost()->AddFilter(new FileUtilitiesMessageFilter(
process_->GetData().id));
process_->GetHost()->AddFilter(new BlobMessageFilter(
- process_->GetData().id, resource_context_->GetBlobStorageContext()));
+ process_->GetData().id,
+ content::GetChromeBlobStorageContextForResourceContext(
+ resource_context_)));
process_->GetHost()->AddFilter(new MimeRegistryMessageFilter());
process_->GetHost()->AddFilter(new DatabaseMessageFilter(
- resource_context_->GetDatabaseTracker()));
+ content::GetDatabaseTrackerForResourceContext(resource_context_)));
SocketStreamDispatcherHost* socket_stream_dispatcher_host =
new SocketStreamDispatcherHost(
@@ -273,7 +282,8 @@ void WorkerProcessHost::CreateMessageFilters(int render_process_id) {
process_->GetHost()->AddFilter(
new content::WorkerDevToolsMessageFilter(process_->GetData().id));
process_->GetHost()->AddFilter(new IndexedDBDispatcherHost(
- process_->GetData().id, resource_context_->GetWebKitContext()));
+ process_->GetData().id,
+ content::GetWebKitContextForResourceContext(resource_context_)));
}
void WorkerProcessHost::CreateWorker(const WorkerInstance& instance) {
diff --git a/content/content_browser.gypi b/content/content_browser.gypi
index ebcf8ed..37a09bb 100644
--- a/content/content_browser.gypi
+++ b/content/content_browser.gypi
@@ -580,6 +580,8 @@
'browser/renderer_host/x509_user_cert_resource_handler.h',
'browser/resolve_proxy_msg_helper.cc',
'browser/resolve_proxy_msg_helper.h',
+ 'browser/resource_context_impl.cc',
+ 'browser/resource_context_impl.h',
'browser/safe_util_win.cc',
'browser/safe_util_win.h',
'browser/sensors/sensors_provider_impl.cc',
diff --git a/content/public/browser/browser_context.h b/content/public/browser/browser_context.h
index dd00b4a..7a5e2e5 100644
--- a/content/public/browser/browser_context.h
+++ b/content/public/browser/browser_context.h
@@ -10,6 +10,10 @@
#include "base/supports_user_data.h"
#include "content/common/content_export.h"
+namespace appcache {
+class AppCacheService;
+}
+
namespace fileapi {
class FileSystemContext;
}
@@ -27,8 +31,6 @@ namespace webkit_database {
class DatabaseTracker;
}
-class ChromeAppCacheService;
-class ChromeBlobStorageContext;
class FilePath;
class WebKitContext;
@@ -49,12 +51,17 @@ class CONTENT_EXPORT BrowserContext : public base::SupportsUserData {
static WebKitContext* GetWebKitContext(BrowserContext* browser_context);
static webkit_database::DatabaseTracker* GetDatabaseTracker(
BrowserContext* browser_context);
- static ChromeAppCacheService* GetAppCacheService(
+ static appcache::AppCacheService* GetAppCacheService(
BrowserContext* browser_context);
static fileapi::FileSystemContext* GetFileSystemContext(
BrowserContext* browser_context);
- static ChromeBlobStorageContext* GetBlobStorageContext(
- BrowserContext* browser_context);
+
+ // Ensures that the corresponding ResourceContext is initialized. Normally the
+ // BrowserContext initializs the corresponding getters when its objects are
+ // created, but if the embedder wants to pass the ResourceContext to another
+ // thread before they use BrowserContext, they should call this to make sure
+ // that the ResourceContext is ready.
+ static void EnsureResourceContextInitialized(BrowserContext* browser_context);
virtual ~BrowserContext();
diff --git a/content/public/browser/resource_context.h b/content/public/browser/resource_context.h
index 7ad6097..94b36fc 100644
--- a/content/public/browser/resource_context.h
+++ b/content/public/browser/resource_context.h
@@ -6,28 +6,32 @@
#define CONTENT_PUBLIC_BROWSER_RESOURCE_CONTEXT_H_
#include "base/basictypes.h"
+#include "base/supports_user_data.h"
+#include "content/common/content_export.h"
class AudioManager;
-class ChromeAppCacheService;
-class ChromeBlobStorageContext;
class MediaObserver;
-class WebKitContext;
+
+namespace appcache {
+class AppCacheService;
+}
+
namespace fileapi {
class FileSystemContext;
-} // namespace fileapi
+}
+
namespace media_stream {
class MediaStreamManager;
-} // namespace media_stream
+}
+
namespace net {
class HostResolver;
class URLRequestContext;
-} // namespace net
-namespace quota {
-class QuotaManager;
-}; // namespace quota
-namespace webkit_database {
-class DatabaseTracker;
-} // namespace webkit_database
+}
+
+namespace webkit_blob {
+class BlobStorageController;
+}
namespace content {
@@ -36,22 +40,22 @@ class HostZoomMap;
// ResourceContext contains the relevant context information required for
// resource loading. It lives on the IO thread, although it is constructed on
// the UI thread.
-class ResourceContext {
+class CONTENT_EXPORT ResourceContext : public base::SupportsUserData {
public:
- virtual ~ResourceContext() {}
+ static appcache::AppCacheService* GetAppCacheService(
+ ResourceContext* resource_context);
+ static fileapi::FileSystemContext* GetFileSystemContext(
+ ResourceContext* resource_context);
+ static webkit_blob::BlobStorageController* GetBlobStorageController(
+ ResourceContext* resource_context);
+ virtual ~ResourceContext() {}
virtual net::HostResolver* GetHostResolver() = 0;
virtual net::URLRequestContext* GetRequestContext() = 0;
- virtual ChromeAppCacheService* GetAppCacheService() = 0;
- virtual webkit_database::DatabaseTracker* GetDatabaseTracker() = 0;
- virtual fileapi::FileSystemContext* GetFileSystemContext() = 0;
- virtual ChromeBlobStorageContext* GetBlobStorageContext() = 0;
- virtual quota::QuotaManager* GetQuotaManager() = 0;
virtual HostZoomMap* GetHostZoomMap() = 0;
virtual MediaObserver* GetMediaObserver() = 0;
virtual media_stream::MediaStreamManager* GetMediaStreamManager() = 0;
virtual AudioManager* GetAudioManager() = 0;
- virtual WebKitContext* GetWebKitContext() = 0;
};
} // namespace content
diff --git a/content/shell/shell_browser_context.cc b/content/shell/shell_browser_context.cc
index b118413..f98c43f 100644
--- a/content/shell/shell_browser_context.cc
+++ b/content/shell/shell_browser_context.cc
@@ -158,8 +158,7 @@ net::URLRequestContextGetter*
ResourceContext* ShellBrowserContext::GetResourceContext() {
if (!resource_context_.get()) {
resource_context_.reset(new ShellResourceContext(
- static_cast<ShellURLRequestContextGetter*>(GetRequestContext()),
- BrowserContext::GetBlobStorageContext(this)));
+ static_cast<ShellURLRequestContextGetter*>(GetRequestContext())));
}
return resource_context_.get();
}
diff --git a/content/shell/shell_resource_context.cc b/content/shell/shell_resource_context.cc
index e58c397..d8c3f29 100644
--- a/content/shell/shell_resource_context.cc
+++ b/content/shell/shell_resource_context.cc
@@ -3,17 +3,13 @@
// found in the LICENSE file.
#include "content/shell/shell_resource_context.h"
-
-#include "content/browser/chrome_blob_storage_context.h"
#include "content/shell/shell_url_request_context_getter.h"
namespace content {
ShellResourceContext::ShellResourceContext(
- ShellURLRequestContextGetter* getter,
- ChromeBlobStorageContext* blob_storage_context)
- : getter_(getter),
- blob_storage_context_(blob_storage_context) {
+ ShellURLRequestContextGetter* getter)
+ : getter_(getter) {
}
ShellResourceContext::~ShellResourceContext() {
@@ -27,26 +23,6 @@ net::URLRequestContext* ShellResourceContext::GetRequestContext() {
return getter_->GetURLRequestContext();
}
-ChromeAppCacheService* ShellResourceContext::GetAppCacheService() {
- return NULL;
-}
-
-webkit_database::DatabaseTracker* ShellResourceContext::GetDatabaseTracker() {
- return NULL;
-}
-
-fileapi::FileSystemContext* ShellResourceContext::GetFileSystemContext() {
- return NULL;
-}
-
-ChromeBlobStorageContext* ShellResourceContext::GetBlobStorageContext() {
- return blob_storage_context_;
-}
-
-quota::QuotaManager* ShellResourceContext::GetQuotaManager() {
- return NULL;
-}
-
HostZoomMap* ShellResourceContext::GetHostZoomMap() {
return NULL;
}
@@ -64,8 +40,4 @@ AudioManager* ShellResourceContext::GetAudioManager() {
return NULL;
}
-WebKitContext* ShellResourceContext::GetWebKitContext() {
- return NULL;
-}
-
} // namespace content
diff --git a/content/shell/shell_resource_context.h b/content/shell/shell_resource_context.h
index ff2db50..91e76bf 100644
--- a/content/shell/shell_resource_context.h
+++ b/content/shell/shell_resource_context.h
@@ -18,28 +18,19 @@ class ShellURLRequestContextGetter;
class ShellResourceContext : public content::ResourceContext {
public:
- ShellResourceContext(
- ShellURLRequestContextGetter* getter,
- ChromeBlobStorageContext* blob_storage_context);
+ explicit ShellResourceContext(ShellURLRequestContextGetter* getter);
virtual ~ShellResourceContext();
private:
// ResourceContext implementation:
virtual net::HostResolver* GetHostResolver() OVERRIDE;
virtual net::URLRequestContext* GetRequestContext() OVERRIDE;
- virtual ChromeAppCacheService* GetAppCacheService() OVERRIDE;
- virtual webkit_database::DatabaseTracker* GetDatabaseTracker() OVERRIDE;
- virtual fileapi::FileSystemContext* GetFileSystemContext() OVERRIDE;
- virtual ChromeBlobStorageContext* GetBlobStorageContext() OVERRIDE;
- virtual quota::QuotaManager* GetQuotaManager() OVERRIDE;
virtual HostZoomMap* GetHostZoomMap() OVERRIDE;
virtual MediaObserver* GetMediaObserver() OVERRIDE;
virtual media_stream::MediaStreamManager* GetMediaStreamManager() OVERRIDE;
virtual AudioManager* GetAudioManager() OVERRIDE;
- virtual WebKitContext* GetWebKitContext() OVERRIDE;
scoped_refptr<ShellURLRequestContextGetter> getter_;
- scoped_refptr<ChromeBlobStorageContext> blob_storage_context_;
DISALLOW_COPY_AND_ASSIGN(ShellResourceContext);
};
diff --git a/content/test/test_browser_context.cc b/content/test/test_browser_context.cc
index df3934e..bbd515e 100644
--- a/content/test/test_browser_context.cc
+++ b/content/test/test_browser_context.cc
@@ -49,8 +49,9 @@ net::URLRequestContextGetter* TestBrowserContext::GetRequestContextForMedia() {
}
content::ResourceContext* TestBrowserContext::GetResourceContext() {
- // TODO(phajdan.jr): Get rid of this nasty global.
- return content::MockResourceContext::GetInstance();
+ if (!resource_context_.get())
+ resource_context_.reset(new content::MockResourceContext());
+ return resource_context_.get();
}
HostZoomMap* TestBrowserContext::GetHostZoomMap() {
diff --git a/content/test/test_browser_context.h b/content/test/test_browser_context.h
index c0873c0..fb6159a 100644
--- a/content/test/test_browser_context.h
+++ b/content/test/test_browser_context.h
@@ -10,11 +10,16 @@
#include "base/file_path.h"
#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
#include "base/scoped_temp_dir.h"
#include "content/public/browser/browser_context.h"
class WebKitContext;
+namespace content {
+class MockResourceContext;
+}
+
class TestBrowserContext : public content::BrowserContext {
public:
TestBrowserContext();
@@ -43,6 +48,7 @@ class TestBrowserContext : public content::BrowserContext {
FRIEND_TEST_ALL_PREFIXES(DOMStorageTest, SessionOnly);
FRIEND_TEST_ALL_PREFIXES(DOMStorageTest, SaveSessionState);
+ scoped_ptr<content::MockResourceContext> resource_context_;
ScopedTempDir browser_context_dir_;
DISALLOW_COPY_AND_ASSIGN(TestBrowserContext);