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 // An enum representing different situations under which function | |
| 30 // TopSitesImpl::SetTopSites and TopSitesBackend::UpdateTopSites can be | |
| 31 // initiated. | |
| 32 // This is needed because a histogram is used to record speed related metrics | |
| 33 // when TopSitesImpl::SetTopSites and TopSitesBackend::UpdateTopSites are | |
| 34 // initiated from TopSitesImpl::OnGotMostVisitedThumbnails, which usually | |
| 35 // happens early and might affect Chrome startup speed. | |
| 36 // TODO(yiyaoliu): Remove this when crbug/223430 is fixed. | |
| 37 enum TopSitesCalledLocation { | |
|
sky
2015/04/01 22:51:48
This is in the topsites files, so prefixing with t
yao
2015/04/02 17:20:31
Done.
| |
| 38 // SetTopSites is called when MostVisitedThumbnails is available (function | |
| 39 // TopSitesImpl::OnGotMostVisitedThumbnails). | |
| 40 fromOnGotMostVisitedThumbnails, | |
|
sky
2015/04/01 22:51:48
Style guide says enums are ALL_CAPS. And generally
yao
2015/04/02 17:20:31
Done.
| |
| 41 // All other situations. | |
| 42 fomOtherPlaces | |
| 43 }; | |
| 44 | |
| 29 // The boolean parameter indicates if the DB existed on disk or needs to be | 45 // The boolean parameter indicates if the DB existed on disk or needs to be |
| 30 // migrated. | 46 // migrated. |
| 31 typedef base::Callback<void(const scoped_refptr<MostVisitedThumbnails>&)> | 47 typedef base::Callback<void(const scoped_refptr<MostVisitedThumbnails>&)> |
| 32 GetMostVisitedThumbnailsCallback; | 48 GetMostVisitedThumbnailsCallback; |
| 33 | 49 |
| 34 explicit TopSitesBackend( | 50 explicit TopSitesBackend( |
| 35 const scoped_refptr<base::SingleThreadTaskRunner>& db_task_runner); | 51 const scoped_refptr<base::SingleThreadTaskRunner>& db_task_runner); |
| 36 | 52 |
| 37 void Init(const base::FilePath& path); | 53 void Init(const base::FilePath& path); |
| 38 | 54 |
| 39 // Schedules the db to be shutdown. | 55 // Schedules the db to be shutdown. |
| 40 void Shutdown(); | 56 void Shutdown(); |
| 41 | 57 |
| 42 // Fetches MostVisitedThumbnails. | 58 // Fetches MostVisitedThumbnails. |
| 43 void GetMostVisitedThumbnails( | 59 void GetMostVisitedThumbnails( |
| 44 const GetMostVisitedThumbnailsCallback& callback, | 60 const GetMostVisitedThumbnailsCallback& callback, |
| 45 base::CancelableTaskTracker* tracker); | 61 base::CancelableTaskTracker* tracker); |
| 46 | 62 |
| 47 // Updates top sites database from the specified delta. | 63 // Updates top sites database from the specified delta. |
| 48 void UpdateTopSites(const TopSitesDelta& delta); | 64 // TODO(yiyaoliu): Remove the 2nd parameter when crbug/223430 is fixed. |
| 65 void UpdateTopSites(const TopSitesDelta& delta, | |
| 66 const TopSitesCalledLocation location); | |
| 49 | 67 |
| 50 // Sets the thumbnail. | 68 // Sets the thumbnail. |
| 51 void SetPageThumbnail(const MostVisitedURL& url, | 69 void SetPageThumbnail(const MostVisitedURL& url, |
| 52 int url_rank, | 70 int url_rank, |
| 53 const Images& thumbnail); | 71 const Images& thumbnail); |
| 54 | 72 |
| 55 // Deletes the database and recreates it. | 73 // Deletes the database and recreates it. |
| 56 void ResetDatabase(); | 74 void ResetDatabase(); |
| 57 | 75 |
| 58 // Schedules a request that does nothing on the DB thread, but then notifies | 76 // 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); | 88 void InitDBOnDBThread(const base::FilePath& path); |
| 71 | 89 |
| 72 // Shuts down the db. | 90 // Shuts down the db. |
| 73 void ShutdownDBOnDBThread(); | 91 void ShutdownDBOnDBThread(); |
| 74 | 92 |
| 75 // Does the work of getting the most visted thumbnails. | 93 // Does the work of getting the most visted thumbnails. |
| 76 void GetMostVisitedThumbnailsOnDBThread( | 94 void GetMostVisitedThumbnailsOnDBThread( |
| 77 scoped_refptr<MostVisitedThumbnails> thumbnails); | 95 scoped_refptr<MostVisitedThumbnails> thumbnails); |
| 78 | 96 |
| 79 // Updates top sites. | 97 // Updates top sites. |
| 80 void UpdateTopSitesOnDBThread(const TopSitesDelta& delta); | 98 // TODO(yiyaoliu): Remove the 2nd parameter when crbug/223430 is fixed. |
| 99 void UpdateTopSitesOnDBThread(const TopSitesDelta& delta, | |
| 100 const TopSitesCalledLocation location); | |
| 81 | 101 |
| 82 // Sets the thumbnail. | 102 // Sets the thumbnail. |
| 83 void SetPageThumbnailOnDBThread(const MostVisitedURL& url, | 103 void SetPageThumbnailOnDBThread(const MostVisitedURL& url, |
| 84 int url_rank, | 104 int url_rank, |
| 85 const Images& thumbnail); | 105 const Images& thumbnail); |
| 86 | 106 |
| 87 // Resets the database. | 107 // Resets the database. |
| 88 void ResetDatabaseOnDBThread(const base::FilePath& file_path); | 108 void ResetDatabaseOnDBThread(const base::FilePath& file_path); |
| 89 | 109 |
| 90 base::FilePath db_path_; | 110 base::FilePath db_path_; |
| 91 | 111 |
| 92 scoped_ptr<TopSitesDatabase> db_; | 112 scoped_ptr<TopSitesDatabase> db_; |
| 93 scoped_refptr<base::SingleThreadTaskRunner> db_task_runner_; | 113 scoped_refptr<base::SingleThreadTaskRunner> db_task_runner_; |
| 94 | 114 |
| 95 DISALLOW_COPY_AND_ASSIGN(TopSitesBackend); | 115 DISALLOW_COPY_AND_ASSIGN(TopSitesBackend); |
| 96 }; | 116 }; |
| 97 | 117 |
| 98 } // namespace history | 118 } // namespace history |
| 99 | 119 |
| 100 #endif // COMPONENTS_HISTORY_CORE_BROWSER_TOP_SITES_BACKEND_H_ | 120 #endif // COMPONENTS_HISTORY_CORE_BROWSER_TOP_SITES_BACKEND_H_ |
| OLD | NEW |