Commit 24130303 authored by Mohammad Refaat's avatar Mohammad Refaat Committed by Commit Bot

Add IsRestoringSession method to sessionRestorationBrowserAgent

This addition makes sure that calling the restoreSession method from
the agent has the same effect as calling it from the TabModel.
Also forward the call from TabModel to call IsRestoringSession of
SessionRestorationAgent.

Bug: 1010164, 783777
Change-Id: Ib4fdfb1c1fe4fc04515b8e4462f3f68df0c9453f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2003911
Commit-Queue: Mohammad Refaat <mrefaat@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#732967}
parent 99dcd52b
...@@ -49,6 +49,11 @@ class SessionRestorationBrowserAgent ...@@ -49,6 +49,11 @@ class SessionRestorationBrowserAgent
// based on the value of |immediately|. // based on the value of |immediately|.
void SaveSession(const bool immediately); void SaveSession(const bool immediately);
// Returns true if there is a session restoration in progress, otherwise it
// returns false. Note that this method can be called from the UI Thread.
// This method exists as a work around for crbug.com/763964.
bool IsRestoringSession();
private: private:
SessionRestorationBrowserAgent(Browser* browser, SessionRestorationBrowserAgent(Browser* browser,
SessionServiceIOS* session_service); SessionServiceIOS* session_service);
...@@ -71,6 +76,9 @@ class SessionRestorationBrowserAgent ...@@ -71,6 +76,9 @@ class SessionRestorationBrowserAgent
// Session Factory used to create session data for saving. // Session Factory used to create session data for saving.
SessionIOSFactory* session_ios_factory_; SessionIOSFactory* session_ios_factory_;
// true when session restoration is in progress.
bool restoring_session_ = false;
}; };
#endif // IOS_CHROME_BROWSER_SESSIONS_SESSION_RESTORATION_BROWSER_AGENT_H_ #endif // IOS_CHROME_BROWSER_SESSIONS_SESSION_RESTORATION_BROWSER_AGENT_H_
...@@ -72,6 +72,7 @@ bool SessionRestorationBrowserAgent::RestoreSessionWindow( ...@@ -72,6 +72,7 @@ bool SessionRestorationBrowserAgent::RestoreSessionWindow(
SessionWindowIOS* window) { SessionWindowIOS* window) {
if (!window.sessions.count) if (!window.sessions.count)
return NO; return NO;
restoring_session_ = true;
for (auto& observer : observers_) { for (auto& observer : observers_) {
observer.WillStartSessionRestoration(); observer.WillStartSessionRestoration();
...@@ -149,9 +150,14 @@ bool SessionRestorationBrowserAgent::RestoreSessionWindow( ...@@ -149,9 +150,14 @@ bool SessionRestorationBrowserAgent::RestoreSessionWindow(
for (auto& observer : observers_) { for (auto& observer : observers_) {
observer.SessionRestorationFinished(restored_web_states); observer.SessionRestorationFinished(restored_web_states);
} }
restoring_session_ = false;
return closed_ntp_tab; return closed_ntp_tab;
} }
bool SessionRestorationBrowserAgent::IsRestoringSession() {
return restoring_session_;
}
void SessionRestorationBrowserAgent::SaveSession(bool immediately) { void SessionRestorationBrowserAgent::SaveSession(bool immediately) {
if (!CanSaveSession()) if (!CanSaveSession())
return; return;
......
...@@ -440,20 +440,16 @@ void RecordMainFrameNavigationMetric(web::WebState* web_state) { ...@@ -440,20 +440,16 @@ void RecordMainFrameNavigationMetric(web::WebState* web_state) {
->IsWebUsageEnabled(); ->IsWebUsageEnabled();
} }
- (BOOL)isRestoringSession {
return _sessionRestorationBrowserAgent->IsRestoringSession();
}
- (BOOL)restoreSessionWindow:(SessionWindowIOS*)window - (BOOL)restoreSessionWindow:(SessionWindowIOS*)window
forInitialRestore:(BOOL)initialRestore { forInitialRestore:(BOOL)initialRestore {
DCHECK(_browserState); DCHECK(_browserState);
// It is only ok to pass a nil |window| during the initial restore. // It is only ok to pass a nil |window| during the initial restore.
DCHECK(window || initialRestore); DCHECK(window || initialRestore);
// Setting the sesion progress to |YES|, so BVC can check it to work around
// crbug.com/763964.
_restoringSession = YES;
base::ScopedClosureRunner updateSessionRestorationProgress(base::BindOnce(^{
_restoringSession = NO;
}));
return _sessionRestorationBrowserAgent->RestoreSessionWindow(window); return _sessionRestorationBrowserAgent->RestoreSessionWindow(window);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment