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

Side by Side Diff: chrome/browser/safe_browsing/protocol_parser.cc

Issue 7004007: iwyu: Include stringprintf.h where appropriate, part 2. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix 2. Created 9 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) 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 // Parse the data returned from the SafeBrowsing v2.1 protocol response. 5 // Parse the data returned from the SafeBrowsing v2.1 protocol response.
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include "base/format_macros.h"
10 #include "base/logging.h"
11 #include "base/stringprintf.h"
12 #include "base/string_split.h"
13 #include "build/build_config.h"
9 #include "chrome/browser/safe_browsing/protocol_parser.h" 14 #include "chrome/browser/safe_browsing/protocol_parser.h"
10 #include "chrome/browser/safe_browsing/safe_browsing_util.h" 15 #include "chrome/browser/safe_browsing/safe_browsing_util.h"
11 16
12 #include "build/build_config.h"
13
14 #if defined(OS_WIN) 17 #if defined(OS_WIN)
15 #include <Winsock2.h> 18 #include <Winsock2.h>
16 #elif defined(OS_POSIX) 19 #elif defined(OS_POSIX)
17 #include <arpa/inet.h> 20 #include <arpa/inet.h>
18 #endif 21 #endif
19 22
20 #include "base/format_macros.h"
21 #include "base/logging.h"
22 #include "base/string_split.h"
23 #include "base/string_util.h"
24
25 namespace { 23 namespace {
26 // Helper function for quick scans of a line oriented protocol. Note that we use 24 // Helper function for quick scans of a line oriented protocol. Note that we use
27 // std::string::assign(const charT* s, size_type n) 25 // std::string::assign(const charT* s, size_type n)
28 // to copy data into 'line'. This form of 'assign' does not call strlen on 26 // to copy data into 'line'. This form of 'assign' does not call strlen on
29 // 'input', which is binary data and is not NULL terminated. 'input' may also 27 // 'input', which is binary data and is not NULL terminated. 'input' may also
30 // contain valid NULL bytes in the payload, which a strlen based copy would 28 // contain valid NULL bytes in the payload, which a strlen based copy would
31 // truncate. 29 // truncate.
32 bool GetLine(const char* input, int input_len, std::string* line) { 30 bool GetLine(const char* input, int input_len, std::string* line) {
33 const char* pos = input; 31 const char* pos = input;
34 while (pos && (pos - input < input_len)) { 32 while (pos && (pos - input < input_len)) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } 111 }
114 112
115 return length == 0; 113 return length == 0;
116 } 114 }
117 115
118 void SafeBrowsingProtocolParser::FormatGetHash( 116 void SafeBrowsingProtocolParser::FormatGetHash(
119 const std::vector<SBPrefix>& prefixes, std::string* request) { 117 const std::vector<SBPrefix>& prefixes, std::string* request) {
120 DCHECK(request); 118 DCHECK(request);
121 119
122 // Format the request for GetHash. 120 // Format the request for GetHash.
123 request->append(StringPrintf("%" PRIuS ":%" PRIuS "\n", 121 request->append(base::StringPrintf("%" PRIuS ":%" PRIuS "\n",
124 sizeof(SBPrefix), 122 sizeof(SBPrefix),
125 sizeof(SBPrefix) * prefixes.size())); 123 sizeof(SBPrefix) * prefixes.size()));
126 for (size_t i = 0; i < prefixes.size(); ++i) { 124 for (size_t i = 0; i < prefixes.size(); ++i) {
127 request->append(reinterpret_cast<const char*>(&prefixes[i]), 125 request->append(reinterpret_cast<const char*>(&prefixes[i]),
128 sizeof(SBPrefix)); 126 sizeof(SBPrefix));
129 } 127 }
130 } 128 }
131 129
132 bool SafeBrowsingProtocolParser::ParseUpdate( 130 bool SafeBrowsingProtocolParser::ParseUpdate(
133 const char* chunk_data, 131 const char* chunk_data,
134 int chunk_len, 132 int chunk_len,
135 const std::string& key, 133 const std::string& key,
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 486
489 data += line.size() + 1; 487 data += line.size() + 1;
490 remaining -= static_cast<int>(line.size()) + 1; 488 remaining -= static_cast<int>(line.size()) + 1;
491 } 489 }
492 490
493 if (client_key->empty() || wrapped_key->empty()) 491 if (client_key->empty() || wrapped_key->empty())
494 return false; 492 return false;
495 493
496 return true; 494 return true;
497 } 495 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/protocol_manager.cc ('k') | chrome/browser/safe_browsing/protocol_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698