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

Side by Side Diff: net/proxy/proxy_script_fetcher_impl.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
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 "net/proxy/proxy_script_fetcher_impl.h" 5 #include "net/proxy/proxy_script_fetcher_impl.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/i18n/icu_string_conversions.h" 8 #include "base/i18n/icu_string_conversions.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 17 matching lines...) Expand all
28 // The maximum size (in bytes) allowed for a PAC script. Responses exceeding 28 // The maximum size (in bytes) allowed for a PAC script. Responses exceeding
29 // this will fail with ERR_FILE_TOO_BIG. 29 // this will fail with ERR_FILE_TOO_BIG.
30 const int kDefaultMaxResponseBytes = 1048576; // 1 megabyte 30 const int kDefaultMaxResponseBytes = 1048576; // 1 megabyte
31 31
32 // The maximum duration (in milliseconds) allowed for fetching the PAC script. 32 // The maximum duration (in milliseconds) allowed for fetching the PAC script.
33 // Responses exceeding this will fail with ERR_TIMED_OUT. 33 // Responses exceeding this will fail with ERR_TIMED_OUT.
34 const int kDefaultMaxDurationMs = 300000; // 5 minutes 34 const int kDefaultMaxDurationMs = 300000; // 5 minutes
35 35
36 // Returns true if |mime_type| is one of the known PAC mime type. 36 // Returns true if |mime_type| is one of the known PAC mime type.
37 bool IsPacMimeType(const std::string& mime_type) { 37 bool IsPacMimeType(const std::string& mime_type) {
38 static const char * const kSupportedPacMimeTypes[] = { 38 static const char* const kSupportedPacMimeTypes[] = {
39 "application/x-ns-proxy-autoconfig", 39 "application/x-ns-proxy-autoconfig", "application/x-javascript-config",
40 "application/x-javascript-config",
41 }; 40 };
42 for (size_t i = 0; i < arraysize(kSupportedPacMimeTypes); ++i) { 41 for (size_t i = 0; i < arraysize(kSupportedPacMimeTypes); ++i) {
43 if (LowerCaseEqualsASCII(mime_type, kSupportedPacMimeTypes[i])) 42 if (LowerCaseEqualsASCII(mime_type, kSupportedPacMimeTypes[i]))
44 return true; 43 return true;
45 } 44 }
46 return false; 45 return false;
47 } 46 }
48 47
49 // Converts |bytes| (which is encoded by |charset|) to UTF16, saving the resul 48 // Converts |bytes| (which is encoded by |charset|) to UTF16, saving the resul
50 // to |*utf16|. 49 // to |*utf16|.
51 // If |charset| is empty, then we don't know what it was and guess. 50 // If |charset| is empty, then we don't know what it was and guess.
52 void ConvertResponseToUTF16(const std::string& charset, 51 void ConvertResponseToUTF16(const std::string& charset,
53 const std::string& bytes, 52 const std::string& bytes,
54 base::string16* utf16) { 53 base::string16* utf16) {
55 const char* codepage; 54 const char* codepage;
56 55
57 if (charset.empty()) { 56 if (charset.empty()) {
58 // Assume ISO-8859-1 if no charset was specified. 57 // Assume ISO-8859-1 if no charset was specified.
59 codepage = base::kCodepageLatin1; 58 codepage = base::kCodepageLatin1;
60 } else { 59 } else {
61 // Otherwise trust the charset that was provided. 60 // Otherwise trust the charset that was provided.
62 codepage = charset.c_str(); 61 codepage = charset.c_str();
63 } 62 }
64 63
65 // We will be generous in the conversion -- if any characters lie 64 // We will be generous in the conversion -- if any characters lie
66 // outside of |charset| (i.e. invalid), then substitute them with 65 // outside of |charset| (i.e. invalid), then substitute them with
67 // U+FFFD rather than failing. 66 // U+FFFD rather than failing.
68 base::CodepageToUTF16(bytes, codepage, 67 base::CodepageToUTF16(
69 base::OnStringConversionError::SUBSTITUTE, 68 bytes, codepage, base::OnStringConversionError::SUBSTITUTE, utf16);
70 utf16);
71 } 69 }
72 70
73 } // namespace 71 } // namespace
74 72
75 ProxyScriptFetcherImpl::ProxyScriptFetcherImpl( 73 ProxyScriptFetcherImpl::ProxyScriptFetcherImpl(
76 URLRequestContext* url_request_context) 74 URLRequestContext* url_request_context)
77 : weak_factory_(this), 75 : weak_factory_(this),
78 url_request_context_(url_request_context), 76 url_request_context_(url_request_context),
79 buf_(new IOBuffer(kBufSize)), 77 buf_(new IOBuffer(kBufSize)),
80 next_id_(0), 78 next_id_(0),
(...skipping 27 matching lines...) Expand all
108 DCHECK_EQ(request, cur_request_.get()); 106 DCHECK_EQ(request, cur_request_.get());
109 107
110 // Use |result_code_| as the request's error if we have already set it to 108 // Use |result_code_| as the request's error if we have already set it to
111 // something specific. 109 // something specific.
112 if (result_code_ == OK && !request->status().is_success()) 110 if (result_code_ == OK && !request->status().is_success())
113 result_code_ = request->status().error(); 111 result_code_ = request->status().error();
114 112
115 FetchCompleted(); 113 FetchCompleted();
116 } 114 }
117 115
118 int ProxyScriptFetcherImpl::Fetch( 116 int ProxyScriptFetcherImpl::Fetch(const GURL& url,
119 const GURL& url, base::string16* text, const CompletionCallback& callback) { 117 base::string16* text,
118 const CompletionCallback& callback) {
120 // It is invalid to call Fetch() while a request is already in progress. 119 // It is invalid to call Fetch() while a request is already in progress.
121 DCHECK(!cur_request_.get()); 120 DCHECK(!cur_request_.get());
122 DCHECK(!callback.is_null()); 121 DCHECK(!callback.is_null());
123 DCHECK(text); 122 DCHECK(text);
124 123
125 // Handle base-64 encoded data-urls that contain custom PAC scripts. 124 // Handle base-64 encoded data-urls that contain custom PAC scripts.
126 if (url.SchemeIs("data")) { 125 if (url.SchemeIs("data")) {
127 std::string mime_type; 126 std::string mime_type;
128 std::string charset; 127 std::string charset;
129 std::string data; 128 std::string data;
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 // is still applicable. 313 // is still applicable.
315 if (cur_request_id_ != id) 314 if (cur_request_id_ != id)
316 return; 315 return;
317 316
318 DCHECK(cur_request_.get()); 317 DCHECK(cur_request_.get());
319 result_code_ = ERR_TIMED_OUT; 318 result_code_ = ERR_TIMED_OUT;
320 cur_request_->Cancel(); 319 cur_request_->Cancel();
321 } 320 }
322 321
323 } // namespace net 322 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698