Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: ios/chrome/browser/crash_report/breakpad_helper.mm

Issue 2497833002: support multiple log message handlers in base/logging.h (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/gpu/gpu_main.cc ('k') | net/tools/stress_cache/stress_cache.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ios/chrome/browser/crash_report/breakpad_helper.h" 5 #include "ios/chrome/browser/crash_report/breakpad_helper.h"
6 6
7 #import <Foundation/Foundation.h> 7 #import <Foundation/Foundation.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 const base::StringPiece& value) { 71 const base::StringPiece& value) {
72 AddReportParameter(base::SysUTF8ToNSString(key.as_string()), 72 AddReportParameter(base::SysUTF8ToNSString(key.as_string()),
73 base::SysUTF8ToNSString(value.as_string()), true); 73 base::SysUTF8ToNSString(value.as_string()), true);
74 } 74 }
75 75
76 // Callback for base::debug::SetCrashKeyReportingFunctions 76 // Callback for base::debug::SetCrashKeyReportingFunctions
77 void ClearCrashKeyValueImpl(const base::StringPiece& key) { 77 void ClearCrashKeyValueImpl(const base::StringPiece& key) {
78 RemoveReportParameter(base::SysUTF8ToNSString(key.as_string())); 78 RemoveReportParameter(base::SysUTF8ToNSString(key.as_string()));
79 } 79 }
80 80
81 // Callback for logging::SetLogMessageHandler 81 // Callback for logging::AddLogMessageHandler
82 bool FatalMessageHandler(int severity, 82 bool FatalMessageHandler(int severity,
83 const char* file, 83 const std::string& file,
84 int line, 84 int line,
85 size_t message_start,
86 const std::string& str) { 85 const std::string& str) {
87 // Do not handle non-FATAL. 86 // Do not handle non-FATAL.
88 if (severity != logging::LOG_FATAL) 87 if (severity != logging::LOG_FATAL)
89 return false; 88 return false;
90 89
91 // In case of OOM condition, this code could be reentered when 90 // In case of OOM condition, this code could be reentered when
92 // constructing and storing the key. Using a static is not 91 // constructing and storing the key. Using a static is not
93 // thread-safe, but if multiple threads are in the process of a 92 // thread-safe, but if multiple threads are in the process of a
94 // fatal crash at the same time, this should work. 93 // fatal crash at the same time, this should work.
95 static bool guarded = false; 94 static bool guarded = false;
96 if (guarded) 95 if (guarded)
97 return false; 96 return false;
98 97
99 base::AutoReset<bool> guard(&guarded, true); 98 base::AutoReset<bool> guard(&guarded, true);
100 99
101 // Only log last path component. This matches logging.cc. 100 // Only log last path component. This matches logging.cc.
102 if (file) { 101 size_t last_slash = file.rfind('/');
103 const char* slash = strrchr(file, '/'); 102 if (last_slash == file.npos)
104 if (slash) 103 last_slash = 0;
105 file = slash + 1; 104 else
106 } 105 last_slash++;
107 106
108 NSString* fatal_key = @"LOG_FATAL"; 107 NSString* fatal_key = @"LOG_FATAL";
109 NSString* fatal_value = [NSString 108 NSString* fatal_value =
110 stringWithFormat:@"%s:%d: %s", file, line, str.c_str() + message_start]; 109 [NSString stringWithFormat:@"%s:%d: %s", file.substr(last_slash).c_str(),
110 line, str.c_str()];
111 AddReportParameter(fatal_key, fatal_value, true); 111 AddReportParameter(fatal_key, fatal_value, true);
112 112
113 // Rather than including the code to force the crash here, allow the 113 // Rather than including the code to force the crash here, allow the
114 // caller to do it. 114 // caller to do it.
115 return false; 115 return false;
116 } 116 }
117 117
118 // Caches the uploading flag in NSUserDefaults, so that we can access the value 118 // Caches the uploading flag in NSUserDefaults, so that we can access the value
119 // in safe mode. 119 // in safe mode.
120 void CacheUploadingEnabled(bool uploading_enabled) { 120 void CacheUploadingEnabled(bool uploading_enabled) {
121 NSUserDefaults* user_defaults = [NSUserDefaults standardUserDefaults]; 121 NSUserDefaults* user_defaults = [NSUserDefaults standardUserDefaults];
122 [user_defaults setBool:uploading_enabled ? YES : NO 122 [user_defaults setBool:uploading_enabled ? YES : NO
123 forKey:kCrashReportsUploadingEnabledKey]; 123 forKey:kCrashReportsUploadingEnabledKey];
124 } 124 }
125 125
126 } // namespace 126 } // namespace
127 127
128 void Start(const std::string& channel_name) { 128 void Start(const std::string& channel_name) {
129 DCHECK(!g_crash_reporter_enabled); 129 DCHECK(!g_crash_reporter_enabled);
130 [[BreakpadController sharedInstance] start:YES]; 130 [[BreakpadController sharedInstance] start:YES];
131 base::debug::SetCrashKeyReportingFunctions(&SetCrashKeyValueImpl, 131 base::debug::SetCrashKeyReportingFunctions(&SetCrashKeyValueImpl,
132 &ClearCrashKeyValueImpl); 132 &ClearCrashKeyValueImpl);
133 logging::SetLogMessageHandler(&FatalMessageHandler); 133 logging::AddLogMessageHandler(&FatalMessageHandler);
134 g_crash_reporter_enabled = true; 134 g_crash_reporter_enabled = true;
135 // Register channel information. 135 // Register channel information.
136 if (channel_name.length()) { 136 if (channel_name.length()) {
137 AddReportParameter(@"channel", base::SysUTF8ToNSString(channel_name), true); 137 AddReportParameter(@"channel", base::SysUTF8ToNSString(channel_name), true);
138 } 138 }
139 // Notifying the PathService on the location of the crashes so that crashes 139 // Notifying the PathService on the location of the crashes so that crashes
140 // can be displayed to the user on the about:crashes page. 140 // can be displayed to the user on the about:crashes page.
141 NSArray* cachesDirectories = NSSearchPathForDirectoriesInDomains( 141 NSArray* cachesDirectories = NSSearchPathForDirectoriesInDomains(
142 NSCachesDirectory, NSUserDomainMask, YES); 142 NSCachesDirectory, NSUserDomainMask, YES);
143 NSString* cachePath = [cachesDirectories objectAtIndex:0]; 143 NSString* cachePath = [cachesDirectories objectAtIndex:0];
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 void RestoreDefaultConfiguration() { 360 void RestoreDefaultConfiguration() {
361 if (!g_crash_reporter_enabled) 361 if (!g_crash_reporter_enabled)
362 return; 362 return;
363 [[BreakpadController sharedInstance] stop]; 363 [[BreakpadController sharedInstance] stop];
364 [[BreakpadController sharedInstance] resetConfiguration]; 364 [[BreakpadController sharedInstance] resetConfiguration];
365 [[BreakpadController sharedInstance] start:NO]; 365 [[BreakpadController sharedInstance] start:NO];
366 [[BreakpadController sharedInstance] setUploadingEnabled:NO]; 366 [[BreakpadController sharedInstance] setUploadingEnabled:NO];
367 } 367 }
368 368
369 } // namespace breakpad_helper 369 } // namespace breakpad_helper
OLDNEW
« no previous file with comments | « content/gpu/gpu_main.cc ('k') | net/tools/stress_cache/stress_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698