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/render_view_host_delegate.h" | |
20 #include "content/public/browser/resource_context.h" | 19 #include "content/public/browser/resource_context.h" |
21 #include "content/public/browser/resource_throttle_controller.h" | 20 #include "content/public/browser/resource_throttle_controller.h" |
| 21 #include "content/public/browser/web_contents.h" |
22 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
23 #include "net/base/net_util.h" | 23 #include "net/base/net_util.h" |
24 #include "net/base/network_change_notifier.h" | 24 #include "net/base/network_change_notifier.h" |
25 #include "net/url_request/url_request.h" | 25 #include "net/url_request/url_request.h" |
26 #include "net/url_request/url_request_context.h" | 26 #include "net/url_request/url_request_context.h" |
27 #include "webkit/appcache/appcache_service.h" | 27 #include "webkit/appcache/appcache_service.h" |
28 | 28 |
29 using content::BrowserThread; | 29 using content::BrowserThread; |
30 using content::RenderViewHost; | 30 using content::RenderViewHost; |
31 using content::ResourceContext; | 31 using content::ResourceContext; |
32 using content::WebContents; | 32 using content::WebContents; |
33 | 33 |
34 namespace { | 34 namespace { |
35 | 35 |
36 void ShowOfflinePage( | 36 void ShowOfflinePage( |
37 int render_process_id, | 37 int render_process_id, |
38 int render_view_id, | 38 int render_view_id, |
39 const GURL& url, | 39 const GURL& url, |
40 const chromeos::OfflineLoadPage::CompletionCallback& callback) { | 40 const chromeos::OfflineLoadPage::CompletionCallback& callback) { |
41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
42 | 42 |
43 // Check again on UI thread and proceed if it's connected. | 43 // Check again on UI thread and proceed if it's connected. |
44 if (!net::NetworkChangeNotifier::IsOffline()) { | 44 if (!net::NetworkChangeNotifier::IsOffline()) { |
45 BrowserThread::PostTask( | 45 BrowserThread::PostTask( |
46 BrowserThread::IO, FROM_HERE, base::Bind(callback, true)); | 46 BrowserThread::IO, FROM_HERE, base::Bind(callback, true)); |
47 } else { | 47 } else { |
48 RenderViewHost* render_view_host = | 48 RenderViewHost* render_view_host = |
49 RenderViewHost::FromID(render_process_id, render_view_id); | 49 RenderViewHost::FromID(render_process_id, render_view_id); |
50 WebContents* web_contents = render_view_host ? | 50 WebContents* web_contents = render_view_host ? |
51 render_view_host->GetDelegate()->GetAsWebContents() : NULL; | 51 WebContents::FromRenderViewHost(render_view_host) : NULL; |
52 // There is a chance that the tab closed after we decided to show | 52 // There is a chance that the tab closed after we decided to show |
53 // the offline page on the IO thread and before we actually show the | 53 // the offline page on the IO thread and before we actually show the |
54 // offline page here on the UI thread. | 54 // offline page here on the UI thread. |
55 if (web_contents) | 55 if (web_contents) |
56 (new chromeos::OfflineLoadPage(web_contents, url, callback))->Show(); | 56 (new chromeos::OfflineLoadPage(web_contents, url, callback))->Show(); |
57 } | 57 } |
58 } | 58 } |
59 | 59 |
60 } // namespace | 60 } // namespace |
61 | 61 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 base::Bind( | 144 base::Bind( |
145 &ShowOfflinePage, | 145 &ShowOfflinePage, |
146 render_process_id_, | 146 render_process_id_, |
147 render_view_id_, | 147 render_view_id_, |
148 request_->url(), | 148 request_->url(), |
149 base::Bind( | 149 base::Bind( |
150 &OfflineResourceThrottle::OnBlockingPageComplete, | 150 &OfflineResourceThrottle::OnBlockingPageComplete, |
151 AsWeakPtr()))); | 151 AsWeakPtr()))); |
152 } | 152 } |
153 } | 153 } |
OLD | NEW |