Commit d6462ea0 authored by Mike Dougherty's avatar Mike Dougherty Committed by Commit Bot

[iOS] Set breadcrumb events from previous sessions on the crash report

Bug: 1117667
Change-Id: I3f2fb6a013697ad414c7d5458d0bebb68ee2749b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2363702
Commit-Queue: Mike Dougherty <michaeldo@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800016}
parent 12ead4d3
......@@ -974,6 +974,7 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
BreadcrumbManagerKeyedServiceFactory::GetForBrowserState(
strongSelf.mainBrowserState)
->SetPreviousEvents(events);
breakpad::SetPreviousSessionEvents(events);
// Notify persistent breadcrumb service to clear old breadcrumbs and
// start storing breadcrumbs for this session.
......
......@@ -5,6 +5,9 @@
#ifndef IOS_CHROME_BROWSER_CRASH_REPORT_CRASH_REPORT_HELPER_H_
#define IOS_CHROME_BROWSER_CRASH_REPORT_CRASH_REPORT_HELPER_H_
#include <string>
#include <vector>
@class NSString;
class BreadcrumbManager;
......@@ -67,6 +70,9 @@ void MonitorBreadcrumbManagerService(
void StopMonitoringBreadcrumbManagerService(
BreadcrumbManagerKeyedService* breadcrumb_manager_service);
// Sets breadcrumb events associated with the previous application session.
void SetPreviousSessionEvents(const std::vector<std::string>& events);
} // namespace breakpad
#endif // IOS_CHROME_BROWSER_CRASH_REPORT_CRASH_REPORT_HELPER_H_
......@@ -258,4 +258,9 @@ void StopMonitoringBreadcrumbManagerService(
stopObservingBreadcrumbManagerService:breadcrumb_manager_service];
}
void SetPreviousSessionEvents(const std::vector<std::string>& events) {
[[CrashReporterBreadcrumbObserver uniqueInstance]
setPreviousSessionEvents:events];
}
} // namespace breakpad
......@@ -21,6 +21,9 @@
// Creates a singleton instance.
+ (CrashReporterBreadcrumbObserver*)uniqueInstance;
// Sets breadcrumb events associated with the previous application session.
- (void)setPreviousSessionEvents:(const std::vector<std::string>&)events;
// Starts collecting breadcrumb events logged to |breadcrumbManager|.
- (void)observeBreadcrumbManager:(BreadcrumbManager*)breadcrumbManager;
......
......@@ -4,6 +4,7 @@
#include "ios/chrome/browser/crash_report/crash_reporter_breadcrumb_observer.h"
#include "base/strings/sys_string_conversions.h"
#include "ios/chrome/browser/crash_report/breadcrumbs/breadcrumb_manager.h"
#import "ios/chrome/browser/crash_report/breadcrumbs/breadcrumb_manager_observer_bridge.h"
#include "ios/chrome/browser/crash_report/crash_keys_helper.h"
......@@ -30,6 +31,10 @@
// in order to reduce overall memory usage.
NSMutableString* _breadcrumbs;
}
// Updates the breadcrumbs stored in the crash log.
- (void)updateBreadcrumbEventsCrashKey;
@end
@implementation CrashReporterBreadcrumbObserver
......@@ -73,13 +78,17 @@
_breadcrumbManagerServiceObservers[breadcrumbManagerService] = nullptr;
}
#pragma mark - BreadcrumbManagerObserving protocol
- (void)setPreviousSessionEvents:(const std::vector<std::string>&)events {
for (auto event_it = events.rbegin(); event_it != events.rend(); ++event_it) {
NSString* event = base::SysUTF8ToNSString(*event_it);
NSString* eventWithSeperator = [NSString stringWithFormat:@"%@\n", event];
[_breadcrumbs appendString:eventWithSeperator];
}
- (void)breadcrumbManager:(BreadcrumbManager*)manager
didAddEvent:(NSString*)event {
NSString* eventWithSeperator = [NSString stringWithFormat:@"%@\n", event];
[_breadcrumbs insertString:eventWithSeperator atIndex:0];
[self updateBreadcrumbEventsCrashKey];
}
- (void)updateBreadcrumbEventsCrashKey {
if (_breadcrumbs.length > kMaxBreadcrumbsDataLength) {
NSRange trimRange =
NSMakeRange(kMaxBreadcrumbsDataLength,
......@@ -90,4 +99,14 @@
crash_keys::SetBreadcrumbEvents(_breadcrumbs);
}
#pragma mark - BreadcrumbManagerObserving protocol
- (void)breadcrumbManager:(BreadcrumbManager*)manager
didAddEvent:(NSString*)event {
NSString* eventWithSeperator = [NSString stringWithFormat:@"%@\n", event];
[_breadcrumbs insertString:eventWithSeperator atIndex:0];
[self updateBreadcrumbEventsCrashKey];
}
@end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment