// Copyright 2023 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifdef UNSAFE_BUFFERS_BUILD // TODO(crbug.com/351564777): Remove this and convert code to safer constructs. #pragma allow_unsafe_buffers #endif #include "extensions/browser/extension_function_crash_keys.h" #include <utility> #include <vector> #include "base/check.h" #include "base/containers/flat_map.h" #include "base/no_destructor.h" #include "base/time/time.h" #include "components/crash/core/common/crash_key.h" #include "extensions/common/extension_id.h" namespace extensions::extension_function_crash_keys { namespace { struct CallInfo { … }; // Returns a map from an extension ID to information about in-flight calls to // ExtensionFunction. Uses base::flat_map<> because the map is typically small // (0 or 1 item) and the size is bounded by the number of installed extensions. // NOTE: This approach isn't perfect. In particular, this call sequence ends up // with slightly odd reporting: // - API A start (1) // - API B start // - API A start (2) // - API A end (2) // This will report crash keys in the order (API A, API B) even though the most // recent API A call has completed. This seemms OK because it's true that API A // was the most recently called. It also avoids storing a stack of all in-flight // API calls with per-call IDs to match them up. During startup when extensions // are initializing there can be hundreds of in-flight calls. base::flat_map<ExtensionId, CallInfo>& ExtensionIdToCallInfoMap() { … } // Updates the crash keys for extensions with in-flight ExtensionFunction calls. void UpdateCrashKeys() { … } } // namespace void StartExtensionFunctionCall(const ExtensionId& extension_id) { … } void EndExtensionFunctionCall(const ExtensionId& extension_id) { … } } // namespace extensions::extension_function_crash_keys