1 // Copyright 2018 The Chromium Embedded Framework Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "libcef/common/cef_crash_report_utils.h" 6 7 #include "base/strings/string_split.h" 8 9 namespace crash_report_utils { 10 FilterParameters(const ParameterMap & parameters)11ParameterMap FilterParameters(const ParameterMap& parameters) { 12 ParameterMap in_map = parameters; 13 14 // Extract the key map, if any. Must match the logic in 15 // CefCrashReporterClient::ReadCrashConfigFile. 16 std::string key_map; 17 for (size_t i = 0; true; ++i) { 18 const std::string& key = "K-" + std::string(1, 'A' + i); 19 ParameterMap::iterator it = in_map.find(key); 20 if (it == in_map.end()) 21 break; 22 key_map += it->second; 23 in_map.erase(it); 24 } 25 26 if (key_map.empty()) { 27 // Nothing to substitute. 28 return parameters; 29 } 30 31 // Parse |key_map|. 32 base::StringPairs kv_pairs; 33 if (!base::SplitStringIntoKeyValuePairs(key_map, '=', ',', &kv_pairs)) { 34 return parameters; 35 } 36 37 ParameterMap subs; 38 for (const auto& pairs : kv_pairs) { 39 subs.insert(std::make_pair(pairs.first, pairs.second)); 40 } 41 42 ParameterMap out_map; 43 44 // Perform key substitutions. 45 for (const auto& params : in_map) { 46 std::string key = params.first; 47 ParameterMap::const_iterator subs_it = subs.find(params.first); 48 if (subs_it != subs.end()) { 49 key = subs_it->second; 50 } 51 out_map.insert(std::make_pair(key, params.second)); 52 } 53 54 return out_map; 55 } 56 57 } // namespace crash_report_utils 58