Commit 63441181 authored by treib's avatar treib Committed by Commit bot

Cleanup: remove dead code from InstantPage and InstantController

BUG=627747

Review-Url: https://codereview.chromium.org/2147483002
Cr-Commit-Position: refs/heads/master@{#405106}
parent b2b9f127
......@@ -8,34 +8,27 @@
#include <utility>
#include "base/location.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/stringprintf.h"
#include "base/threading/thread_task_runner_handle.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/instant_service.h"
#include "chrome/browser/search/instant_service_factory.h"
#include "chrome/browser/search/search.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/ui/browser_instant_controller.h"
#include "chrome/browser/ui/search/instant_tab.h"
#include "chrome/browser/ui/search/search_tab_helper.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/search/search_urls.h"
#include "chrome/common/url_constants.h"
#include "components/prefs/pref_service.h"
#include "components/search_engines/template_url_service.h"
#include "components/sessions/core/serialized_navigation_entry.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "net/base/escape.h"
#include "net/base/network_change_notifier.h"
#include "url/gurl.h"
// Macro used for logging debug events. |message| should be a std::string.
#define LOG_INSTANT_DEBUG_EVENT(controller, message) \
controller->LogDebugEvent(message)
namespace {
bool IsContentsFrom(const InstantPage* page,
......@@ -169,7 +162,7 @@ void InstantController::ResetInstantTab() {
if (!search_mode_.is_origin_default()) {
content::WebContents* active_tab = browser_->GetActiveWebContents();
if (!instant_tab_ || active_tab != instant_tab_->web_contents()) {
instant_tab_.reset(new InstantTab(this, browser_->profile()));
instant_tab_.reset(new InstantTab(this));
instant_tab_->Init(active_tab);
UpdateInfoForInstantTab();
}
......
......@@ -11,14 +11,12 @@
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/strings/string16.h"
#include "chrome/browser/ui/search/instant_page.h"
#include "chrome/common/search/search_types.h"
#include "ui/gfx/native_widget_types.h"
class BrowserInstantController;
class GURL;
......@@ -31,10 +29,6 @@ namespace content {
class WebContents;
}
// Macro used for logging debug events. |message| should be a std::string.
#define LOG_INSTANT_DEBUG_EVENT(controller, message) \
controller->LogDebugEvent(message)
// InstantController drives Chrome Instant, i.e., the browser implementation of
// the Embedded Search API (see http://dev.chromium.org/embeddedsearch).
//
......@@ -118,18 +112,11 @@ class InstantController : public InstantPage::Delegate {
void InstantPageAboutToNavigateMainFrame(const content::WebContents* contents,
const GURL& url) override;
// Helper function to navigate the given contents to the local fallback
// Instant URL and trim the history correctly.
void RedirectToLocalNTP(content::WebContents* contents);
// Helper for OmniboxFocusChanged. Commit or discard the overlay.
void OmniboxLostFocus(gfx::NativeView view_gaining_focus);
// If the active tab is an Instant search results page, sets |instant_tab_| to
// point to it. Else, deletes any existing |instant_tab_|.
void ResetInstantTab();
// Sends theme info, omnibox bounds, etc. down to the Instant tab.
// Sends theme info and most visited items to the Instant tab.
void UpdateInfoForInstantTab();
// Returns the InstantService for the browser profile.
......
......@@ -4,19 +4,11 @@
#include "chrome/browser/ui/search/instant_page.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/search.h"
#include "chrome/browser/ui/search/search_model.h"
#include "chrome/browser/ui/search/search_tab_helper.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_details.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/frame_navigate_params.h"
InstantPage::Delegate::~Delegate() {
}
......@@ -33,21 +25,13 @@ bool InstantPage::supports_instant() const {
SearchTabHelper::FromWebContents(web_contents())->SupportsInstant();
}
const std::string& InstantPage::instant_url() const {
return instant_url_;
}
bool InstantPage::IsLocal() const {
return web_contents() &&
web_contents()->GetURL() == GURL(chrome::kChromeSearchLocalNtpUrl);
}
InstantPage::InstantPage(Delegate* delegate,
const std::string& instant_url,
Profile* profile)
: profile_(profile),
delegate_(delegate),
instant_url_(instant_url) {
InstantPage::InstantPage(Delegate* delegate)
: delegate_(delegate) {
}
void InstantPage::SetContents(content::WebContents* new_web_contents) {
......@@ -75,8 +59,9 @@ void InstantPage::DidCommitProvisionalLoadForFrame(
const GURL& url,
ui::PageTransition /* transition_type */) {
if (!render_frame_host->GetParent() &&
ShouldProcessAboutToNavigateMainFrame())
ShouldProcessAboutToNavigateMainFrame()) {
delegate_->InstantPageAboutToNavigateMainFrame(web_contents(), url);
}
}
void InstantPage::ModelChanged(const SearchModel::State& old_state,
......
......@@ -5,33 +5,23 @@
#ifndef CHROME_BROWSER_UI_SEARCH_INSTANT_PAGE_H_
#define CHROME_BROWSER_UI_SEARCH_INSTANT_PAGE_H_
#include <vector>
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/strings/string16.h"
#include "chrome/browser/ui/search/search_model_observer.h"
#include "content/public/browser/web_contents_observer.h"
#include "ui/base/page_transition_types.h"
class GURL;
class Profile;
namespace content {
struct FrameNavigateParams;
struct LoadCommittedDetails;
class RenderFrameHost;
class WebContents;
}
namespace gfx {
class Rect;
}
// InstantPage is used to exchange messages with a page that implements the
// Instant/Embedded Search API (http://dev.chromium.org/embeddedsearch).
// InstantPage is not used directly but via one of its derived classes,
// InstantNTP and InstantTab.
// InstantPage is not used directly but via its derived class, InstantTab.
class InstantPage : public content::WebContentsObserver,
public SearchModelObserver {
public:
......@@ -56,24 +46,18 @@ class InstantPage : public content::WebContentsObserver,
~InstantPage() override;
// Returns the Instant URL that was loaded for this page. Returns the empty
// string if no URL was explicitly loaded as is the case for InstantTab.
virtual const std::string& instant_url() const;
// Returns true if the page is known to support the Instant API. This starts
// out false, and is set to true whenever we get any message from the page.
// Once true, it never becomes false (the page isn't expected to drop API
// support suddenly).
virtual bool supports_instant() const;
bool supports_instant() const;
// Returns true if the page is the local NTP (i.e. its URL is
// chrome::kChromeSearchLocalNTPURL).
virtual bool IsLocal() const;
bool IsLocal() const;
protected:
InstantPage(Delegate* delegate,
const std::string& instant_url,
Profile* profile);
explicit InstantPage(Delegate* delegate);
// Sets |web_contents| as the page to communicate with. |web_contents| may be
// NULL, which effectively stops all communication.
......@@ -81,12 +65,7 @@ class InstantPage : public content::WebContentsObserver,
Delegate* delegate() const { return delegate_; }
Profile* profile() const { return profile_; }
// These functions are called before processing messages received from the
// page. By default, all messages are handled, but any derived classes may
// choose to ignore some or all of the received messages by overriding these
// methods.
// This method is called before processing messages received from the page.
virtual bool ShouldProcessAboutToNavigateMainFrame();
private:
......@@ -114,12 +93,7 @@ class InstantPage : public content::WebContentsObserver,
void ClearContents();
// TODO(kmadhusu): Remove |profile_| from here and update InstantNTP to get
// |profile| from InstantNTPPrerenderer.
Profile* profile_;
Delegate* const delegate_;
const std::string instant_url_;
DISALLOW_COPY_AND_ASSIGN(InstantPage);
};
......
......@@ -68,7 +68,7 @@ void InstantPageTest::SetUp() {
}
TEST_F(InstantPageTest, IsLocal) {
page.reset(new InstantPage(&delegate, "", NULL));
page.reset(new InstantPage(&delegate));
EXPECT_FALSE(page->supports_instant());
EXPECT_FALSE(page->IsLocal());
page->SetContents(web_contents());
......@@ -79,7 +79,7 @@ TEST_F(InstantPageTest, IsLocal) {
}
TEST_F(InstantPageTest, DetermineIfPageSupportsInstant_Local) {
page.reset(new InstantPage(&delegate, "", NULL));
page.reset(new InstantPage(&delegate));
EXPECT_FALSE(page->supports_instant());
page->SetContents(web_contents());
NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
......@@ -92,7 +92,7 @@ TEST_F(InstantPageTest, DetermineIfPageSupportsInstant_Local) {
}
TEST_F(InstantPageTest, DetermineIfPageSupportsInstant_NonLocal) {
page.reset(new InstantPage(&delegate, "", NULL));
page.reset(new InstantPage(&delegate));
EXPECT_FALSE(page->supports_instant());
page->SetContents(web_contents());
NavigateAndCommit(GURL("chrome-search://foo/bar"));
......@@ -107,7 +107,7 @@ TEST_F(InstantPageTest, DetermineIfPageSupportsInstant_NonLocal) {
}
TEST_F(InstantPageTest, PageURLDoesntBelongToInstantRenderer) {
page.reset(new InstantPage(&delegate, "", NULL));
page.reset(new InstantPage(&delegate));
EXPECT_FALSE(page->supports_instant());
NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
page->SetContents(web_contents());
......@@ -132,7 +132,7 @@ TEST_F(InstantPageTest, PageURLDoesntBelongToInstantRenderer) {
// Test to verify that ChromeViewMsg_DetermineIfPageSupportsInstant message
// reply handler updates the instant support state in InstantPage.
TEST_F(InstantPageTest, PageSupportsInstant) {
page.reset(new InstantPage(&delegate, "", NULL));
page.reset(new InstantPage(&delegate));
EXPECT_FALSE(page->supports_instant());
page->SetContents(web_contents());
NavigateAndCommit(GURL("chrome-search://foo/bar"));
......
......@@ -4,13 +4,11 @@
#include "chrome/browser/ui/search/instant_tab.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h"
#include "content/public/browser/web_contents.h"
InstantTab::InstantTab(InstantPage::Delegate* delegate,
Profile* profile)
: InstantPage(delegate, "", profile) {
InstantTab::InstantTab(InstantPage::Delegate* delegate)
: InstantPage(delegate) {
}
InstantTab::~InstantTab() {
......
......@@ -9,13 +9,11 @@
#include "base/macros.h"
#include "chrome/browser/ui/search/instant_page.h"
class Profile;
// InstantTab represents a committed page (i.e. an actual tab on the tab strip)
// that supports the Instant API.
class InstantTab : public InstantPage {
public:
InstantTab(InstantPage::Delegate* delegate, Profile* profile);
explicit InstantTab(InstantPage::Delegate* delegate);
~InstantTab() override;
// Start observing |contents| for messages. Sends a message to determine if
......
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