| 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/prerendering_offliner.h" | 5 #include "chrome/browser/android/offline_pages/prerendering_offliner.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/sys_info.h" | 9 #include "base/sys_info.h" |
| 10 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" | 10 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 save_page_params.is_background = true; | 87 save_page_params.is_background = true; |
| 88 // Pass in the original URL if it is different from the last committed URL | 88 // Pass in the original URL if it is different from the last committed URL |
| 89 // when redirects occur. | 89 // when redirects occur. |
| 90 if (!request.original_url().is_empty()) | 90 if (!request.original_url().is_empty()) |
| 91 save_page_params.original_url = request.original_url(); | 91 save_page_params.original_url = request.original_url(); |
| 92 else if (save_page_params.url != request.url()) | 92 else if (save_page_params.url != request.url()) |
| 93 save_page_params.original_url = request.url(); | 93 save_page_params.original_url = request.url(); |
| 94 | 94 |
| 95 if (IsOfflinePagesLoadSignalCollectingEnabled()) { | 95 if (IsOfflinePagesLoadSignalCollectingEnabled()) { |
| 96 // Stash loading signals for writing when we write out the MHTML. | 96 // Stash loading signals for writing when we write out the MHTML. |
| 97 std::string headers = | 97 // TODO(petewil): Add this data to the BackgroundLoaderOffliner too. |
| 98 base::StringPrintf("%s\r\n%s\r\n\r\n", kContentTransferEncodingBinary, | 98 std::string extra_headers = base::StringPrintf( |
| 99 kXHeaderForSignals); | 99 "%s\r\n%s", kContentTransferEncodingBinary, kXHeaderForSignals); |
| 100 std::string body = headers + SerializeLoadingSignalData(); | 100 std::string body = SerializeLoadingSignalData(); |
| 101 std::string content_type = kContentType; | 101 std::string content_type = kContentType; |
| 102 std::string content_location = base::StringPrintf( | 102 std::string content_location = base::StringPrintf( |
| 103 "cid:signal-data-%" PRId64 "@mhtml.blink", request.request_id()); | 103 "cid:signal-data-%" PRId64 "@mhtml.blink", request.request_id()); |
| 104 | 104 |
| 105 content::MHTMLExtraParts* extra_parts = | 105 content::MHTMLExtraParts* extra_parts = |
| 106 content::MHTMLExtraParts::FromWebContents(web_contents); | 106 content::MHTMLExtraParts::FromWebContents(web_contents); |
| 107 DCHECK(extra_parts); | 107 DCHECK(extra_parts); |
| 108 if (extra_parts != nullptr) { | 108 if (extra_parts != nullptr) { |
| 109 extra_parts->AddExtraMHTMLPart(content_type, content_location, body); | 109 extra_parts->AddExtraMHTMLPart(content_type, content_location, |
| 110 extra_headers, body); |
| 110 } | 111 } |
| 111 } | 112 } |
| 112 | 113 |
| 113 SavePage(save_page_params, std::move(archiver), | 114 SavePage(save_page_params, std::move(archiver), |
| 114 base::Bind(&PrerenderingOffliner::OnSavePageDone, | 115 base::Bind(&PrerenderingOffliner::OnSavePageDone, |
| 115 weak_ptr_factory_.GetWeakPtr(), request)); | 116 weak_ptr_factory_.GetWeakPtr(), request)); |
| 116 } else { | 117 } else { |
| 117 // Clear pending request and app listener then run completion callback. | 118 // Clear pending request and app listener then run completion callback. |
| 118 pending_request_.reset(nullptr); | 119 pending_request_.reset(nullptr); |
| 119 app_listener_.reset(nullptr); | 120 app_listener_.reset(nullptr); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 void PrerenderingOffliner::HandleApplicationStateChangeCancel( | 324 void PrerenderingOffliner::HandleApplicationStateChangeCancel( |
| 324 const SavePageRequest& request, | 325 const SavePageRequest& request, |
| 325 int64_t offline_id) { | 326 int64_t offline_id) { |
| 326 // This shouldn't be immediate, but account for case where request was reset | 327 // This shouldn't be immediate, but account for case where request was reset |
| 327 // while waiting for callback. | 328 // while waiting for callback. |
| 328 if (pending_request_ && pending_request_->request_id() != offline_id) | 329 if (pending_request_ && pending_request_->request_id() != offline_id) |
| 329 return; | 330 return; |
| 330 completion_callback_.Run(request, RequestStatus::FOREGROUND_CANCELED); | 331 completion_callback_.Run(request, RequestStatus::FOREGROUND_CANCELED); |
| 331 } | 332 } |
| 332 } // namespace offline_pages | 333 } // namespace offline_pages |
| OLD | NEW |