From 23f1ef1a445a53bcefc8ddab9f4184b1db7321c5 Mon Sep 17 00:00:00 2001 From: "michaeln@google.com" Date: Tue, 1 Sep 2009 22:30:30 +0000 Subject: Plumb request interception into the appcache library for both chrome and test_shell. AppCache library: * Added AppCacheInterceptor, which is derived from URLRequest::Interceptor. Chrome: * Each UserProfile instantiates a ChromeAppCacheService, which is derived from an appcache library class. * Each ChromeURLRequestContext associated with that profile has a reference to that instance. * ResourceDispatcherHost pokes AppCacheInterceptor when initiating URLRequests and when returning the response head. TestShell: * Added SimpleAppCacheSystem which bundles together appcache lib components for use in a single process with an UI and IO thread. * TestShellWebKit instantiates and initializes an instance of the above, aimed at at temp directory that will get cleaned up when the test run is over. * SimpleResourceLoaderBridge pokes the system when initiating URLRequests and when returning the response head. TEST=none, although many existing tests exercise this stuff BUG=none Review URL: http://codereview.chromium.org/173406 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25099 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/profile.cc | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'chrome/browser/profile.cc') diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc index fb92549..1aa04e8 100644 --- a/chrome/browser/profile.cc +++ b/chrome/browser/profile.cc @@ -39,6 +39,7 @@ #include "chrome/browser/visitedlink_master.h" #include "chrome/browser/visitedlink_event_listener.h" #include "chrome/browser/webdata/web_data_service.h" +#include "chrome/common/appcache/chrome_appcache_service.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" @@ -115,6 +116,16 @@ static void CleanupRequestContext(ChromeURLRequestContext* context) { } } +static void CleanupAppCacheService(ChromeAppCacheService* service) { + if (service) { + MessageLoop* io_thread = ChromeThread::GetMessageLoop(ChromeThread::IO); + if (io_thread) + io_thread->ReleaseSoon(FROM_HERE, service); + else + service->Release(); + } +} + // static void Profile::RegisterUserPrefs(PrefService* prefs) { prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true); @@ -187,6 +198,7 @@ class OffTheRecordProfileImpl : public Profile, virtual ~OffTheRecordProfileImpl() { CleanupRequestContext(request_context_); CleanupRequestContext(extensions_request_context_); + CleanupAppCacheService(appcache_service_.release()); } virtual FilePath GetPath() { return profile_->GetPath(); } @@ -208,6 +220,14 @@ class OffTheRecordProfileImpl : public Profile, return profile_; } + virtual ChromeAppCacheService* GetAppCacheService() { + if (!appcache_service_.get()) { + appcache_service_ = new ChromeAppCacheService(); + appcache_service_->InitializeOnUIThread(GetPath(), true); + } + return appcache_service_.get(); + } + virtual VisitedLinkMaster* 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. @@ -484,6 +504,9 @@ class OffTheRecordProfileImpl : public Profile, ChromeURLRequestContext* extensions_request_context_; + // Use a seperate appcache service for OTR. + scoped_refptr appcache_service_; + // The download manager that only stores downloaded items in memory. scoped_refptr download_manager_; @@ -700,6 +723,7 @@ ProfileImpl::~ProfileImpl() { CleanupRequestContext(request_context_); CleanupRequestContext(media_request_context_); CleanupRequestContext(extensions_request_context_); + CleanupAppCacheService(appcache_service_.release()); // When the request contexts are gone, the blacklist wont be needed anymore. delete blacklist_; @@ -749,6 +773,14 @@ Profile* ProfileImpl::GetOriginalProfile() { return this; } +ChromeAppCacheService* ProfileImpl::GetAppCacheService() { + if (!appcache_service_.get()) { + appcache_service_ = new ChromeAppCacheService(); + appcache_service_->InitializeOnUIThread(GetPath(), false); + } + return appcache_service_.get(); +} + VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() { if (!visited_link_master_.get()) { scoped_ptr visited_links( -- cgit v1.1