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

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

Issue 2916253003: [ObjC ARC] Converts ios/chrome/browser/crash_report:crash_report_internal to ARC. (Closed)
Patch Set: Created 3 years, 6 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
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/crash_report_helper.h" 5 #include "ios/chrome/browser/crash_report/crash_report_helper.h"
6 6
7 #import <Foundation/Foundation.h> 7 #import <Foundation/Foundation.h>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/debug/crash_logging.h" 11 #include "base/debug/crash_logging.h"
12 #include "base/files/file_enumerator.h" 12 #include "base/files/file_enumerator.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
15 #include "base/location.h" 15 #include "base/location.h"
16 #include "base/mac/scoped_nsobject.h"
17 #include "base/path_service.h" 16 #include "base/path_service.h"
18 #include "base/strings/sys_string_conversions.h" 17 #include "base/strings/sys_string_conversions.h"
19 #include "base/time/time.h" 18 #include "base/time/time.h"
20 #include "components/upload_list/crash_upload_list.h" 19 #include "components/upload_list/crash_upload_list.h"
21 #include "ios/chrome/browser/chrome_paths.h" 20 #include "ios/chrome/browser/chrome_paths.h"
22 #include "ios/chrome/browser/crash_report/breakpad_helper.h" 21 #include "ios/chrome/browser/crash_report/breakpad_helper.h"
23 #import "ios/chrome/browser/crash_report/crash_report_user_application_state.h" 22 #import "ios/chrome/browser/crash_report/crash_report_user_application_state.h"
24 #import "ios/chrome/browser/tabs/tab.h" 23 #import "ios/chrome/browser/tabs/tab.h"
25 #import "ios/chrome/browser/tabs/tab_model.h" 24 #import "ios/chrome/browser/tabs/tab_model.h"
26 #import "ios/chrome/browser/tabs/tab_model_observer.h" 25 #import "ios/chrome/browser/tabs/tab_model_observer.h"
27 #include "ios/web/public/browser_state.h" 26 #include "ios/web/public/browser_state.h"
28 #import "ios/web/public/navigation_item.h" 27 #import "ios/web/public/navigation_item.h"
29 #include "ios/web/public/web_state/web_state.h" 28 #include "ios/web/public/web_state/web_state.h"
30 #include "ios/web/public/web_thread.h" 29 #include "ios/web/public/web_thread.h"
31 #import "net/base/mac/url_conversions.h" 30 #import "net/base/mac/url_conversions.h"
32 31
32 #if !defined(__has_feature) || !__has_feature(objc_arc)
33 #error "This file requires ARC support."
34 #endif
35
33 // TabModelObserver that allows loaded urls to be sent to the crash server. 36 // TabModelObserver that allows loaded urls to be sent to the crash server.
34 @interface CrashReporterURLObserver : NSObject<TabModelObserver> { 37 @interface CrashReporterURLObserver : NSObject<TabModelObserver> {
35 @private 38 @private
36 // Map associating the tab id to the breakpad key used to keep track of the 39 // Map associating the tab id to the breakpad key used to keep track of the
37 // loaded URL. 40 // loaded URL.
38 base::scoped_nsobject<NSMutableDictionary> breakpadKeyByTabId_; 41 NSMutableDictionary* breakpadKeyByTabId_;
39 // List of keys to use for recording URLs. This list is sorted such that a new 42 // List of keys to use for recording URLs. This list is sorted such that a new
40 // tab must use the first key in this list to record its URLs. 43 // tab must use the first key in this list to record its URLs.
41 base::scoped_nsobject<NSMutableArray> breakpadKeys_; 44 NSMutableArray* breakpadKeys_;
42 } 45 }
43 + (CrashReporterURLObserver*)uniqueInstance; 46 + (CrashReporterURLObserver*)uniqueInstance;
44 // Removes the URL for the tab with the given id from the URLs sent to the crash 47 // Removes the URL for the tab with the given id from the URLs sent to the crash
45 // server. 48 // server.
46 - (void)removeTabId:(NSString*)tabId; 49 - (void)removeTabId:(NSString*)tabId;
47 // Records the given URL associated to the given id to the list of URLs to send 50 // Records the given URL associated to the given id to the list of URLs to send
48 // to the crash server. If |pending| is true, the URL is one that is 51 // to the crash server. If |pending| is true, the URL is one that is
49 // expected to start loading, but hasn't actually been seen yet. 52 // expected to start loading, but hasn't actually been seen yet.
50 - (void)recordURL:(NSString*)url 53 - (void)recordURL:(NSString*)url
51 forTabId:(NSString*)tabId 54 forTabId:(NSString*)tabId
52 pending:(BOOL)pending; 55 pending:(BOOL)pending;
53 // Callback for the kTabUrlStartedLoadingNotificationForCrashReporting 56 // Callback for the kTabUrlStartedLoadingNotificationForCrashReporting
54 // notification. Extracts the parameter from the notification and calls 57 // notification. Extracts the parameter from the notification and calls
55 // |recordURL:forTabId:pending:|. 58 // |recordURL:forTabId:pending:|.
56 - (void)urlChanged:(NSNotification*)notification; 59 - (void)urlChanged:(NSNotification*)notification;
57 // Callback for the kTabUrlMayStartLoadingNotificationForCrashReporting 60 // Callback for the kTabUrlMayStartLoadingNotificationForCrashReporting
58 // notification. Extracts the parameter from the notification and calls 61 // notification. Extracts the parameter from the notification and calls
59 // |recordURL:forTabId:pending:|. 62 // |recordURL:forTabId:pending:|.
60 - (void)urlChangeExpected:(NSNotification*)notification; 63 - (void)urlChangeExpected:(NSNotification*)notification;
61 @end 64 @end
62 65
63 // TabModelObserver that some tabs stats to be sent to the crash server. 66 // TabModelObserver that some tabs stats to be sent to the crash server.
64 @interface CrashReporterTabStateObserver : NSObject<TabModelObserver> { 67 @interface CrashReporterTabStateObserver : NSObject<TabModelObserver> {
65 @private 68 @private
66 // Map associating the tab id to an object describing the current state of the 69 // Map associating the tab id to an object describing the current state of the
67 // tab. 70 // tab.
68 base::scoped_nsobject<NSMutableDictionary> tabCurrentStateByTabId_; 71 NSMutableDictionary* tabCurrentStateByTabId_;
69 } 72 }
70 + (CrashReporterURLObserver*)uniqueInstance; 73 + (CrashReporterURLObserver*)uniqueInstance;
71 // Removes the stats for the tab tabId 74 // Removes the stats for the tab tabId
72 - (void)removeTabId:(NSString*)tabId; 75 - (void)removeTabId:(NSString*)tabId;
73 // Callback for the kTabClosingCurrentDocumentNotificationForCrashReporting 76 // Callback for the kTabClosingCurrentDocumentNotificationForCrashReporting
74 // notification. Removes document related information from 77 // notification. Removes document related information from
75 // tabCurrentStateByTabId_ by calling closingDocumentInTab:tabId. 78 // tabCurrentStateByTabId_ by calling closingDocumentInTab:tabId.
76 - (void)closingDocument:(NSNotification*)notification; 79 - (void)closingDocument:(NSNotification*)notification;
77 // Removes document related information from tabCurrentStateByTabId_. 80 // Removes document related information from tabCurrentStateByTabId_.
78 - (void)closingDocumentInTab:(NSString*)tabId; 81 - (void)closingDocumentInTab:(NSString*)tabId;
(...skipping 28 matching lines...) Expand all
107 @implementation CrashReporterURLObserver 110 @implementation CrashReporterURLObserver
108 111
109 + (CrashReporterURLObserver*)uniqueInstance { 112 + (CrashReporterURLObserver*)uniqueInstance {
110 static CrashReporterURLObserver* instance = 113 static CrashReporterURLObserver* instance =
111 [[CrashReporterURLObserver alloc] init]; 114 [[CrashReporterURLObserver alloc] init];
112 return instance; 115 return instance;
113 } 116 }
114 117
115 - (id)init { 118 - (id)init {
116 if ((self = [super init])) { 119 if ((self = [super init])) {
117 breakpadKeyByTabId_.reset( 120 breakpadKeyByTabId_ =
118 [[NSMutableDictionary alloc] initWithCapacity:kNumberOfURLsToSend]); 121 [[NSMutableDictionary alloc] initWithCapacity:kNumberOfURLsToSend];
119 breakpadKeys_.reset( 122 breakpadKeys_ =
120 [[NSMutableArray alloc] initWithCapacity:kNumberOfURLsToSend]); 123 [[NSMutableArray alloc] initWithCapacity:kNumberOfURLsToSend];
121 for (int i = 0; i < kNumberOfURLsToSend; ++i) 124 for (int i = 0; i < kNumberOfURLsToSend; ++i)
122 [breakpadKeys_ addObject:[NSString stringWithFormat:@"url%d", i]]; 125 [breakpadKeys_ addObject:[NSString stringWithFormat:@"url%d", i]];
123 // Register for url changed notifications. 126 // Register for url changed notifications.
124 [[NSNotificationCenter defaultCenter] 127 [[NSNotificationCenter defaultCenter]
125 addObserver:self 128 addObserver:self
126 selector:@selector(urlChanged:) 129 selector:@selector(urlChanged:)
127 name:kTabUrlStartedLoadingNotificationForCrashReporting 130 name:kTabUrlStartedLoadingNotificationForCrashReporting
128 object:nil]; 131 object:nil];
129 [[NSNotificationCenter defaultCenter] 132 [[NSNotificationCenter defaultCenter]
130 addObserver:self 133 addObserver:self
(...skipping 21 matching lines...) Expand all
152 return; 155 return;
153 NSString* url = [notification.userInfo objectForKey:kTabUrlKey]; 156 NSString* url = [notification.userInfo objectForKey:kTabUrlKey];
154 DCHECK(url); 157 DCHECK(url);
155 [self recordURL:url forTabId:tab.tabId pending:YES]; 158 [self recordURL:url forTabId:tab.tabId pending:YES];
156 } 159 }
157 160
158 - (void)removeTabId:(NSString*)tabId { 161 - (void)removeTabId:(NSString*)tabId {
159 NSString* key = [breakpadKeyByTabId_ objectForKey:tabId]; 162 NSString* key = [breakpadKeyByTabId_ objectForKey:tabId];
160 if (!key) 163 if (!key)
161 return; 164 return;
162 base::scoped_nsobject<NSString> alive([key retain]);
163 breakpad_helper::RemoveReportParameter(key); 165 breakpad_helper::RemoveReportParameter(key);
164 breakpad_helper::RemoveReportParameter(PendingURLKeyForKey(key)); 166 breakpad_helper::RemoveReportParameter(PendingURLKeyForKey(key));
165 [breakpadKeyByTabId_ removeObjectForKey:tabId]; 167 [breakpadKeyByTabId_ removeObjectForKey:tabId];
166 [breakpadKeys_ removeObject:key]; 168 [breakpadKeys_ removeObject:key];
167 [breakpadKeys_ insertObject:key atIndex:0]; 169 [breakpadKeys_ insertObject:key atIndex:0];
168 } 170 }
169 171
170 - (void)recordURL:(NSString*)url 172 - (void)recordURL:(NSString*)url
171 forTabId:(NSString*)tabId 173 forTabId:(NSString*)tabId
172 pending:(BOOL)pending { 174 pending:(BOOL)pending {
173 NSString* breakpadKey = [breakpadKeyByTabId_ objectForKey:tabId]; 175 NSString* breakpadKey = [breakpadKeyByTabId_ objectForKey:tabId];
174 BOOL reusingKey = NO; 176 BOOL reusingKey = NO;
175 if (!breakpadKey) { 177 if (!breakpadKey) {
176 // Get the first breakpad key and push it back at the end of the keys. 178 // Get the first breakpad key and push it back at the end of the keys.
177 base::scoped_nsobject<NSString> alive( 179 breakpadKey = [breakpadKeys_ objectAtIndex:0];
178 [[breakpadKeys_ objectAtIndex:0] retain]);
179 breakpadKey = alive.get();
180 [breakpadKeys_ removeObject:breakpadKey]; 180 [breakpadKeys_ removeObject:breakpadKey];
181 [breakpadKeys_ addObject:breakpadKey]; 181 [breakpadKeys_ addObject:breakpadKey];
182 // Remove the current mapping to the breakpad key. 182 // Remove the current mapping to the breakpad key.
183 for (NSString* tabId in 183 for (NSString* tabId in
184 [breakpadKeyByTabId_ allKeysForObject:breakpadKey]) { 184 [breakpadKeyByTabId_ allKeysForObject:breakpadKey]) {
185 reusingKey = YES; 185 reusingKey = YES;
186 [breakpadKeyByTabId_ removeObjectForKey:tabId]; 186 [breakpadKeyByTabId_ removeObjectForKey:tabId];
187 } 187 }
188 // Associate the breakpad key to the tab id. 188 // Associate the breakpad key to the tab id.
189 [breakpadKeyByTabId_ setObject:breakpadKey forKey:tabId]; 189 [breakpadKeyByTabId_ setObject:breakpadKey forKey:tabId];
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 @implementation CrashReporterTabStateObserver 235 @implementation CrashReporterTabStateObserver
236 236
237 + (CrashReporterTabStateObserver*)uniqueInstance { 237 + (CrashReporterTabStateObserver*)uniqueInstance {
238 static CrashReporterTabStateObserver* instance = 238 static CrashReporterTabStateObserver* instance =
239 [[CrashReporterTabStateObserver alloc] init]; 239 [[CrashReporterTabStateObserver alloc] init];
240 return instance; 240 return instance;
241 } 241 }
242 242
243 - (id)init { 243 - (id)init {
244 if ((self = [super init])) { 244 if ((self = [super init])) {
245 tabCurrentStateByTabId_.reset([[NSMutableDictionary alloc] init]); 245 tabCurrentStateByTabId_ = [[NSMutableDictionary alloc] init];
246 // Register for url changed notifications. 246 // Register for url changed notifications.
247 [[NSNotificationCenter defaultCenter] 247 [[NSNotificationCenter defaultCenter]
248 addObserver:self 248 addObserver:self
249 selector:@selector(closingDocument:) 249 selector:@selector(closingDocument:)
250 name:kTabClosingCurrentDocumentNotificationForCrashReporting 250 name:kTabClosingCurrentDocumentNotificationForCrashReporting
251 object:nil]; 251 object:nil];
252 [[NSNotificationCenter defaultCenter] 252 [[NSNotificationCenter defaultCenter]
253 addObserver:self 253 addObserver:self
254 selector:@selector(showingExportableDocument:) 254 selector:@selector(showingExportableDocument:)
255 name:kTabIsShowingExportableNotificationForCrashReporting 255 name:kTabIsShowingExportableNotificationForCrashReporting
(...skipping 13 matching lines...) Expand all
269 breakpad_helper::SetCurrentTabIsPDF(false); 269 breakpad_helper::SetCurrentTabIsPDF(false);
270 [self removeTabInfo:@"mime" forTab:tabId]; 270 [self removeTabInfo:@"mime" forTab:tabId];
271 } 271 }
272 272
273 - (void)setTabInfo:(NSString*)key 273 - (void)setTabInfo:(NSString*)key
274 withValue:(NSString*)value 274 withValue:(NSString*)value
275 forTab:(NSString*)tabId { 275 forTab:(NSString*)tabId {
276 NSMutableDictionary* tabCurrentState = 276 NSMutableDictionary* tabCurrentState =
277 [tabCurrentStateByTabId_ objectForKey:tabId]; 277 [tabCurrentStateByTabId_ objectForKey:tabId];
278 if (tabCurrentState == nil) { 278 if (tabCurrentState == nil) {
279 base::scoped_nsobject<NSMutableDictionary> currentStateOfNewTab( 279 NSMutableDictionary* currentStateOfNewTab =
280 [[NSMutableDictionary alloc] init]); 280 [[NSMutableDictionary alloc] init];
281 [tabCurrentStateByTabId_ setObject:currentStateOfNewTab.get() forKey:tabId]; 281 [tabCurrentStateByTabId_ setObject:currentStateOfNewTab forKey:tabId];
282 tabCurrentState = [tabCurrentStateByTabId_ objectForKey:tabId]; 282 tabCurrentState = [tabCurrentStateByTabId_ objectForKey:tabId];
283 } 283 }
284 [tabCurrentState setObject:value forKey:key]; 284 [tabCurrentState setObject:value forKey:key];
285 } 285 }
286 286
287 - (id)getTabInfo:(NSString*)key forTab:(NSString*)tabId { 287 - (id)getTabInfo:(NSString*)key forTab:(NSString*)tabId {
288 NSMutableDictionary* tabValues = [tabCurrentStateByTabId_ objectForKey:tabId]; 288 NSMutableDictionary* tabValues = [tabCurrentStateByTabId_ objectForKey:tabId];
289 return [tabValues objectForKey:key]; 289 return [tabValues objectForKey:key];
290 } 290 }
291 291
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 void ClearStateForTabModel(TabModel* tab_model) { 348 void ClearStateForTabModel(TabModel* tab_model) {
349 CrashReporterURLObserver* observer = 349 CrashReporterURLObserver* observer =
350 [CrashReporterURLObserver uniqueInstance]; 350 [CrashReporterURLObserver uniqueInstance];
351 for (Tab* tab in tab_model) { 351 for (Tab* tab in tab_model) {
352 [observer removeTabId:tab.tabId]; 352 [observer removeTabId:tab.tabId];
353 } 353 }
354 } 354 }
355 355
356 } // namespace breakpad 356 } // namespace breakpad
357 } // namespace ios_internal 357 } // namespace ios_internal
OLDNEW
« no previous file with comments | « ios/chrome/browser/crash_report/BUILD.gn ('k') | ios/chrome/browser/crash_report/crash_restore_helper.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698