Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(673)

Side by Side Diff: chrome/browser/renderer_host/offline_resource_throttle.cc

Issue 9147026: API for connection type (Ethernet/WIFI/WWAN ...) in NetworkChangeNotifier. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: sync Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 22 matching lines...) Expand all
33 namespace { 33 namespace {
34 34
35 void ShowOfflinePage( 35 void ShowOfflinePage(
36 int render_process_id, 36 int render_process_id,
37 int render_view_id, 37 int render_view_id,
38 const GURL& url, 38 const GURL& url,
39 const chromeos::OfflineLoadPage::CompletionCallback& callback) { 39 const chromeos::OfflineLoadPage::CompletionCallback& callback) {
40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
41 41
42 // Check again on UI thread and proceed if it's connected. 42 // Check again on UI thread and proceed if it's connected.
43 if (!net::NetworkChangeNotifier::IsOffline()) { 43 if (net::NetworkChangeNotifier::GetConnectionType() !=
44 net::NetworkChangeNotifier::CONNECTION_NONE) {
wtc 2012/05/11 01:35:05 Nit: this line doesn't need to be indented. Simila
44 BrowserThread::PostTask( 45 BrowserThread::PostTask(
45 BrowserThread::IO, FROM_HERE, base::Bind(callback, true)); 46 BrowserThread::IO, FROM_HERE, base::Bind(callback, true));
46 } else { 47 } else {
47 RenderViewHost* render_view_host = 48 RenderViewHost* render_view_host =
48 RenderViewHost::FromID(render_process_id, render_view_id); 49 RenderViewHost::FromID(render_process_id, render_view_id);
49 WebContents* web_contents = render_view_host ? 50 WebContents* web_contents = render_view_host ?
50 render_view_host->GetDelegate()->GetAsWebContents() : NULL; 51 render_view_host->GetDelegate()->GetAsWebContents() : NULL;
51 // 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
52 // 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
53 // offline page here on the UI thread. 54 // offline page here on the UI thread.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 121
121 bool OfflineResourceThrottle::IsRemote(const GURL& url) const { 122 bool OfflineResourceThrottle::IsRemote(const GURL& url) const {
122 return url.SchemeIs(chrome::kFtpScheme) || 123 return url.SchemeIs(chrome::kFtpScheme) ||
123 url.SchemeIs(chrome::kHttpScheme) || 124 url.SchemeIs(chrome::kHttpScheme) ||
124 url.SchemeIs(chrome::kHttpsScheme); 125 url.SchemeIs(chrome::kHttpsScheme);
125 } 126 }
126 127
127 bool OfflineResourceThrottle::ShouldShowOfflinePage(const GURL& url) const { 128 bool OfflineResourceThrottle::ShouldShowOfflinePage(const GURL& url) const {
128 // If the network is disconnected while loading other resources, we'll simply 129 // If the network is disconnected while loading other resources, we'll simply
129 // show broken link/images. 130 // show broken link/images.
130 return IsRemote(url) && net::NetworkChangeNotifier::IsOffline(); 131 return IsRemote(url) &&
132 net::NetworkChangeNotifier::GetConnectionType() ==
133 net::NetworkChangeNotifier::CONNECTION_NONE;
131 } 134 }
132 135
133 void OfflineResourceThrottle::OnCanHandleOfflineComplete(int rv) { 136 void OfflineResourceThrottle::OnCanHandleOfflineComplete(int rv) {
134 appcache_completion_callback_.Cancel(); 137 appcache_completion_callback_.Cancel();
135 138
136 if (rv == net::OK) { 139 if (rv == net::OK) {
137 controller()->Resume(); 140 controller()->Resume();
138 } else { 141 } else {
139 BrowserThread::PostTask( 142 BrowserThread::PostTask(
140 BrowserThread::UI, 143 BrowserThread::UI,
141 FROM_HERE, 144 FROM_HERE,
142 base::Bind( 145 base::Bind(
143 &ShowOfflinePage, 146 &ShowOfflinePage,
144 render_process_id_, 147 render_process_id_,
145 render_view_id_, 148 render_view_id_,
146 request_->url(), 149 request_->url(),
147 base::Bind( 150 base::Bind(
148 &OfflineResourceThrottle::OnBlockingPageComplete, 151 &OfflineResourceThrottle::OnBlockingPageComplete,
149 AsWeakPtr()))); 152 AsWeakPtr())));
150 } 153 }
151 } 154 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698