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 // An enum representing whether the UpdateTopSites execution time related |
| 32 // histogram should be recorded. |
| 33 enum RecordHistogram { |
| 34 RECORD_HISTOGRAM_YES, |
| 35 RECORD_HISTOGRAM_NO |
| 36 }; |
| 37 |
29 // The boolean parameter indicates if the DB existed on disk or needs to be | 38 // The boolean parameter indicates if the DB existed on disk or needs to be |
30 // migrated. | 39 // migrated. |
31 typedef base::Callback<void(const scoped_refptr<MostVisitedThumbnails>&)> | 40 typedef base::Callback<void(const scoped_refptr<MostVisitedThumbnails>&)> |
32 GetMostVisitedThumbnailsCallback; | 41 GetMostVisitedThumbnailsCallback; |
33 | 42 |
34 explicit TopSitesBackend( | 43 explicit TopSitesBackend( |
35 const scoped_refptr<base::SingleThreadTaskRunner>& db_task_runner); | 44 const scoped_refptr<base::SingleThreadTaskRunner>& db_task_runner); |
36 | 45 |
37 void Init(const base::FilePath& path); | 46 void Init(const base::FilePath& path); |
38 | 47 |
39 // Schedules the db to be shutdown. | 48 // Schedules the db to be shutdown. |
40 void Shutdown(); | 49 void Shutdown(); |
41 | 50 |
42 // Fetches MostVisitedThumbnails. | 51 // Fetches MostVisitedThumbnails. |
43 void GetMostVisitedThumbnails( | 52 void GetMostVisitedThumbnails( |
44 const GetMostVisitedThumbnailsCallback& callback, | 53 const GetMostVisitedThumbnailsCallback& callback, |
45 base::CancelableTaskTracker* tracker); | 54 base::CancelableTaskTracker* tracker); |
46 | 55 |
47 // Updates top sites database from the specified delta. | 56 // Updates top sites database from the specified delta. |
48 void UpdateTopSites(const TopSitesDelta& delta); | 57 void UpdateTopSites(const TopSitesDelta& delta, |
| 58 const RecordHistogram record_or_not); |
49 | 59 |
50 // Sets the thumbnail. | 60 // Sets the thumbnail. |
51 void SetPageThumbnail(const MostVisitedURL& url, | 61 void SetPageThumbnail(const MostVisitedURL& url, |
52 int url_rank, | 62 int url_rank, |
53 const Images& thumbnail); | 63 const Images& thumbnail); |
54 | 64 |
55 // Deletes the database and recreates it. | 65 // Deletes the database and recreates it. |
56 void ResetDatabase(); | 66 void ResetDatabase(); |
57 | 67 |
58 // Schedules a request that does nothing on the DB thread, but then notifies | 68 // 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); | 80 void InitDBOnDBThread(const base::FilePath& path); |
71 | 81 |
72 // Shuts down the db. | 82 // Shuts down the db. |
73 void ShutdownDBOnDBThread(); | 83 void ShutdownDBOnDBThread(); |
74 | 84 |
75 // Does the work of getting the most visted thumbnails. | 85 // Does the work of getting the most visted thumbnails. |
76 void GetMostVisitedThumbnailsOnDBThread( | 86 void GetMostVisitedThumbnailsOnDBThread( |
77 scoped_refptr<MostVisitedThumbnails> thumbnails); | 87 scoped_refptr<MostVisitedThumbnails> thumbnails); |
78 | 88 |
79 // Updates top sites. | 89 // Updates top sites. |
80 void UpdateTopSitesOnDBThread(const TopSitesDelta& delta); | 90 void UpdateTopSitesOnDBThread(const TopSitesDelta& delta, |
| 91 const RecordHistogram record_or_not); |
81 | 92 |
82 // Sets the thumbnail. | 93 // Sets the thumbnail. |
83 void SetPageThumbnailOnDBThread(const MostVisitedURL& url, | 94 void SetPageThumbnailOnDBThread(const MostVisitedURL& url, |
84 int url_rank, | 95 int url_rank, |
85 const Images& thumbnail); | 96 const Images& thumbnail); |
86 | 97 |
87 // Resets the database. | 98 // Resets the database. |
88 void ResetDatabaseOnDBThread(const base::FilePath& file_path); | 99 void ResetDatabaseOnDBThread(const base::FilePath& file_path); |
89 | 100 |
90 base::FilePath db_path_; | 101 base::FilePath db_path_; |
91 | 102 |
92 scoped_ptr<TopSitesDatabase> db_; | 103 scoped_ptr<TopSitesDatabase> db_; |
93 scoped_refptr<base::SingleThreadTaskRunner> db_task_runner_; | 104 scoped_refptr<base::SingleThreadTaskRunner> db_task_runner_; |
94 | 105 |
95 DISALLOW_COPY_AND_ASSIGN(TopSitesBackend); | 106 DISALLOW_COPY_AND_ASSIGN(TopSitesBackend); |
96 }; | 107 }; |
97 | 108 |
98 } // namespace history | 109 } // namespace history |
99 | 110 |
100 #endif // COMPONENTS_HISTORY_CORE_BROWSER_TOP_SITES_BACKEND_H_ | 111 #endif // COMPONENTS_HISTORY_CORE_BROWSER_TOP_SITES_BACKEND_H_ |
OLD | NEW |