From 33c282f0e299b711f0f18f1222ead28a7623cbbd Mon Sep 17 00:00:00 2001 From: "olli.raula" Date: Thu, 21 Jan 2016 04:12:49 -0800 Subject: Remove use of void** from HttpResponseHeaders::EnumerateHeaderLines Remove use of of obaque void** and use instead size_t* parameter. Logic inside is untouched. TBR=jam@chromium.org Review URL: https://codereview.chromium.org/1594973004 Cr-Commit-Position: refs/heads/master@{#370672} --- android_webview/native/aw_contents_io_thread_client_impl.cc | 2 +- chrome/browser/devtools/devtools_ui_bindings.cc | 2 +- .../extensions/api/streams_private/streams_private_api.cc | 2 +- .../extensions/api/web_request/web_request_api_unittest.cc | 6 +++--- chrome/browser/mod_pagespeed/mod_pagespeed_metrics.cc | 2 +- chrome/browser/safe_browsing/threat_details_cache.cc | 2 +- components/cronet/android/chromium_url_request.cc | 2 +- components/cronet/android/cronet_url_request_adapter.cc | 2 +- content/browser/appcache/appcache_internals_ui.cc | 2 +- content/browser/devtools/devtools_netlog_observer.cc | 4 ++-- content/browser/renderer_host/websocket_host.cc | 2 +- content/child/web_url_loader_impl.cc | 2 +- content/shell/browser/shell_devtools_frontend.cc | 2 +- .../declarative_webrequest/webrequest_condition_attribute.cc | 2 +- .../browser/api/mime_handler_private/mime_handler_private.cc | 2 +- extensions/browser/api/web_request/web_request_api_helpers.cc | 4 ++-- .../browser/api/web_request/web_request_event_details.cc | 2 +- ios/net/protocol_handler_util.mm | 2 +- .../public/test/response_providers/data_response_provider.mm | 2 +- mojo/services/network/url_loader_impl.cc | 2 +- net/http/http_response_headers.cc | 10 +++++----- net/http/http_response_headers.h | 5 +++-- net/http/http_response_headers_unittest.cc | 2 +- net/spdy/spdy_http_utils.cc | 2 +- net/spdy/spdy_network_transaction_unittest.cc | 4 ++-- net/url_request/url_request_http_job.cc | 2 +- net/url_request/view_cache_helper.cc | 2 +- net/websockets/websocket_stream_create_test_base.cc | 2 +- 28 files changed, 39 insertions(+), 38 deletions(-) diff --git a/android_webview/native/aw_contents_io_thread_client_impl.cc b/android_webview/native/aw_contents_io_thread_client_impl.cc index d00b260..674832d 100644 --- a/android_webview/native/aw_contents_io_thread_client_impl.cc +++ b/android_webview/native/aw_contents_io_thread_client_impl.cc @@ -466,7 +466,7 @@ void AwContentsIoThreadClientImpl::OnReceivedHttpError( vector response_header_names; vector response_header_values; { - void* headers_iterator = NULL; + size_t headers_iterator = 0; string header_name, header_value; while (response_headers->EnumerateHeaderLines( &headers_iterator, &header_name, &header_value)) { diff --git a/chrome/browser/devtools/devtools_ui_bindings.cc b/chrome/browser/devtools/devtools_ui_bindings.cc index d86ecd9..4ecdab0 100644 --- a/chrome/browser/devtools/devtools_ui_bindings.cc +++ b/chrome/browser/devtools/devtools_ui_bindings.cc @@ -982,7 +982,7 @@ void DevToolsUIBindings::OnURLFetchComplete(const net::URLFetcher* source) { response.SetInteger("statusCode", rh ? rh->response_code() : 200); response.Set("headers", headers); - void* iterator = NULL; + size_t iterator = 0; std::string name; std::string value; while (rh && rh->EnumerateHeaderLines(&iterator, &name, &value)) diff --git a/chrome/browser/extensions/api/streams_private/streams_private_api.cc b/chrome/browser/extensions/api/streams_private/streams_private_api.cc index 3f95560..1bd0b3f 100644 --- a/chrome/browser/extensions/api/streams_private/streams_private_api.cc +++ b/chrome/browser/extensions/api/streams_private/streams_private_api.cc @@ -29,7 +29,7 @@ void CreateResponseHeadersDictionary(const net::HttpResponseHeaders* headers, if (!headers) return; - void* iter = NULL; + size_t iter = 0; std::string header_name; std::string header_value; while (headers->EnumerateHeaderLines(&iter, &header_name, &header_value)) { diff --git a/chrome/browser/extensions/api/web_request/web_request_api_unittest.cc b/chrome/browser/extensions/api/web_request/web_request_api_unittest.cc index 3b672fe..fb391c1 100644 --- a/chrome/browser/extensions/api/web_request/web_request_api_unittest.cc +++ b/chrome/browser/extensions/api/web_request/web_request_api_unittest.cc @@ -2090,7 +2090,7 @@ TEST(ExtensionWebRequestHelpersTest, TestMergeOnHeadersReceivedResponses) { EXPECT_TRUE(allowed_unsafe_redirect_url1.is_empty()); std::multimap expected1; expected1.insert(std::pair("Key2", "Value3")); - void* iter = NULL; + size_t iter = 0; std::string name; std::string value; std::multimap actual1; @@ -2122,7 +2122,7 @@ TEST(ExtensionWebRequestHelpersTest, TestMergeOnHeadersReceivedResponses) { &net_log); ASSERT_TRUE(new_headers2.get()); EXPECT_TRUE(allowed_unsafe_redirect_url2.is_empty()); - iter = NULL; + iter = 0; std::multimap actual2; while (new_headers2->EnumerateHeaderLines(&iter, &name, &value)) { actual2.insert(std::pair(name, value)); @@ -2172,7 +2172,7 @@ TEST(ExtensionWebRequestHelpersTest, expected1.insert(std::pair("Key1", "Value1")); expected1.insert(std::pair("Key1", "Value3")); expected1.insert(std::pair("Key2", "Value4")); - void* iter = NULL; + size_t iter = 0; std::string name; std::string value; std::multimap actual1; diff --git a/chrome/browser/mod_pagespeed/mod_pagespeed_metrics.cc b/chrome/browser/mod_pagespeed/mod_pagespeed_metrics.cc index 6ef2d29..6e028dd 100644 --- a/chrome/browser/mod_pagespeed/mod_pagespeed_metrics.cc +++ b/chrome/browser/mod_pagespeed/mod_pagespeed_metrics.cc @@ -86,7 +86,7 @@ void RecordMetrics(const content::ResourceType resource_type, if (!response_headers) return; - void* iter = nullptr; + size_t iter = 0; std::string name; std::string value; while (response_headers->EnumerateHeaderLines(&iter, &name, &value)) { diff --git a/chrome/browser/safe_browsing/threat_details_cache.cc b/chrome/browser/safe_browsing/threat_details_cache.cc index 4782bde..900d17f 100644 --- a/chrome/browser/safe_browsing/threat_details_cache.cc +++ b/chrome/browser/safe_browsing/threat_details_cache.cc @@ -151,7 +151,7 @@ void ThreatDetailsCacheCollector::ReadResponse( ClientSafeBrowsingReportRequest::HTTPResponse* pb_response = pb_resource->mutable_response(); pb_response->mutable_firstline()->set_code(headers->response_code()); - void* iter = NULL; + size_t iter = 0; std::string name, value; while (headers->EnumerateHeaderLines(&iter, &name, &value)) { ClientSafeBrowsingReportRequest::HTTPHeader* pb_header = diff --git a/components/cronet/android/chromium_url_request.cc b/components/cronet/android/chromium_url_request.cc index 2e82409..6f047e6 100644 --- a/components/cronet/android/chromium_url_request.cc +++ b/components/cronet/android/chromium_url_request.cc @@ -376,7 +376,7 @@ static void GetAllHeaders(JNIEnv* env, if (headers == NULL) return; - void* iter = NULL; + size_t iter = 0; std::string header_name; std::string header_value; while (headers->EnumerateHeaderLines(&iter, &header_name, &header_value)) { diff --git a/components/cronet/android/cronet_url_request_adapter.cc b/components/cronet/android/cronet_url_request_adapter.cc index 2994e24..5a56d6e 100644 --- a/components/cronet/android/cronet_url_request_adapter.cc +++ b/components/cronet/android/cronet_url_request_adapter.cc @@ -359,7 +359,7 @@ CronetURLRequestAdapter::GetResponseHeaders(JNIEnv* env) { const net::HttpResponseHeaders* headers = url_request_->response_headers(); // Returns an empty array if |headers| is nullptr. if (headers != nullptr) { - void* iter = nullptr; + size_t iter = 0; std::string header_name; std::string header_value; while (headers->EnumerateHeaderLines(&iter, &header_name, &header_value)) { diff --git a/content/browser/appcache/appcache_internals_ui.cc b/content/browser/appcache/appcache_internals_ui.cc index 3abd692..0c40212 100644 --- a/content/browser/appcache/appcache_internals_ui.cc +++ b/content/browser/appcache/appcache_internals_ui.cc @@ -462,7 +462,7 @@ void AppCacheInternalsUI::OnFileDetailsReady( response_info->http_response_info()->headers->GetStatusLine())); headers.push_back('\n'); - void* iter = nullptr; + size_t iter = 0; std::string name, value; while (response_info->http_response_info()->headers->EnumerateHeaderLines( &iter, &name, &value)) { diff --git a/content/browser/devtools/devtools_netlog_observer.cc b/content/browser/devtools/devtools_netlog_observer.cc index 24448e3..6a2a3c4 100644 --- a/content/browser/devtools/devtools_netlog_observer.cc +++ b/content/browser/devtools/devtools_netlog_observer.cc @@ -138,8 +138,8 @@ void DevToolsNetLogObserver::OnAddURLRequestEntry( // several http requests (e.g. see http://crbug.com/80157). info->response_headers.clear(); - for (void* it = NULL; - response_headers->EnumerateHeaderLines(&it, &name, &value); ) { + for (size_t it = 0; + response_headers->EnumerateHeaderLines(&it, &name, &value);) { info->response_headers.push_back(std::make_pair(name, value)); } diff --git a/content/browser/renderer_host/websocket_host.cc b/content/browser/renderer_host/websocket_host.cc index 5551e96..d578145 100644 --- a/content/browser/renderer_host/websocket_host.cc +++ b/content/browser/renderer_host/websocket_host.cc @@ -254,7 +254,7 @@ ChannelState WebSocketEventHandler::OnFinishOpeningHandshake( response_to_pass.url.Swap(&response->url); response_to_pass.status_code = response->status_code; response_to_pass.status_text.swap(response->status_text); - void* iter = NULL; + size_t iter = 0; std::string name, value; while (response->headers->EnumerateHeaderLines(&iter, &name, &value)) response_to_pass.headers.push_back(std::make_pair(name, value)); diff --git a/content/child/web_url_loader_impl.cc b/content/child/web_url_loader_impl.cc index b6fdd6a..2726c76 100644 --- a/content/child/web_url_loader_impl.cc +++ b/content/child/web_url_loader_impl.cc @@ -1003,7 +1003,7 @@ void WebURLLoaderImpl::PopulateURLResponse(const GURL& url, response->setLastModifiedDate(time_val.ToDoubleT()); // Build up the header map. - void* iter = NULL; + size_t iter = 0; std::string name; while (headers->EnumerateHeaderLines(&iter, &name, &value)) { response->addHTTPHeaderField(WebString::fromLatin1(name), diff --git a/content/shell/browser/shell_devtools_frontend.cc b/content/shell/browser/shell_devtools_frontend.cc index 3acbab1..f0b2fe6 100644 --- a/content/shell/browser/shell_devtools_frontend.cc +++ b/content/shell/browser/shell_devtools_frontend.cc @@ -293,7 +293,7 @@ void ShellDevToolsFrontend::OnURLFetchComplete(const net::URLFetcher* source) { response.SetInteger("statusCode", rh ? rh->response_code() : 200); response.Set("headers", headers); - void* iterator = NULL; + size_t iterator = 0; std::string name; std::string value; while (rh && rh->EnumerateHeaderLines(&iterator, &name, &value)) diff --git a/extensions/browser/api/declarative_webrequest/webrequest_condition_attribute.cc b/extensions/browser/api/declarative_webrequest/webrequest_condition_attribute.cc index 1e85b1c..f9ef6752 100644 --- a/extensions/browser/api/declarative_webrequest/webrequest_condition_attribute.cc +++ b/extensions/browser/api/declarative_webrequest/webrequest_condition_attribute.cc @@ -694,7 +694,7 @@ bool WebRequestConditionAttributeResponseHeaders::IsFulfilled( bool passed = false; // Did some header pass TestNameValue? std::string name; std::string value; - void* iter = NULL; + size_t iter = 0; while (!passed && headers->EnumerateHeaderLines(&iter, &name, &value)) { passed |= header_matcher_->TestNameValue(name, value); } diff --git a/extensions/browser/api/mime_handler_private/mime_handler_private.cc b/extensions/browser/api/mime_handler_private/mime_handler_private.cc index 4a5bb42..120363c 100644 --- a/extensions/browser/api/mime_handler_private/mime_handler_private.cc +++ b/extensions/browser/api/mime_handler_private/mime_handler_private.cc @@ -24,7 +24,7 @@ mojo::Map CreateResponseHeadersMap( if (!headers) return mojo::Map::From(result); - void* iter = nullptr; + size_t iter = 0; std::string header_name; std::string header_value; while (headers->EnumerateHeaderLines(&iter, &header_name, &header_value)) { diff --git a/extensions/browser/api/web_request/web_request_api_helpers.cc b/extensions/browser/api/web_request/web_request_api_helpers.cc index 6f86bf4..c998367 100644 --- a/extensions/browser/api/web_request/web_request_api_helpers.cc +++ b/extensions/browser/api/web_request/web_request_api_helpers.cc @@ -378,7 +378,7 @@ EventResponseDelta* CalculateOnHeadersReceivedDelta( // Find deleted headers (header keys are treated case insensitively). { - void* iter = NULL; + size_t iter = 0; std::string name; std::string value; while (old_response_headers->EnumerateHeaderLines(&iter, &name, &value)) { @@ -401,7 +401,7 @@ EventResponseDelta* CalculateOnHeadersReceivedDelta( { for (const auto& i : *new_response_headers) { std::string name_lowercase = base::ToLowerASCII(i.first); - void* iter = nullptr; + size_t iter = 0; std::string name; std::string value; bool header_found = false; diff --git a/extensions/browser/api/web_request/web_request_event_details.cc b/extensions/browser/api/web_request/web_request_event_details.cc index 958faea..2382dcd 100644 --- a/extensions/browser/api/web_request/web_request_event_details.cc +++ b/extensions/browser/api/web_request/web_request_event_details.cc @@ -133,7 +133,7 @@ void WebRequestEventDetails::SetResponseHeaders( if (extra_info_spec_ & ExtraInfoSpec::RESPONSE_HEADERS) { base::ListValue* headers = new base::ListValue(); if (response_headers) { - void* iter = nullptr; + size_t iter = 0; std::string name; std::string value; while (response_headers->EnumerateHeaderLines(&iter, &name, &value)) diff --git a/ios/net/protocol_handler_util.mm b/ios/net/protocol_handler_util.mm index d1878c5..c76f19a 100644 --- a/ios/net/protocol_handler_util.mm +++ b/ios/net/protocol_handler_util.mm @@ -90,7 +90,7 @@ NSURLResponse* GetNSURLResponseForRequest(URLRequest* request) { NSMutableDictionary* header_fields = [NSMutableDictionary dictionary]; HttpResponseHeaders* headers = request->response_headers(); if (headers != nullptr) { - void* iter = nullptr; + size_t iter = 0; std::string name, value; while (headers->EnumerateHeaderLines(&iter, &name, &value)) { NSString* key = base::SysUTF8ToNSString(name); diff --git a/ios/web/public/test/response_providers/data_response_provider.mm b/ios/web/public/test/response_providers/data_response_provider.mm index a109dbe..4b1cd80 100644 --- a/ios/web/public/test/response_providers/data_response_provider.mm +++ b/ios/web/public/test/response_providers/data_response_provider.mm @@ -17,7 +17,7 @@ GCDWebServerResponse* DataResponseProvider::GetGCDWebServerResponse( GCDWebServerDataResponse* data_response = [GCDWebServerDataResponse responseWithHTML:base::SysUTF8ToNSString(response_body)]; data_response.statusCode = response_headers->response_code(); - void* iter = nullptr; + size_t iter = 0; std::string name; std::string value; while (response_headers->EnumerateHeaderLines(&iter, &name, &value)) { diff --git a/mojo/services/network/url_loader_impl.cc b/mojo/services/network/url_loader_impl.cc index 2496f3a..e8727ca 100644 --- a/mojo/services/network/url_loader_impl.cc +++ b/mojo/services/network/url_loader_impl.cc @@ -77,7 +77,7 @@ URLResponsePtr MakeURLResponse(const net::URLRequest* url_request) { response->headers = Array::New(0); std::vector header_lines; - void* iter = nullptr; + size_t iter = 0; std::string name, value; while (headers->EnumerateHeaderLines(&iter, &name, &value)) { HttpHeaderPtr header = HttpHeader::New(); diff --git a/net/http/http_response_headers.cc b/net/http/http_response_headers.cc index ba51cfd..7cf2d0c 100644 --- a/net/http/http_response_headers.cc +++ b/net/http/http_response_headers.cc @@ -313,7 +313,7 @@ void HttpResponseHeaders::RemoveHeaderLine(const std::string& name, new_raw_headers.reserve(raw_headers_.size()); - void* iter = NULL; + size_t iter = 0; std::string old_header_name; std::string old_header_value; while (EnumerateHeaderLines(&iter, &old_header_name, &old_header_value)) { @@ -549,10 +549,10 @@ std::string HttpResponseHeaders::GetStatusText() const { return std::string(begin, end); } -bool HttpResponseHeaders::EnumerateHeaderLines(void** iter, +bool HttpResponseHeaders::EnumerateHeaderLines(size_t* iter, std::string* name, std::string* value) const { - size_t i = reinterpret_cast(*iter); + size_t i = *iter; if (i == parsed_.size()) return false; @@ -567,7 +567,7 @@ bool HttpResponseHeaders::EnumerateHeaderLines(void** iter, value->assign(value_begin, value_end); - *iter = reinterpret_cast(i); + *iter = i; return true; } @@ -1394,7 +1394,7 @@ scoped_ptr HttpResponseHeaders::NetLogCallback( scoped_ptr dict(new base::DictionaryValue()); base::ListValue* headers = new base::ListValue(); headers->Append(new base::StringValue(GetStatusLine())); - void* iterator = NULL; + size_t iterator = 0; std::string name; std::string value; while (EnumerateHeaderLines(&iterator, &name, &value)) { diff --git a/net/http/http_response_headers.h b/net/http/http_response_headers.h index 91c223e..7d75c63 100644 --- a/net/http/http_response_headers.h +++ b/net/http/http_response_headers.h @@ -163,10 +163,10 @@ class NET_EXPORT HttpResponseHeaders // header appears on multiple lines, then it will appear multiple times in // this enumeration (in the order the header lines were received from the // server). Also, a given header might have an empty value. Initialize a - // 'void*' variable to NULL and pass it by address to EnumerateHeaderLines. + // 'size_t' variable to 0 and pass it by address to EnumerateHeaderLines. // Call EnumerateHeaderLines repeatedly until it returns false. The // out-params 'name' and 'value' are set upon success. - bool EnumerateHeaderLines(void** iter, + bool EnumerateHeaderLines(size_t* iter, std::string* name, std::string* value) const; @@ -176,6 +176,7 @@ class NET_EXPORT HttpResponseHeaders // initialize a 'void*' variable to NULL and pass it by address to // EnumerateHeader. Note that a header might have an empty value. Call // EnumerateHeader repeatedly until it returns false. + // TODO(Olli Raula) Remove void** bool EnumerateHeader(void** iter, const base::StringPiece& name, std::string* value) const; diff --git a/net/http/http_response_headers_unittest.cc b/net/http/http_response_headers_unittest.cc index 1bc99bb..9c58807 100644 --- a/net/http/http_response_headers_unittest.cc +++ b/net/http/http_response_headers_unittest.cc @@ -1055,7 +1055,7 @@ TEST_P(EnumerateHeaderLinesTest, EnumerateHeaderLines) { std::string name, value, lines; - void* iter = NULL; + size_t iter = 0; while (parsed->EnumerateHeaderLines(&iter, &name, &value)) { lines.append(name); lines.append(": "); diff --git a/net/spdy/spdy_http_utils.cc b/net/spdy/spdy_http_utils.cc index 0091edf..7bf46b6 100644 --- a/net/spdy/spdy_http_utils.cc +++ b/net/spdy/spdy_http_utils.cc @@ -164,7 +164,7 @@ void CreateSpdyHeadersFromHttpResponse( std::find(after_version + 1, status_line.end(), ' '); (*headers)[status_key] = std::string(after_version + 1, after_status); - void* iter = NULL; + size_t iter = 0; std::string raw_name, value; while (response_headers.EnumerateHeaderLines(&iter, &raw_name, &value)) { std::string name = base::ToLowerASCII(raw_name); diff --git a/net/spdy/spdy_network_transaction_unittest.cc b/net/spdy/spdy_network_transaction_unittest.cc index 59951ae..851abce 100644 --- a/net/spdy/spdy_network_transaction_unittest.cc +++ b/net/spdy/spdy_network_transaction_unittest.cc @@ -3067,7 +3067,7 @@ TEST_P(SpdyNetworkTransactionTest, SynReplyHeaders) { scoped_refptr headers = out.response_info.headers; EXPECT_TRUE(headers.get() != NULL); - void* iter = NULL; + size_t iter = 0; std::string name, value; SpdyHeaderBlock header_block; while (headers->EnumerateHeaderLines(&iter, &name, &value)) { @@ -3180,7 +3180,7 @@ TEST_P(SpdyNetworkTransactionTest, SynReplyHeadersVary) { // Check the headers. scoped_refptr headers = out.response_info.headers; ASSERT_TRUE(headers.get() != NULL) << i; - void* iter = NULL; + size_t iter = 0; std::string name, value, lines; while (headers->EnumerateHeaderLines(&iter, &name, &value)) { lines.append(name); diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc index 3315d7e9..b7606d3 100644 --- a/net/url_request/url_request_http_job.cc +++ b/net/url_request/url_request_http_job.cc @@ -965,7 +965,7 @@ void URLRequestHttpJob::OnStartCompleted(int result) { scoped_refptr headers = GetResponseHeaders(); if (headers) { - void* iter = NULL; + size_t iter = 0; std::string name; std::string value; bool invalid_header_values_in_rfc7230 = false; diff --git a/net/url_request/view_cache_helper.cc b/net/url_request/view_cache_helper.cc index 36d3ae5..b18d336 100644 --- a/net/url_request/view_cache_helper.cc +++ b/net/url_request/view_cache_helper.cc @@ -311,7 +311,7 @@ int ViewCacheHelper::DoReadResponseComplete(int result) { data_->append(EscapeForHTML(response.headers->GetStatusLine())); data_->push_back('\n'); - void* iter = NULL; + size_t iter = 0; std::string name, value; while (response.headers->EnumerateHeaderLines(&iter, &name, &value)) { data_->append(EscapeForHTML(name)); diff --git a/net/websockets/websocket_stream_create_test_base.cc b/net/websockets/websocket_stream_create_test_base.cc index 4211e1a..00e5f7f 100644 --- a/net/websockets/websocket_stream_create_test_base.cc +++ b/net/websockets/websocket_stream_create_test_base.cc @@ -133,7 +133,7 @@ WebSocketStreamCreateTestBase::RequestHeadersToVector( std::vector WebSocketStreamCreateTestBase::ResponseHeadersToVector( const HttpResponseHeaders& headers) { - void* iter = NULL; + size_t iter = 0; std::string name, value; std::vector result; while (headers.EnumerateHeaderLines(&iter, &name, &value)) -- cgit v1.1