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.
5 #ifndef CHROME_BROWSER_HISTORY_TOP_SITES_BACKEND_H_
6 #define CHROME_BROWSER_HISTORY_TOP_SITES_BACKEND_H_
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 "chrome/browser/history/history_types.h"
14 class CancelableTaskTracker;
22 class TopSitesDatabase;
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
27 class TopSitesBackend : public base::RefCountedThreadSafe<TopSitesBackend> {
29 // The boolean parameter indicates if the DB existed on disk or needs to be
31 typedef base::Callback<void(const scoped_refptr<MostVisitedThumbnails>&)>
32 GetMostVisitedThumbnailsCallback;
36 void Init(const base::FilePath& path);
38 // Schedules the db to be shutdown.
41 // Fetches MostVisitedThumbnails.
42 void GetMostVisitedThumbnails(
43 const GetMostVisitedThumbnailsCallback& callback,
44 CancelableTaskTracker* tracker);
46 // Updates top sites database from the specified delta.
47 void UpdateTopSites(const TopSitesDelta& delta);
49 // Sets the thumbnail.
50 void SetPageThumbnail(const MostVisitedURL& url,
52 const Images& thumbnail);
54 // Deletes the database and recreates it.
57 // 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
59 // finished processing a request.
60 void DoEmptyRequest(const base::Closure& reply,
61 CancelableTaskTracker* tracker);
64 friend class base::RefCountedThreadSafe<TopSitesBackend>;
66 virtual ~TopSitesBackend();
68 // Invokes Init on the db_.
69 void InitDBOnDBThread(const base::FilePath& path);
72 void ShutdownDBOnDBThread();
74 // Does the work of getting the most visted thumbnails.
75 void GetMostVisitedThumbnailsOnDBThread(
76 scoped_refptr<MostVisitedThumbnails> thumbnails);
79 void UpdateTopSitesOnDBThread(const TopSitesDelta& delta);
81 // Sets the thumbnail.
82 void SetPageThumbnailOnDBThread(const MostVisitedURL& url,
84 const Images& thumbnail);
86 // Resets the database.
87 void ResetDatabaseOnDBThread(const base::FilePath& file_path);
89 base::FilePath db_path_;
91 scoped_ptr<TopSitesDatabase> db_;
93 DISALLOW_COPY_AND_ASSIGN(TopSitesBackend);
96 } // namespace history
98 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_BACKEND_H_