| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_HISTORY_TOP_SITES_IMPL_H_ | 5 #ifndef CHROME_BROWSER_HISTORY_TOP_SITES_IMPL_H_ |
| 6 #define CHROME_BROWSER_HISTORY_TOP_SITES_IMPL_H_ | 6 #define CHROME_BROWSER_HISTORY_TOP_SITES_IMPL_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 bool loaded() const override; | 91 bool loaded() const override; |
| 92 bool AddForcedURL(const GURL& url, const base::Time& time) override; | 92 bool AddForcedURL(const GURL& url, const base::Time& time) override; |
| 93 | 93 |
| 94 // RefcountedKeyedService: | 94 // RefcountedKeyedService: |
| 95 void ShutdownOnUIThread() override; | 95 void ShutdownOnUIThread() override; |
| 96 | 96 |
| 97 protected: | 97 protected: |
| 98 ~TopSitesImpl() override; | 98 ~TopSitesImpl() override; |
| 99 | 99 |
| 100 private: | 100 private: |
| 101 // TODO(yiyaoliu): Remove the enums and related code when crbug/223430 is |
| 102 // fixed. |
| 103 // An enum representing different situations under which function |
| 104 // SetTopSites can be initiated. |
| 105 // This is needed because a histogram is used to record speed related metrics |
| 106 // when SetTopSites are initiated from OnGotMostVisitedThumbnails, which |
| 107 // usually happens early and might affect Chrome startup speed. |
| 108 enum CallLocation { |
| 109 // SetTopSites is called from function OnGotMostVisitedThumbnails. |
| 110 CALL_LOCATION_FROM_ON_GOT_MOST_VISITED_THUMBNAILS, |
| 111 // All other situations. |
| 112 CALL_LOCATION_FROM_OTHER_PLACES |
| 113 }; |
| 114 |
| 101 friend class TopSitesImplTest; | 115 friend class TopSitesImplTest; |
| 102 FRIEND_TEST_ALL_PREFIXES(TopSitesImplTest, DiffMostVisited); | 116 FRIEND_TEST_ALL_PREFIXES(TopSitesImplTest, DiffMostVisited); |
| 103 FRIEND_TEST_ALL_PREFIXES(TopSitesImplTest, DiffMostVisitedWithForced); | 117 FRIEND_TEST_ALL_PREFIXES(TopSitesImplTest, DiffMostVisitedWithForced); |
| 104 | 118 |
| 105 typedef base::Callback<void(const MostVisitedURLList&, | 119 typedef base::Callback<void(const MostVisitedURLList&, |
| 106 const MostVisitedURLList&)> PendingCallback; | 120 const MostVisitedURLList&)> PendingCallback; |
| 107 | 121 |
| 108 typedef std::pair<GURL, Images> TempImage; | 122 typedef std::pair<GURL, Images> TempImage; |
| 109 typedef std::list<TempImage> TempImages; | 123 typedef std::list<TempImage> TempImages; |
| 110 typedef std::vector<PendingCallback> PendingCallbacks; | 124 typedef std::vector<PendingCallback> PendingCallbacks; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 void Observe(int type, | 202 void Observe(int type, |
| 189 const content::NotificationSource& source, | 203 const content::NotificationSource& source, |
| 190 const content::NotificationDetails& details) override; | 204 const content::NotificationDetails& details) override; |
| 191 | 205 |
| 192 // Updates URLs in |cache_| and the db (in the background). | 206 // Updates URLs in |cache_| and the db (in the background). |
| 193 // The non-forced URLs in |new_top_sites| replace those in |cache_|. | 207 // The non-forced URLs in |new_top_sites| replace those in |cache_|. |
| 194 // The forced URLs of |new_top_sites| are merged with those in |cache_|, | 208 // The forced URLs of |new_top_sites| are merged with those in |cache_|, |
| 195 // if the list of forced URLs overflows, the oldest ones are dropped. | 209 // if the list of forced URLs overflows, the oldest ones are dropped. |
| 196 // All mutations to cache_ *must* go through this. Should | 210 // All mutations to cache_ *must* go through this. Should |
| 197 // be called from the UI thread. | 211 // be called from the UI thread. |
| 198 void SetTopSites(const MostVisitedURLList& new_top_sites); | 212 void SetTopSites(const MostVisitedURLList& new_top_sites, |
| 213 const CallLocation location); |
| 199 | 214 |
| 200 // Returns the number of most visited results to request from history. This | 215 // Returns the number of most visited results to request from history. This |
| 201 // changes depending upon how many urls have been blacklisted. Should be | 216 // changes depending upon how many urls have been blacklisted. Should be |
| 202 // called from the UI thread. | 217 // called from the UI thread. |
| 203 int num_results_to_request_from_history() const; | 218 int num_results_to_request_from_history() const; |
| 204 | 219 |
| 205 // Invoked when transitioning to LOADED. Notifies any queued up callbacks. | 220 // Invoked when transitioning to LOADED. Notifies any queued up callbacks. |
| 206 // Should be called from the UI thread. | 221 // Should be called from the UI thread. |
| 207 void MoveStateToLoaded(); | 222 void MoveStateToLoaded(); |
| 208 | 223 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 // enough Top Sites (new profile), we store it until the next | 284 // enough Top Sites (new profile), we store it until the next |
| 270 // SetNonForcedTopSites call. | 285 // SetNonForcedTopSites call. |
| 271 TempImages temp_images_; | 286 TempImages temp_images_; |
| 272 | 287 |
| 273 // URL List of prepopulated page. | 288 // URL List of prepopulated page. |
| 274 PrepopulatedPageList prepopulated_pages_; | 289 PrepopulatedPageList prepopulated_pages_; |
| 275 | 290 |
| 276 // Are we loaded? | 291 // Are we loaded? |
| 277 bool loaded_; | 292 bool loaded_; |
| 278 | 293 |
| 294 // Have the SetTopSites execution time related histograms been recorded? |
| 295 // The histogram should only be recorded once for each Chrome execution. |
| 296 static bool histogram_recorded_; |
| 297 |
| 279 ScopedObserver<HistoryService, HistoryServiceObserver> | 298 ScopedObserver<HistoryService, HistoryServiceObserver> |
| 280 history_service_observer_; | 299 history_service_observer_; |
| 281 | 300 |
| 282 DISALLOW_COPY_AND_ASSIGN(TopSitesImpl); | 301 DISALLOW_COPY_AND_ASSIGN(TopSitesImpl); |
| 283 }; | 302 }; |
| 284 | 303 |
| 285 } // namespace history | 304 } // namespace history |
| 286 | 305 |
| 287 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_IMPL_H_ | 306 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_IMPL_H_ |
| OLD | NEW |