summaryrefslogtreecommitdiffstats
path: root/webkit/appcache/appcache_interceptor.cc
diff options
context:
space:
mode:
authormichaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-15 22:07:15 +0000
committermichaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-15 22:07:15 +0000
commit97e3edc23314c476859c22c8db601f9b3dec552d (patch)
tree9c589f47545b88c1453c2481a7844a921636485c /webkit/appcache/appcache_interceptor.cc
parent34fce2a5030cb53a1e2decb37b5f7517f98457f7 (diff)
downloadchromium_src-97e3edc23314c476859c22c8db601f9b3dec552d.zip
chromium_src-97e3edc23314c476859c22c8db601f9b3dec552d.tar.gz
chromium_src-97e3edc23314c476859c22c8db601f9b3dec552d.tar.bz2
* Fleshed out AppCacheHost class a fair amount, in particular the cache selection algorithm.
* Added some AppCacheHost unit tests. * Introduced AppCacheRequestHandler class, which replaces the clunkyApp CacheInterceptor::ExtraInfo struct. This impl is entirely skeletal stubs for now. TEST=appcache_unittest.cc, but really needs more BUG=none Review URL: http://codereview.chromium.org/192043 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26275 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache/appcache_interceptor.cc')
-rw-r--r--webkit/appcache/appcache_interceptor.cc116
1 files changed, 40 insertions, 76 deletions
diff --git a/webkit/appcache/appcache_interceptor.cc b/webkit/appcache/appcache_interceptor.cc
index a66fea8..88bcd56 100644
--- a/webkit/appcache/appcache_interceptor.cc
+++ b/webkit/appcache/appcache_interceptor.cc
@@ -7,84 +7,51 @@
#include "webkit/appcache/appcache_backend_impl.h"
#include "webkit/appcache/appcache_host.h"
#include "webkit/appcache/appcache_interfaces.h"
+#include "webkit/appcache/appcache_request_handler.h"
#include "webkit/appcache/appcache_service.h"
namespace appcache {
-// Extra info we associate with requests for use at MaybeIntercept time. This
-// info is deleted when the URLRequest is deleted which occurs after the
-// request is complete and all data has been read.
-struct AppCacheInterceptor::ExtraInfo : public URLRequest::UserData {
- // Inputs, extra request info
- AppCacheService* service;
- int process_id;
- int host_id;
- ResourceType::Type resource_type;
-
- // Outputs, extra response info
- int64 cache_id;
- GURL manifest_url;
-
- // The host associated with the request
- // TODO(michaeln): Be careful with this data member, its not clear
- // if a URLRequest can outlive the associated host. As we get further
- // along, we'll need to notify reqeust waiting on cache selection to
- // allow them to continue upon completion of selection. But we also need
- // to handle navigating away from the page away prior to selection being
- // complete.
- AppCacheHost* host_;
-
- ExtraInfo(AppCacheService* service, int process_id, int host_id,
- ResourceType::Type resource_type, AppCacheHost* host)
- : service(service), process_id(process_id), host_id(host_id),
- resource_type(resource_type), cache_id(kNoCacheId), host_(host) {
- }
-
- static void SetInfo(URLRequest* request, ExtraInfo* info) {
- request->SetUserData(instance(), info); // request takes ownership
- }
-
- static ExtraInfo* GetInfo(URLRequest* request) {
- return static_cast<ExtraInfo*>(request->GetUserData(instance()));
- }
-};
-
-static bool IsMainRequest(ResourceType::Type type) {
- // TODO(michaeln): SHARED_WORKER type?
- return ResourceType::IsFrame(type);
+void AppCacheInterceptor::SetHandler(
+ URLRequest* request, AppCacheRequestHandler* handler) {
+ request->SetUserData(instance(), handler); // request takes ownership
+}
+
+AppCacheRequestHandler* AppCacheInterceptor::GetHandler(URLRequest* request) {
+ return reinterpret_cast<AppCacheRequestHandler*>(
+ request->GetUserData(instance()));
}
void AppCacheInterceptor::SetExtraRequestInfo(
URLRequest* request, AppCacheService* service, int process_id,
int host_id, ResourceType::Type resource_type) {
- if (service && (host_id != kNoHostId)) {
- AppCacheHost* host = service->GetBackend(process_id)->GetHost(host_id);
- DCHECK(host);
- if (IsMainRequest(resource_type) || host->selected_cache() ||
- host->is_selection_pending()) {
- ExtraInfo* info = new ExtraInfo(service, process_id,
- host_id, resource_type, host);
- ExtraInfo::SetInfo(request, info);
- }
- }
+ if (!service || (host_id == kNoHostId))
+ return;
+
+ // TODO(michaeln): An invalid host id is indicative of bad data
+ // from a child process. How should we handle that here?
+ AppCacheHost* host = service->GetBackend(process_id)->GetHost(host_id);
+ if (!host)
+ return;
+
+ // TODO(michaeln): SHARED_WORKER type too
+ bool is_main_request = ResourceType::IsFrame(resource_type);
+
+ // Create a handler for this request and associate it with the request.
+ AppCacheRequestHandler* handler =
+ host->CreateRequestHandler(request, is_main_request);
+ if (handler)
+ SetHandler(request, handler);
}
void AppCacheInterceptor::GetExtraResponseInfo(URLRequest* request,
int64* cache_id,
GURL* manifest_url) {
- ExtraInfo* info = ExtraInfo::GetInfo(request);
- if (info) {
- // TODO(michaeln): If this is a main request and it was retrieved from
- // an appcache, ensure that appcache survives the frame navigation. The
- // AppCacheHost should hold reference to that cache to prevent it from
- // being dropped from the in-memory collection of AppCaches. When cache
- // selection occurs, that extra reference should be dropped.
- *cache_id = info->cache_id;
- *manifest_url = info->manifest_url;
- } else {
- DCHECK(*cache_id == kNoCacheId);
- DCHECK(manifest_url->is_empty());
- }
+ DCHECK(*cache_id == kNoCacheId);
+ DCHECK(manifest_url->is_empty());
+ AppCacheRequestHandler* handler = GetHandler(request);
+ if (handler)
+ handler->GetExtraResponseInfo(cache_id, manifest_url);
}
AppCacheInterceptor::AppCacheInterceptor() {
@@ -96,30 +63,27 @@ AppCacheInterceptor::~AppCacheInterceptor() {
}
URLRequestJob* AppCacheInterceptor::MaybeIntercept(URLRequest* request) {
- ExtraInfo* info = ExtraInfo::GetInfo(request);
- if (!info)
+ AppCacheRequestHandler* handler = GetHandler(request);
+ if (!handler)
return NULL;
- // TODO(michaeln): write me
- return NULL;
+ return handler->MaybeLoadResource(request);
}
URLRequestJob* AppCacheInterceptor::MaybeInterceptRedirect(
URLRequest* request,
const GURL& location) {
- ExtraInfo* info = ExtraInfo::GetInfo(request);
- if (!info)
+ AppCacheRequestHandler* handler = GetHandler(request);
+ if (!handler)
return NULL;
- // TODO(michaeln): write me
- return NULL;
+ return handler->MaybeLoadFallbackForRedirect(request, location);
}
URLRequestJob* AppCacheInterceptor::MaybeInterceptResponse(
URLRequest* request) {
- ExtraInfo* info = ExtraInfo::GetInfo(request);
- if (!info)
+ AppCacheRequestHandler* handler = GetHandler(request);
+ if (!handler)
return NULL;
- // TODO(michaeln): write me
- return NULL;
+ return handler->MaybeLoadFallbackForResponse(request);
}
} // namespace appcache