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 #ifndef WEBKIT_BROWSER_APPCACHE_APPCACHE_INTERCEPTOR_H_
6 #define WEBKIT_BROWSER_APPCACHE_APPCACHE_INTERCEPTOR_H_
8 #include "base/memory/singleton.h"
9 #include "net/url_request/url_request.h"
11 #include "webkit/browser/webkit_storage_browser_export.h"
12 #include "webkit/common/resource_type.h"
16 class AppCacheRequestHandler
;
17 class AppCacheService
;
19 // An interceptor to hijack requests and potentially service them out of
21 class WEBKIT_STORAGE_BROWSER_EXPORT AppCacheInterceptor
22 : public net::URLRequest::Interceptor
{
24 // Registers a singleton instance with the net library.
25 // Should be called early in the IO thread prior to initiating requests.
26 static void EnsureRegistered() {
30 // Must be called to make a request eligible for retrieval from an appcache.
31 static void SetExtraRequestInfo(net::URLRequest
* request
,
32 AppCacheService
* service
,
35 ResourceType::Type resource_type
);
37 // May be called after response headers are complete to retrieve extra
38 // info about the response.
39 static void GetExtraResponseInfo(net::URLRequest
* request
,
43 static AppCacheInterceptor
* GetInstance();
46 // Override from net::URLRequest::Interceptor:
47 virtual net::URLRequestJob
* MaybeIntercept(
48 net::URLRequest
* request
,
49 net::NetworkDelegate
* network_delegate
) OVERRIDE
;
50 virtual net::URLRequestJob
* MaybeInterceptResponse(
51 net::URLRequest
* request
,
52 net::NetworkDelegate
* network_delegate
) OVERRIDE
;
53 virtual net::URLRequestJob
* MaybeInterceptRedirect(
54 net::URLRequest
* request
,
55 net::NetworkDelegate
* network_delegate
,
56 const GURL
& location
) OVERRIDE
;
59 friend struct DefaultSingletonTraits
<AppCacheInterceptor
>;
61 AppCacheInterceptor();
62 virtual ~AppCacheInterceptor();
64 static void SetHandler(net::URLRequest
* request
,
65 AppCacheRequestHandler
* handler
);
66 static AppCacheRequestHandler
* GetHandler(net::URLRequest
* request
);
68 DISALLOW_COPY_AND_ASSIGN(AppCacheInterceptor
);
71 } // namespace appcache
73 #endif // WEBKIT_BROWSER_APPCACHE_APPCACHE_INTERCEPTOR_H_