Commit 0da66759 authored by Sylvain Defresne's avatar Sylvain Defresne Committed by Commit Bot

Revert "Fix restoration of session after a crash."

This reverts commit 13de3702.

Reason for revert: breaks '-[ExternalURLSigninTestCase testSignInReauthenticate]' EarlGrey test.

Original change's description:
> Fix restoration of session after a crash.
> 
> Disable sending kTabModelNewTabWillOpenNotification notification
> when the TabModel is restoring a session as this breaks the BVC
> state that does not expect the notification to be sent when a tab
> is added due to session restoration.
> 
> Bug: 763964
> Change-Id: I404487b5a561e43fe4d23303c004e4d3e8701dfe
> Reviewed-on: https://chromium-review.googlesource.com/664557
> Reviewed-by: Rohit Rao (ping after 24h) <rohitrao@chromium.org>
> Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#501614}

TBR=rohitrao@chromium.org,sdefresne@chromium.org

Change-Id: I917e129b14d351bf66527a6620c4f67f97eaa8aa
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 763964
Reviewed-on: https://chromium-review.googlesource.com/664706Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#501667}
parent d8a72b4f
......@@ -58,8 +58,6 @@ source_set("tabs_internal") {
"tab_model_synced_window_delegate_getter.mm",
"tab_model_web_state_list_delegate.h",
"tab_model_web_state_list_delegate.mm",
"tab_model_web_usage_enabled_observer.h",
"tab_model_web_usage_enabled_observer.mm",
"tab_parenting_observer.h",
"tab_parenting_observer.mm",
]
......
......@@ -42,7 +42,6 @@
#import "ios/chrome/browser/tabs/tab_model_selected_tab_observer.h"
#import "ios/chrome/browser/tabs/tab_model_synced_window_delegate.h"
#import "ios/chrome/browser/tabs/tab_model_web_state_list_delegate.h"
#import "ios/chrome/browser/tabs/tab_model_web_usage_enabled_observer.h"
#import "ios/chrome/browser/tabs/tab_parenting_observer.h"
#import "ios/chrome/browser/web/page_placeholder_tab_helper.h"
#import "ios/chrome/browser/web_state_list/web_state_list.h"
......@@ -157,9 +156,6 @@ void CleanCertificatePolicyCache(
// The delegate for sync.
std::unique_ptr<TabModelSyncedWindowDelegate> _syncedWindowDelegate;
// The observer that sends kTabModelNewTabWillOpenNotification notifications.
TabModelNotificationObserver* _tabModelNotificationObserver;
// Counters for metrics.
WebStateListMetricsObserver* _webStateListMetricsObserver;
......@@ -317,12 +313,7 @@ void CleanCertificatePolicyCache(
_webStateListObservers.push_back(std::move(webStateListMetricsObserver));
_webStateListObservers.push_back(
base::MakeUnique<TabModelWebUsageEnabledObserver>(self));
auto tabModelNotificationObserver =
base::MakeUnique<TabModelNotificationObserver>(self);
_tabModelNotificationObserver = tabModelNotificationObserver.get();
_webStateListObservers.push_back(std::move(tabModelNotificationObserver));
base::MakeUnique<TabModelNotificationObserver>(self));
for (const auto& webStateListObserver : _webStateListObservers)
_webStateList->AddObserver(webStateListObserver.get());
......@@ -578,8 +569,7 @@ void CleanCertificatePolicyCache(
UnregisterTabModelFromChromeBrowserState(_browserState, self);
_browserState = nullptr;
// Clear weak pointer to observers before destroying them.
_tabModelNotificationObserver = nullptr;
// Clear weak pointer to WebStateListMetricsObserver before destroying it.
_webStateListMetricsObserver = nullptr;
// Close all tabs. Do this in an @autoreleasepool as WebStateList observers
......@@ -656,11 +646,6 @@ void CleanCertificatePolicyCache(
if (!window.sessions.count)
return NO;
// Disable sending the kTabModelNewTabWillOpenNotification notification
// while restoring a session as it breaks the BVC (see crbug.com/763964).
if (_tabModelNotificationObserver)
_tabModelNotificationObserver->set_enabled(false);
int oldCount = _webStateList->count();
DCHECK_GE(oldCount, 0);
......@@ -710,10 +695,6 @@ void CleanCertificatePolicyCache(
_tabUsageRecorder->InitialRestoredTabs(self.currentTab.webState,
restoredWebStates);
}
if (_tabModelNotificationObserver)
_tabModelNotificationObserver->set_enabled(true);
return closedNTPTab;
}
......
......@@ -15,18 +15,18 @@ class TabModelNotificationObserver : public WebStateListObserver {
explicit TabModelNotificationObserver(TabModel* tab_model);
~TabModelNotificationObserver() override;
// Controls whether sending notification is enabled or not.
void set_enabled(bool enabled) { enabled_ = enabled; }
// WebStateListObserver implementation.
void WebStateInsertedAt(WebStateList* web_state_list,
web::WebState* web_state,
int index,
bool activating) override;
void WebStateReplacedAt(WebStateList* web_state_list,
web::WebState* old_web_state,
web::WebState* new_web_state,
int index) override;
private:
__weak TabModel* tab_model_;
bool enabled_ = false;
DISALLOW_COPY_AND_ASSIGN(TabModelNotificationObserver);
};
......
......@@ -12,6 +12,18 @@
#error "This file requires ARC support."
#endif
namespace {
// Sets |web_state| web usage enabled property and starts loading the content
// if necessary.
void SetWebUsageEnabled(web::WebState* web_state, bool web_usage_enabled) {
web_state->SetWebUsageEnabled(web_usage_enabled);
if (web_usage_enabled)
web_state->GetNavigationManager()->LoadIfNecessary();
}
} // namespace
TabModelNotificationObserver::TabModelNotificationObserver(TabModel* tab_model)
: tab_model_(tab_model) {}
......@@ -22,8 +34,7 @@ void TabModelNotificationObserver::WebStateInsertedAt(
web::WebState* web_state,
int index,
bool activating) {
if (!enabled_)
return;
SetWebUsageEnabled(web_state, tab_model_.webUsageEnabled);
Tab* tab = LegacyTabHelper::GetTabForWebState(web_state);
[[NSNotificationCenter defaultCenter]
......@@ -35,3 +46,10 @@ void TabModelNotificationObserver::WebStateInsertedAt(
}];
}
void TabModelNotificationObserver::WebStateReplacedAt(
WebStateList* web_state_list,
web::WebState* old_web_state,
web::WebState* new_web_state,
int index) {
SetWebUsageEnabled(new_web_state, tab_model_.webUsageEnabled);
}
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_TABS_TAB_MODEL_WEB_USAGE_ENABLED_OBSERVER_H_
#define IOS_CHROME_BROWSER_TABS_TAB_MODEL_WEB_USAGE_ENABLED_OBSERVER_H_
#include "base/macros.h"
#import "ios/chrome/browser/web_state_list/web_state_list_observer.h"
@class TabModel;
class TabModelWebUsageEnabledObserver : public WebStateListObserver {
public:
explicit TabModelWebUsageEnabledObserver(TabModel* tab_model);
~TabModelWebUsageEnabledObserver() override;
// WebStateListObserver implementation.
void WebStateInsertedAt(WebStateList* web_state_list,
web::WebState* web_state,
int index,
bool activating) override;
void WebStateReplacedAt(WebStateList* web_state_list,
web::WebState* old_web_state,
web::WebState* new_web_state,
int index) override;
private:
__weak TabModel* tab_model_;
DISALLOW_COPY_AND_ASSIGN(TabModelWebUsageEnabledObserver);
};
#endif // IOS_CHROME_BROWSER_TABS_TAB_MODEL_WEB_USAGE_ENABLED_OBSERVER_H_
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/tabs/tab_model_web_usage_enabled_observer.h"
#import "ios/chrome/browser/tabs/tab_model.h"
#import "ios/web/public/web_state/web_state.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Sets |web_state| web usage enabled property and starts loading the content
// if necessary.
void SetWebUsageEnabled(web::WebState* web_state, bool web_usage_enabled) {
web_state->SetWebUsageEnabled(web_usage_enabled);
if (web_usage_enabled)
web_state->GetNavigationManager()->LoadIfNecessary();
}
} // namespace
TabModelWebUsageEnabledObserver::TabModelWebUsageEnabledObserver(
TabModel* tab_model)
: tab_model_(tab_model) {}
TabModelWebUsageEnabledObserver::~TabModelWebUsageEnabledObserver() = default;
void TabModelWebUsageEnabledObserver::WebStateInsertedAt(
WebStateList* web_state_list,
web::WebState* web_state,
int index,
bool activating) {
SetWebUsageEnabled(web_state, tab_model_.webUsageEnabled);
}
void TabModelWebUsageEnabledObserver::WebStateReplacedAt(
WebStateList* web_state_list,
web::WebState* old_web_state,
web::WebState* new_web_state,
int index) {
SetWebUsageEnabled(new_web_state, tab_model_.webUsageEnabled);
}
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