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 <set> | 9 #include <set> |
| 10 #include <string> |
9 #include <vector> | 11 #include <vector> |
10 | 12 |
11 #include "base/gtest_prod_util.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
13 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 18 #include "base/prefs/pref_change_registrar.h" |
| 19 #include "chrome/browser/google/google_url_tracker.h" |
14 #include "chrome/browser/history/history_types.h" | 20 #include "chrome/browser/history/history_types.h" |
15 #include "chrome/browser/search_engines/template_url_service_observer.h" | 21 #include "chrome/browser/ui/search/instant_search_prerenderer.h" |
| 22 #include "chrome/common/instant_types.h" |
16 #include "components/keyed_service/core/keyed_service.h" | 23 #include "components/keyed_service/core/keyed_service.h" |
17 #include "content/public/browser/notification_observer.h" | 24 #include "content/public/browser/notification_observer.h" |
18 #include "content/public/browser/notification_registrar.h" | 25 #include "content/public/browser/notification_registrar.h" |
19 #include "url/gurl.h" | |
20 | 26 |
| 27 class GURL; |
21 class InstantIOContext; | 28 class InstantIOContext; |
22 struct InstantMostVisitedItem; | |
23 class InstantSearchPrerenderer; | |
24 class InstantServiceObserver; | 29 class InstantServiceObserver; |
| 30 class InstantTestBase; |
| 31 class InstantServiceTest; |
25 class Profile; | 32 class Profile; |
26 struct TemplateURLData; | |
27 class TemplateURLService; | |
28 struct ThemeBackgroundInfo; | |
29 class ThemeService; | 33 class ThemeService; |
30 | 34 |
31 namespace content { | 35 namespace content { |
32 class RenderProcessHost; | 36 class RenderProcessHost; |
33 } | 37 } |
34 | 38 |
| 39 namespace net { |
| 40 class URLRequest; |
| 41 } |
| 42 |
35 // Tracks render process host IDs that are associated with Instant. | 43 // Tracks render process host IDs that are associated with Instant. |
36 class InstantService : public KeyedService, | 44 class InstantService : public KeyedService, |
37 public content::NotificationObserver, | 45 public content::NotificationObserver { |
38 public TemplateURLServiceObserver { | |
39 public: | 46 public: |
40 explicit InstantService(Profile* profile); | 47 explicit InstantService(Profile* profile); |
41 virtual ~InstantService(); | 48 virtual ~InstantService(); |
42 | 49 |
43 // Add, remove, and query RenderProcessHost IDs that are associated with | 50 // Add, remove, and query RenderProcessHost IDs that are associated with |
44 // Instant processes. | 51 // Instant processes. |
45 void AddInstantProcess(int process_id); | 52 void AddInstantProcess(int process_id); |
46 bool IsInstantProcess(int process_id) const; | 53 bool IsInstantProcess(int process_id) const; |
47 | 54 |
48 // Adds/Removes InstantService observers. | 55 // Adds/Removes InstantService observers. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 101 |
95 private: | 102 private: |
96 friend class InstantExtendedTest; | 103 friend class InstantExtendedTest; |
97 friend class InstantServiceTest; | 104 friend class InstantServiceTest; |
98 friend class InstantTestBase; | 105 friend class InstantTestBase; |
99 friend class InstantUnitTestBase; | 106 friend class InstantUnitTestBase; |
100 | 107 |
101 FRIEND_TEST_ALL_PREFIXES(InstantExtendedManualTest, | 108 FRIEND_TEST_ALL_PREFIXES(InstantExtendedManualTest, |
102 MANUAL_SearchesFromFakebox); | 109 MANUAL_SearchesFromFakebox); |
103 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ProcessIsolation); | 110 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ProcessIsolation); |
104 FRIEND_TEST_ALL_PREFIXES(InstantServiceEnabledTest, | 111 FRIEND_TEST_ALL_PREFIXES(InstantServiceTest, SendsSearchURLsToRenderer); |
105 SendsSearchURLsToRenderer); | |
106 | 112 |
107 // KeyedService: | 113 // Overridden from KeyedService: |
108 virtual void Shutdown() OVERRIDE; | 114 virtual void Shutdown() OVERRIDE; |
109 | 115 |
110 // content::NotificationObserver: | 116 // Overridden from content::NotificationObserver: |
111 virtual void Observe(int type, | 117 virtual void Observe(int type, |
112 const content::NotificationSource& source, | 118 const content::NotificationSource& source, |
113 const content::NotificationDetails& details) OVERRIDE; | 119 const content::NotificationDetails& details) OVERRIDE; |
114 | 120 |
115 // TemplateURLServiceObserver: | |
116 // Caches the previous value of the Default Search Provider and the Google | |
117 // base URL to filter out changes other than those affecting the Default | |
118 // Search Provider. | |
119 virtual void OnTemplateURLServiceChanged() OVERRIDE; | |
120 | |
121 // Called when a renderer process is terminated. | 121 // Called when a renderer process is terminated. |
122 void OnRendererProcessTerminated(int process_id); | 122 void OnRendererProcessTerminated(int process_id); |
123 | 123 |
124 // Called when we get new most visited items from TopSites, registered as an | 124 // Called when we get new most visited items from TopSites, registered as an |
125 // async callback. Parses them and sends them to the renderer via | 125 // async callback. Parses them and sends them to the renderer via |
126 // SendMostVisitedItems. | 126 // SendMostVisitedItems. |
127 void OnMostVisitedItemsReceived(const history::MostVisitedURLList& data); | 127 void OnMostVisitedItemsReceived(const history::MostVisitedURLList& data); |
128 | 128 |
129 // Notifies the observer about the last known most visited items. | 129 // Notifies the observer about the last known most visited items. |
130 void NotifyAboutMostVisitedItems(); | 130 void NotifyAboutMostVisitedItems(); |
131 | 131 |
132 // Theme changed notification handler. | 132 // Theme changed notification handler. |
133 void OnThemeChanged(ThemeService* theme_service); | 133 void OnThemeChanged(ThemeService* theme_service); |
134 | 134 |
| 135 void OnGoogleURLUpdated(Profile* profile, |
| 136 GoogleURLTracker::UpdatedDetails* details); |
| 137 |
| 138 void OnDefaultSearchProviderChanged(const std::string& pref_name); |
| 139 |
135 void ResetInstantSearchPrerenderer(); | 140 void ResetInstantSearchPrerenderer(); |
136 | 141 |
137 Profile* const profile_; | 142 Profile* const profile_; |
138 | 143 |
139 // The TemplateURLService that we are observing. It will outlive this | |
140 // InstantService due to the dependency declared in InstantServiceFactory. | |
141 TemplateURLService* template_url_service_; | |
142 | |
143 // The process ids associated with Instant processes. | 144 // The process ids associated with Instant processes. |
144 std::set<int> process_ids_; | 145 std::set<int> process_ids_; |
145 | 146 |
146 // InstantMostVisitedItems sent to the Instant Pages. | 147 // InstantMostVisitedItems sent to the Instant Pages. |
147 std::vector<InstantMostVisitedItem> most_visited_items_; | 148 std::vector<InstantMostVisitedItem> most_visited_items_; |
148 | 149 |
149 // Theme-related data for NTP overlay to adopt themes. | 150 // Theme-related data for NTP overlay to adopt themes. |
150 scoped_ptr<ThemeBackgroundInfo> theme_info_; | 151 scoped_ptr<ThemeBackgroundInfo> theme_info_; |
151 | 152 |
152 // The start-edge margin of the omnibox, used by the Instant page to align | 153 // The start-edge margin of the omnibox, used by the Instant page to align |
153 // text or assets properly with the omnibox. | 154 // text or assets properly with the omnibox. |
154 int omnibox_start_margin_; | 155 int omnibox_start_margin_; |
155 | 156 |
156 ObserverList<InstantServiceObserver> observers_; | 157 ObserverList<InstantServiceObserver> observers_; |
157 | 158 |
158 content::NotificationRegistrar registrar_; | 159 content::NotificationRegistrar registrar_; |
159 | 160 |
| 161 PrefChangeRegistrar profile_pref_registrar_; |
| 162 |
160 scoped_refptr<InstantIOContext> instant_io_context_; | 163 scoped_refptr<InstantIOContext> instant_io_context_; |
161 | 164 |
162 // Set to NULL if the default search provider does not support Instant. | 165 // Set to NULL if the default search provider does not support Instant. |
163 scoped_ptr<InstantSearchPrerenderer> instant_prerenderer_; | 166 scoped_ptr<InstantSearchPrerenderer> instant_prerenderer_; |
164 | 167 |
165 // Used for Top Sites async retrieval. | 168 // Used for Top Sites async retrieval. |
166 base::WeakPtrFactory<InstantService> weak_ptr_factory_; | 169 base::WeakPtrFactory<InstantService> weak_ptr_factory_; |
167 | 170 |
168 // Used to check whether notifications from TemplateURLService indicate a | |
169 // change that affects the default search provider. | |
170 scoped_ptr<TemplateURLData> previous_default_search_provider_; | |
171 GURL previous_google_base_url_; | |
172 | |
173 DISALLOW_COPY_AND_ASSIGN(InstantService); | 171 DISALLOW_COPY_AND_ASSIGN(InstantService); |
174 }; | 172 }; |
175 | 173 |
176 #endif // CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_ | 174 #endif // CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_ |
OLD | NEW |