diff options
author | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-01 22:30:30 +0000 |
---|---|---|
committer | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-01 22:30:30 +0000 |
commit | 23f1ef1a445a53bcefc8ddab9f4184b1db7321c5 (patch) | |
tree | c9f17a33025ed5b5c5dee76a7b4fef9104e9a995 /chrome/browser | |
parent | e143c823ce66af5a83a9a17b6f5938eb16e49392 (diff) | |
download | chromium_src-23f1ef1a445a53bcefc8ddab9f4184b1db7321c5.zip chromium_src-23f1ef1a445a53bcefc8ddab9f4184b1db7321c5.tar.gz chromium_src-23f1ef1a445a53bcefc8ddab9f4184b1db7321c5.tar.bz2 |
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
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/automation/automation_profile_impl.h | 3 | ||||
-rw-r--r-- | chrome/browser/net/chrome_url_request_context.cc | 3 | ||||
-rw-r--r-- | chrome/browser/net/chrome_url_request_context.h | 9 | ||||
-rw-r--r-- | chrome/browser/profile.cc | 32 | ||||
-rw-r--r-- | chrome/browser/profile.h | 8 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_dispatcher_host.cc | 15 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_message_filter.cc | 5 |
7 files changed, 71 insertions, 4 deletions
diff --git a/chrome/browser/automation/automation_profile_impl.h b/chrome/browser/automation/automation_profile_impl.h index c0f2592..7a22fc3 100644 --- a/chrome/browser/automation/automation_profile_impl.h +++ b/chrome/browser/automation/automation_profile_impl.h @@ -45,6 +45,9 @@ class AutomationProfileImpl : public Profile { virtual Profile* GetOriginalProfile() { return original_profile_->GetOriginalProfile(); } + virtual ChromeAppCacheService* GetAppCacheService() { + return original_profile_->GetAppCacheService(); + } virtual VisitedLinkMaster* GetVisitedLinkMaster() { return original_profile_->GetVisitedLinkMaster(); } diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index 65671d4..0bc5572 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -354,6 +354,8 @@ ChromeURLRequestContext::ChromeURLRequestContext(Profile* profile) } ssl_config_service_ = profile->GetSSLConfigService(); + + appcache_service_ = profile->GetAppCacheService(); } ChromeURLRequestContext::ChromeURLRequestContext( @@ -378,6 +380,7 @@ ChromeURLRequestContext::ChromeURLRequestContext( blacklist_ = other->blacklist_; is_media_ = other->is_media_; is_off_the_record_ = other->is_off_the_record_; + appcache_service_ = other->appcache_service_; } // NotificationObserver implementation. diff --git a/chrome/browser/net/chrome_url_request_context.h b/chrome/browser/net/chrome_url_request_context.h index f4baea6..d0303d7 100644 --- a/chrome/browser/net/chrome_url_request_context.h +++ b/chrome/browser/net/chrome_url_request_context.h @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "base/file_path.h" +#include "chrome/common/appcache/chrome_appcache_service.h" #include "chrome/common/net/cookie_monster_sqlite.h" #include "chrome/common/notification_registrar.h" #include "chrome/common/pref_service.h" @@ -65,6 +66,12 @@ class ChromeURLRequestContext : public URLRequestContext, return user_script_dir_path_; } + // Gets the appcache service to be used for requests in this context. + // May be NULL if requests for this context aren't subject to appcaching. + ChromeAppCacheService* appcache_service() const { + return appcache_service_.get(); + } + virtual const std::string& GetUserAgent(const GURL& url) const; virtual bool InterceptCookie(const URLRequest* request, std::string* cookie); @@ -118,6 +125,8 @@ class ChromeURLRequestContext : public URLRequestContext, // Path to the directory user scripts are stored in. FilePath user_script_dir_path_; + scoped_refptr<ChromeAppCacheService> appcache_service_; + scoped_ptr<SQLitePersistentCookieStore> cookie_db_; PrefService* prefs_; const Blacklist* blacklist_; 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<ChromeAppCacheService> appcache_service_; + // The download manager that only stores downloaded items in memory. scoped_refptr<DownloadManager> 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<VisitedLinkMaster> visited_links( diff --git a/chrome/browser/profile.h b/chrome/browser/profile.h index 36679a7..83ae64c 100644 --- a/chrome/browser/profile.h +++ b/chrome/browser/profile.h @@ -25,6 +25,7 @@ class SSLConfigService; class Blacklist; class BookmarkModel; class BrowserThemeProvider; +class ChromeAppCacheService; class ChromeURLRequestContext; class DownloadManager; class Extension; @@ -117,6 +118,11 @@ class Profile { // profile is not off the record. virtual Profile* GetOriginalProfile() = 0; + // Retrieves a pointer to the AppCacheService for this profile. + // Chrome request contexts associated with this profile also have + // a reference to this instance. + virtual ChromeAppCacheService* GetAppCacheService() = 0; + // Retrieves a pointer to the VisitedLinkMaster associated with this // profile. The VisitedLinkMaster is lazily created the first time // that this method is called. @@ -359,6 +365,7 @@ class ProfileImpl : public Profile, virtual Profile* GetOffTheRecordProfile(); virtual void DestroyOffTheRecordProfile(); virtual Profile* GetOriginalProfile(); + virtual ChromeAppCacheService* GetAppCacheService(); virtual VisitedLinkMaster* GetVisitedLinkMaster(); virtual UserScriptMaster* GetUserScriptMaster(); virtual SSLHostState* GetSSLHostState(); @@ -444,6 +451,7 @@ class ProfileImpl : public Profile, FilePath path_; FilePath base_cache_path_; + scoped_refptr<ChromeAppCacheService> appcache_service_; scoped_ptr<VisitedLinkEventListener> visited_link_event_listener_; scoped_ptr<VisitedLinkMaster> visited_link_master_; scoped_refptr<ExtensionsService> extensions_service_; diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.cc b/chrome/browser/renderer_host/resource_dispatcher_host.cc index 7d42929..669118b 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host.cc +++ b/chrome/browser/renderer_host/resource_dispatcher_host.cc @@ -54,6 +54,7 @@ #include "net/base/ssl_cert_request_info.h" #include "net/url_request/url_request.h" #include "net/url_request/url_request_context.h" +#include "webkit/appcache/appcache_interceptor.h" #include "webkit/appcache/appcache_interfaces.h" // TODO(port): Move these includes to the above section when porting is done. @@ -239,9 +240,11 @@ void PopulateResourceResponse(URLRequest* request, request->GetCharset(&response->response_head.charset); response->response_head.filter_policy = filter_policy; response->response_head.content_length = request->GetExpectedContentSize(); - response->response_head.appcache_id = appcache::kNoCacheId; - response->response_head.appcache_manifest_url = GURL(); request->GetMimeType(&response->response_head.mime_type); + appcache::AppCacheInterceptor::GetExtraResponseInfo( + request, + &response->response_head.appcache_id, + &response->response_head.appcache_manifest_url); } } // namespace @@ -294,6 +297,9 @@ void ResourceDispatcherHost::Initialize() { DCHECK(MessageLoop::current() == ui_loop_); download_file_manager_->Initialize(); safe_browsing_->Initialize(io_loop_); + io_loop_->PostTask( + FROM_HERE, + NewRunnableFunction(&appcache::AppCacheInterceptor::EnsureRegistered)); } void ResourceDispatcherHost::Shutdown() { @@ -582,6 +588,11 @@ void ResourceDispatcherHost::BeginRequest( chrome_browser_net::SetOriginProcessUniqueIDForRequest( request_data.origin_child_id, request); + // Have the appcache associate its extra info with the request. + appcache::AppCacheInterceptor::SetExtraRequestInfo( + request, context ? context->appcache_service() : NULL, child_id, + request_data.appcache_host_id, request_data.resource_type); + BeginRequestInternal(request); } diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc index 61debd5..b211f67 100644 --- a/chrome/browser/renderer_host/resource_message_filter.cc +++ b/chrome/browser/renderer_host/resource_message_filter.cc @@ -156,7 +156,8 @@ ResourceMessageFilter::ResourceMessageFilter( profile_(profile), render_widget_helper_(render_widget_helper), audio_renderer_host_(audio_renderer_host), - appcache_dispatcher_host_(new AppCacheDispatcherHost), + appcache_dispatcher_host_( + new AppCacheDispatcherHost(profile->GetAppCacheService())), ALLOW_THIS_IN_INITIALIZER_LIST(dom_storage_dispatcher_host_( new DOMStorageDispatcherHost(this, profile->GetWebKitContext(), resource_dispatcher_host->webkit_thread()))), @@ -193,7 +194,7 @@ ResourceMessageFilter::~ResourceMessageFilter() { void ResourceMessageFilter::Init() { render_widget_helper_->Init(id(), resource_dispatcher_host_); - appcache_dispatcher_host_->Initialize(this); + appcache_dispatcher_host_->Initialize(this, id()); } // Called on the IPC thread: |