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

Side by Side Diff: chrome/browser/android/offline_pages/offline_page_request_job.cc

Issue 2699933002: Re-ordering triggering priority of offline pages (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/android/offline_pages/offline_page_request_job.h" 5 #include "chrome/browser/android/offline_pages/offline_page_request_job.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 NetworkState GetNetworkState(net::URLRequest* request, 127 NetworkState GetNetworkState(net::URLRequest* request,
128 const OfflinePageHeader& offline_header, 128 const OfflinePageHeader& offline_header,
129 previews::PreviewsDecider* previews_decider) { 129 previews::PreviewsDecider* previews_decider) {
130 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 130 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
131 131
132 if (offline_header.reason == OfflinePageHeader::Reason::NET_ERROR) 132 if (offline_header.reason == OfflinePageHeader::Reason::NET_ERROR)
133 return NetworkState::FLAKY_NETWORK; 133 return NetworkState::FLAKY_NETWORK;
134 134
135 if (net::NetworkChangeNotifier::IsOffline()) 135 if (net::NetworkChangeNotifier::IsOffline())
136 return NetworkState::DISCONNECTED_NETWORK; 136 return NetworkState::DISCONNECTED_NETWORK;
137
138 // If offline header contains a reason other than RELOAD, the offline page
139 // should be forced to load even when the network is connected.
140 if (offline_header.reason != OfflinePageHeader::Reason::NONE &&
141 offline_header.reason != OfflinePageHeader::Reason::RELOAD) {
142 return NetworkState::FORCE_OFFLINE_ON_CONNECTED_NETWORK;
143 }
144
137 // Checks if previews are allowed, the network is slow, and the request is 145 // Checks if previews are allowed, the network is slow, and the request is
138 // allowed to be shown for previews. 146 // allowed to be shown for previews.
139 if (previews_decider && 147 if (previews_decider &&
140 previews_decider->ShouldAllowPreview(*request, 148 previews_decider->ShouldAllowPreview(*request,
141 previews::PreviewsType::OFFLINE)) { 149 previews::PreviewsType::OFFLINE)) {
142 return NetworkState::PROHIBITIVELY_SLOW_NETWORK; 150 return NetworkState::PROHIBITIVELY_SLOW_NETWORK;
143 } 151 }
144 152
145 // If offline header contains a reason other than RELOAD, the offline page 153 // Otherwise, the network state is a good network.
146 // should be forced to load even when the network is connected. 154 return NetworkState::CONNECTED_NETWORK;
147 return (offline_header.reason != OfflinePageHeader::Reason::NONE &&
148 offline_header.reason != OfflinePageHeader::Reason::RELOAD)
149 ? NetworkState::FORCE_OFFLINE_ON_CONNECTED_NETWORK
150 : NetworkState::CONNECTED_NETWORK;
151 } 155 }
152 156
153 OfflinePageRequestJob::AggregatedRequestResult 157 OfflinePageRequestJob::AggregatedRequestResult
154 RequestResultToAggregatedRequestResult( 158 RequestResultToAggregatedRequestResult(
155 RequestResult request_result, NetworkState network_state) { 159 RequestResult request_result, NetworkState network_state) {
156 if (request_result == RequestResult::NO_TAB_ID) 160 if (request_result == RequestResult::NO_TAB_ID)
157 return OfflinePageRequestJob::AggregatedRequestResult::NO_TAB_ID; 161 return OfflinePageRequestJob::AggregatedRequestResult::NO_TAB_ID;
158 162
159 if (request_result == RequestResult::NO_WEB_CONTENTS) 163 if (request_result == RequestResult::NO_WEB_CONTENTS)
160 return OfflinePageRequestJob::AggregatedRequestResult::NO_WEB_CONTENTS; 164 return OfflinePageRequestJob::AggregatedRequestResult::NO_WEB_CONTENTS;
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 710
707 URLRequestJob::NotifyHeadersComplete(); 711 URLRequestJob::NotifyHeadersComplete();
708 } 712 }
709 713
710 void OfflinePageRequestJob::SetDelegateForTesting( 714 void OfflinePageRequestJob::SetDelegateForTesting(
711 std::unique_ptr<Delegate> delegate) { 715 std::unique_ptr<Delegate> delegate) {
712 delegate_ = std::move(delegate); 716 delegate_ = std::move(delegate);
713 } 717 }
714 718
715 } // namespace offline_pages 719 } // namespace offline_pages
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698