summaryrefslogtreecommitdiff
path: root/libcef/common/cef_crash_report_utils.cc
blob: 2980643d6c5ba267e5237dd3575f6f39e478fd3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2018 The Chromium Embedded Framework Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "libcef/common/cef_crash_report_utils.h"

#include "base/strings/string_split.h"

namespace crash_report_utils {

ParameterMap FilterParameters(const ParameterMap& parameters) {
  ParameterMap in_map = parameters;

  // Extract the key map, if any. Must match the logic in
  // CefCrashReporterClient::ReadCrashConfigFile.
  std::string key_map;
  for (size_t i = 0; true; ++i) {
    const std::string& key = "K-" + std::string(1, 'A' + i);
    ParameterMap::iterator it = in_map.find(key);
    if (it == in_map.end()) {
      break;
    }
    key_map += it->second;
    in_map.erase(it);
  }

  if (key_map.empty()) {
    // Nothing to substitute.
    return parameters;
  }

  // Parse |key_map|.
  base::StringPairs kv_pairs;
  if (!base::SplitStringIntoKeyValuePairs(key_map, '=', ',', &kv_pairs)) {
    return parameters;
  }

  ParameterMap subs;
  for (const auto& pairs : kv_pairs) {
    subs.insert(std::make_pair(pairs.first, pairs.second));
  }

  ParameterMap out_map;

  // Perform key substitutions.
  for (const auto& params : in_map) {
    std::string key = params.first;
    ParameterMap::const_iterator subs_it = subs.find(params.first);
    if (subs_it != subs.end()) {
      key = subs_it->second;
    }
    out_map.insert(std::make_pair(key, params.second));
  }

  return out_map;
}

}  // namespace crash_report_utils