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 <memory> | 8 #include <memory> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" |
14 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
15 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
16 #include "components/history/core/browser/history_types.h" | 17 #include "components/history/core/browser/history_types.h" |
17 #include "components/history/core/browser/top_sites_observer.h" | 18 #include "components/history/core/browser/top_sites_observer.h" |
18 #include "components/keyed_service/core/keyed_service.h" | 19 #include "components/keyed_service/core/keyed_service.h" |
| 20 #include "components/ntp_tiles/most_visited_sites.h" |
| 21 #include "components/ntp_tiles/ntp_tile.h" |
19 #include "components/search_engines/template_url_service_observer.h" | 22 #include "components/search_engines/template_url_service_observer.h" |
20 #include "content/public/browser/notification_observer.h" | 23 #include "content/public/browser/notification_observer.h" |
21 #include "content/public/browser/notification_registrar.h" | 24 #include "content/public/browser/notification_registrar.h" |
22 #include "url/gurl.h" | 25 #include "url/gurl.h" |
23 | 26 |
24 class InstantIOContext; | 27 class InstantIOContext; |
25 struct InstantMostVisitedItem; | 28 struct InstantMostVisitedItem; |
26 class InstantSearchPrerenderer; | 29 class InstantSearchPrerenderer; |
27 class InstantServiceObserver; | 30 class InstantServiceObserver; |
28 class Profile; | 31 class Profile; |
29 struct TemplateURLData; | 32 struct TemplateURLData; |
30 class TemplateURLService; | 33 class TemplateURLService; |
31 struct ThemeBackgroundInfo; | 34 struct ThemeBackgroundInfo; |
32 | 35 |
33 namespace content { | 36 namespace content { |
34 class RenderProcessHost; | 37 class RenderProcessHost; |
35 } | 38 } |
36 | 39 |
| 40 namespace history { |
| 41 class TopSites; |
| 42 } |
| 43 |
37 // Tracks render process host IDs that are associated with Instant. | 44 // Tracks render process host IDs that are associated with Instant. |
38 class InstantService : public KeyedService, | 45 class InstantService : public KeyedService, |
39 public content::NotificationObserver, | 46 public content::NotificationObserver, |
40 public TemplateURLServiceObserver, | 47 public TemplateURLServiceObserver, |
41 public history::TopSitesObserver { | 48 public history::TopSitesObserver, |
| 49 public ntp_tiles::MostVisitedSites::Observer { |
42 public: | 50 public: |
43 explicit InstantService(Profile* profile); | 51 explicit InstantService(Profile* profile); |
44 ~InstantService() override; | 52 ~InstantService() override; |
45 | 53 |
46 // Add, remove, and query RenderProcessHost IDs that are associated with | 54 // Add, remove, and query RenderProcessHost IDs that are associated with |
47 // Instant processes. | 55 // Instant processes. |
48 void AddInstantProcess(int process_id); | 56 void AddInstantProcess(int process_id); |
49 bool IsInstantProcess(int process_id) const; | 57 bool IsInstantProcess(int process_id) const; |
50 | 58 |
51 // Adds/Removes InstantService observers. | 59 // Adds/Removes InstantService observers. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 void TopSitesLoaded(history::TopSites* top_sites) override; | 128 void TopSitesLoaded(history::TopSites* top_sites) override; |
121 void TopSitesChanged(history::TopSites* top_sites, | 129 void TopSitesChanged(history::TopSites* top_sites, |
122 ChangeReason change_reason) override; | 130 ChangeReason change_reason) override; |
123 | 131 |
124 // Called when a renderer process is terminated. | 132 // Called when a renderer process is terminated. |
125 void OnRendererProcessTerminated(int process_id); | 133 void OnRendererProcessTerminated(int process_id); |
126 | 134 |
127 // Called when we get new most visited items from TopSites, registered as an | 135 // Called when we get new most visited items from TopSites, registered as an |
128 // async callback. Parses them and sends them to the renderer via | 136 // async callback. Parses them and sends them to the renderer via |
129 // NotifyAboutMostVisitedItems. | 137 // NotifyAboutMostVisitedItems. |
130 void OnMostVisitedItemsReceived(const history::MostVisitedURLList& data); | 138 void OnTopSitesReceived(const history::MostVisitedURLList& data); |
| 139 |
| 140 // ntp_tiles::MostVisitedSites::Observer implementation. |
| 141 void OnMostVisitedURLsAvailable( |
| 142 const ntp_tiles::NTPTilesVector& tiles) override; |
| 143 void OnIconMadeAvailable(const GURL& site_url) override; |
131 | 144 |
132 // Notifies the observer about the last known most visited items. | 145 // Notifies the observer about the last known most visited items. |
133 void NotifyAboutMostVisitedItems(); | 146 void NotifyAboutMostVisitedItems(); |
134 | 147 |
135 #if defined(ENABLE_THEMES) | 148 #if defined(ENABLE_THEMES) |
136 // Theme changed notification handler. | 149 // Theme changed notification handler. |
137 void OnThemeChanged(); | 150 void OnThemeChanged(); |
138 #endif | 151 #endif |
139 | 152 |
140 void ResetInstantSearchPrerendererIfNecessary(); | 153 void ResetInstantSearchPrerendererIfNecessary(); |
(...skipping 20 matching lines...) Expand all Loading... |
161 scoped_refptr<InstantIOContext> instant_io_context_; | 174 scoped_refptr<InstantIOContext> instant_io_context_; |
162 | 175 |
163 // Set to NULL if the default search provider does not support Instant. | 176 // Set to NULL if the default search provider does not support Instant. |
164 std::unique_ptr<InstantSearchPrerenderer> instant_prerenderer_; | 177 std::unique_ptr<InstantSearchPrerenderer> instant_prerenderer_; |
165 | 178 |
166 // Used to check whether notifications from TemplateURLService indicate a | 179 // Used to check whether notifications from TemplateURLService indicate a |
167 // change that affects the default search provider. | 180 // change that affects the default search provider. |
168 std::unique_ptr<TemplateURLData> previous_default_search_provider_; | 181 std::unique_ptr<TemplateURLData> previous_default_search_provider_; |
169 GURL previous_google_base_url_; | 182 GURL previous_google_base_url_; |
170 | 183 |
| 184 // Data sources for NTP tiles (aka Most Visited tiles). Only one of these will |
| 185 // be non-null. |
| 186 std::unique_ptr<ntp_tiles::MostVisitedSites> most_visited_sites_; |
| 187 scoped_refptr<history::TopSites> top_sites_; |
| 188 |
171 // Used for Top Sites async retrieval. | 189 // Used for Top Sites async retrieval. |
172 base::WeakPtrFactory<InstantService> weak_ptr_factory_; | 190 base::WeakPtrFactory<InstantService> weak_ptr_factory_; |
173 | 191 |
174 DISALLOW_COPY_AND_ASSIGN(InstantService); | 192 DISALLOW_COPY_AND_ASSIGN(InstantService); |
175 }; | 193 }; |
176 | 194 |
177 #endif // CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_ | 195 #endif // CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_ |
OLD | NEW |