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

Side by Side Diff: pdf/document_loader.cc

Issue 1172753003: Move LowerCaseEqualsASCII to base namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@string_util
Patch Set: Created 5 years, 6 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 | « net/websockets/websocket_basic_handshake_stream.cc ('k') | ui/accessibility/ax_node_data.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "ppapi/cpp/url_loader.h" 11 #include "ppapi/cpp/url_loader.h"
12 #include "ppapi/cpp/url_request_info.h" 12 #include "ppapi/cpp/url_request_info.h"
13 #include "ppapi/cpp/url_response_info.h" 13 #include "ppapi/cpp/url_response_info.h"
14 14
15 namespace chrome_pdf { 15 namespace chrome_pdf {
16 16
17 namespace { 17 namespace {
18 18
19 // Document below size will be downloaded in one chunk. 19 // Document below size will be downloaded in one chunk.
20 const uint32_t kMinFileSize = 64 * 1024; 20 const uint32_t kMinFileSize = 64 * 1024;
21 21
22 // If the headers have a byte-range response, writes the start and end 22 // If the headers have a byte-range response, writes the start and end
23 // positions and returns true if at least the start position was parsed. 23 // positions and returns true if at least the start position was parsed.
24 // The end position will be set to 0 if it was not found or parsed from the 24 // The end position will be set to 0 if it was not found or parsed from the
25 // response. 25 // response.
26 // Returns false if not even a start position could be parsed. 26 // Returns false if not even a start position could be parsed.
27 bool GetByteRange(const std::string& headers, uint32_t* start, uint32_t* end) { 27 bool GetByteRange(const std::string& headers, uint32_t* start, uint32_t* end) {
28 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n"); 28 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n");
29 while (it.GetNext()) { 29 while (it.GetNext()) {
30 if (LowerCaseEqualsASCII(it.name(), "content-range")) { 30 if (base::LowerCaseEqualsASCII(it.name(), "content-range")) {
31 std::string range = it.values().c_str(); 31 std::string range = it.values().c_str();
32 if (StartsWithASCII(range, "bytes", false)) { 32 if (StartsWithASCII(range, "bytes", false)) {
33 range = range.substr(strlen("bytes")); 33 range = range.substr(strlen("bytes"));
34 std::string::size_type pos = range.find('-'); 34 std::string::size_type pos = range.find('-');
35 std::string range_end; 35 std::string range_end;
36 if (pos != std::string::npos) 36 if (pos != std::string::npos)
37 range_end = range.substr(pos + 1); 37 range_end = range.substr(pos + 1);
38 TrimWhitespaceASCII(range, base::TRIM_LEADING, &range); 38 TrimWhitespaceASCII(range, base::TRIM_LEADING, &range);
39 TrimWhitespaceASCII(range_end, base::TRIM_LEADING, &range_end); 39 TrimWhitespaceASCII(range_end, base::TRIM_LEADING, &range_end);
40 *start = atoi(range.c_str()); 40 *start = atoi(range.c_str());
41 *end = atoi(range_end.c_str()); 41 *end = atoi(range_end.c_str());
42 return true; 42 return true;
43 } 43 }
44 } 44 }
45 } 45 }
46 return false; 46 return false;
47 } 47 }
48 48
49 // If the headers have a multi-part response, returns the boundary name. 49 // If the headers have a multi-part response, returns the boundary name.
50 // Otherwise returns an empty string. 50 // Otherwise returns an empty string.
51 std::string GetMultiPartBoundary(const std::string& headers) { 51 std::string GetMultiPartBoundary(const std::string& headers) {
52 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n"); 52 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n");
53 while (it.GetNext()) { 53 while (it.GetNext()) {
54 if (LowerCaseEqualsASCII(it.name(), "content-type")) { 54 if (base::LowerCaseEqualsASCII(it.name(), "content-type")) {
55 std::string type = base::StringToLowerASCII(it.values()); 55 std::string type = base::StringToLowerASCII(it.values());
56 if (StartsWithASCII(type, "multipart/", true)) { 56 if (StartsWithASCII(type, "multipart/", true)) {
57 const char* boundary = strstr(type.c_str(), "boundary="); 57 const char* boundary = strstr(type.c_str(), "boundary=");
58 if (!boundary) { 58 if (!boundary) {
59 NOTREACHED(); 59 NOTREACHED();
60 break; 60 break;
61 } 61 }
62 62
63 return std::string(boundary + 9); 63 return std::string(boundary + 9);
64 } 64 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 if (response_headers == "Content-Type: text/plain") { 120 if (response_headers == "Content-Type: text/plain") {
121 if (!StartsWithASCII(url, "http://", false) && 121 if (!StartsWithASCII(url, "http://", false) &&
122 !StartsWithASCII(url, "https://", false)) { 122 !StartsWithASCII(url, "https://", false)) {
123 type = "application/pdf"; 123 type = "application/pdf";
124 } 124 }
125 } 125 }
126 if (type.empty() && !response_headers.empty()) { 126 if (type.empty() && !response_headers.empty()) {
127 net::HttpUtil::HeadersIterator it(response_headers.begin(), 127 net::HttpUtil::HeadersIterator it(response_headers.begin(),
128 response_headers.end(), "\n"); 128 response_headers.end(), "\n");
129 while (it.GetNext()) { 129 while (it.GetNext()) {
130 if (LowerCaseEqualsASCII(it.name(), "content-length")) { 130 if (base::LowerCaseEqualsASCII(it.name(), "content-length")) {
131 content_length = atoi(it.values().c_str()); 131 content_length = atoi(it.values().c_str());
132 } else if (LowerCaseEqualsASCII(it.name(), "accept-ranges")) { 132 } else if (base::LowerCaseEqualsASCII(it.name(), "accept-ranges")) {
133 accept_ranges_bytes = LowerCaseEqualsASCII(it.values(), "bytes"); 133 accept_ranges_bytes = base::LowerCaseEqualsASCII(it.values(), "bytes");
134 } else if (LowerCaseEqualsASCII(it.name(), "content-encoding")) { 134 } else if (base::LowerCaseEqualsASCII(it.name(), "content-encoding")) {
135 content_encoded = true; 135 content_encoded = true;
136 } else if (LowerCaseEqualsASCII(it.name(), "content-type")) { 136 } else if (base::LowerCaseEqualsASCII(it.name(), "content-type")) {
137 type = it.values(); 137 type = it.values();
138 size_t semi_colon_pos = type.find(';'); 138 size_t semi_colon_pos = type.find(';');
139 if (semi_colon_pos != std::string::npos) { 139 if (semi_colon_pos != std::string::npos) {
140 type = type.substr(0, semi_colon_pos); 140 type = type.substr(0, semi_colon_pos);
141 } 141 }
142 TrimWhitespace(type, base::TRIM_ALL, &type); 142 TrimWhitespace(type, base::TRIM_ALL, &type);
143 } else if (LowerCaseEqualsASCII(it.name(), "content-disposition")) { 143 } else if (base::LowerCaseEqualsASCII(it.name(), "content-disposition")) {
144 disposition = it.values(); 144 disposition = it.values();
145 } 145 }
146 } 146 }
147 } 147 }
148 if (!type.empty() && !IsValidContentType(type)) 148 if (!type.empty() && !IsValidContentType(type))
149 return false; 149 return false;
150 if (StartsWithASCII(disposition, "attachment", false)) 150 if (StartsWithASCII(disposition, "attachment", false))
151 return false; 151 return false;
152 152
153 if (content_length > 0) 153 if (content_length > 0)
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 uint32_t DocumentLoader::GetRequestSize() const { 526 uint32_t DocumentLoader::GetRequestSize() const {
527 // Document loading strategy: 527 // Document loading strategy:
528 // For first 10 requests, we use 32k chunk sizes, for the next 10 requests we 528 // For first 10 requests, we use 32k chunk sizes, for the next 10 requests we
529 // double the size (64k), and so on, until we cap max request size at 2M for 529 // double the size (64k), and so on, until we cap max request size at 2M for
530 // 71 or more requests. 530 // 71 or more requests.
531 uint32_t limited_count = std::min(std::max(requests_count_, 10u), 70u); 531 uint32_t limited_count = std::min(std::max(requests_count_, 10u), 70u);
532 return 32 * 1024 * (1 << ((limited_count - 1) / 10u)); 532 return 32 * 1024 * (1 << ((limited_count - 1) / 10u));
533 } 533 }
534 534
535 } // namespace chrome_pdf 535 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « net/websockets/websocket_basic_handshake_stream.cc ('k') | ui/accessibility/ax_node_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698