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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
lpromero 2015/07/08 13:37:16 I don't know the rules when upstreaming. Should we
droger 2015/07/08 14:04:37 The policy is to keep the original year when upstr
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "ios/chrome/browser/crash_report/crash_report_multi_parameter.h"
6
7 #include "base/json/json_writer.h"
8 #include "base/logging.h"
9 #import "base/mac/scoped_nsobject.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/values.h"
12 #import "ios/chrome/browser/crash_report/breakpad_helper.h"
13
14 namespace {
15 // Maximum size of a breakpad parameter. he length of the dictionary serialized
16 // into JSON cannot exceed this length. See declaration in (BreakPad.h) for
17 // details.
18 const int kMaximumBreakpadValueSize = 255;
19 }
20
21 @implementation CrashReportMultiParameter {
22 @private
23 base::scoped_nsobject<NSString> crashReportKey_;
24 scoped_ptr<base::DictionaryValue> dictionary_;
25 }
26
27 - (id)init {
28 NOTREACHED();
29 return nil;
30 }
31
32 - (id)initWithKey:(NSString*)key {
33 if ((self = [super init])) {
34 DCHECK([key length] && ([key length] <= kMaximumBreakpadValueSize));
35 dictionary_.reset(new base::DictionaryValue());
36 crashReportKey_.reset([key copy]);
37 }
38 return self;
39 }
40
41 - (void)removeValue:(NSString*)key {
42 dictionary_->Remove([key UTF8String], NULL);
43 [self updateCrashReport];
44 }
45
46 - (void)setValue:(NSString*)key withValue:(int)value {
47 dictionary_->SetInteger([key UTF8String], value);
48 [self updateCrashReport];
49 }
50
51 - (void)incrementValue:(NSString*)key {
52 int value;
53 if (dictionary_->GetInteger([key UTF8String], &value)) {
54 dictionary_->SetInteger([key UTF8String], value + 1);
55 } else {
56 dictionary_->SetInteger([key UTF8String], 1);
57 }
58 [self updateCrashReport];
59 }
60
61 - (void)decrementValue:(NSString*)key {
62 int value;
63 if (dictionary_->GetInteger([key UTF8String], &value)) {
64 if (value <= 1) {
65 dictionary_->Remove([key UTF8String], NULL);
66 } else {
67 dictionary_->SetInteger([key UTF8String], value - 1);
68 }
69 [self updateCrashReport];
70 }
71 }
72
73 - (void)updateCrashReport {
74 std::string stateAsJson;
75 base::JSONWriter::Write(*dictionary_.get(), &stateAsJson);
76 if (stateAsJson.length() > kMaximumBreakpadValueSize) {
77 NOTREACHED();
78 return;
79 }
80 breakpad_helper::AddReportParameter(
81 crashReportKey_,
82 [NSString stringWithCString:stateAsJson.c_str()
83 encoding:[NSString defaultCStringEncoding]],
84 true);
85 }
86
87 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698