| 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 CHROME_BROWSER_HISTORY_TOP_SITES_BACKEND_H_ | 5 #ifndef CHROME_BROWSER_HISTORY_TOP_SITES_BACKEND_H_ |
| 6 #define CHROME_BROWSER_HISTORY_TOP_SITES_BACKEND_H_ | 6 #define CHROME_BROWSER_HISTORY_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 "chrome/browser/history/history_types.h" | 12 #include "chrome/browser/history/history_types.h" |
| 13 | 13 |
| 14 namespace base { |
| 14 class CancelableTaskTracker; | 15 class CancelableTaskTracker; |
| 15 | |
| 16 namespace base { | |
| 17 class FilePath; | 16 class FilePath; |
| 18 } | 17 } |
| 19 | 18 |
| 20 namespace history { | 19 namespace history { |
| 21 | 20 |
| 22 class TopSitesDatabase; | 21 class TopSitesDatabase; |
| 23 | 22 |
| 24 // Service used by TopSites to have db interaction happen on the DB thread. All | 23 // 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 | 24 // public methods are invoked on the ui thread and get funneled to the DB |
| 26 // thread. | 25 // thread. |
| 27 class TopSitesBackend : public base::RefCountedThreadSafe<TopSitesBackend> { | 26 class TopSitesBackend : public base::RefCountedThreadSafe<TopSitesBackend> { |
| 28 public: | 27 public: |
| 29 // The boolean parameter indicates if the DB existed on disk or needs to be | 28 // The boolean parameter indicates if the DB existed on disk or needs to be |
| 30 // migrated. | 29 // migrated. |
| 31 typedef base::Callback<void(const scoped_refptr<MostVisitedThumbnails>&)> | 30 typedef base::Callback<void(const scoped_refptr<MostVisitedThumbnails>&)> |
| 32 GetMostVisitedThumbnailsCallback; | 31 GetMostVisitedThumbnailsCallback; |
| 33 | 32 |
| 34 TopSitesBackend(); | 33 TopSitesBackend(); |
| 35 | 34 |
| 36 void Init(const base::FilePath& path); | 35 void Init(const base::FilePath& path); |
| 37 | 36 |
| 38 // Schedules the db to be shutdown. | 37 // Schedules the db to be shutdown. |
| 39 void Shutdown(); | 38 void Shutdown(); |
| 40 | 39 |
| 41 // Fetches MostVisitedThumbnails. | 40 // Fetches MostVisitedThumbnails. |
| 42 void GetMostVisitedThumbnails( | 41 void GetMostVisitedThumbnails( |
| 43 const GetMostVisitedThumbnailsCallback& callback, | 42 const GetMostVisitedThumbnailsCallback& callback, |
| 44 CancelableTaskTracker* tracker); | 43 base::CancelableTaskTracker* tracker); |
| 45 | 44 |
| 46 // Updates top sites database from the specified delta. | 45 // Updates top sites database from the specified delta. |
| 47 void UpdateTopSites(const TopSitesDelta& delta); | 46 void UpdateTopSites(const TopSitesDelta& delta); |
| 48 | 47 |
| 49 // Sets the thumbnail. | 48 // Sets the thumbnail. |
| 50 void SetPageThumbnail(const MostVisitedURL& url, | 49 void SetPageThumbnail(const MostVisitedURL& url, |
| 51 int url_rank, | 50 int url_rank, |
| 52 const Images& thumbnail); | 51 const Images& thumbnail); |
| 53 | 52 |
| 54 // Deletes the database and recreates it. | 53 // Deletes the database and recreates it. |
| 55 void ResetDatabase(); | 54 void ResetDatabase(); |
| 56 | 55 |
| 57 // Schedules a request that does nothing on the DB thread, but then notifies | 56 // Schedules a request that does nothing on the DB thread, but then notifies |
| 58 // the the calling thread with a reply. This is used to make sure the db has | 57 // the the calling thread with a reply. This is used to make sure the db has |
| 59 // finished processing a request. | 58 // finished processing a request. |
| 60 void DoEmptyRequest(const base::Closure& reply, | 59 void DoEmptyRequest(const base::Closure& reply, |
| 61 CancelableTaskTracker* tracker); | 60 base::CancelableTaskTracker* tracker); |
| 62 | 61 |
| 63 private: | 62 private: |
| 64 friend class base::RefCountedThreadSafe<TopSitesBackend>; | 63 friend class base::RefCountedThreadSafe<TopSitesBackend>; |
| 65 | 64 |
| 66 virtual ~TopSitesBackend(); | 65 virtual ~TopSitesBackend(); |
| 67 | 66 |
| 68 // Invokes Init on the db_. | 67 // Invokes Init on the db_. |
| 69 void InitDBOnDBThread(const base::FilePath& path); | 68 void InitDBOnDBThread(const base::FilePath& path); |
| 70 | 69 |
| 71 // Shuts down the db. | 70 // Shuts down the db. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 89 base::FilePath db_path_; | 88 base::FilePath db_path_; |
| 90 | 89 |
| 91 scoped_ptr<TopSitesDatabase> db_; | 90 scoped_ptr<TopSitesDatabase> db_; |
| 92 | 91 |
| 93 DISALLOW_COPY_AND_ASSIGN(TopSitesBackend); | 92 DISALLOW_COPY_AND_ASSIGN(TopSitesBackend); |
| 94 }; | 93 }; |
| 95 | 94 |
| 96 } // namespace history | 95 } // namespace history |
| 97 | 96 |
| 98 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_BACKEND_H_ | 97 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_BACKEND_H_ |
| OLD | NEW |