Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_HISTORY_CORE_BROWSER_TOP_SITES_BACKEND_H_ | 5 #ifndef COMPONENTS_HISTORY_CORE_BROWSER_TOP_SITES_BACKEND_H_ |
| 6 #define COMPONENTS_HISTORY_CORE_BROWSER_TOP_SITES_BACKEND_H_ | 6 #define COMPONENTS_HISTORY_CORE_BROWSER_TOP_SITES_BACKEND_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "components/history/core/browser/history_types.h" | 12 #include "components/history/core/browser/history_types.h" |
| 13 | 13 |
| 14 namespace base { | 14 namespace base { |
| 15 class CancelableTaskTracker; | 15 class CancelableTaskTracker; |
| 16 class FilePath; | 16 class FilePath; |
| 17 class SingleThreadTaskRunner; | 17 class SingleThreadTaskRunner; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace history { | 20 namespace history { |
| 21 | 21 |
| 22 class TopSitesDatabase; | 22 class TopSitesDatabase; |
| 23 | 23 |
| 24 // Service used by TopSites to have db interaction happen on the DB thread. All | 24 // Service used by TopSites to have db interaction happen on the DB thread. All |
| 25 // public methods are invoked on the ui thread and get funneled to the DB | 25 // public methods are invoked on the ui thread and get funneled to the DB |
| 26 // thread. | 26 // thread. |
| 27 class TopSitesBackend : public base::RefCountedThreadSafe<TopSitesBackend> { | 27 class TopSitesBackend : public base::RefCountedThreadSafe<TopSitesBackend> { |
| 28 public: | 28 public: |
| 29 // TODO(yiyaoliu): Remove the enums and related code when crbug/223430 is | |
| 30 // fixed. | |
| 31 | |
| 32 // An enum representing different situations under which function | |
| 33 // TopSitesImpl::SetTopSites and TopSitesBackend::UpdateTopSites can be | |
| 34 // initiated. | |
| 35 // This is needed because a histogram is used to record speed related metrics | |
| 36 // when TopSitesImpl::SetTopSites and TopSitesBackend::UpdateTopSites are | |
| 37 // initiated from TopSitesImpl::OnGotMostVisitedThumbnails, which usually | |
| 38 // happens early and might affect Chrome startup speed. | |
| 39 enum CallLocation { | |
| 40 // SetTopSites is called when MostVisitedThumbnails is available (function | |
| 41 // TopSitesImpl::OnGotMostVisitedThumbnails). | |
| 42 CALL_LOCATION_FROM_ON_GOT_MOST_VISITED_THUMBNAILS, | |
| 43 // All other situations. | |
| 44 CALL_LOCATION_FROM_OTHER_PLACES | |
| 45 }; | |
| 46 | |
| 47 // An enum representing the histogram recording status used by class | |
| 48 // TopSitesImpl and class TopSitesBackend. The purpose is to make sure that | |
| 49 // TopSitesImpl and TopSitesBackend records the relevant histograms at most | |
| 50 // once during startup. | |
| 51 // The initial value will be HISTOGRAM_RECORDING_NOT_YET. TopSitesImpl will | |
| 52 // change it to HISTOGRAM_RECORDING_IN_PROGRESS and records a histogram. | |
| 53 // TopSitesBackend will only records the value if this enum is | |
| 54 // HISTOGRAM_RECORDING_IN_PROGRESS and after that it changes the enum value to | |
| 55 // HISTOGRAM_RECORDING_DONE. | |
| 56 enum HistogramRecording { | |
| 57 HISTOGRAM_RECORDING_NOT_YET, | |
| 58 HISTOGRAM_RECORDING_IN_PROGRESS, | |
| 59 HISTOGRAM_RECORDING_DONE | |
| 60 }; | |
| 61 | |
| 62 // Move the histogram recording status to the next step. | |
| 63 static void IncraseHistogramRecordingStatus(); | |
|
sky
2015/04/16 16:05:10
Increase
Why does this need to be public? Doesn't
| |
| 64 static HistogramRecording histogram_recorded() { return histogram_recorded_; } | |
| 65 | |
| 29 // The boolean parameter indicates if the DB existed on disk or needs to be | 66 // The boolean parameter indicates if the DB existed on disk or needs to be |
| 30 // migrated. | 67 // migrated. |
| 31 typedef base::Callback<void(const scoped_refptr<MostVisitedThumbnails>&)> | 68 typedef base::Callback<void(const scoped_refptr<MostVisitedThumbnails>&)> |
| 32 GetMostVisitedThumbnailsCallback; | 69 GetMostVisitedThumbnailsCallback; |
| 33 | 70 |
| 34 explicit TopSitesBackend( | 71 explicit TopSitesBackend( |
| 35 const scoped_refptr<base::SingleThreadTaskRunner>& db_task_runner); | 72 const scoped_refptr<base::SingleThreadTaskRunner>& db_task_runner); |
| 36 | 73 |
| 37 void Init(const base::FilePath& path); | 74 void Init(const base::FilePath& path); |
| 38 | 75 |
| 39 // Schedules the db to be shutdown. | 76 // Schedules the db to be shutdown. |
| 40 void Shutdown(); | 77 void Shutdown(); |
| 41 | 78 |
| 42 // Fetches MostVisitedThumbnails. | 79 // Fetches MostVisitedThumbnails. |
| 43 void GetMostVisitedThumbnails( | 80 void GetMostVisitedThumbnails( |
| 44 const GetMostVisitedThumbnailsCallback& callback, | 81 const GetMostVisitedThumbnailsCallback& callback, |
| 45 base::CancelableTaskTracker* tracker); | 82 base::CancelableTaskTracker* tracker); |
| 46 | 83 |
| 47 // Updates top sites database from the specified delta. | 84 // Updates top sites database from the specified delta. |
| 48 void UpdateTopSites(const TopSitesDelta& delta); | 85 // TODO(yiyaoliu): Remove the 2nd parameter when crbug/223430 is fixed. |
| 86 void UpdateTopSites(const TopSitesDelta& delta, | |
| 87 const CallLocation location); | |
| 49 | 88 |
| 50 // Sets the thumbnail. | 89 // Sets the thumbnail. |
| 51 void SetPageThumbnail(const MostVisitedURL& url, | 90 void SetPageThumbnail(const MostVisitedURL& url, |
| 52 int url_rank, | 91 int url_rank, |
| 53 const Images& thumbnail); | 92 const Images& thumbnail); |
| 54 | 93 |
| 55 // Deletes the database and recreates it. | 94 // Deletes the database and recreates it. |
| 56 void ResetDatabase(); | 95 void ResetDatabase(); |
| 57 | 96 |
| 58 // Schedules a request that does nothing on the DB thread, but then notifies | 97 // Schedules a request that does nothing on the DB thread, but then notifies |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 70 void InitDBOnDBThread(const base::FilePath& path); | 109 void InitDBOnDBThread(const base::FilePath& path); |
| 71 | 110 |
| 72 // Shuts down the db. | 111 // Shuts down the db. |
| 73 void ShutdownDBOnDBThread(); | 112 void ShutdownDBOnDBThread(); |
| 74 | 113 |
| 75 // Does the work of getting the most visted thumbnails. | 114 // Does the work of getting the most visted thumbnails. |
| 76 void GetMostVisitedThumbnailsOnDBThread( | 115 void GetMostVisitedThumbnailsOnDBThread( |
| 77 scoped_refptr<MostVisitedThumbnails> thumbnails); | 116 scoped_refptr<MostVisitedThumbnails> thumbnails); |
| 78 | 117 |
| 79 // Updates top sites. | 118 // Updates top sites. |
| 80 void UpdateTopSitesOnDBThread(const TopSitesDelta& delta); | 119 // TODO(yiyaoliu): Remove the 2nd parameter when crbug/223430 is fixed. |
| 120 void UpdateTopSitesOnDBThread(const TopSitesDelta& delta, | |
| 121 const CallLocation location); | |
| 81 | 122 |
| 82 // Sets the thumbnail. | 123 // Sets the thumbnail. |
| 83 void SetPageThumbnailOnDBThread(const MostVisitedURL& url, | 124 void SetPageThumbnailOnDBThread(const MostVisitedURL& url, |
| 84 int url_rank, | 125 int url_rank, |
| 85 const Images& thumbnail); | 126 const Images& thumbnail); |
| 86 | 127 |
| 87 // Resets the database. | 128 // Resets the database. |
| 88 void ResetDatabaseOnDBThread(const base::FilePath& file_path); | 129 void ResetDatabaseOnDBThread(const base::FilePath& file_path); |
| 89 | 130 |
| 90 base::FilePath db_path_; | 131 base::FilePath db_path_; |
| 91 | 132 |
| 92 scoped_ptr<TopSitesDatabase> db_; | 133 scoped_ptr<TopSitesDatabase> db_; |
| 93 scoped_refptr<base::SingleThreadTaskRunner> db_task_runner_; | 134 scoped_refptr<base::SingleThreadTaskRunner> db_task_runner_; |
| 94 | 135 |
| 136 static HistogramRecording histogram_recorded_; | |
| 137 | |
| 95 DISALLOW_COPY_AND_ASSIGN(TopSitesBackend); | 138 DISALLOW_COPY_AND_ASSIGN(TopSitesBackend); |
| 96 }; | 139 }; |
| 97 | 140 |
| 98 } // namespace history | 141 } // namespace history |
| 99 | 142 |
| 100 #endif // COMPONENTS_HISTORY_CORE_BROWSER_TOP_SITES_BACKEND_H_ | 143 #endif // COMPONENTS_HISTORY_CORE_BROWSER_TOP_SITES_BACKEND_H_ |
| OLD | NEW |