OLD | NEW |
---|---|
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; | |
22 class Profile; | 21 class Profile; |
23 | 22 |
24 // InstantNTPPrerenderer maintains a prerendered instance of InstantNTP. | 23 // InstantNTPPrerenderer maintains a prerendered instance of InstantNTP. |
25 // | 24 // |
26 // An InstantNTP instance is a preloaded search page that will be swapped-in the | 25 // 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 | 26 // 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 | 27 // the user in an uncommitted state. It is backed by a WebContents and that is |
29 // owned by InstantNTP. | 28 // owned by InstantNTP. |
30 // | 29 // |
31 // InstantNTPPrerenderer is owned by InstantService. | 30 // InstantNTPPrerenderer is owned by InstantService. |
32 class InstantNTPPrerenderer | 31 class InstantNTPPrerenderer |
33 : public InstantPage::Delegate, | 32 : public InstantPage::Delegate, |
34 public net::NetworkChangeNotifier::NetworkChangeObserver { | 33 public net::NetworkChangeNotifier::NetworkChangeObserver, |
34 public InstantServiceObserver { | |
35 public: | 35 public: |
36 InstantNTPPrerenderer(Profile* profile, PrefService* prefs); | 36 InstantNTPPrerenderer(Profile* profile, PrefService* prefs); |
37 virtual ~InstantNTPPrerenderer(); | 37 virtual ~InstantNTPPrerenderer(); |
38 | 38 |
39 // Preloads |ntp_| with a new InstantNTP. | 39 // Preloads |ntp_| with a new InstantNTP. |
40 void PreloadInstantNTP(); | 40 void ReloadInstantNTP(); |
41 | 41 |
42 // Releases and returns the InstantNTP WebContents. May be NULL. Loads a new | 42 // Releases and returns the InstantNTP WebContents. May be NULL. Loads a new |
43 // WebContents for the InstantNTP. | 43 // WebContents for the InstantNTP. |
44 scoped_ptr<content::WebContents> ReleaseNTPContents() WARN_UNUSED_RESULT; | 44 scoped_ptr<content::WebContents> ReleaseNTPContents() WARN_UNUSED_RESULT; |
45 | 45 |
46 // The NTP WebContents. May be NULL. InstantNTPPrerenderer retains ownership. | 46 // The NTP WebContents. May be NULL. InstantNTPPrerenderer retains ownership. |
47 content::WebContents* GetNTPContents() const; | 47 content::WebContents* GetNTPContents() const; |
48 | 48 |
49 // Invoked to null out |ntp_|. | 49 // Invoked to null out |ntp_|. |
50 void DeleteNTPContents(); | 50 void DeleteNTPContents(); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 virtual void NavigateToURL(const content::WebContents* contents, | 129 virtual void NavigateToURL(const content::WebContents* contents, |
130 const GURL& url, | 130 const GURL& url, |
131 content::PageTransition transition, | 131 content::PageTransition transition, |
132 WindowOpenDisposition disposition, | 132 WindowOpenDisposition disposition, |
133 bool is_search_type) OVERRIDE; | 133 bool is_search_type) OVERRIDE; |
134 virtual void DeleteMostVisitedItem(const GURL& url) OVERRIDE; | 134 virtual void DeleteMostVisitedItem(const GURL& url) OVERRIDE; |
135 virtual void UndoMostVisitedDeletion(const GURL& url) OVERRIDE; | 135 virtual void UndoMostVisitedDeletion(const GURL& url) OVERRIDE; |
136 virtual void UndoAllMostVisitedDeletions() OVERRIDE; | 136 virtual void UndoAllMostVisitedDeletions() OVERRIDE; |
137 virtual void InstantPageLoadFailed(content::WebContents* contents) OVERRIDE; | 137 virtual void InstantPageLoadFailed(content::WebContents* contents) OVERRIDE; |
138 | 138 |
139 // Overridden from InstantServiceObserver: | |
139 // Called when the default search provider changes. Resets InstantNTP. | 140 // Called when the default search provider changes. Resets InstantNTP. |
samarth
2013/08/02 21:51:15
nit: just delete this line
Anuj
2013/08/09 07:22:00
Done.
| |
140 void OnDefaultSearchProviderChanged(const std::string& pref_name); | 141 virtual void DefaultSearchProviderChanged() OVERRIDE; |
142 virtual void GoogleURLUpdated() OVERRIDE; | |
141 | 143 |
142 // Recreates |ntp_| using |instant_url|. | 144 // Recreates |ntp_| using |instant_url|. |
143 void ResetNTP(const std::string& instant_url); | 145 void ResetNTP(const std::string& instant_url); |
144 | 146 |
145 // Resets |ntp_| with a new InstantNTP. Called when |ntp_| is stale or when a | |
146 // pref is changed. | |
147 void ReloadStaleNTP(); | |
148 | |
149 // Returns true if |ntp_| has an up-to-date Instant URL and supports Instant. | 147 // Returns true if |ntp_| has an up-to-date Instant URL and supports Instant. |
150 // Note that local URLs will not pass this check. | 148 // Note that local URLs will not pass this check. |
151 bool PageIsCurrent() const; | 149 bool PageIsCurrent() const; |
152 | 150 |
153 // Returns true if we should switch to using the local NTP. | 151 // Returns true if we should switch to using the local NTP. |
154 bool ShouldSwitchToLocalNTP() const; | 152 bool ShouldSwitchToLocalNTP() const; |
155 | 153 |
156 Profile* profile_; | 154 Profile* profile_; |
157 | 155 |
158 // Whether the extended API is enabled. | 156 // Whether the extended API is enabled. |
159 const bool extended_enabled_; | 157 const bool extended_enabled_; |
160 | 158 |
161 // Preloaded InstantNTP. | 159 // Preloaded InstantNTP. |
162 scoped_ptr<InstantNTP> ntp_; | 160 scoped_ptr<InstantNTP> ntp_; |
163 | 161 |
164 PrefChangeRegistrar profile_pref_registrar_; | 162 PrefChangeRegistrar profile_pref_registrar_; |
165 | 163 |
166 DISALLOW_COPY_AND_ASSIGN(InstantNTPPrerenderer); | 164 DISALLOW_COPY_AND_ASSIGN(InstantNTPPrerenderer); |
167 }; | 165 }; |
168 | 166 |
169 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_NTP_PRERENDERER_H_ | 167 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_NTP_PRERENDERER_H_ |
OLD | NEW |