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

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: test fix 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* web_state) { 69 void UpdateCertificatePolicyCacheFromWebState(web::WebState* web_state) {
70 DCHECK([NSThread isMainThread]); 70 DCHECK([NSThread isMainThread]);
71 DCHECK(web_state); 71 DCHECK(web_state);
72 scoped_refptr<web::CertificatePolicyCache> policy_cache = 72 scoped_refptr<web::CertificatePolicyCache> policy_cache =
73 web::BrowserState::GetCertificatePolicyCache( 73 web::BrowserState::GetCertificatePolicyCache(
74 web_state->GetBrowserState()); 74 web_state->GetBrowserState());
75 CRWSessionController* controller = 75 // TODO(crbug.com/454984): Remove CRWSessionController usage once certificate
76 web_state->GetNavigationManagerImpl().GetSessionController(); 76 // policy manager is moved to NavigationManager.
77 CRWSessionController* controller = static_cast<web::WebStateImpl*>(web_state)
78 ->GetNavigationManagerImpl()
79 .GetSessionController();
77 [[controller sessionCertificatePolicyManager] 80 [[controller sessionCertificatePolicyManager]
78 updateCertificatePolicyCache:policy_cache]; 81 updateCertificatePolicyCache:policy_cache];
79 } 82 }
80 83
81 // 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
82 // given tabs. 85 // given tabs.
83 void RestoreCertificatePolicyCacheFromTabs(WebStateList* web_state_list) { 86 void RestoreCertificatePolicyCacheFromTabs(WebStateList* web_state_list) {
84 DCHECK([NSThread isMainThread]); 87 DCHECK([NSThread isMainThread]);
85 for (id<WebStateHandle> web_state in web_state_list) { 88 for (id<WebStateHandle> web_state in web_state_list) {
86 UpdateCertificatePolicyCacheFromWebState(web_state.webStateImpl); 89 UpdateCertificatePolicyCacheFromWebState(web_state.webStateImpl);
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 // handles incognito browser states by filtering on profile, so it's 260 // handles incognito browser states by filtering on profile, so it's
258 // important to the backend code to always have a sync window delegate. 261 // important to the backend code to always have a sync window delegate.
259 if (!_browserState->IsOffTheRecord()) { 262 if (!_browserState->IsOffTheRecord()) {
260 // Set up the usage recorder before tabs are created. 263 // Set up the usage recorder before tabs are created.
261 _tabUsageRecorder.reset(new TabUsageRecorder(self)); 264 _tabUsageRecorder.reset(new TabUsageRecorder(self));
262 } 265 }
263 _syncedWindowDelegate.reset(new TabModelSyncedWindowDelegate(self)); 266 _syncedWindowDelegate.reset(new TabModelSyncedWindowDelegate(self));
264 267
265 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; 268 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
266 if (window) { 269 if (window) {
267 while (window.unclaimedSessions) { 270 for (CRWNavigationManagerSerialization* session in window.sessions) {
268 std::unique_ptr<web::WebStateImpl> webState = [window nextSession]; 271 web::WebState::CreateParams params(_browserState, session);
272 std::unique_ptr<web::WebState> webState = web::WebState::Create(params);
269 DCHECK_EQ(webState->GetBrowserState(), _browserState); 273 DCHECK_EQ(webState->GetBrowserState(), _browserState);
270 // Restore the CertificatePolicyCache. 274 // Restore the CertificatePolicyCache.
271 UpdateCertificatePolicyCacheFromWebState(webState.get()); 275 UpdateCertificatePolicyCacheFromWebState(webState.get());
272 // Create a new tab for each entry in the window. Don't send delegate 276 // Create a new tab for each entry in the window. Don't send delegate
273 // notifications for each restored tab, only when all done. 277 // notifications for each restored tab, only when all done.
274 base::scoped_nsobject<Tab> tab( 278 base::scoped_nsobject<Tab> tab(
275 [[Tab alloc] initWithWebState:std::move(webState) model:self]); 279 [[Tab alloc] initWithWebState:std::move(webState) model:self]);
276 [tab webController].usePlaceholderOverlay = YES; 280 [tab webController].usePlaceholderOverlay = YES;
277 [tab fetchFavicon]; 281 [tab fetchFavicon];
278 [self addWebState:tab]; 282 [self addWebState:tab];
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 } 325 }
322 326
323 - (instancetype)init { 327 - (instancetype)init {
324 NOTREACHED(); 328 NOTREACHED();
325 return nil; 329 return nil;
326 } 330 }
327 331
328 - (BOOL)restoreSessionWindow:(SessionWindowIOS*)window { 332 - (BOOL)restoreSessionWindow:(SessionWindowIOS*)window {
329 DCHECK(_browserState); 333 DCHECK(_browserState);
330 DCHECK(window); 334 DCHECK(window);
331 if (!window.unclaimedSessions) 335 NSArray* sessions = window.sessions;
336 if (!sessions.count)
332 return NO; 337 return NO;
333 size_t oldCount = self.count; 338 size_t oldCount = self.count;
334 size_t index = oldCount; 339 size_t index = oldCount;
335 while (window.unclaimedSessions) { 340 for (CRWNavigationManagerSerialization* session in sessions) {
336 std::unique_ptr<web::WebStateImpl> webState = [window nextSession]; 341 web::WebState::CreateParams params(_browserState, session);
342 std::unique_ptr<web::WebState> webState = web::WebState::Create(params);
337 DCHECK_EQ(webState->GetBrowserState(), _browserState); 343 DCHECK_EQ(webState->GetBrowserState(), _browserState);
338 Tab* tab = [self insertTabWithWebState:std::move(webState) atIndex:index++]; 344 Tab* tab = [self insertTabWithWebState:std::move(webState) atIndex:index++];
339 tab.webController.usePlaceholderOverlay = YES; 345 tab.webController.usePlaceholderOverlay = YES;
340 // Restore the CertificatePolicyCache. Note that after calling Pass() 346 // Restore the CertificatePolicyCache. Note that after calling Pass()
341 // |webState| is invalid, so we need to get the webstate from |tab|. 347 // |webState| is invalid, so we need to get the webstate from |tab|.
342 UpdateCertificatePolicyCacheFromWebState(tab.webStateImpl); 348 UpdateCertificatePolicyCacheFromWebState(tab.webStateImpl);
343 } 349 }
344 DCHECK(self.count > oldCount); 350 DCHECK(self.count > oldCount);
345 // If any tab was restored, the saved selected tab must be selected. 351 // If any tab was restored, the saved selected tab must be selected.
346 if (self.count > oldCount) { 352 if (self.count > oldCount) {
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 // Background tabs will already have their state preserved, but not the 854 // Background tabs will already have their state preserved, but not the
849 // fg tab. Do it now. 855 // fg tab. Do it now.
850 [_currentTab recordStateInHistory]; 856 [_currentTab recordStateInHistory];
851 857
852 // Build the array of sessions. Copy the session objects as the saving will 858 // Build the array of sessions. Copy the session objects as the saving will
853 // be done on a separate thread. 859 // be done on a separate thread.
854 // TODO(crbug.com/661986): This could get expensive especially since this 860 // TODO(crbug.com/661986): This could get expensive especially since this
855 // window may never be saved (if another call comes in before the delay). 861 // window may never be saved (if another call comes in before the delay).
856 SessionWindowIOS* window = [[[SessionWindowIOS alloc] init] autorelease]; 862 SessionWindowIOS* window = [[[SessionWindowIOS alloc] init] autorelease];
857 for (Tab* tab in self) { 863 for (Tab* tab in self) {
858 DCHECK(tab.webStateImpl); 864 web::WebState* webState = tab.webState;
859 std::unique_ptr<web::WebStateImpl> webStateCopy( 865 DCHECK(webState);
860 tab.webStateImpl->CopyForSessionWindow()); 866 [window addSerializedSession:webState->BuildSerializedNavigationManager()];
861 [window addSession:std::move(webStateCopy)];
862 } 867 }
863 window.selectedIndex = [self indexOfTab:_currentTab]; 868 window.selectedIndex = [self indexOfTab:_currentTab];
864 return window; 869 return window;
865 } 870 }
866 871
867 - (BOOL)isNTPTab:(Tab*)tab { 872 - (BOOL)isNTPTab:(Tab*)tab {
868 std::string host = tab.url.host(); 873 std::string host = tab.url.host();
869 return host == kChromeUINewTabHost || host == kChromeUIBookmarksHost; 874 return host == kChromeUINewTabHost || host == kChromeUIBookmarksHost;
870 } 875 }
871 876
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 web::NavigationManager::WebLoadParams params(URL); 1076 web::NavigationManager::WebLoadParams params(URL);
1072 params.referrer = referrer; 1077 params.referrer = referrer;
1073 params.transition_type = ui::PAGE_TRANSITION_TYPED; 1078 params.transition_type = ui::PAGE_TRANSITION_TYPED;
1074 [[tab webController] loadWithParams:params]; 1079 [[tab webController] loadWithParams:params];
1075 [tab webController].webUsageEnabled = webUsageEnabled_; 1080 [tab webController].webUsageEnabled = webUsageEnabled_;
1076 [self insertTab:tab atIndex:index]; 1081 [self insertTab:tab atIndex:index];
1077 return tab; 1082 return tab;
1078 } 1083 }
1079 1084
1080 @end 1085 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698