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