Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 CONNECTED_NETWORK, | 52 CONNECTED_NETWORK, |
| 53 // Force to load the offline page if it is available, though network is in | 53 // Force to load the offline page if it is available, though network is in |
| 54 // working condition. | 54 // working condition. |
| 55 FORCE_OFFLINE_ON_CONNECTED_NETWORK | 55 FORCE_OFFLINE_ON_CONNECTED_NETWORK |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 // This enum is used to tell all possible outcomes of handling network requests | 58 // This enum is used to tell all possible outcomes of handling network requests |
| 59 // that might serve offline contents. | 59 // that might serve offline contents. |
| 60 enum class RequestResult { | 60 enum class RequestResult { |
| 61 OFFLINE_PAGE_SERVED, | 61 OFFLINE_PAGE_SERVED, |
| 62 REDIRECTED, | |
|
fgorski
2016/11/18 23:52:22
add a comment someplace whether this indicates suc
jianli
2016/11/19 00:54:05
Done.
| |
| 62 NO_TAB_ID, | 63 NO_TAB_ID, |
| 63 NO_WEB_CONTENTS, | 64 NO_WEB_CONTENTS, |
| 64 PAGE_NOT_FRESH, | 65 PAGE_NOT_FRESH, |
| 65 OFFLINE_PAGE_NOT_FOUND | 66 OFFLINE_PAGE_NOT_FOUND |
| 66 }; | 67 }; |
| 67 | 68 |
| 68 const char kUserDataKey[] = "offline_page_key"; | 69 const char kUserDataKey[] = "offline_page_key"; |
| 69 | 70 |
| 70 // Contains the info to handle offline page request. | 71 // Contains the info to handle offline page request. |
| 71 class OfflinePageRequestInfo : public base::SupportsUserData::Data { | 72 class OfflinePageRequestInfo : public base::SupportsUserData::Data { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 return OfflinePageRequestJob::AggregatedRequestResult:: | 167 return OfflinePageRequestJob::AggregatedRequestResult:: |
| 167 PAGE_NOT_FOUND_ON_FLAKY_NETWORK; | 168 PAGE_NOT_FOUND_ON_FLAKY_NETWORK; |
| 168 case NetworkState::FORCE_OFFLINE_ON_CONNECTED_NETWORK: | 169 case NetworkState::FORCE_OFFLINE_ON_CONNECTED_NETWORK: |
| 169 return OfflinePageRequestJob::AggregatedRequestResult:: | 170 return OfflinePageRequestJob::AggregatedRequestResult:: |
| 170 PAGE_NOT_FOUND_ON_CONNECTED_NETWORK; | 171 PAGE_NOT_FOUND_ON_CONNECTED_NETWORK; |
| 171 default: | 172 default: |
| 172 NOTREACHED(); | 173 NOTREACHED(); |
| 173 } | 174 } |
| 174 } | 175 } |
| 175 | 176 |
| 177 if (request_result == RequestResult::REDIRECTED) { | |
| 178 switch (network_state) { | |
| 179 case NetworkState::DISCONNECTED_NETWORK: | |
| 180 return OfflinePageRequestJob::AggregatedRequestResult:: | |
| 181 REDIRECTED_ON_DISCONNECTED_NETWORK; | |
| 182 case NetworkState::PROHIBITIVELY_SLOW_NETWORK: | |
| 183 return OfflinePageRequestJob::AggregatedRequestResult:: | |
| 184 REDIRECTED_ON_PROHIBITIVELY_SLOW_NETWORK; | |
| 185 case NetworkState::FLAKY_NETWORK: | |
| 186 return OfflinePageRequestJob::AggregatedRequestResult:: | |
| 187 REDIRECTED_ON_FLAKY_NETWORK; | |
| 188 case NetworkState::FORCE_OFFLINE_ON_CONNECTED_NETWORK: | |
| 189 return OfflinePageRequestJob::AggregatedRequestResult:: | |
| 190 REDIRECTED_ON_CONNECTED_NETWORK; | |
| 191 default: | |
| 192 NOTREACHED(); | |
| 193 } | |
| 194 } | |
| 195 | |
| 176 DCHECK_EQ(RequestResult::OFFLINE_PAGE_SERVED, request_result); | 196 DCHECK_EQ(RequestResult::OFFLINE_PAGE_SERVED, request_result); |
| 177 DCHECK_NE(NetworkState::CONNECTED_NETWORK, network_state); | 197 DCHECK_NE(NetworkState::CONNECTED_NETWORK, network_state); |
| 178 switch (network_state) { | 198 switch (network_state) { |
| 179 case NetworkState::DISCONNECTED_NETWORK: | 199 case NetworkState::DISCONNECTED_NETWORK: |
| 180 return OfflinePageRequestJob::AggregatedRequestResult:: | 200 return OfflinePageRequestJob::AggregatedRequestResult:: |
| 181 SHOW_OFFLINE_ON_DISCONNECTED_NETWORK; | 201 SHOW_OFFLINE_ON_DISCONNECTED_NETWORK; |
| 182 case NetworkState::PROHIBITIVELY_SLOW_NETWORK: | 202 case NetworkState::PROHIBITIVELY_SLOW_NETWORK: |
| 183 return OfflinePageRequestJob::AggregatedRequestResult:: | 203 return OfflinePageRequestJob::AggregatedRequestResult:: |
| 184 SHOW_OFFLINE_ON_PROHIBITIVELY_SLOW_NETWORK; | 204 SHOW_OFFLINE_ON_PROHIBITIVELY_SLOW_NETWORK; |
| 185 case NetworkState::FLAKY_NETWORK: | 205 case NetworkState::FLAKY_NETWORK: |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 const GURL& url, | 337 const GURL& url, |
| 318 const OfflinePageHeader& offline_header, | 338 const OfflinePageHeader& offline_header, |
| 319 NetworkState network_state, | 339 NetworkState network_state, |
| 320 base::WeakPtr<OfflinePageRequestJob> job, | 340 base::WeakPtr<OfflinePageRequestJob> job, |
| 321 content::ResourceRequestInfo::WebContentsGetter web_contents_getter, | 341 content::ResourceRequestInfo::WebContentsGetter web_contents_getter, |
| 322 const OfflinePageItem* offline_page) { | 342 const OfflinePageItem* offline_page) { |
| 323 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 343 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 324 | 344 |
| 325 // If the match is for original URL, trigger the redirect. | 345 // If the match is for original URL, trigger the redirect. |
| 326 if (offline_page && url == offline_page->original_url) { | 346 if (offline_page && url == offline_page->original_url) { |
| 347 ReportRequestResult(RequestResult::REDIRECTED, network_state); | |
| 327 NotifyOfflineRedirectOnUI(job, offline_page->url); | 348 NotifyOfflineRedirectOnUI(job, offline_page->url); |
| 328 return; | 349 return; |
| 329 } | 350 } |
| 330 | 351 |
| 331 base::FilePath offline_file_path; | 352 base::FilePath offline_file_path; |
| 332 RequestResult request_result = AccessOfflineFile( | 353 RequestResult request_result = AccessOfflineFile( |
| 333 offline_header, network_state, job, web_contents_getter, offline_page, | 354 offline_header, network_state, job, web_contents_getter, offline_page, |
| 334 &offline_file_path); | 355 &offline_file_path); |
| 335 | 356 |
| 336 ReportRequestResult(request_result, network_state); | 357 ReportRequestResult(request_result, network_state); |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 657 | 678 |
| 658 URLRequestJob::NotifyHeadersComplete(); | 679 URLRequestJob::NotifyHeadersComplete(); |
| 659 } | 680 } |
| 660 | 681 |
| 661 void OfflinePageRequestJob::SetDelegateForTesting( | 682 void OfflinePageRequestJob::SetDelegateForTesting( |
| 662 std::unique_ptr<Delegate> delegate) { | 683 std::unique_ptr<Delegate> delegate) { |
| 663 delegate_ = std::move(delegate); | 684 delegate_ = std::move(delegate); |
| 664 } | 685 } |
| 665 | 686 |
| 666 } // namespace offline_pages | 687 } // namespace offline_pages |
| OLD | NEW |