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