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

Side by Side Diff: ios/chrome/browser/tabs/tab_model.mm

Issue 1360993002: Moved NavigationManagerImpl serialization out of CRWSessionController. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: compilation fix after rebase Created 3 years, 11 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 #import "ios/chrome/browser/tabs/tab_model.h" 5 #import "ios/chrome/browser/tabs/tab_model.h"
6 6
7 #include <list> 7 #include <list>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 @"kTabModelTabDeselectedNotification"; 59 @"kTabModelTabDeselectedNotification";
60 NSString* const kTabModelNewTabWillOpenNotification = 60 NSString* const kTabModelNewTabWillOpenNotification =
61 @"kTabModelNewTabWillOpenNotification"; 61 @"kTabModelNewTabWillOpenNotification";
62 NSString* const kTabModelTabKey = @"tab"; 62 NSString* const kTabModelTabKey = @"tab";
63 NSString* const kTabModelPageLoadSuccess = @"pageLoadSuccess"; 63 NSString* const kTabModelPageLoadSuccess = @"pageLoadSuccess";
64 NSString* const kTabModelOpenInBackgroundKey = @"shouldOpenInBackground"; 64 NSString* const kTabModelOpenInBackgroundKey = @"shouldOpenInBackground";
65 65
66 namespace { 66 namespace {
67 67
68 // Updates CRWSessionCertificatePolicyManager's certificate policy cache. 68 // Updates CRWSessionCertificatePolicyManager's certificate policy cache.
69 void UpdateCertificatePolicyCacheFromWebState(web::WebStateImpl* webState) { 69 void UpdateCertificatePolicyCacheFromWebState(web::WebState* web_state) {
70 DCHECK([NSThread isMainThread]); 70 DCHECK([NSThread isMainThread]);
71 DCHECK(webState); 71 DCHECK(web_state);
72 scoped_refptr<web::CertificatePolicyCache> policy_cache = 72 scoped_refptr<web::CertificatePolicyCache> policy_cache =
73 web::BrowserState::GetCertificatePolicyCache(webState->GetBrowserState()); 73 web::BrowserState::GetCertificatePolicyCache(
74 CRWSessionController* controller = 74 web_state->GetBrowserState());
75 webState->GetNavigationManagerImpl().GetSessionController(); 75 // TODO(crbug.com/454984): Remove CRWSessionController usage once certificate
76 // policy manager is moved to NavigationManager.
77 CRWSessionController* controller = static_cast<web::WebStateImpl*>(web_state)
78 ->GetNavigationManagerImpl()
79 .GetSessionController();
76 [[controller sessionCertificatePolicyManager] 80 [[controller sessionCertificatePolicyManager]
77 updateCertificatePolicyCache:policy_cache]; 81 updateCertificatePolicyCache:policy_cache];
78 } 82 }
79 83
80 // Populates the certificate policy cache based on the current entries of the 84 // Populates the certificate policy cache based on the current entries of the
81 // given tabs. 85 // given tabs.
82 void RestoreCertificatePolicyCacheFromTabs(NSArray* tabs) { 86 void RestoreCertificatePolicyCacheFromTabs(NSArray* tabs) {
83 DCHECK([NSThread isMainThread]); 87 DCHECK([NSThread isMainThread]);
84 for (Tab* tab in tabs) { 88 for (Tab* tab in tabs) {
85 UpdateCertificatePolicyCacheFromWebState(tab.webStateImpl); 89 UpdateCertificatePolicyCacheFromWebState(tab.webStateImpl);
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 // important to the backend code to always have a sync window delegate. 251 // important to the backend code to always have a sync window delegate.
248 if (!_browserState->IsOffTheRecord()) { 252 if (!_browserState->IsOffTheRecord()) {
249 // Set up the usage recorder before tabs are created. 253 // Set up the usage recorder before tabs are created.
250 _tabUsageRecorder.reset(new TabUsageRecorder(self)); 254 _tabUsageRecorder.reset(new TabUsageRecorder(self));
251 } 255 }
252 _syncedWindowDelegate.reset(new TabModelSyncedWindowDelegate(self)); 256 _syncedWindowDelegate.reset(new TabModelSyncedWindowDelegate(self));
253 257
254 _tabs.reset([[NSMutableArray alloc] init]); 258 _tabs.reset([[NSMutableArray alloc] init]);
255 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; 259 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
256 if (window) { 260 if (window) {
257 while (window.unclaimedSessions) { 261 web::WebState::CreateParams params(_browserState);
258 std::unique_ptr<web::WebStateImpl> webState = [window nextSession]; 262 for (CRWNavigationManagerStorage* session in window.sessions) {
263 std::unique_ptr<web::WebState> webState =
264 web::WebState::Create(params, session);
259 DCHECK_EQ(webState->GetBrowserState(), _browserState); 265 DCHECK_EQ(webState->GetBrowserState(), _browserState);
260 // Restore the CertificatePolicyCache. 266 // Restore the CertificatePolicyCache.
261 UpdateCertificatePolicyCacheFromWebState(webState.get()); 267 UpdateCertificatePolicyCacheFromWebState(webState.get());
262 // Create a new tab for each entry in the window. Don't send delegate 268 // Create a new tab for each entry in the window. Don't send delegate
263 // notifications for each restored tab, only when all done. 269 // notifications for each restored tab, only when all done.
264 base::scoped_nsobject<Tab> tab( 270 base::scoped_nsobject<Tab> tab(
265 [[Tab alloc] initWithWebState:std::move(webState) model:self]); 271 [[Tab alloc] initWithWebState:std::move(webState) model:self]);
266 [tab webController].usePlaceholderOverlay = YES; 272 [tab webController].usePlaceholderOverlay = YES;
267 [tab fetchFavicon]; 273 [tab fetchFavicon];
268 [_tabs addObject:tab]; 274 [_tabs addObject:tab];
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 } 314 }
309 315
310 - (instancetype)init { 316 - (instancetype)init {
311 NOTREACHED(); 317 NOTREACHED();
312 return nil; 318 return nil;
313 } 319 }
314 320
315 - (BOOL)restoreSessionWindow:(SessionWindowIOS*)window { 321 - (BOOL)restoreSessionWindow:(SessionWindowIOS*)window {
316 DCHECK(_browserState); 322 DCHECK(_browserState);
317 DCHECK(window); 323 DCHECK(window);
318 if (!window.unclaimedSessions) 324 NSArray* sessions = window.sessions;
325 if (!sessions.count)
319 return NO; 326 return NO;
320 size_t oldCount = [_tabs count]; 327 size_t oldCount = [_tabs count];
321 size_t index = oldCount; 328 size_t index = oldCount;
322 while (window.unclaimedSessions) { 329 web::WebState::CreateParams params(_browserState);
323 std::unique_ptr<web::WebStateImpl> webState = [window nextSession]; 330 for (CRWNavigationManagerStorage* session in sessions) {
331 std::unique_ptr<web::WebState> webState =
332 web::WebState::Create(params, session);
324 DCHECK_EQ(webState->GetBrowserState(), _browserState); 333 DCHECK_EQ(webState->GetBrowserState(), _browserState);
325 Tab* tab = [self insertTabWithWebState:std::move(webState) atIndex:index++]; 334 Tab* tab = [self insertTabWithWebState:std::move(webState) atIndex:index++];
326 tab.webController.usePlaceholderOverlay = YES; 335 tab.webController.usePlaceholderOverlay = YES;
327 // Restore the CertificatePolicyCache. Note that after calling Pass() 336 // Restore the CertificatePolicyCache. Note that after calling Pass()
328 // |webState| is invalid, so we need to get the webstate from |tab|. 337 // |webState| is invalid, so we need to get the webstate from |tab|.
329 UpdateCertificatePolicyCacheFromWebState(tab.webStateImpl); 338 UpdateCertificatePolicyCacheFromWebState(tab.webStateImpl);
330 } 339 }
331 DCHECK([_tabs count] > oldCount); 340 DCHECK([_tabs count] > oldCount);
332 // If any tab was restored, the saved selected tab must be selected. 341 // If any tab was restored, the saved selected tab must be selected.
333 if ([_tabs count] > oldCount) { 342 if ([_tabs count] > oldCount) {
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 - (SessionWindowIOS*)windowForSavingSession { 850 - (SessionWindowIOS*)windowForSavingSession {
842 // Background tabs will already have their state preserved, but not the 851 // Background tabs will already have their state preserved, but not the
843 // fg tab. Do it now. 852 // fg tab. Do it now.
844 [_currentTab recordStateInHistory]; 853 [_currentTab recordStateInHistory];
845 854
846 // Build the array of sessions. Copy the session objects as the saving will 855 // Build the array of sessions. Copy the session objects as the saving will
847 // be done on a separate thread. 856 // be done on a separate thread.
848 // TODO(crbug.com/661986): This could get expensive especially since this 857 // TODO(crbug.com/661986): This could get expensive especially since this
849 // window may never be saved (if another call comes in before the delay). 858 // window may never be saved (if another call comes in before the delay).
850 SessionWindowIOS* window = [[[SessionWindowIOS alloc] init] autorelease]; 859 SessionWindowIOS* window = [[[SessionWindowIOS alloc] init] autorelease];
851 for (Tab* tab in _tabs.get()) { 860 for (Tab* tab in self) {
852 DCHECK(tab.webStateImpl); 861 web::WebState* webState = tab.webState;
853 std::unique_ptr<web::WebStateImpl> webStateCopy( 862 DCHECK(webState);
854 tab.webStateImpl->CopyForSessionWindow()); 863 [window addSerializedSession:webState->BuildSerializedNavigationManager()];
855 [window addSession:std::move(webStateCopy)];
856 } 864 }
857 window.selectedIndex = [self indexOfTab:_currentTab]; 865 window.selectedIndex = [self indexOfTab:_currentTab];
858 return window; 866 return window;
859 } 867 }
860 868
861 - (BOOL)isNTPTab:(Tab*)tab { 869 - (BOOL)isNTPTab:(Tab*)tab {
862 std::string host = tab.url.host(); 870 std::string host = tab.url.host();
863 return host == kChromeUINewTabHost || host == kChromeUIBookmarksHost; 871 return host == kChromeUINewTabHost || host == kChromeUIBookmarksHost;
864 } 872 }
865 873
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 web::NavigationManager::WebLoadParams params(URL); 1073 web::NavigationManager::WebLoadParams params(URL);
1066 params.referrer = referrer; 1074 params.referrer = referrer;
1067 params.transition_type = ui::PAGE_TRANSITION_TYPED; 1075 params.transition_type = ui::PAGE_TRANSITION_TYPED;
1068 [[tab webController] loadWithParams:params]; 1076 [[tab webController] loadWithParams:params];
1069 [tab webController].webUsageEnabled = webUsageEnabled_; 1077 [tab webController].webUsageEnabled = webUsageEnabled_;
1070 [self insertTab:tab atIndex:index]; 1078 [self insertTab:tab atIndex:index];
1071 return tab; 1079 return tab;
1072 } 1080 }
1073 1081
1074 @end 1082 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/sessions/session_window_unittest.mm ('k') | ios/chrome/browser/tabs/tab_model_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698