f2c341b655
* chore: bump chromium in DEPS to 108.0.5339.0 * chore: bump chromium in DEPS to 108.0.5341.0 * chore: sync patch to unrelated upstream code shear patches/chromium/network_service_allow_remote_certificate_verification_logic.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3927793 * chore: sync patch to unrelated upstream code shear patches/chromium/printing.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3927793 * chore: sync patch to unrelated upstream code shear patches/chromium/chore_add_electron_deps_to_gitignores.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3906023 * chore: refresh patches - `e patches all` * chore: remove unused parameter from WillCreateURLLoaderRequestInterceptors Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3932218 * perf: avoid unique pointer round trip Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3913938 * refactor: Simplify entropy provider management. Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3901211 * fixup! perf: avoid unique pointer round trip * fixup! perf: avoid unique pointer round trip * refactor: update typeof FileSelectHelper::select_file_dialog_ Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3930092 * fixup! fixup! perf: avoid unique pointer round trip * chore: bump chromium in DEPS to 108.0.5343.0 * chore: update patches * chore: bump chromium in DEPS to 108.0.5345.0 * chore: bump chromium in DEPS to 108.0.5347.0 * chore: bump chromium in DEPS to 108.0.5349.0 * chore: bump chromium in DEPS to 108.0.5351.0 * chore: bump chromium in DEPS to 108.0.5353.0 * chore: bump chromium in DEPS to 108.0.5355.0 * chore: update patches * Refactor display::win::DisplayInfo to display::win::internal::DisplayInfo Refs https://chromium-review.googlesource.com/c/chromium/src/+/3929014 * Update proxy resolution to use NAK - Part 2 Refs https://chromium-review.googlesource.com/c/chromium/src/+/3934016 * Disable PreconnectManager when the user disabled preloading. Refs https://chromium-review.googlesource.com/c/chromium/src/+/3928470 Refs https://chromium-review.googlesource.com/c/chromium/src/+/3937183 * chore: update patches * chore: update sysroot * linux: Remove breakpad integration Refs https://chromium-review.googlesource.com/c/chromium/src/+/3764621 * chore: update comments Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: electron-patch-conflict-fixer[bot] <83340002+electron-patch-conflict-fixer[bot]@users.noreply.github.com>
143 lines
4.4 KiB
C++
143 lines
4.4 KiB
C++
// Copyright (c) 2020 Slack Technologies, Inc.
|
|
// Use of this source code is governed by the MIT license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "shell/common/crash_keys.h"
|
|
|
|
#include <deque>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
#include "base/command_line.h"
|
|
#include "base/environment.h"
|
|
#include "base/no_destructor.h"
|
|
#include "base/strings/string_split.h"
|
|
#include "components/crash/core/common/crash_key.h"
|
|
#include "content/public/common/content_switches.h"
|
|
#include "electron/buildflags/buildflags.h"
|
|
#include "electron/fuses.h"
|
|
#include "shell/browser/javascript_environment.h"
|
|
#include "shell/common/electron_constants.h"
|
|
#include "shell/common/node_includes.h"
|
|
#include "shell/common/options_switches.h"
|
|
#include "shell/common/process_util.h"
|
|
#include "third_party/crashpad/crashpad/client/annotation.h"
|
|
|
|
namespace electron::crash_keys {
|
|
|
|
namespace {
|
|
|
|
constexpr size_t kMaxCrashKeyValueSize = 20320;
|
|
static_assert(kMaxCrashKeyValueSize < crashpad::Annotation::kValueMaxSize,
|
|
"max crash key value length above what crashpad supports");
|
|
|
|
using ExtraCrashKeys =
|
|
std::deque<crash_reporter::CrashKeyString<kMaxCrashKeyValueSize>>;
|
|
ExtraCrashKeys& GetExtraCrashKeys() {
|
|
static base::NoDestructor<ExtraCrashKeys> extra_keys;
|
|
return *extra_keys;
|
|
}
|
|
|
|
std::deque<std::string>& GetExtraCrashKeyNames() {
|
|
static base::NoDestructor<std::deque<std::string>> crash_key_names;
|
|
return *crash_key_names;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
constexpr uint32_t kMaxCrashKeyNameLength = 40;
|
|
static_assert(kMaxCrashKeyNameLength <= crashpad::Annotation::kNameMaxLength,
|
|
"max crash key name length above what crashpad supports");
|
|
|
|
void SetCrashKey(const std::string& key, const std::string& value) {
|
|
// Chrome DCHECK()s if we try to set an annotation with a name longer than
|
|
// the max.
|
|
if (key.size() >= kMaxCrashKeyNameLength) {
|
|
node::Environment* env =
|
|
node::Environment::GetCurrent(JavascriptEnvironment::GetIsolate());
|
|
EmitWarning(env,
|
|
"The crash key name, \"" + key + "\", is longer than " +
|
|
std::to_string(kMaxCrashKeyNameLength) +
|
|
" bytes, ignoring it.",
|
|
"electron");
|
|
return;
|
|
}
|
|
|
|
auto& crash_key_names = GetExtraCrashKeyNames();
|
|
|
|
auto iter = std::find(crash_key_names.begin(), crash_key_names.end(), key);
|
|
if (iter == crash_key_names.end()) {
|
|
crash_key_names.emplace_back(key);
|
|
GetExtraCrashKeys().emplace_back(crash_key_names.back().c_str());
|
|
iter = crash_key_names.end() - 1;
|
|
}
|
|
GetExtraCrashKeys()[iter - crash_key_names.begin()].Set(value);
|
|
}
|
|
|
|
void ClearCrashKey(const std::string& key) {
|
|
const auto& crash_key_names = GetExtraCrashKeyNames();
|
|
|
|
auto iter = std::find(crash_key_names.begin(), crash_key_names.end(), key);
|
|
if (iter != crash_key_names.end()) {
|
|
GetExtraCrashKeys()[iter - crash_key_names.begin()].Clear();
|
|
}
|
|
}
|
|
|
|
void GetCrashKeys(std::map<std::string, std::string>* keys) {
|
|
const auto& crash_key_names = GetExtraCrashKeyNames();
|
|
const auto& crash_keys = GetExtraCrashKeys();
|
|
int i = 0;
|
|
for (const auto& key : crash_key_names) {
|
|
const auto& value = crash_keys[i++];
|
|
if (value.is_set()) {
|
|
keys->emplace(key, value.value());
|
|
}
|
|
}
|
|
}
|
|
|
|
namespace {
|
|
bool IsRunningAsNode() {
|
|
#if BUILDFLAG(ENABLE_RUN_AS_NODE)
|
|
if (!electron::fuses::IsRunAsNodeEnabled())
|
|
return false;
|
|
|
|
return base::Environment::Create()->HasVar(electron::kRunAsNode);
|
|
#else
|
|
return false;
|
|
#endif
|
|
}
|
|
} // namespace
|
|
|
|
void SetCrashKeysFromCommandLine(const base::CommandLine& command_line) {
|
|
// NB. this is redundant with the 'ptype' key that //components/crash
|
|
// reports; it's present for backwards compatibility.
|
|
static crash_reporter::CrashKeyString<16> process_type_key("process_type");
|
|
if (IsRunningAsNode()) {
|
|
process_type_key.Set("node");
|
|
} else {
|
|
std::string process_type =
|
|
command_line.GetSwitchValueASCII(::switches::kProcessType);
|
|
if (process_type.empty()) {
|
|
process_type_key.Set("browser");
|
|
} else {
|
|
process_type_key.Set(process_type);
|
|
}
|
|
}
|
|
}
|
|
|
|
void SetPlatformCrashKey() {
|
|
// TODO(nornagon): this is redundant with the 'plat' key that
|
|
// //components/crash already includes. Remove it.
|
|
static crash_reporter::CrashKeyString<8> platform_key("platform");
|
|
#if BUILDFLAG(IS_WIN)
|
|
platform_key.Set("win32");
|
|
#elif BUILDFLAG(IS_MAC)
|
|
platform_key.Set("darwin");
|
|
#elif BUILDFLAG(IS_LINUX)
|
|
platform_key.Set("linux");
|
|
#else
|
|
platform_key.Set("unknown");
|
|
#endif
|
|
}
|
|
|
|
} // namespace electron::crash_keys
|