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

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

Issue 2034393004: Allow multiple logging::LogMessage{Handler,Listener}s Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 3 years, 11 months 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/test/gtest_util.h » ('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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 const base::StringPiece& value) { 75 const base::StringPiece& value) {
76 AddReportParameter(base::SysUTF8ToNSString(key.as_string()), 76 AddReportParameter(base::SysUTF8ToNSString(key.as_string()),
77 base::SysUTF8ToNSString(value.as_string()), true); 77 base::SysUTF8ToNSString(value.as_string()), true);
78 } 78 }
79 79
80 // Callback for base::debug::SetCrashKeyReportingFunctions 80 // Callback for base::debug::SetCrashKeyReportingFunctions
81 void ClearCrashKeyValueImpl(const base::StringPiece& key) { 81 void ClearCrashKeyValueImpl(const base::StringPiece& key) {
82 RemoveReportParameter(base::SysUTF8ToNSString(key.as_string())); 82 RemoveReportParameter(base::SysUTF8ToNSString(key.as_string()));
83 } 83 }
84 84
85 // Callback for logging::SetLogMessageHandler 85 class FatalMessageListener : logging::LogMessageListener {
86 bool FatalMessageHandler(int severity, 86 void OnMessage(int severity,
87 const char* file, 87 const char* file,
88 int line, 88 int line,
89 size_t message_start, 89 size_t message_start,
90 const std::string& str) { 90 const std::string& str) override;
91 };
92
93 void FatalMessageListener::OnMessage(int severity,
94 const char* file,
95 int line,
96 size_t message_start,
97 const std::string& str) {
91 // Do not handle non-FATAL. 98 // Do not handle non-FATAL.
92 if (severity != logging::LOG_FATAL) 99 if (severity != logging::LOG_FATAL)
93 return false; 100 return;
94 101
95 // In case of OOM condition, this code could be reentered when 102 // In case of OOM condition, this code could be reentered when
96 // constructing and storing the key. Using a static is not 103 // constructing and storing the key. Using a static is not
97 // thread-safe, but if multiple threads are in the process of a 104 // thread-safe, but if multiple threads are in the process of a
98 // fatal crash at the same time, this should work. 105 // fatal crash at the same time, this should work.
99 static bool guarded = false; 106 static bool guarded = false;
100 if (guarded) 107 if (guarded)
101 return false; 108 return;
102 109
103 base::AutoReset<bool> guard(&guarded, true); 110 base::AutoReset<bool> guard(&guarded, true);
104 111
105 // Only log last path component. This matches logging.cc. 112 // Only log last path component. This matches logging.cc.
106 if (file) { 113 if (file) {
107 const char* slash = strrchr(file, '/'); 114 const char* slash = strrchr(file, '/');
108 if (slash) 115 if (slash)
109 file = slash + 1; 116 file = slash + 1;
110 } 117 }
111 118
112 NSString* fatal_key = @"LOG_FATAL"; 119 NSString* fatal_key = @"LOG_FATAL";
113 NSString* fatal_value = [NSString 120 NSString* fatal_value = [NSString
114 stringWithFormat:@"%s:%d: %s", file, line, str.c_str() + message_start]; 121 stringWithFormat:@"%s:%d: %s", file, line, str.c_str() + message_start];
115 AddReportParameter(fatal_key, fatal_value, true); 122 AddReportParameter(fatal_key, fatal_value, true);
116 123
117 // Rather than including the code to force the crash here, allow the 124 // Rather than including the code to force the crash here, allow the
118 // caller to do it. 125 // caller to do it.
119 return false;
120 } 126 }
121 127
122 // Caches the uploading flag in NSUserDefaults, so that we can access the value 128 // Caches the uploading flag in NSUserDefaults, so that we can access the value
123 // in safe mode. 129 // in safe mode.
124 void CacheUploadingEnabled(bool uploading_enabled) { 130 void CacheUploadingEnabled(bool uploading_enabled) {
125 NSUserDefaults* user_defaults = [NSUserDefaults standardUserDefaults]; 131 NSUserDefaults* user_defaults = [NSUserDefaults standardUserDefaults];
126 [user_defaults setBool:uploading_enabled ? YES : NO 132 [user_defaults setBool:uploading_enabled ? YES : NO
127 forKey:kCrashReportsUploadingEnabledKey]; 133 forKey:kCrashReportsUploadingEnabledKey];
128 } 134 }
129 135
130 } // namespace 136 } // namespace
131 137
132 void Start(const std::string& channel_name) { 138 void Start(const std::string& channel_name) {
133 DCHECK(!g_crash_reporter_enabled); 139 DCHECK(!g_crash_reporter_enabled);
134 [[BreakpadController sharedInstance] start:YES]; 140 [[BreakpadController sharedInstance] start:YES];
135 base::debug::SetCrashKeyReportingFunctions(&SetCrashKeyValueImpl, 141 base::debug::SetCrashKeyReportingFunctions(&SetCrashKeyValueImpl,
136 &ClearCrashKeyValueImpl); 142 &ClearCrashKeyValueImpl);
137 logging::SetLogMessageHandler(&FatalMessageHandler); 143 // Intentionally leak the listener.
144 auto* listener = new FatalMessageListener();
145 CHECK(listener);
146
138 g_crash_reporter_enabled = true; 147 g_crash_reporter_enabled = true;
139 // Register channel information. 148 // Register channel information.
140 if (channel_name.length()) { 149 if (channel_name.length()) {
141 AddReportParameter(@"channel", base::SysUTF8ToNSString(channel_name), true); 150 AddReportParameter(@"channel", base::SysUTF8ToNSString(channel_name), true);
142 } 151 }
143 // Notifying the PathService on the location of the crashes so that crashes 152 // Notifying the PathService on the location of the crashes so that crashes
144 // can be displayed to the user on the about:crashes page. 153 // can be displayed to the user on the about:crashes page.
145 NSArray* cachesDirectories = NSSearchPathForDirectoriesInDomains( 154 NSArray* cachesDirectories = NSSearchPathForDirectoriesInDomains(
146 NSCachesDirectory, NSUserDomainMask, YES); 155 NSCachesDirectory, NSUserDomainMask, YES);
147 NSString* cachePath = [cachesDirectories objectAtIndex:0]; 156 NSString* cachePath = [cachesDirectories objectAtIndex:0];
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 void RestoreDefaultConfiguration() { 371 void RestoreDefaultConfiguration() {
363 if (!g_crash_reporter_enabled) 372 if (!g_crash_reporter_enabled)
364 return; 373 return;
365 [[BreakpadController sharedInstance] stop]; 374 [[BreakpadController sharedInstance] stop];
366 [[BreakpadController sharedInstance] resetConfiguration]; 375 [[BreakpadController sharedInstance] resetConfiguration];
367 [[BreakpadController sharedInstance] start:NO]; 376 [[BreakpadController sharedInstance] start:NO];
368 [[BreakpadController sharedInstance] setUploadingEnabled:NO]; 377 [[BreakpadController sharedInstance] setUploadingEnabled:NO];
369 } 378 }
370 379
371 } // namespace breakpad_helper 380 } // namespace breakpad_helper
OLDNEW
« no previous file with comments | « content/gpu/gpu_main.cc ('k') | net/test/gtest_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698