OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_RENDERER_HOST_OFFLINE_RESOURCE_THROTTLE_H_ | 5 #ifndef CHROME_BROWSER_RENDERER_HOST_OFFLINE_RESOURCE_THROTTLE_H_ |
6 #define CHROME_BROWSER_RENDERER_HOST_OFFLINE_RESOURCE_THROTTLE_H_ | 6 #define CHROME_BROWSER_RENDERER_HOST_OFFLINE_RESOURCE_THROTTLE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "chrome/browser/chromeos/offline/offline_load_page.h" | 13 #include "chrome/browser/chromeos/offline/offline_load_page.h" |
14 #include "content/public/browser/resource_throttle.h" | 14 #include "content/public/browser/resource_throttle.h" |
15 #include "net/base/completion_callback.h" | 15 #include "net/base/completion_callback.h" |
16 | 16 |
17 class ChromeAppCacheService; | 17 class ChromeAppCacheService; |
18 class ResourceDispatcherHost; | 18 class ResourceDispatcherHost; |
19 | 19 |
| 20 namespace content { |
| 21 class ResourceContext; |
| 22 } |
| 23 |
20 namespace net { | 24 namespace net { |
21 class URLRequest; | 25 class URLRequest; |
22 } // namespace net | 26 } // namespace net |
23 | 27 |
24 // Used to show an offline interstitial page when the network is not available. | 28 // Used to show an offline interstitial page when the network is not available. |
25 class OfflineResourceThrottle | 29 class OfflineResourceThrottle |
26 : public content::ResourceThrottle, | 30 : public content::ResourceThrottle, |
27 public base::SupportsWeakPtr<OfflineResourceThrottle> { | 31 public base::SupportsWeakPtr<OfflineResourceThrottle> { |
28 public: | 32 public: |
29 OfflineResourceThrottle(int render_process_id, | 33 OfflineResourceThrottle(int render_process_id, |
30 int render_view_id, | 34 int render_view_id, |
31 net::URLRequest* request, | 35 net::URLRequest* request, |
32 ChromeAppCacheService* appcache_service); | 36 content::ResourceContext* resource_context); |
33 virtual ~OfflineResourceThrottle(); | 37 virtual ~OfflineResourceThrottle(); |
34 | 38 |
35 // content::ResourceThrottle implementation: | 39 // content::ResourceThrottle implementation: |
36 virtual void WillStartRequest(bool* defer) OVERRIDE; | 40 virtual void WillStartRequest(bool* defer) OVERRIDE; |
37 | 41 |
38 private: | 42 private: |
39 // OfflineLoadPage callback. | 43 // OfflineLoadPage callback. |
40 void OnBlockingPageComplete(bool proceed); | 44 void OnBlockingPageComplete(bool proceed); |
41 | 45 |
42 // Erase the state associated with a deferred load request. | 46 // Erase the state associated with a deferred load request. |
43 void ClearRequestInfo(); | 47 void ClearRequestInfo(); |
44 bool IsRemote(const GURL& url) const; | 48 bool IsRemote(const GURL& url) const; |
45 | 49 |
46 // True if chrome should show the offline page. | 50 // True if chrome should show the offline page. |
47 bool ShouldShowOfflinePage(const GURL& url) const; | 51 bool ShouldShowOfflinePage(const GURL& url) const; |
48 | 52 |
49 // A callback to tell if an appcache exists. | 53 // A callback to tell if an appcache exists. |
50 void OnCanHandleOfflineComplete(int rv); | 54 void OnCanHandleOfflineComplete(int rv); |
51 | 55 |
52 int render_process_id_; | 56 int render_process_id_; |
53 int render_view_id_; | 57 int render_view_id_; |
54 net::URLRequest* request_; | 58 net::URLRequest* request_; |
55 ChromeAppCacheService* const appcache_service_; | 59 // Safe to keep a pointer around since ResourceContext outlives all requests. |
| 60 content::ResourceContext* resource_context_; |
56 net::CancelableCompletionCallback appcache_completion_callback_; | 61 net::CancelableCompletionCallback appcache_completion_callback_; |
57 | 62 |
58 DISALLOW_COPY_AND_ASSIGN(OfflineResourceThrottle); | 63 DISALLOW_COPY_AND_ASSIGN(OfflineResourceThrottle); |
59 }; | 64 }; |
60 | 65 |
61 #endif // CHROME_BROWSER_RENDERER_HOST_OFFLINE_RESOURCE_THROTTLE_H_ | 66 #endif // CHROME_BROWSER_RENDERER_HOST_OFFLINE_RESOURCE_THROTTLE_H_ |
OLD | NEW |