| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/feedback/anonymizer_tool.h" | 5 #include "components/feedback/anonymizer_tool.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" |
| 9 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 11 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 12 #include "third_party/re2/src/re2/re2.h" | 13 #include "third_party/re2/src/re2/re2.h" |
| 13 | 14 |
| 14 using re2::RE2; | 15 using re2::RE2; |
| 15 | 16 |
| 16 namespace feedback { | 17 namespace feedback { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 std::string anonymized = AnonymizeMACAddresses(input); | 232 std::string anonymized = AnonymizeMACAddresses(input); |
| 232 anonymized = AnonymizeCustomPatterns(std::move(anonymized)); | 233 anonymized = AnonymizeCustomPatterns(std::move(anonymized)); |
| 233 return anonymized; | 234 return anonymized; |
| 234 } | 235 } |
| 235 | 236 |
| 236 RE2* AnonymizerTool::GetRegExp(const std::string& pattern) { | 237 RE2* AnonymizerTool::GetRegExp(const std::string& pattern) { |
| 237 if (regexp_cache_.find(pattern) == regexp_cache_.end()) { | 238 if (regexp_cache_.find(pattern) == regexp_cache_.end()) { |
| 238 RE2::Options options; | 239 RE2::Options options; |
| 239 // set_multiline of pcre is not supported by RE2, yet. | 240 // set_multiline of pcre is not supported by RE2, yet. |
| 240 options.set_dot_nl(true); // Dot matches a new line. | 241 options.set_dot_nl(true); // Dot matches a new line. |
| 241 scoped_ptr<RE2> re = make_scoped_ptr(new RE2(pattern, options)); | 242 std::unique_ptr<RE2> re = base::WrapUnique(new RE2(pattern, options)); |
| 242 DCHECK_EQ(re2::RE2::NoError, re->error_code()) | 243 DCHECK_EQ(re2::RE2::NoError, re->error_code()) |
| 243 << "Failed to parse:\n" << pattern << "\n" << re->error(); | 244 << "Failed to parse:\n" << pattern << "\n" << re->error(); |
| 244 regexp_cache_[pattern] = std::move(re); | 245 regexp_cache_[pattern] = std::move(re); |
| 245 } | 246 } |
| 246 return regexp_cache_[pattern].get(); | 247 return regexp_cache_[pattern].get(); |
| 247 } | 248 } |
| 248 | 249 |
| 249 std::string AnonymizerTool::AnonymizeMACAddresses(const std::string& input) { | 250 std::string AnonymizerTool::AnonymizeMACAddresses(const std::string& input) { |
| 250 // This regular expression finds the next MAC address. It splits the data into | 251 // This regular expression finds the next MAC address. It splits the data into |
| 251 // an OUI (Organizationally Unique Identifier) part and a NIC (Network | 252 // an OUI (Organizationally Unique Identifier) part and a NIC (Network |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 } | 364 } |
| 364 | 365 |
| 365 skipped.AppendToString(&result); | 366 skipped.AppendToString(&result); |
| 366 result += replacement_id; | 367 result += replacement_id; |
| 367 } | 368 } |
| 368 text.AppendToString(&result); | 369 text.AppendToString(&result); |
| 369 return result; | 370 return result; |
| 370 } | 371 } |
| 371 | 372 |
| 372 } // namespace feedback | 373 } // namespace feedback |
| OLD | NEW |