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