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 #include "chrome/browser/renderer_host/offline_resource_throttle.h" | 5 #include "chrome/browser/renderer_host/offline_resource_throttle.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "chrome/browser/chromeos/offline/offline_load_page.h" | 14 #include "chrome/browser/chromeos/offline/offline_load_page.h" |
15 #include "chrome/browser/net/chrome_url_request_context.h" | 15 #include "chrome/browser/net/chrome_url_request_context.h" |
16 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
18 #include "content/public/browser/render_view_host.h" | 18 #include "content/public/browser/render_view_host.h" |
19 #include "content/public/browser/resource_context.h" | |
20 #include "content/public/browser/resource_controller.h" | 19 #include "content/public/browser/resource_controller.h" |
21 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
22 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
23 #include "net/base/net_util.h" | 22 #include "net/base/net_util.h" |
24 #include "net/base/network_change_notifier.h" | 23 #include "net/base/network_change_notifier.h" |
25 #include "net/url_request/url_request.h" | 24 #include "net/url_request/url_request.h" |
26 #include "net/url_request/url_request_context.h" | 25 #include "net/url_request/url_request_context.h" |
27 #include "webkit/appcache/appcache_service.h" | 26 #include "webkit/appcache/appcache_service.h" |
28 | 27 |
29 using content::BrowserThread; | 28 using content::BrowserThread; |
30 using content::RenderViewHost; | 29 using content::RenderViewHost; |
31 using content::ResourceContext; | |
32 using content::WebContents; | 30 using content::WebContents; |
33 | 31 |
34 namespace { | 32 namespace { |
35 | 33 |
36 void ShowOfflinePage( | 34 void ShowOfflinePage( |
37 int render_process_id, | 35 int render_process_id, |
38 int render_view_id, | 36 int render_view_id, |
39 const GURL& url, | 37 const GURL& url, |
40 const chromeos::OfflineLoadPage::CompletionCallback& callback) { | 38 const chromeos::OfflineLoadPage::CompletionCallback& callback) { |
41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 14 matching lines...) Expand all Loading... |
56 (new chromeos::OfflineLoadPage(web_contents, url, callback))->Show(); | 54 (new chromeos::OfflineLoadPage(web_contents, url, callback))->Show(); |
57 } | 55 } |
58 } | 56 } |
59 | 57 |
60 } // namespace | 58 } // namespace |
61 | 59 |
62 OfflineResourceThrottle::OfflineResourceThrottle( | 60 OfflineResourceThrottle::OfflineResourceThrottle( |
63 int render_process_id, | 61 int render_process_id, |
64 int render_view_id, | 62 int render_view_id, |
65 net::URLRequest* request, | 63 net::URLRequest* request, |
66 content::ResourceContext* resource_context) | 64 appcache::AppCacheService* appcache_service) |
67 : render_process_id_(render_process_id), | 65 : render_process_id_(render_process_id), |
68 render_view_id_(render_view_id), | 66 render_view_id_(render_view_id), |
69 request_(request), | 67 request_(request), |
70 resource_context_(resource_context) { | 68 appcache_service_(appcache_service) { |
71 DCHECK(resource_context); | 69 DCHECK(appcache_service); |
72 } | 70 } |
73 | 71 |
74 OfflineResourceThrottle::~OfflineResourceThrottle() { | 72 OfflineResourceThrottle::~OfflineResourceThrottle() { |
75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
76 | 74 |
77 if (!appcache_completion_callback_.IsCancelled()) | 75 if (!appcache_completion_callback_.IsCancelled()) |
78 appcache_completion_callback_.Cancel(); | 76 appcache_completion_callback_.Cancel(); |
79 } | 77 } |
80 | 78 |
81 void OfflineResourceThrottle::WillStartRequest(bool* defer) { | 79 void OfflineResourceThrottle::WillStartRequest(bool* defer) { |
(...skipping 12 matching lines...) Expand all Loading... |
94 if (url->GetOrigin() == first_party->GetOrigin()) | 92 if (url->GetOrigin() == first_party->GetOrigin()) |
95 first_party = &redirect_url; | 93 first_party = &redirect_url; |
96 url = &redirect_url; | 94 url = &redirect_url; |
97 } | 95 } |
98 | 96 |
99 DCHECK(appcache_completion_callback_.IsCancelled()); | 97 DCHECK(appcache_completion_callback_.IsCancelled()); |
100 | 98 |
101 appcache_completion_callback_.Reset( | 99 appcache_completion_callback_.Reset( |
102 base::Bind(&OfflineResourceThrottle::OnCanHandleOfflineComplete, | 100 base::Bind(&OfflineResourceThrottle::OnCanHandleOfflineComplete, |
103 AsWeakPtr())); | 101 AsWeakPtr())); |
104 ResourceContext::GetAppCacheService(resource_context_)-> | 102 appcache_service_->CanHandleMainResourceOffline( |
105 CanHandleMainResourceOffline( | 103 *url, *first_party, |
106 *url, *first_party, | 104 appcache_completion_callback_.callback()); |
107 appcache_completion_callback_.callback()); | |
108 | 105 |
109 *defer = true; | 106 *defer = true; |
110 } | 107 } |
111 | 108 |
112 void OfflineResourceThrottle::OnBlockingPageComplete(bool proceed) { | 109 void OfflineResourceThrottle::OnBlockingPageComplete(bool proceed) { |
113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
114 | 111 |
115 if (proceed) { | 112 if (proceed) { |
116 controller()->Resume(); | 113 controller()->Resume(); |
117 } else { | 114 } else { |
(...skipping 26 matching lines...) Expand all Loading... |
144 base::Bind( | 141 base::Bind( |
145 &ShowOfflinePage, | 142 &ShowOfflinePage, |
146 render_process_id_, | 143 render_process_id_, |
147 render_view_id_, | 144 render_view_id_, |
148 request_->url(), | 145 request_->url(), |
149 base::Bind( | 146 base::Bind( |
150 &OfflineResourceThrottle::OnBlockingPageComplete, | 147 &OfflineResourceThrottle::OnBlockingPageComplete, |
151 AsWeakPtr()))); | 148 AsWeakPtr()))); |
152 } | 149 } |
153 } | 150 } |
OLD | NEW |