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

Unified Diff: chrome/browser/ui/search/instant_tab.cc

Issue 2166023004: Cleanup in InstantTab and InstantController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: bring back Init() Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/search/instant_tab.cc
diff --git a/chrome/browser/ui/search/instant_tab.cc b/chrome/browser/ui/search/instant_tab.cc
index dea3f31c2427ca2e8dfff6ea8d108473bd6e264e..9e47432fb306c485cecb036f69a9e0c42ef906ca 100644
--- a/chrome/browser/ui/search/instant_tab.cc
+++ b/chrome/browser/ui/search/instant_tab.cc
@@ -10,8 +10,10 @@
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
-InstantTab::Delegate::~Delegate() {
-}
+InstantTab::Delegate::~Delegate() {}
+
+InstantTab::InstantTab(Delegate* delegate, content::WebContents* web_contents)
+ : delegate_(delegate), pending_web_contents_(web_contents) {}
InstantTab::~InstantTab() {
if (web_contents()) {
@@ -20,27 +22,13 @@ InstantTab::~InstantTab() {
}
}
-bool InstantTab::supports_instant() const {
- return web_contents() &&
- SearchTabHelper::FromWebContents(web_contents())->SupportsInstant();
-}
-
-bool InstantTab::IsLocal() const {
- return web_contents() &&
- web_contents()->GetURL() == GURL(chrome::kChromeSearchLocalNtpUrl);
-}
-
-InstantTab::InstantTab(Delegate* delegate)
- : delegate_(delegate) {
-}
-
-void InstantTab::Init(content::WebContents* new_web_contents) {
- ClearContents();
-
- if (!new_web_contents)
+void InstantTab::Init() {
+ if (!pending_web_contents_)
return;
- Observe(new_web_contents);
+ Observe(pending_web_contents_);
+ pending_web_contents_ = nullptr;
+
SearchModel* model =
SearchTabHelper::FromWebContents(web_contents())->model();
model->AddObserver(this);
@@ -54,13 +42,12 @@ void InstantTab::DidCommitProvisionalLoadForFrame(
content::RenderFrameHost* render_frame_host,
const GURL& url,
ui::PageTransition /* transition_type */) {
- if (!render_frame_host->GetParent()) {
+ if (!render_frame_host->GetParent())
delegate_->InstantTabAboutToNavigateMainFrame(web_contents(), url);
- }
}
void InstantTab::ModelChanged(const SearchModel::State& old_state,
- const SearchModel::State& new_state) {
+ const SearchModel::State& new_state) {
if (old_state.instant_support != new_state.instant_support)
InstantSupportDetermined(new_state.instant_support == INSTANT_SUPPORT_YES);
}
@@ -69,15 +56,12 @@ void InstantTab::InstantSupportDetermined(bool supports_instant) {
delegate_->InstantSupportDetermined(web_contents(), supports_instant);
// If the page doesn't support Instant, stop listening to it.
- if (!supports_instant)
- ClearContents();
-}
+ if (!supports_instant) {
+ if (web_contents()) {
+ SearchTabHelper::FromWebContents(web_contents())->model()->RemoveObserver(
+ this);
+ }
-void InstantTab::ClearContents() {
- if (web_contents()) {
- SearchTabHelper::FromWebContents(web_contents())->model()->RemoveObserver(
- this);
+ Observe(nullptr);
}
-
- Observe(NULL);
}

Powered by Google App Engine
This is Rietveld 408576698