| OLD | NEW |
| 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 // Implementation of ChunkRange class. | 5 // Implementation of ChunkRange class. |
| 6 | 6 |
| 7 #include "chrome/browser/safe_browsing/chunk_range.h" | 7 #include "chrome/browser/safe_browsing/chunk_range.h" |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 bool StringToRanges(const std::string& input, | 74 bool StringToRanges(const std::string& input, |
| 75 std::vector<ChunkRange>* ranges) { | 75 std::vector<ChunkRange>* ranges) { |
| 76 DCHECK(ranges); | 76 DCHECK(ranges); |
| 77 | 77 |
| 78 // Crack the string into chunk parts, then crack each part looking for a | 78 // Crack the string into chunk parts, then crack each part looking for a |
| 79 // range. | 79 // range. |
| 80 std::vector<std::string> chunk_parts; | 80 std::vector<std::string> chunk_parts; |
| 81 SplitString(input, ',', &chunk_parts); | 81 base::SplitString(input, ',', &chunk_parts); |
| 82 | 82 |
| 83 for (size_t i = 0; i < chunk_parts.size(); ++i) { | 83 for (size_t i = 0; i < chunk_parts.size(); ++i) { |
| 84 std::vector<std::string> chunk_ranges; | 84 std::vector<std::string> chunk_ranges; |
| 85 SplitString(chunk_parts[i], '-', &chunk_ranges); | 85 base::SplitString(chunk_parts[i], '-', &chunk_ranges); |
| 86 int start = atoi(chunk_ranges[0].c_str()); | 86 int start = atoi(chunk_ranges[0].c_str()); |
| 87 int stop = start; | 87 int stop = start; |
| 88 if (chunk_ranges.size() == 2) | 88 if (chunk_ranges.size() == 2) |
| 89 stop = atoi(chunk_ranges[1].c_str()); | 89 stop = atoi(chunk_ranges[1].c_str()); |
| 90 if (start == 0 || stop == 0) { | 90 if (start == 0 || stop == 0) { |
| 91 // atoi error, since chunk numbers are guaranteed to never be 0. | 91 // atoi error, since chunk numbers are guaranteed to never be 0. |
| 92 ranges->clear(); | 92 ranges->clear(); |
| 93 return false; | 93 return false; |
| 94 } | 94 } |
| 95 ranges->push_back(ChunkRange(start, stop)); | 95 ranges->push_back(ChunkRange(start, stop)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 115 | 115 |
| 116 // Adjust our mid point. | 116 // Adjust our mid point. |
| 117 if (chunk.stop() < chunk_number) | 117 if (chunk.stop() < chunk_number) |
| 118 low = mid + 1; | 118 low = mid + 1; |
| 119 else | 119 else |
| 120 high = mid - 1; | 120 high = mid - 1; |
| 121 } | 121 } |
| 122 | 122 |
| 123 return false; | 123 return false; |
| 124 } | 124 } |
| OLD | NEW |