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" |
11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
12 #include "components/infobars/core/confirm_infobar_delegate.h" | 12 #include "components/infobars/core/confirm_infobar_delegate.h" |
13 #include "components/infobars/core/infobar.h" | 13 #include "components/infobars/core/infobar.h" |
14 #include "components/infobars/core/infobar_manager.h" | 14 #include "components/infobars/core/infobar_manager.h" |
15 #include "components/sessions/core/tab_restore_service.h" | 15 #include "components/sessions/core/tab_restore_service.h" |
16 #include "components/sessions/ios/ios_live_tab.h" | 16 #include "components/sessions/ios/ios_live_tab.h" |
17 #include "components/strings/grit/components_chromium_strings.h" | 17 #include "components/strings/grit/components_chromium_strings.h" |
18 #include "components/strings/grit/components_google_chrome_strings.h" | 18 #include "components/strings/grit/components_google_chrome_strings.h" |
19 #include "components/strings/grit/components_strings.h" | 19 #include "components/strings/grit/components_strings.h" |
20 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 20 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
21 #import "ios/chrome/browser/crash_report/breakpad_helper.h" | 21 #import "ios/chrome/browser/crash_report/breakpad_helper.h" |
22 #include "ios/chrome/browser/sessions/ios_chrome_tab_restore_service_factory.h" | 22 #include "ios/chrome/browser/sessions/ios_chrome_tab_restore_service_factory.h" |
| 23 #import "ios/chrome/browser/sessions/session_ios.h" |
23 #import "ios/chrome/browser/sessions/session_service_ios.h" | 24 #import "ios/chrome/browser/sessions/session_service_ios.h" |
24 #import "ios/chrome/browser/sessions/session_window_ios.h" | 25 #import "ios/chrome/browser/sessions/session_window_ios.h" |
25 #import "ios/chrome/browser/tabs/tab.h" | 26 #import "ios/chrome/browser/tabs/tab.h" |
26 #import "ios/chrome/browser/tabs/tab_model.h" | 27 #import "ios/chrome/browser/tabs/tab_model.h" |
27 #include "ios/chrome/grit/ios_theme_resources.h" | 28 #include "ios/chrome/grit/ios_theme_resources.h" |
28 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
29 #include "ui/base/resource/resource_bundle.h" | 30 #include "ui/base/resource/resource_bundle.h" |
30 | 31 |
31 @protocol InfoBarManagerObserverBridgeProtocol | 32 @protocol InfoBarManagerObserverBridgeProtocol |
32 - (void)infoBarRemoved:(infobars::InfoBar*)infobar; | 33 - (void)infoBarRemoved:(infobars::InfoBar*)infobar; |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 [self deleteSessionForBrowserState:otrBrowserState backupFile:nil]; | 253 [self deleteSessionForBrowserState:otrBrowserState backupFile:nil]; |
253 _needRestoration = | 254 _needRestoration = |
254 [self deleteSessionForBrowserState:_browserState | 255 [self deleteSessionForBrowserState:_browserState |
255 backupFile:[self sessionBackupPath]]; | 256 backupFile:[self sessionBackupPath]]; |
256 } | 257 } |
257 | 258 |
258 - (BOOL)restoreSessionsAfterCrash { | 259 - (BOOL)restoreSessionsAfterCrash { |
259 DCHECK(!_sessionRestored); | 260 DCHECK(!_sessionRestored); |
260 _sessionRestored = YES; | 261 _sessionRestored = YES; |
261 _infoBarBridge.reset(); | 262 _infoBarBridge.reset(); |
262 SessionWindowIOS* sessionWindow = [[SessionServiceIOS sharedService] | 263 |
263 loadSessionWindowFromPath:[self sessionBackupPath]]; | 264 SessionIOS* session = [[SessionServiceIOS sharedService] |
264 if (sessionWindow) { | 265 loadSessionFromPath:[self sessionBackupPath]]; |
265 breakpad_helper::WillStartCrashRestoration(); | 266 if (!session) |
266 return [_tabModel restoreSessionWindow:sessionWindow]; | 267 return NO; |
267 } | 268 |
268 return NO; | 269 DCHECK_EQ(session.sessionWindows.count, 1u); |
| 270 breakpad_helper::WillStartCrashRestoration(); |
| 271 return [_tabModel restoreSessionWindow:session.sessionWindows[0]]; |
269 } | 272 } |
270 | 273 |
271 - (void)infoBarRemoved:(infobars::InfoBar*)infobar { | 274 - (void)infoBarRemoved:(infobars::InfoBar*)infobar { |
272 DCHECK(infobar->delegate()); | 275 DCHECK(infobar->delegate()); |
273 if (_sessionRestored || | 276 if (_sessionRestored || |
274 infobar->delegate()->GetIdentifier() != | 277 infobar->delegate()->GetIdentifier() != |
275 infobars::InfoBarDelegate::SESSION_CRASHED_INFOBAR_DELEGATE) { | 278 infobars::InfoBarDelegate::SESSION_CRASHED_INFOBAR_DELEGATE) { |
276 return; | 279 return; |
277 } | 280 } |
278 | 281 |
279 // If the infobar is dismissed without restoring the tabs (either by closing | 282 // If the infobar is dismissed without restoring the tabs (either by closing |
280 // it with the cross or after a navigation), all the entries will be added to | 283 // it with the cross or after a navigation), all the entries will be added to |
281 // the recently closed tabs. | 284 // the recently closed tabs. |
282 _sessionRestored = YES; | 285 _sessionRestored = YES; |
283 | 286 |
284 SessionWindowIOS* window = [[SessionServiceIOS sharedService] | 287 SessionIOS* session = [[SessionServiceIOS sharedService] |
285 loadSessionWindowFromPath:[self sessionBackupPath]]; | 288 loadSessionFromPath:[self sessionBackupPath]]; |
286 DCHECK(window); | 289 DCHECK_EQ(session.sessionWindows.count, 1u); |
287 NSArray* sessions = window.sessions; | 290 |
| 291 NSArray<CRWSessionStorage*>* sessions = session.sessionWindows[0].sessions; |
288 if (!sessions.count) | 292 if (!sessions.count) |
289 return; | 293 return; |
| 294 |
290 sessions::TabRestoreService* const tabRestoreService = | 295 sessions::TabRestoreService* const tabRestoreService = |
291 IOSChromeTabRestoreServiceFactory::GetForBrowserState(_browserState); | 296 IOSChromeTabRestoreServiceFactory::GetForBrowserState(_browserState); |
292 tabRestoreService->LoadTabsFromLastSession(); | 297 tabRestoreService->LoadTabsFromLastSession(); |
293 | 298 |
294 web::WebState::CreateParams params(_browserState); | 299 web::WebState::CreateParams params(_browserState); |
295 for (CRWSessionStorage* session in sessions) { | 300 for (CRWSessionStorage* session in sessions) { |
296 std::unique_ptr<web::WebState> webState = | 301 std::unique_ptr<web::WebState> webState = |
297 web::WebState::CreateWithStorageSession(params, session); | 302 web::WebState::CreateWithStorageSession(params, session); |
298 // Add all tabs at the 0 position as the position is relative to an old | 303 // Add all tabs at the 0 position as the position is relative to an old |
299 // tabModel. | 304 // tabModel. |
300 tabRestoreService->CreateHistoricalTab( | 305 tabRestoreService->CreateHistoricalTab( |
301 sessions::IOSLiveTab::GetForWebState(webState.get()), 0); | 306 sessions::IOSLiveTab::GetForWebState(webState.get()), 0); |
302 } | 307 } |
303 return; | 308 return; |
304 } | 309 } |
305 | 310 |
306 @end | 311 @end |
OLD | NEW |