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_SEARCH_INSTANT_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_ |
6 #define CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_ | 6 #define CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/compiler_specific.h" |
| 15 #include "base/gtest_prod_util.h" |
14 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
17 #include "base/observer_list.h" | 19 #include "base/observer_list.h" |
18 #include "base/prefs/pref_change_registrar.h" | 20 #include "base/prefs/pref_change_registrar.h" |
19 #include "chrome/browser/google/google_url_tracker.h" | 21 #include "chrome/browser/google/google_url_tracker.h" |
20 #include "chrome/browser/history/history_types.h" | 22 #include "chrome/browser/history/history_types.h" |
| 23 #include "chrome/browser/ui/search/instant_ntp_prerenderer.h" |
21 #include "chrome/browser/ui/search/instant_search_prerenderer.h" | 24 #include "chrome/browser/ui/search/instant_search_prerenderer.h" |
22 #include "chrome/common/instant_types.h" | 25 #include "chrome/common/instant_types.h" |
23 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" | 26 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" |
24 #include "content/public/browser/notification_observer.h" | 27 #include "content/public/browser/notification_observer.h" |
25 #include "content/public/browser/notification_registrar.h" | 28 #include "content/public/browser/notification_registrar.h" |
26 | 29 |
27 class GURL; | 30 class GURL; |
28 class InstantIOContext; | 31 class InstantIOContext; |
29 class InstantServiceObserver; | 32 class InstantServiceObserver; |
30 class InstantTestBase; | 33 class InstantTestBase; |
31 class InstantServiceTest; | 34 class InstantServiceTest; |
32 class Profile; | 35 class Profile; |
33 class ThemeService; | 36 class ThemeService; |
34 | 37 |
35 namespace content { | 38 namespace content { |
36 class RenderProcessHost; | 39 class WebContents; |
37 } | 40 } |
38 | 41 |
39 namespace net { | 42 namespace net { |
40 class URLRequest; | 43 class URLRequest; |
41 } | 44 } |
42 | 45 |
43 // Tracks render process host IDs that are associated with Instant. | 46 // Tracks render process host IDs that are associated with Instant. |
44 class InstantService : public BrowserContextKeyedService, | 47 class InstantService : public BrowserContextKeyedService, |
45 public content::NotificationObserver { | 48 public content::NotificationObserver { |
46 public: | 49 public: |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 // Invoked by the InstantController to update theme information for NTP. | 82 // Invoked by the InstantController to update theme information for NTP. |
80 // | 83 // |
81 // TODO(kmadhusu): Invoking this from InstantController shouldn't be | 84 // TODO(kmadhusu): Invoking this from InstantController shouldn't be |
82 // necessary. Investigate more and remove this from here. | 85 // necessary. Investigate more and remove this from here. |
83 void UpdateThemeInfo(); | 86 void UpdateThemeInfo(); |
84 | 87 |
85 // Invoked by the InstantController to update most visited items details for | 88 // Invoked by the InstantController to update most visited items details for |
86 // NTP. | 89 // NTP. |
87 void UpdateMostVisitedItemsInfo(); | 90 void UpdateMostVisitedItemsInfo(); |
88 | 91 |
| 92 // Forwards the request to InstantNTPPrerenderer to release and return the |
| 93 // preloaded InstantNTP WebContents. May be NULL. InstantNTPPrerenderer will |
| 94 // load a new InstantNTP after releasing the preloaded contents. |
| 95 scoped_ptr<content::WebContents> ReleaseNTPContents() WARN_UNUSED_RESULT; |
| 96 |
| 97 // The NTP WebContents. May be NULL. InstantNTPPrerenderer retains ownership. |
| 98 content::WebContents* GetNTPContents() const; |
| 99 |
| 100 // Notifies InstantService about the creation of a BrowserInstantController |
| 101 // object. Used to preload InstantNTP. |
| 102 void OnBrowserInstantControllerCreated(); |
| 103 |
| 104 // Notifies InstantService about the destruction of a BrowserInstantController |
| 105 // object. Used to destroy the preloaded InstantNTP. |
| 106 void OnBrowserInstantControllerDestroyed(); |
| 107 |
89 // Sends the current set of search URLs to a renderer process. | 108 // Sends the current set of search URLs to a renderer process. |
90 void SendSearchURLsToRenderer(content::RenderProcessHost* rph); | 109 void SendSearchURLsToRenderer(content::RenderProcessHost* rph); |
91 | 110 |
92 InstantSearchPrerenderer* instant_search_prerenderer() { | 111 InstantSearchPrerenderer* instant_search_prerenderer() { |
93 return instant_prerenderer_.get(); | 112 return instant_prerenderer_.get(); |
94 } | 113 } |
95 | 114 |
96 private: | 115 private: |
97 friend class InstantExtendedTest; | 116 friend class InstantExtendedTest; |
98 friend class InstantServiceTest; | 117 friend class InstantServiceTest; |
99 friend class InstantTestBase; | 118 friend class InstantTestBase; |
100 friend class InstantUnitTestBase; | 119 friend class InstantUnitTestBase; |
101 | 120 |
| 121 FRIEND_TEST_ALL_PREFIXES(InstantExtendedNetworkTest, |
| 122 NTPReactsToNetworkChanges); |
| 123 FRIEND_TEST_ALL_PREFIXES(InstantExtendedManualTest, |
| 124 MANUAL_ShowsGoogleNTP); |
102 FRIEND_TEST_ALL_PREFIXES(InstantExtendedManualTest, | 125 FRIEND_TEST_ALL_PREFIXES(InstantExtendedManualTest, |
103 MANUAL_SearchesFromFakebox); | 126 MANUAL_SearchesFromFakebox); |
104 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ProcessIsolation); | 127 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ProcessIsolation); |
105 FRIEND_TEST_ALL_PREFIXES(InstantServiceTest, SendsSearchURLsToRenderer); | 128 FRIEND_TEST_ALL_PREFIXES(InstantServiceTest, SendsSearchURLsToRenderer); |
106 | 129 |
107 // Overridden from BrowserContextKeyedService: | 130 // Overridden from BrowserContextKeyedService: |
108 virtual void Shutdown() OVERRIDE; | 131 virtual void Shutdown() OVERRIDE; |
109 | 132 |
110 // Overridden from content::NotificationObserver: | 133 // Overridden from content::NotificationObserver: |
111 virtual void Observe(int type, | 134 virtual void Observe(int type, |
(...skipping 12 matching lines...) Expand all Loading... |
124 void NotifyAboutMostVisitedItems(); | 147 void NotifyAboutMostVisitedItems(); |
125 | 148 |
126 // Theme changed notification handler. | 149 // Theme changed notification handler. |
127 void OnThemeChanged(ThemeService* theme_service); | 150 void OnThemeChanged(ThemeService* theme_service); |
128 | 151 |
129 void OnGoogleURLUpdated(Profile* profile, | 152 void OnGoogleURLUpdated(Profile* profile, |
130 GoogleURLTracker::UpdatedDetails* details); | 153 GoogleURLTracker::UpdatedDetails* details); |
131 | 154 |
132 void OnDefaultSearchProviderChanged(const std::string& pref_name); | 155 void OnDefaultSearchProviderChanged(const std::string& pref_name); |
133 | 156 |
| 157 // Used by tests. |
| 158 InstantNTPPrerenderer* ntp_prerenderer(); |
| 159 |
134 void ResetInstantSearchPrerenderer(); | 160 void ResetInstantSearchPrerenderer(); |
135 | 161 |
136 Profile* const profile_; | 162 Profile* const profile_; |
137 | 163 |
138 // The process ids associated with Instant processes. | 164 // The process ids associated with Instant processes. |
139 std::set<int> process_ids_; | 165 std::set<int> process_ids_; |
140 | 166 |
141 // InstantMostVisitedItems sent to the Instant Pages. | 167 // InstantMostVisitedItems sent to the Instant Pages. |
142 std::vector<InstantMostVisitedItem> most_visited_items_; | 168 std::vector<InstantMostVisitedItem> most_visited_items_; |
143 | 169 |
144 // Theme-related data for NTP overlay to adopt themes. | 170 // Theme-related data for NTP overlay to adopt themes. |
145 scoped_ptr<ThemeBackgroundInfo> theme_info_; | 171 scoped_ptr<ThemeBackgroundInfo> theme_info_; |
146 | 172 |
147 ObserverList<InstantServiceObserver> observers_; | 173 ObserverList<InstantServiceObserver> observers_; |
148 | 174 |
149 content::NotificationRegistrar registrar_; | 175 content::NotificationRegistrar registrar_; |
150 | 176 |
151 PrefChangeRegistrar profile_pref_registrar_; | 177 PrefChangeRegistrar profile_pref_registrar_; |
152 | 178 |
153 scoped_refptr<InstantIOContext> instant_io_context_; | 179 scoped_refptr<InstantIOContext> instant_io_context_; |
154 | 180 |
| 181 InstantNTPPrerenderer ntp_prerenderer_; |
| 182 |
| 183 // Total number of BrowserInstantController objects (does not include objects |
| 184 // created for OTR browser windows). Used to preload and delete InstantNTP. |
| 185 size_t browser_instant_controller_object_count_; |
| 186 |
155 // Set to NULL if the default search provider does not support Instant. | 187 // Set to NULL if the default search provider does not support Instant. |
156 scoped_ptr<InstantSearchPrerenderer> instant_prerenderer_; | 188 scoped_ptr<InstantSearchPrerenderer> instant_prerenderer_; |
157 | 189 |
158 // Used for Top Sites async retrieval. | 190 // Used for Top Sites async retrieval. |
159 base::WeakPtrFactory<InstantService> weak_ptr_factory_; | 191 base::WeakPtrFactory<InstantService> weak_ptr_factory_; |
160 | 192 |
161 DISALLOW_COPY_AND_ASSIGN(InstantService); | 193 DISALLOW_COPY_AND_ASSIGN(InstantService); |
162 }; | 194 }; |
163 | 195 |
164 #endif // CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_ | 196 #endif // CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_ |
OLD | NEW |