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