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 "content/browser/download/download_request_core.h" | 5 #include "content/browser/download/download_request_core.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 27 matching lines...) Expand all Loading... | |
38 #include "net/base/net_errors.h" | 38 #include "net/base/net_errors.h" |
39 #include "net/base/upload_bytes_element_reader.h" | 39 #include "net/base/upload_bytes_element_reader.h" |
40 #include "net/http/http_response_headers.h" | 40 #include "net/http/http_response_headers.h" |
41 #include "net/http/http_status_code.h" | 41 #include "net/http/http_status_code.h" |
42 #include "net/url_request/url_request_context.h" | 42 #include "net/url_request/url_request_context.h" |
43 | 43 |
44 namespace content { | 44 namespace content { |
45 | 45 |
46 namespace { | 46 namespace { |
47 | 47 |
48 // Mime type of download resource that should trigger handoff to OfflinePages | |
49 // backend for full page load+snapshot. | |
50 const char kHTMLType[] = "text/html"; | |
51 | |
48 // This is a UserData::Data that will be attached to a URLRequest as a | 52 // This is a UserData::Data that will be attached to a URLRequest as a |
49 // side-channel for passing download parameters. | 53 // side-channel for passing download parameters. |
50 class DownloadRequestData : public base::SupportsUserData::Data { | 54 class DownloadRequestData : public base::SupportsUserData::Data { |
51 public: | 55 public: |
52 ~DownloadRequestData() override {} | 56 ~DownloadRequestData() override {} |
53 | 57 |
54 static void Attach(net::URLRequest* request, | 58 static void Attach(net::URLRequest* request, |
55 DownloadUrlParameters* download_parameters, | 59 DownloadUrlParameters* download_parameters, |
56 uint32_t download_id); | 60 uint32_t download_id); |
57 static DownloadRequestData* Get(net::URLRequest* request); | 61 static DownloadRequestData* Get(net::URLRequest* request); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 256 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
253 DVLOG(20) << __func__ << "() " << DebugString(); | 257 DVLOG(20) << __func__ << "() " << DebugString(); |
254 download_start_time_ = base::TimeTicks::Now(); | 258 download_start_time_ = base::TimeTicks::Now(); |
255 | 259 |
256 DownloadInterruptReason result = | 260 DownloadInterruptReason result = |
257 request()->response_headers() | 261 request()->response_headers() |
258 ? HandleSuccessfulServerResponse(*request()->response_headers(), | 262 ? HandleSuccessfulServerResponse(*request()->response_headers(), |
259 save_info_.get()) | 263 save_info_.get()) |
260 : DOWNLOAD_INTERRUPT_REASON_NONE; | 264 : DOWNLOAD_INTERRUPT_REASON_NONE; |
261 | 265 |
266 // If the download resource is an HTML page, interrupt this download with | |
267 // a result code that allows handoff to the OfflinePage backend. | |
268 if (result == DOWNLOAD_INTERRUPT_REASON_NONE && | |
269 override_mime_type == kHTMLType) { | |
270 result = DOWNLOAD_INTERRUPT_REASON_PAGE_DOWNLOAD_HANDOFF; | |
jianli
2016/11/23 01:27:32
Do we want to return instead?
| |
271 } | |
272 | |
262 std::unique_ptr<DownloadCreateInfo> create_info = | 273 std::unique_ptr<DownloadCreateInfo> create_info = |
263 CreateDownloadCreateInfo(result); | 274 CreateDownloadCreateInfo(result); |
264 if (result != DOWNLOAD_INTERRUPT_REASON_NONE) { | 275 if (result != DOWNLOAD_INTERRUPT_REASON_NONE) { |
265 delegate_->OnStart(std::move(create_info), | 276 delegate_->OnStart(std::move(create_info), |
266 std::unique_ptr<ByteStreamReader>(), | 277 std::unique_ptr<ByteStreamReader>(), |
267 base::ResetAndReturn(&on_started_callback_)); | 278 base::ResetAndReturn(&on_started_callback_)); |
268 return false; | 279 return false; |
269 } | 280 } |
270 | 281 |
271 // If it's a download, we don't want to poison the cache with it. | 282 // If it's a download, we don't want to poison the cache with it. |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
627 return DOWNLOAD_INTERRUPT_REASON_NONE; | 638 return DOWNLOAD_INTERRUPT_REASON_NONE; |
628 } | 639 } |
629 | 640 |
630 if (http_headers.response_code() == net::HTTP_PARTIAL_CONTENT) | 641 if (http_headers.response_code() == net::HTTP_PARTIAL_CONTENT) |
631 return DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT; | 642 return DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT; |
632 | 643 |
633 return DOWNLOAD_INTERRUPT_REASON_NONE; | 644 return DOWNLOAD_INTERRUPT_REASON_NONE; |
634 } | 645 } |
635 | 646 |
636 } // namespace content | 647 } // namespace content |
OLD | NEW |