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