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 // Add itself as observer on InstantService, preload instant NTP. | |
samarth
2013/08/12 19:07:28
nit: Adds itself .. and preloads Instant NTP.
Anuj
2013/08/13 00:18:09
Done.
| |
40 void Init(); | |
41 | |
39 // Preloads |ntp_| with a new InstantNTP. | 42 // Preloads |ntp_| with a new InstantNTP. |
40 void PreloadInstantNTP(); | 43 void ReloadInstantNTP(); |
41 | 44 |
42 // Releases and returns the InstantNTP WebContents. May be NULL. Loads a new | 45 // Releases and returns the InstantNTP WebContents. May be NULL. Loads a new |
43 // WebContents for the InstantNTP. | 46 // WebContents for the InstantNTP. |
44 scoped_ptr<content::WebContents> ReleaseNTPContents() WARN_UNUSED_RESULT; | 47 scoped_ptr<content::WebContents> ReleaseNTPContents() WARN_UNUSED_RESULT; |
45 | 48 |
46 // The NTP WebContents. May be NULL. InstantNTPPrerenderer retains ownership. | 49 // The NTP WebContents. May be NULL. InstantNTPPrerenderer retains ownership. |
47 content::WebContents* GetNTPContents() const; | 50 content::WebContents* GetNTPContents() const; |
48 | 51 |
49 // Invoked to null out |ntp_|. | 52 // Invoked to null out |ntp_|. |
50 void DeleteNTPContents(); | 53 void DeleteNTPContents(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 virtual void NavigateToURL(const content::WebContents* contents, | 131 virtual void NavigateToURL(const content::WebContents* contents, |
129 const GURL& url, | 132 const GURL& url, |
130 content::PageTransition transition, | 133 content::PageTransition transition, |
131 WindowOpenDisposition disposition, | 134 WindowOpenDisposition disposition, |
132 bool is_search_type) OVERRIDE; | 135 bool is_search_type) OVERRIDE; |
133 virtual void DeleteMostVisitedItem(const GURL& url) OVERRIDE; | 136 virtual void DeleteMostVisitedItem(const GURL& url) OVERRIDE; |
134 virtual void UndoMostVisitedDeletion(const GURL& url) OVERRIDE; | 137 virtual void UndoMostVisitedDeletion(const GURL& url) OVERRIDE; |
135 virtual void UndoAllMostVisitedDeletions() OVERRIDE; | 138 virtual void UndoAllMostVisitedDeletions() OVERRIDE; |
136 virtual void InstantPageLoadFailed(content::WebContents* contents) OVERRIDE; | 139 virtual void InstantPageLoadFailed(content::WebContents* contents) OVERRIDE; |
137 | 140 |
138 // Called when the default search provider changes. Resets InstantNTP. | 141 // Overridden from InstantServiceObserver: |
139 void OnDefaultSearchProviderChanged(const std::string& pref_name); | 142 virtual void DefaultSearchProviderChanged() OVERRIDE; |
143 virtual void GoogleURLUpdated() OVERRIDE; | |
140 | 144 |
141 // Recreates |ntp_| using |instant_url|. | 145 // Recreates |ntp_| using |instant_url|. |
142 void ResetNTP(const std::string& instant_url); | 146 void ResetNTP(const std::string& instant_url); |
143 | 147 |
144 // Resets |ntp_| with a new InstantNTP. Called when |ntp_| is stale or when a | |
145 // pref is changed. | |
146 void ReloadStaleNTP(); | |
147 | |
148 // Returns true if |ntp_| has an up-to-date Instant URL and supports Instant. | 148 // Returns true if |ntp_| has an up-to-date Instant URL and supports Instant. |
149 // Note that local URLs will not pass this check. | 149 // Note that local URLs will not pass this check. |
150 bool PageIsCurrent() const; | 150 bool PageIsCurrent() const; |
151 | 151 |
152 // Returns true if we should switch to using the local NTP. | 152 // Returns true if we should switch to using the local NTP. |
153 bool ShouldSwitchToLocalNTP() const; | 153 bool ShouldSwitchToLocalNTP() const; |
154 | 154 |
155 Profile* profile_; | 155 Profile* profile_; |
156 | 156 |
157 // Preloaded InstantNTP. | 157 // Preloaded InstantNTP. |
158 scoped_ptr<InstantNTP> ntp_; | 158 scoped_ptr<InstantNTP> ntp_; |
159 | 159 |
160 PrefChangeRegistrar profile_pref_registrar_; | 160 PrefChangeRegistrar profile_pref_registrar_; |
161 | 161 |
162 DISALLOW_COPY_AND_ASSIGN(InstantNTPPrerenderer); | 162 DISALLOW_COPY_AND_ASSIGN(InstantNTPPrerenderer); |
163 }; | 163 }; |
164 | 164 |
165 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_NTP_PRERENDERER_H_ | 165 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_NTP_PRERENDERER_H_ |
OLD | NEW |