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

Unified Diff: ios/chrome/browser/crash_report/crash_report_multi_parameter.mm

Issue 1207353005: [iOS] Upstream some stability code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/crash_report/crash_report_multi_parameter.mm
diff --git a/ios/chrome/browser/crash_report/crash_report_multi_parameter.mm b/ios/chrome/browser/crash_report/crash_report_multi_parameter.mm
new file mode 100644
index 0000000000000000000000000000000000000000..969ae1464af04b5b24a0f268e08ab9f27d8a1692
--- /dev/null
+++ b/ios/chrome/browser/crash_report/crash_report_multi_parameter.mm
@@ -0,0 +1,87 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/chrome/browser/crash_report/crash_report_multi_parameter.h"
+
+#include "base/json/json_writer.h"
+#include "base/logging.h"
+#import "base/mac/scoped_nsobject.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/values.h"
+#import "ios/chrome/browser/crash_report/breakpad_helper.h"
+
+namespace {
+// Maximum size of a breakpad parameter. he length of the dictionary serialized
+// into JSON cannot exceed this length. See declaration in (BreakPad.h) for
+// details.
+const int kMaximumBreakpadValueSize = 255;
+}
+
+@implementation CrashReportMultiParameter {
+ @private
sdefresne 2015/07/08 14:18:34 @private is not required since it is in the implem
+ base::scoped_nsobject<NSString> crashReportKey_;
+ scoped_ptr<base::DictionaryValue> dictionary_;
+}
+
+- (id)init {
sdefresne 2015/07/08 14:18:34 id -> instancetype
+ NOTREACHED();
+ return nil;
+}
+
+- (id)initWithKey:(NSString*)key {
sdefresne 2015/07/08 14:18:34 id -> instancetype
+ if ((self = [super init])) {
+ DCHECK([key length] && ([key length] <= kMaximumBreakpadValueSize));
+ dictionary_.reset(new base::DictionaryValue());
+ crashReportKey_.reset([key copy]);
+ }
+ return self;
+}
+
+- (void)removeValue:(NSString*)key {
+ dictionary_->Remove([key UTF8String], NULL);
sdefresne 2015/07/08 14:18:34 Shouldn't all those [... UTF8String] be SysNSStrin
+ [self updateCrashReport];
+}
+
+- (void)setValue:(NSString*)key withValue:(int)value {
+ dictionary_->SetInteger([key UTF8String], value);
+ [self updateCrashReport];
+}
+
+- (void)incrementValue:(NSString*)key {
+ int value;
+ if (dictionary_->GetInteger([key UTF8String], &value)) {
+ dictionary_->SetInteger([key UTF8String], value + 1);
+ } else {
+ dictionary_->SetInteger([key UTF8String], 1);
+ }
+ [self updateCrashReport];
+}
+
+- (void)decrementValue:(NSString*)key {
+ int value;
+ if (dictionary_->GetInteger([key UTF8String], &value)) {
+ if (value <= 1) {
+ dictionary_->Remove([key UTF8String], NULL);
+ } else {
+ dictionary_->SetInteger([key UTF8String], value - 1);
+ }
+ [self updateCrashReport];
+ }
+}
+
+- (void)updateCrashReport {
+ std::string stateAsJson;
+ base::JSONWriter::Write(*dictionary_.get(), &stateAsJson);
+ if (stateAsJson.length() > kMaximumBreakpadValueSize) {
+ NOTREACHED();
+ return;
+ }
+ breakpad_helper::AddReportParameter(
+ crashReportKey_,
+ [NSString stringWithCString:stateAsJson.c_str()
+ encoding:[NSString defaultCStringEncoding]],
+ true);
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698