| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "pdf/document_loader.h" | 5 #include "pdf/document_loader.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "net/http/http_util.h" | 9 #include "net/http/http_util.h" |
| 10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 if (StartsWithASCII(disposition, "attachment", false)) { | 86 if (StartsWithASCII(disposition, "attachment", false)) { |
| 87 return false; | 87 return false; |
| 88 } | 88 } |
| 89 | 89 |
| 90 if (content_length > 0) | 90 if (content_length > 0) |
| 91 chunk_stream_.Preallocate(content_length); | 91 chunk_stream_.Preallocate(content_length); |
| 92 | 92 |
| 93 document_size_ = content_length; | 93 document_size_ = content_length; |
| 94 requests_count_ = 0; | 94 requests_count_ = 0; |
| 95 | 95 |
| 96 // Document loading strategy. | |
| 97 // Following table shows the growth on the minimal request size depending | |
| 98 // on the number requests that has been made already. | |
| 99 chunk_size_table_[10] = 32*1024; | |
| 100 chunk_size_table_[20] = 64*1024; | |
| 101 chunk_size_table_[30] = 128*1024; | |
| 102 chunk_size_table_[40] = 256*1024; | |
| 103 chunk_size_table_[50] = 512*1024; | |
| 104 chunk_size_table_[60] = 1024*1024; | |
| 105 chunk_size_table_[70] = 2048*1024; | |
| 106 | |
| 107 // Enable partial loading only if file size is above the threshold. | 96 // Enable partial loading only if file size is above the threshold. |
| 108 // It will allow avoiding latency for multiple requests. | 97 // It will allow avoiding latency for multiple requests. |
| 109 if (content_length > kMinFileSize && | 98 if (content_length > kMinFileSize && |
| 110 accept_ranges_bytes && | 99 accept_ranges_bytes && |
| 111 !content_encoded) { | 100 !content_encoded) { |
| 112 LoadPartialDocument(); | 101 LoadPartialDocument(); |
| 113 } else { | 102 } else { |
| 114 LoadFullDocument(); | 103 LoadFullDocument(); |
| 115 } | 104 } |
| 116 return true; | 105 return true; |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 // Let's keep downloading PDF file in small chunks. | 487 // Let's keep downloading PDF file in small chunks. |
| 499 uint32 pos = chunk_stream_.GetFirstMissingByte(); | 488 uint32 pos = chunk_stream_.GetFirstMissingByte(); |
| 500 std::vector<std::pair<size_t, size_t> > ranges; | 489 std::vector<std::pair<size_t, size_t> > ranges; |
| 501 chunk_stream_.GetMissedRanges(pos, GetRequestSize(), &ranges); | 490 chunk_stream_.GetMissedRanges(pos, GetRequestSize(), &ranges); |
| 502 DCHECK(ranges.size() > 0); | 491 DCHECK(ranges.size() > 0); |
| 503 RequestData(ranges[0].first, ranges[0].second); | 492 RequestData(ranges[0].first, ranges[0].second); |
| 504 } | 493 } |
| 505 } | 494 } |
| 506 | 495 |
| 507 uint32 DocumentLoader::GetRequestSize() const { | 496 uint32 DocumentLoader::GetRequestSize() const { |
| 508 std::map<uint32, uint32>::const_iterator iter = | 497 // Document loading strategy: |
| 509 chunk_size_table_.lower_bound(requests_count_); | 498 // For first 10 requests, we use 32k chunk sizes, for the next 10 requests we |
| 510 if (iter == chunk_size_table_.end()) | 499 // double the size (64k), and so on, until we cap max request size at 2M for |
| 511 iter--; | 500 // 71 or more requests. |
| 512 return iter->second; | 501 uint32 limited_count = std::min(std::max(requests_count_, 10u), 70u); |
| 502 return 32*1024 * (1 << ((limited_count - 1) / 10u)); |
| 513 } | 503 } |
| 514 | 504 |
| 515 } // namespace chrome_pdf | 505 } // namespace chrome_pdf |
| OLD | NEW |