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

Side by Side Diff: chrome/browser/ui/search/instant_ntp_prerenderer.h

Issue 20388003: Reload Instant NTP and Instant-process tabs on search url change (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed InstantNTPPrerendererTest Created 7 years, 3 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #ifndef CHROME_BROWSER_UI_SEARCH_INSTANT_NTP_PRERENDERER_H_ 5 #ifndef CHROME_BROWSER_UI_SEARCH_INSTANT_NTP_PRERENDERER_H_
6 #define CHROME_BROWSER_UI_SEARCH_INSTANT_NTP_PRERENDERER_H_ 6 #define CHROME_BROWSER_UI_SEARCH_INSTANT_NTP_PRERENDERER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/gtest_prod_util.h" 11 #include "base/gtest_prod_util.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/prefs/pref_change_registrar.h" 13 #include "base/prefs/pref_change_registrar.h"
14 #include "chrome/browser/search/instant_service_observer.h"
14 #include "chrome/browser/ui/search/instant_page.h" 15 #include "chrome/browser/ui/search/instant_page.h"
15 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
16 #include "net/base/network_change_notifier.h" 17 #include "net/base/network_change_notifier.h"
17 18
18 class InstantExtendedTest;
19 class InstantNTP; 19 class InstantNTP;
20 class InstantService; 20 class InstantService;
21 class InstantTestBase; 21 class PrefService;
22 class Profile; 22 class Profile;
23 23
24 // InstantNTPPrerenderer maintains a prerendered instance of InstantNTP. 24 // InstantNTPPrerenderer maintains a prerendered instance of InstantNTP.
25 // 25 //
26 // An InstantNTP instance is a preloaded search page that will be swapped-in the 26 // An InstantNTP instance is a preloaded search page that will be swapped-in the
27 // next time when the user navigates to the New Tab Page. It is never shown to 27 // next time when the user navigates to the New Tab Page. It is never shown to
28 // the user in an uncommitted state. It is backed by a WebContents and that is 28 // the user in an uncommitted state. It is backed by a WebContents and that is
29 // owned by InstantNTP. 29 // owned by InstantNTP.
30 // 30 //
31 // InstantNTPPrerenderer is owned by InstantService. 31 // InstantNTPPrerenderer is owned by InstantService.
32 class InstantNTPPrerenderer 32 class InstantNTPPrerenderer
33 : public InstantPage::Delegate, 33 : public InstantPage::Delegate,
34 public net::NetworkChangeNotifier::NetworkChangeObserver { 34 public net::NetworkChangeNotifier::NetworkChangeObserver,
35 public InstantServiceObserver {
35 public: 36 public:
36 InstantNTPPrerenderer(Profile* profile, PrefService* prefs); 37 InstantNTPPrerenderer(Profile* profile, InstantService* instant_service,
38 PrefService* prefs);
37 virtual ~InstantNTPPrerenderer(); 39 virtual ~InstantNTPPrerenderer();
38 40
39 // Preloads |ntp_| with a new InstantNTP. 41 // Preloads |ntp_| with a new InstantNTP.
40 void PreloadInstantNTP(); 42 void ReloadInstantNTP();
41 43
42 // Releases and returns the InstantNTP WebContents. May be NULL. Loads a new 44 // Releases and returns the InstantNTP WebContents. May be NULL. Loads a new
43 // WebContents for the InstantNTP. 45 // WebContents for the InstantNTP.
44 scoped_ptr<content::WebContents> ReleaseNTPContents() WARN_UNUSED_RESULT; 46 scoped_ptr<content::WebContents> ReleaseNTPContents() WARN_UNUSED_RESULT;
45 47
46 // The NTP WebContents. May be NULL. InstantNTPPrerenderer retains ownership. 48 // The NTP WebContents. May be NULL. InstantNTPPrerenderer retains ownership.
47 content::WebContents* GetNTPContents() const; 49 content::WebContents* GetNTPContents() const;
48 50
49 // Invoked to null out |ntp_|. 51 // Invoked to null out |ntp_|.
50 void DeleteNTPContents(); 52 void DeleteNTPContents();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 content::PageTransition transition, 132 content::PageTransition transition,
131 WindowOpenDisposition disposition, 133 WindowOpenDisposition disposition,
132 bool is_search_type) OVERRIDE; 134 bool is_search_type) OVERRIDE;
133 virtual void PasteIntoOmnibox(const content::WebContents* contents, 135 virtual void PasteIntoOmnibox(const content::WebContents* contents,
134 const string16& text) OVERRIDE; 136 const string16& text) OVERRIDE;
135 virtual void DeleteMostVisitedItem(const GURL& url) OVERRIDE; 137 virtual void DeleteMostVisitedItem(const GURL& url) OVERRIDE;
136 virtual void UndoMostVisitedDeletion(const GURL& url) OVERRIDE; 138 virtual void UndoMostVisitedDeletion(const GURL& url) OVERRIDE;
137 virtual void UndoAllMostVisitedDeletions() OVERRIDE; 139 virtual void UndoAllMostVisitedDeletions() OVERRIDE;
138 virtual void InstantPageLoadFailed(content::WebContents* contents) OVERRIDE; 140 virtual void InstantPageLoadFailed(content::WebContents* contents) OVERRIDE;
139 141
140 // Called when the default search provider changes. Resets InstantNTP. 142 // Overridden from InstantServiceObserver:
141 void OnDefaultSearchProviderChanged(const std::string& pref_name); 143 virtual void DefaultSearchProviderChanged() OVERRIDE;
144 virtual void GoogleURLUpdated() OVERRIDE;
142 145
143 // Recreates |ntp_| using |instant_url|. 146 // Recreates |ntp_| using |instant_url|.
144 void ResetNTP(const std::string& instant_url); 147 void ResetNTP(const std::string& instant_url);
145 148
146 // Resets |ntp_| with a new InstantNTP. Called when |ntp_| is stale or when a
147 // pref is changed.
148 void ReloadStaleNTP();
149
150 // Returns true if |ntp_| has an up-to-date Instant URL and supports Instant. 149 // Returns true if |ntp_| has an up-to-date Instant URL and supports Instant.
151 // Note that local URLs will not pass this check. 150 // Note that local URLs will not pass this check.
152 bool PageIsCurrent() const; 151 bool PageIsCurrent() const;
153 152
154 // Returns true if we should switch to using the local NTP. 153 // Returns true if we should switch to using the local NTP.
155 bool ShouldSwitchToLocalNTP() const; 154 bool ShouldSwitchToLocalNTP() const;
156 155
157 Profile* profile_; 156 Profile* profile_;
158 157
159 // Preloaded InstantNTP. 158 // Preloaded InstantNTP.
160 scoped_ptr<InstantNTP> ntp_; 159 scoped_ptr<InstantNTP> ntp_;
161 160
162 PrefChangeRegistrar profile_pref_registrar_; 161 PrefChangeRegistrar profile_pref_registrar_;
163 162
164 DISALLOW_COPY_AND_ASSIGN(InstantNTPPrerenderer); 163 DISALLOW_COPY_AND_ASSIGN(InstantNTPPrerenderer);
165 }; 164 };
166 165
167 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_NTP_PRERENDERER_H_ 166 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_NTP_PRERENDERER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698