When Retrier succeeds, record errors it encountered.
[chromium-blink-merge.git] / webkit / appcache / appcache_interceptor.cc
blob6342b93fd270dd393a9f05ee1dc5a1cecb3b786f
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "webkit/appcache/appcache_interceptor.h"
7 #include "webkit/appcache/appcache_backend_impl.h"
8 #include "webkit/appcache/appcache_host.h"
9 #include "webkit/appcache/appcache_interfaces.h"
10 #include "webkit/appcache/appcache_request_handler.h"
11 #include "webkit/appcache/appcache_service.h"
12 #include "webkit/appcache/appcache_url_request_job.h"
14 namespace appcache {
16 // static
17 AppCacheInterceptor* AppCacheInterceptor::GetInstance() {
18 return Singleton<AppCacheInterceptor>::get();
21 void AppCacheInterceptor::SetHandler(
22 net::URLRequest* request, AppCacheRequestHandler* handler) {
23 request->SetUserData(GetInstance(), handler); // request takes ownership
26 AppCacheRequestHandler* AppCacheInterceptor::GetHandler(
27 net::URLRequest* request) {
28 return reinterpret_cast<AppCacheRequestHandler*>(
29 request->GetUserData(GetInstance()));
32 void AppCacheInterceptor::SetExtraRequestInfo(
33 net::URLRequest* request, AppCacheService* service, int process_id,
34 int host_id, ResourceType::Type resource_type) {
35 if (!service || (host_id == kNoHostId))
36 return;
38 AppCacheBackendImpl* backend = service->GetBackend(process_id);
39 if (!backend)
40 return;
42 // TODO(michaeln): An invalid host id is indicative of bad data
43 // from a child process. How should we handle that here?
44 AppCacheHost* host = backend->GetHost(host_id);
45 if (!host)
46 return;
48 // Create a handler for this request and associate it with the request.
49 AppCacheRequestHandler* handler =
50 host->CreateRequestHandler(request, resource_type);
51 if (handler)
52 SetHandler(request, handler);
55 void AppCacheInterceptor::GetExtraResponseInfo(net::URLRequest* request,
56 int64* cache_id,
57 GURL* manifest_url) {
58 DCHECK(*cache_id == kNoCacheId);
59 DCHECK(manifest_url->is_empty());
60 AppCacheRequestHandler* handler = GetHandler(request);
61 if (handler)
62 handler->GetExtraResponseInfo(cache_id, manifest_url);
65 AppCacheInterceptor::AppCacheInterceptor() {
66 net::URLRequest::Deprecated::RegisterRequestInterceptor(this);
69 AppCacheInterceptor::~AppCacheInterceptor() {
70 net::URLRequest::Deprecated::UnregisterRequestInterceptor(this);
73 net::URLRequestJob* AppCacheInterceptor::MaybeIntercept(
74 net::URLRequest* request, net::NetworkDelegate* network_delegate) {
75 AppCacheRequestHandler* handler = GetHandler(request);
76 if (!handler)
77 return NULL;
78 return handler->MaybeLoadResource(request, network_delegate);
81 net::URLRequestJob* AppCacheInterceptor::MaybeInterceptRedirect(
82 net::URLRequest* request,
83 net::NetworkDelegate* network_delegate,
84 const GURL& location) {
85 AppCacheRequestHandler* handler = GetHandler(request);
86 if (!handler)
87 return NULL;
88 return handler->MaybeLoadFallbackForRedirect(
89 request, network_delegate, location);
92 net::URLRequestJob* AppCacheInterceptor::MaybeInterceptResponse(
93 net::URLRequest* request, net::NetworkDelegate* network_delegate) {
94 AppCacheRequestHandler* handler = GetHandler(request);
95 if (!handler)
96 return NULL;
97 return handler->MaybeLoadFallbackForResponse(request, network_delegate);
100 } // namespace appcache