| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_HISTORY_TOP_SITES_BACKEND_H_ | |
| 6 #define CHROME_BROWSER_HISTORY_TOP_SITES_BACKEND_H_ | |
| 7 | |
| 8 #include "base/callback.h" | |
| 9 #include "base/files/file_path.h" | |
| 10 #include "base/memory/ref_counted.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "components/history/core/browser/history_types.h" | |
| 13 | |
| 14 namespace base { | |
| 15 class CancelableTaskTracker; | |
| 16 class FilePath; | |
| 17 } | |
| 18 | |
| 19 namespace history { | |
| 20 | |
| 21 class TopSitesDatabase; | |
| 22 | |
| 23 // Service used by TopSites to have db interaction happen on the DB thread. All | |
| 24 // public methods are invoked on the ui thread and get funneled to the DB | |
| 25 // thread. | |
| 26 class TopSitesBackend : public base::RefCountedThreadSafe<TopSitesBackend> { | |
| 27 public: | |
| 28 // The boolean parameter indicates if the DB existed on disk or needs to be | |
| 29 // migrated. | |
| 30 typedef base::Callback<void(const scoped_refptr<MostVisitedThumbnails>&)> | |
| 31 GetMostVisitedThumbnailsCallback; | |
| 32 | |
| 33 TopSitesBackend(); | |
| 34 | |
| 35 void Init(const base::FilePath& path); | |
| 36 | |
| 37 // Schedules the db to be shutdown. | |
| 38 void Shutdown(); | |
| 39 | |
| 40 // Fetches MostVisitedThumbnails. | |
| 41 void GetMostVisitedThumbnails( | |
| 42 const GetMostVisitedThumbnailsCallback& callback, | |
| 43 base::CancelableTaskTracker* tracker); | |
| 44 | |
| 45 // Updates top sites database from the specified delta. | |
| 46 void UpdateTopSites(const TopSitesDelta& delta); | |
| 47 | |
| 48 // Sets the thumbnail. | |
| 49 void SetPageThumbnail(const MostVisitedURL& url, | |
| 50 int url_rank, | |
| 51 const Images& thumbnail); | |
| 52 | |
| 53 // Deletes the database and recreates it. | |
| 54 void ResetDatabase(); | |
| 55 | |
| 56 // Schedules a request that does nothing on the DB thread, but then notifies | |
| 57 // the the calling thread with a reply. This is used to make sure the db has | |
| 58 // finished processing a request. | |
| 59 void DoEmptyRequest(const base::Closure& reply, | |
| 60 base::CancelableTaskTracker* tracker); | |
| 61 | |
| 62 private: | |
| 63 friend class base::RefCountedThreadSafe<TopSitesBackend>; | |
| 64 | |
| 65 virtual ~TopSitesBackend(); | |
| 66 | |
| 67 // Invokes Init on the db_. | |
| 68 void InitDBOnDBThread(const base::FilePath& path); | |
| 69 | |
| 70 // Shuts down the db. | |
| 71 void ShutdownDBOnDBThread(); | |
| 72 | |
| 73 // Does the work of getting the most visted thumbnails. | |
| 74 void GetMostVisitedThumbnailsOnDBThread( | |
| 75 scoped_refptr<MostVisitedThumbnails> thumbnails); | |
| 76 | |
| 77 // Updates top sites. | |
| 78 void UpdateTopSitesOnDBThread(const TopSitesDelta& delta); | |
| 79 | |
| 80 // Sets the thumbnail. | |
| 81 void SetPageThumbnailOnDBThread(const MostVisitedURL& url, | |
| 82 int url_rank, | |
| 83 const Images& thumbnail); | |
| 84 | |
| 85 // Resets the database. | |
| 86 void ResetDatabaseOnDBThread(const base::FilePath& file_path); | |
| 87 | |
| 88 base::FilePath db_path_; | |
| 89 | |
| 90 scoped_ptr<TopSitesDatabase> db_; | |
| 91 | |
| 92 DISALLOW_COPY_AND_ASSIGN(TopSitesBackend); | |
| 93 }; | |
| 94 | |
| 95 } // namespace history | |
| 96 | |
| 97 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_BACKEND_H_ | |
| OLD | NEW |