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