• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 The Chromium 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 "base/debug/crash_logging.h"
6 
7 namespace base {
8 namespace debug {
9 
10 namespace {
11 
12 CrashKeyImplementation* g_crash_key_impl = nullptr;
13 
14 }  // namespace
15 
AllocateCrashKeyString(const char name[],CrashKeySize value_length)16 CrashKeyString* AllocateCrashKeyString(const char name[],
17                                        CrashKeySize value_length) {
18   if (!g_crash_key_impl)
19     return nullptr;
20 
21   return g_crash_key_impl->Allocate(name, value_length);
22 }
23 
SetCrashKeyString(CrashKeyString * crash_key,base::StringPiece value)24 void SetCrashKeyString(CrashKeyString* crash_key, base::StringPiece value) {
25   if (!g_crash_key_impl || !crash_key)
26     return;
27 
28   g_crash_key_impl->Set(crash_key, value);
29 }
30 
ClearCrashKeyString(CrashKeyString * crash_key)31 void ClearCrashKeyString(CrashKeyString* crash_key) {
32   if (!g_crash_key_impl || !crash_key)
33     return;
34 
35   g_crash_key_impl->Clear(crash_key);
36 }
37 
ScopedCrashKeyString(CrashKeyString * crash_key,base::StringPiece value)38 ScopedCrashKeyString::ScopedCrashKeyString(CrashKeyString* crash_key,
39                                            base::StringPiece value)
40     : crash_key_(crash_key) {
41   SetCrashKeyString(crash_key_, value);
42 }
43 
~ScopedCrashKeyString()44 ScopedCrashKeyString::~ScopedCrashKeyString() {
45   ClearCrashKeyString(crash_key_);
46 }
47 
SetCrashKeyImplementation(std::unique_ptr<CrashKeyImplementation> impl)48 void SetCrashKeyImplementation(std::unique_ptr<CrashKeyImplementation> impl) {
49   delete g_crash_key_impl;
50   g_crash_key_impl = impl.release();
51 }
52 
53 }  // namespace debug
54 }  // namespace base
55