| 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 COMPONENTS_NTP_TILES_MOST_VISITED_SITES_H_ | 5 #ifndef COMPONENTS_NTP_TILES_MOST_VISITED_SITES_H_ |
| 6 #define COMPONENTS_NTP_TILES_MOST_VISITED_SITES_H_ | 6 #define COMPONENTS_NTP_TILES_MOST_VISITED_SITES_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 void RecordOpenedMostVisitedItem(int index, int tile_type); | 154 void RecordOpenedMostVisitedItem(int index, int tile_type); |
| 155 | 155 |
| 156 // MostVisitedSitesSupervisor::Observer implementation. | 156 // MostVisitedSitesSupervisor::Observer implementation. |
| 157 void OnBlockedSitesChanged() override; | 157 void OnBlockedSitesChanged() override; |
| 158 | 158 |
| 159 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 159 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 160 | 160 |
| 161 private: | 161 private: |
| 162 friend class MostVisitedSitesTest; | 162 friend class MostVisitedSitesTest; |
| 163 | 163 |
| 164 // TODO(treib): use SuggestionsVector in internal functions. crbug.com/601734 | |
| 165 using SuggestionsPtrVector = std::vector<std::unique_ptr<Suggestion>>; | |
| 166 | |
| 167 void BuildCurrentSuggestions(); | 164 void BuildCurrentSuggestions(); |
| 168 | 165 |
| 169 // Initialize the query to Top Sites. Called if the SuggestionsService | 166 // Initialize the query to Top Sites. Called if the SuggestionsService |
| 170 // returned no data. | 167 // returned no data. |
| 171 void InitiateTopSitesQuery(); | 168 void InitiateTopSitesQuery(); |
| 172 | 169 |
| 173 // If there's a whitelist entry point for the URL, return the large icon path. | 170 // If there's a whitelist entry point for the URL, return the large icon path. |
| 174 base::FilePath GetWhitelistLargeIconPath(const GURL& url); | 171 base::FilePath GetWhitelistLargeIconPath(const GURL& url); |
| 175 | 172 |
| 176 // Callback for when data is available from TopSites. | 173 // Callback for when data is available from TopSites. |
| 177 void OnMostVisitedURLsAvailable( | 174 void OnMostVisitedURLsAvailable( |
| 178 const history::MostVisitedURLList& visited_list); | 175 const history::MostVisitedURLList& visited_list); |
| 179 | 176 |
| 180 // Callback for when data is available from the SuggestionsService. | 177 // Callback for when data is available from the SuggestionsService. |
| 181 void OnSuggestionsProfileAvailable( | 178 void OnSuggestionsProfileAvailable( |
| 182 const suggestions::SuggestionsProfile& suggestions_profile); | 179 const suggestions::SuggestionsProfile& suggestions_profile); |
| 183 | 180 |
| 184 // Takes the personal suggestions and creates whitelist entry point | 181 // Takes the personal suggestions and creates whitelist entry point |
| 185 // suggestions if necessary. | 182 // suggestions if necessary. |
| 186 SuggestionsPtrVector CreateWhitelistEntryPointSuggestions( | 183 SuggestionsVector CreateWhitelistEntryPointSuggestions( |
| 187 const SuggestionsPtrVector& personal_suggestions); | 184 const SuggestionsVector& personal_suggestions); |
| 188 | 185 |
| 189 // Takes the personal and whitelist suggestions and creates popular | 186 // Takes the personal and whitelist suggestions and creates popular |
| 190 // suggestions if necessary. | 187 // suggestions if necessary. |
| 191 SuggestionsPtrVector CreatePopularSitesSuggestions( | 188 SuggestionsVector CreatePopularSitesSuggestions( |
| 192 const SuggestionsPtrVector& personal_suggestions, | 189 const SuggestionsVector& personal_suggestions, |
| 193 const SuggestionsPtrVector& whitelist_suggestions); | 190 const SuggestionsVector& whitelist_suggestions); |
| 194 | 191 |
| 195 // Takes the personal suggestions, creates and merges in whitelist and popular | 192 // Takes the personal suggestions, creates and merges in whitelist and popular |
| 196 // suggestions if appropriate, and saves the new suggestions. | 193 // suggestions if appropriate, and saves the new suggestions. |
| 197 void SaveNewSuggestions(SuggestionsPtrVector* personal_suggestions); | 194 void SaveNewSuggestions(SuggestionsVector personal_suggestions); |
| 198 | 195 |
| 199 // Workhorse for SaveNewSuggestions above. Implemented as a separate static | 196 // Workhorse for SaveNewSuggestions above. Implemented as a separate static |
| 200 // method for ease of testing. | 197 // method for ease of testing. |
| 201 static SuggestionsPtrVector MergeSuggestions( | 198 static SuggestionsVector MergeSuggestions( |
| 202 SuggestionsPtrVector* personal_suggestions, | 199 SuggestionsVector personal_suggestions, |
| 203 SuggestionsPtrVector* whitelist_suggestions, | 200 SuggestionsVector whitelist_suggestions, |
| 204 SuggestionsPtrVector* popular_suggestions); | 201 SuggestionsVector popular_suggestions); |
| 205 | |
| 206 // Appends suggestions from |src| to |dst|. | |
| 207 static void AppendSuggestions(SuggestionsPtrVector* src, | |
| 208 SuggestionsPtrVector* dst); | |
| 209 | 202 |
| 210 void SaveCurrentSuggestionsToPrefs(); | 203 void SaveCurrentSuggestionsToPrefs(); |
| 211 | 204 |
| 212 // Notifies the observer about the availability of suggestions. | 205 // Notifies the observer about the availability of suggestions. |
| 213 // Also records impressions UMA if not done already. | 206 // Also records impressions UMA if not done already. |
| 214 void NotifyMostVisitedURLsObserver(); | 207 void NotifyMostVisitedURLsObserver(); |
| 215 | 208 |
| 216 void OnPopularSitesAvailable(bool success); | 209 void OnPopularSitesAvailable(bool success); |
| 217 | 210 |
| 218 // Runs on the UI Thread. | 211 // Runs on the UI Thread. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 | 277 |
| 285 // For callbacks may be run after destruction. | 278 // For callbacks may be run after destruction. |
| 286 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; | 279 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; |
| 287 | 280 |
| 288 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites); | 281 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites); |
| 289 }; | 282 }; |
| 290 | 283 |
| 291 } // namespace ntp_tiles | 284 } // namespace ntp_tiles |
| 292 | 285 |
| 293 #endif // COMPONENTS_NTP_TILES_MOST_VISITED_SITES_H_ | 286 #endif // COMPONENTS_NTP_TILES_MOST_VISITED_SITES_H_ |
| OLD | NEW |