| OLD | NEW |
| 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/quic/quic_utils.h" | 5 #include "net/quic/quic_utils.h" |
| 6 | 6 |
| 7 #include <ctype.h> | 7 #include <ctype.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/containers/adapters.h" |
| 12 #include "base/logging.h" | 14 #include "base/logging.h" |
| 13 #include "base/port.h" | 15 #include "base/port.h" |
| 14 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 15 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/string_split.h" |
| 16 #include "net/quic/quic_write_blocked_list.h" | 19 #include "net/quic/quic_write_blocked_list.h" |
| 17 | 20 |
| 18 using base::StringPiece; | 21 using base::StringPiece; |
| 19 using std::string; | 22 using std::string; |
| 20 | 23 |
| 21 namespace net { | 24 namespace net { |
| 22 | 25 |
| 23 // static | 26 // static |
| 24 uint64 QuicUtils::FNV1a_64_Hash(const char* data, int len) { | 27 uint64 QuicUtils::FNV1a_64_Hash(const char* data, int len) { |
| 25 static const uint64 kOffset = GG_UINT64_C(14695981039346656037); | 28 static const uint64 kOffset = GG_UINT64_C(14695981039346656037); |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 } | 276 } |
| 274 | 277 |
| 275 if (ascii) { | 278 if (ascii) { |
| 276 return string(chars, sizeof(chars)); | 279 return string(chars, sizeof(chars)); |
| 277 } | 280 } |
| 278 | 281 |
| 279 return base::UintToString(orig_tag); | 282 return base::UintToString(orig_tag); |
| 280 } | 283 } |
| 281 | 284 |
| 282 // static | 285 // static |
| 286 QuicTagVector QuicUtils::ParseQuicConnectionOptions( |
| 287 const std::string& connection_options) { |
| 288 QuicTagVector options; |
| 289 std::vector<std::string> tokens; |
| 290 base::SplitString(connection_options, ',', &tokens); |
| 291 // Tokens are expected to be no more than 4 characters long, but we |
| 292 // handle overflow gracefully. |
| 293 for (const std::string& token : tokens) { |
| 294 uint32 option = 0; |
| 295 for (char token_char : base::Reversed(token)) { |
| 296 option <<= 8; |
| 297 option |= static_cast<unsigned char>(token_char); |
| 298 } |
| 299 options.push_back(option); |
| 300 } |
| 301 return options; |
| 302 } |
| 303 |
| 304 // static |
| 283 string QuicUtils::StringToHexASCIIDump(StringPiece in_buffer) { | 305 string QuicUtils::StringToHexASCIIDump(StringPiece in_buffer) { |
| 284 int offset = 0; | 306 int offset = 0; |
| 285 const int kBytesPerLine = 16; // Max bytes dumped per line | 307 const int kBytesPerLine = 16; // Max bytes dumped per line |
| 286 const char* buf = in_buffer.data(); | 308 const char* buf = in_buffer.data(); |
| 287 int bytes_remaining = in_buffer.size(); | 309 int bytes_remaining = in_buffer.size(); |
| 288 string s; // our output | 310 string s; // our output |
| 289 const char* p = buf; | 311 const char* p = buf; |
| 290 while (bytes_remaining > 0) { | 312 while (bytes_remaining > 0) { |
| 291 const int line_bytes = std::min(bytes_remaining, kBytesPerLine); | 313 const int line_bytes = std::min(bytes_remaining, kBytesPerLine); |
| 292 base::StringAppendF(&s, "0x%04x: ", offset); // Do the line header | 314 base::StringAppendF(&s, "0x%04x: ", offset); // Do the line header |
| (...skipping 22 matching lines...) Expand all Loading... |
| 315 QuicPriority QuicUtils::LowestPriority() { | 337 QuicPriority QuicUtils::LowestPriority() { |
| 316 return QuicWriteBlockedList::kLowestPriority; | 338 return QuicWriteBlockedList::kLowestPriority; |
| 317 } | 339 } |
| 318 | 340 |
| 319 // static | 341 // static |
| 320 QuicPriority QuicUtils::HighestPriority() { | 342 QuicPriority QuicUtils::HighestPriority() { |
| 321 return QuicWriteBlockedList::kHighestPriority; | 343 return QuicWriteBlockedList::kHighestPriority; |
| 322 } | 344 } |
| 323 | 345 |
| 324 } // namespace net | 346 } // namespace net |
| OLD | NEW |