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