OLD | NEW |
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 #import "ios/chrome/browser/crash_report/crash_restore_helper.h" | 5 #import "ios/chrome/browser/crash_report/crash_restore_helper.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 DCHECK([tabModel currentTab]); | 194 DCHECK([tabModel currentTab]); |
195 infobars::InfoBarManager* infoBarManager = | 195 infobars::InfoBarManager* infoBarManager = |
196 [[tabModel currentTab] infoBarManager]; | 196 [[tabModel currentTab] infoBarManager]; |
197 _tabModel.reset([tabModel retain]); | 197 _tabModel.reset([tabModel retain]); |
198 SessionCrashedInfoBarDelegate::Create(infoBarManager, self); | 198 SessionCrashedInfoBarDelegate::Create(infoBarManager, self); |
199 _infoBarBridge.reset(new InfoBarManagerObserverBridge(infoBarManager, self)); | 199 _infoBarBridge.reset(new InfoBarManagerObserverBridge(infoBarManager, self)); |
200 } | 200 } |
201 | 201 |
202 - (BOOL)deleteSessionForBrowserState:(ios::ChromeBrowserState*)browserState | 202 - (BOOL)deleteSessionForBrowserState:(ios::ChromeBrowserState*)browserState |
203 backupFile:(NSString*)file { | 203 backupFile:(NSString*)file { |
204 SessionServiceIOS* sessionService = [SessionServiceIOS sharedService]; | |
205 NSString* stashPath = | 204 NSString* stashPath = |
206 base::SysUTF8ToNSString(browserState->GetStatePath().value()); | 205 base::SysUTF8ToNSString(browserState->GetStatePath().value()); |
207 NSString* sessionPath = | 206 NSString* sessionPath = [SessionServiceIOS sessionPathForDirectory:stashPath]; |
208 [sessionService sessionFilePathForDirectory:stashPath]; | |
209 NSFileManager* fileManager = [NSFileManager defaultManager]; | 207 NSFileManager* fileManager = [NSFileManager defaultManager]; |
210 if (![fileManager fileExistsAtPath:sessionPath]) | 208 if (![fileManager fileExistsAtPath:sessionPath]) |
211 return NO; | 209 return NO; |
212 if (file) { | 210 if (file) { |
213 NSError* error = nil; | 211 NSError* error = nil; |
214 BOOL fileOperationSuccess = | 212 BOOL fileOperationSuccess = |
215 [fileManager removeItemAtPath:file error:&error]; | 213 [fileManager removeItemAtPath:file error:&error]; |
216 NSInteger errorCode = fileOperationSuccess ? 0 : [error code]; | 214 NSInteger errorCode = fileOperationSuccess ? 0 : [error code]; |
217 UMA_HISTOGRAM_SPARSE_SLOWLY("TabRestore.error_remove_backup_at_path", | 215 UMA_HISTOGRAM_SPARSE_SLOWLY("TabRestore.error_remove_backup_at_path", |
218 errorCode); | 216 errorCode); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 _needRestoration = | 253 _needRestoration = |
256 [self deleteSessionForBrowserState:_browserState | 254 [self deleteSessionForBrowserState:_browserState |
257 backupFile:[self sessionBackupPath]]; | 255 backupFile:[self sessionBackupPath]]; |
258 } | 256 } |
259 | 257 |
260 - (BOOL)restoreSessionsAfterCrash { | 258 - (BOOL)restoreSessionsAfterCrash { |
261 DCHECK(!_sessionRestored); | 259 DCHECK(!_sessionRestored); |
262 _sessionRestored = YES; | 260 _sessionRestored = YES; |
263 _infoBarBridge.reset(); | 261 _infoBarBridge.reset(); |
264 SessionWindowIOS* sessionWindow = [[SessionServiceIOS sharedService] | 262 SessionWindowIOS* sessionWindow = [[SessionServiceIOS sharedService] |
265 loadWindowFromPath:[self sessionBackupPath]]; | 263 loadSessionWindowFromPath:[self sessionBackupPath]]; |
266 if (sessionWindow) { | 264 if (sessionWindow) { |
267 breakpad_helper::WillStartCrashRestoration(); | 265 breakpad_helper::WillStartCrashRestoration(); |
268 return [_tabModel restoreSessionWindow:sessionWindow]; | 266 return [_tabModel restoreSessionWindow:sessionWindow]; |
269 } | 267 } |
270 return NO; | 268 return NO; |
271 } | 269 } |
272 | 270 |
273 - (void)infoBarRemoved:(infobars::InfoBar*)infobar { | 271 - (void)infoBarRemoved:(infobars::InfoBar*)infobar { |
274 DCHECK(infobar->delegate()); | 272 DCHECK(infobar->delegate()); |
275 if (_sessionRestored || | 273 if (_sessionRestored || |
276 infobar->delegate()->GetIdentifier() != | 274 infobar->delegate()->GetIdentifier() != |
277 infobars::InfoBarDelegate::SESSION_CRASHED_INFOBAR_DELEGATE) { | 275 infobars::InfoBarDelegate::SESSION_CRASHED_INFOBAR_DELEGATE) { |
278 return; | 276 return; |
279 } | 277 } |
280 | 278 |
281 // If the infobar is dismissed without restoring the tabs (either by closing | 279 // If the infobar is dismissed without restoring the tabs (either by closing |
282 // it with the cross or after a navigation), all the entries will be added to | 280 // it with the cross or after a navigation), all the entries will be added to |
283 // the recently closed tabs. | 281 // the recently closed tabs. |
284 _sessionRestored = YES; | 282 _sessionRestored = YES; |
285 | 283 |
286 SessionWindowIOS* window = [[SessionServiceIOS sharedService] | 284 SessionWindowIOS* window = [[SessionServiceIOS sharedService] |
287 loadWindowFromPath:[self sessionBackupPath]]; | 285 loadSessionWindowFromPath:[self sessionBackupPath]]; |
288 DCHECK(window); | 286 DCHECK(window); |
289 NSArray* sessions = window.sessions; | 287 NSArray* sessions = window.sessions; |
290 if (!sessions.count) | 288 if (!sessions.count) |
291 return; | 289 return; |
292 sessions::TabRestoreService* const tabRestoreService = | 290 sessions::TabRestoreService* const tabRestoreService = |
293 IOSChromeTabRestoreServiceFactory::GetForBrowserState(_browserState); | 291 IOSChromeTabRestoreServiceFactory::GetForBrowserState(_browserState); |
294 tabRestoreService->LoadTabsFromLastSession(); | 292 tabRestoreService->LoadTabsFromLastSession(); |
295 | 293 |
296 web::WebState::CreateParams params(_browserState); | 294 web::WebState::CreateParams params(_browserState); |
297 for (CRWSessionStorage* session in sessions) { | 295 for (CRWSessionStorage* session in sessions) { |
298 std::unique_ptr<web::WebState> webState = | 296 std::unique_ptr<web::WebState> webState = |
299 web::WebState::CreateWithStorageSession(params, session); | 297 web::WebState::CreateWithStorageSession(params, session); |
300 // Add all tabs at the 0 position as the position is relative to an old | 298 // Add all tabs at the 0 position as the position is relative to an old |
301 // tabModel. | 299 // tabModel. |
302 tabRestoreService->CreateHistoricalTab( | 300 tabRestoreService->CreateHistoricalTab( |
303 sessions::IOSLiveTab::GetForWebState(webState.get()), 0); | 301 sessions::IOSLiveTab::GetForWebState(webState.get()), 0); |
304 } | 302 } |
305 return; | 303 return; |
306 } | 304 } |
307 | 305 |
308 @end | 306 @end |
OLD | NEW |