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

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

Issue 2802763002: [ios] Cleanup SessionServiceIOS implementation. (Closed)
Patch Set: Address comments. Created 3 years, 8 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
« no previous file with comments | « no previous file | ios/chrome/browser/crash_report/crash_restore_helper_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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_service.h" 23 #import "ios/chrome/browser/sessions/session_service_ios.h"
24 #import "ios/chrome/browser/sessions/session_window_ios.h" 24 #import "ios/chrome/browser/sessions/session_window_ios.h"
25 #import "ios/chrome/browser/tabs/tab.h" 25 #import "ios/chrome/browser/tabs/tab.h"
26 #import "ios/chrome/browser/tabs/tab_model.h" 26 #import "ios/chrome/browser/tabs/tab_model.h"
27 #include "ios/chrome/grit/ios_theme_resources.h" 27 #include "ios/chrome/grit/ios_theme_resources.h"
28 #include "ui/base/l10n/l10n_util.h" 28 #include "ui/base/l10n/l10n_util.h"
29 #include "ui/base/resource/resource_bundle.h" 29 #include "ui/base/resource/resource_bundle.h"
30 30
31 @protocol InfoBarManagerObserverBridgeProtocol 31 @protocol InfoBarManagerObserverBridgeProtocol
32 - (void)infoBarRemoved:(infobars::InfoBar*)infobar; 32 - (void)infoBarRemoved:(infobars::InfoBar*)infobar;
33 @end 33 @end
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 _needRestoration = 255 _needRestoration =
256 [self deleteSessionForBrowserState:_browserState 256 [self deleteSessionForBrowserState:_browserState
257 backupFile:[self sessionBackupPath]]; 257 backupFile:[self sessionBackupPath]];
258 } 258 }
259 259
260 - (BOOL)restoreSessionsAfterCrash { 260 - (BOOL)restoreSessionsAfterCrash {
261 DCHECK(!_sessionRestored); 261 DCHECK(!_sessionRestored);
262 _sessionRestored = YES; 262 _sessionRestored = YES;
263 _infoBarBridge.reset(); 263 _infoBarBridge.reset();
264 SessionWindowIOS* sessionWindow = [[SessionServiceIOS sharedService] 264 SessionWindowIOS* sessionWindow = [[SessionServiceIOS sharedService]
265 loadWindowFromPath:[self sessionBackupPath] 265 loadWindowFromPath:[self sessionBackupPath]];
266 forBrowserState:[_tabModel browserState]];
267 if (sessionWindow) { 266 if (sessionWindow) {
268 breakpad_helper::WillStartCrashRestoration(); 267 breakpad_helper::WillStartCrashRestoration();
269 return [_tabModel restoreSessionWindow:sessionWindow]; 268 return [_tabModel restoreSessionWindow:sessionWindow];
270 } 269 }
271 return NO; 270 return NO;
272 } 271 }
273 272
274 - (void)infoBarRemoved:(infobars::InfoBar*)infobar { 273 - (void)infoBarRemoved:(infobars::InfoBar*)infobar {
275 DCHECK(infobar->delegate()); 274 DCHECK(infobar->delegate());
276 if (_sessionRestored || 275 if (_sessionRestored ||
277 infobar->delegate()->GetIdentifier() != 276 infobar->delegate()->GetIdentifier() !=
278 infobars::InfoBarDelegate::SESSION_CRASHED_INFOBAR_DELEGATE) { 277 infobars::InfoBarDelegate::SESSION_CRASHED_INFOBAR_DELEGATE) {
279 return; 278 return;
280 } 279 }
281 280
282 // If the infobar is dismissed without restoring the tabs (either by closing 281 // If the infobar is dismissed without restoring the tabs (either by closing
283 // it with the cross or after a navigation), all the entries will be added to 282 // it with the cross or after a navigation), all the entries will be added to
284 // the recently closed tabs. 283 // the recently closed tabs.
285 _sessionRestored = YES; 284 _sessionRestored = YES;
286 285
287 SessionWindowIOS* window = [[SessionServiceIOS sharedService] 286 SessionWindowIOS* window = [[SessionServiceIOS sharedService]
288 loadWindowFromPath:[self sessionBackupPath] 287 loadWindowFromPath:[self sessionBackupPath]];
289 forBrowserState:[_tabModel browserState]];
290 DCHECK(window); 288 DCHECK(window);
291 NSArray* sessions = window.sessions; 289 NSArray* sessions = window.sessions;
292 if (!sessions.count) 290 if (!sessions.count)
293 return; 291 return;
294 sessions::TabRestoreService* const tabRestoreService = 292 sessions::TabRestoreService* const tabRestoreService =
295 IOSChromeTabRestoreServiceFactory::GetForBrowserState(_browserState); 293 IOSChromeTabRestoreServiceFactory::GetForBrowserState(_browserState);
296 tabRestoreService->LoadTabsFromLastSession(); 294 tabRestoreService->LoadTabsFromLastSession();
297 295
298 web::WebState::CreateParams params(_browserState); 296 web::WebState::CreateParams params(_browserState);
299 for (CRWSessionStorage* session in sessions) { 297 for (CRWSessionStorage* session in sessions) {
300 std::unique_ptr<web::WebState> webState = 298 std::unique_ptr<web::WebState> webState =
301 web::WebState::CreateWithStorageSession(params, session); 299 web::WebState::CreateWithStorageSession(params, session);
302 // Add all tabs at the 0 position as the position is relative to an old 300 // Add all tabs at the 0 position as the position is relative to an old
303 // tabModel. 301 // tabModel.
304 tabRestoreService->CreateHistoricalTab( 302 tabRestoreService->CreateHistoricalTab(
305 sessions::IOSLiveTab::GetForWebState(webState.get()), 0); 303 sessions::IOSLiveTab::GetForWebState(webState.get()), 0);
306 } 304 }
307 return; 305 return;
308 } 306 }
309 307
310 @end 308 @end
OLDNEW
« no previous file with comments | « no previous file | ios/chrome/browser/crash_report/crash_restore_helper_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698