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 "components/history/core/browser/history_types.h"
15 class CancelableTaskTracker;
21 class TopSitesDatabase;
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
26 class TopSitesBackend : public base::RefCountedThreadSafe<TopSitesBackend> {
28 // The boolean parameter indicates if the DB existed on disk or needs to be
30 typedef base::Callback<void(const scoped_refptr<MostVisitedThumbnails>&)>
31 GetMostVisitedThumbnailsCallback;
35 void Init(const base::FilePath& path);
37 // Schedules the db to be shutdown.
40 // Fetches MostVisitedThumbnails.
41 void GetMostVisitedThumbnails(
42 const GetMostVisitedThumbnailsCallback& callback,
43 base::CancelableTaskTracker* tracker);
45 // Updates top sites database from the specified delta.
46 void UpdateTopSites(const TopSitesDelta& delta);
48 // Sets the thumbnail.
49 void SetPageThumbnail(const MostVisitedURL& url,
51 const Images& thumbnail);
53 // Deletes the database and recreates it.
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);
63 friend class base::RefCountedThreadSafe<TopSitesBackend>;
65 virtual ~TopSitesBackend();
67 // Invokes Init on the db_.
68 void InitDBOnDBThread(const base::FilePath& path);
71 void ShutdownDBOnDBThread();
73 // Does the work of getting the most visted thumbnails.
74 void GetMostVisitedThumbnailsOnDBThread(
75 scoped_refptr<MostVisitedThumbnails> thumbnails);
78 void UpdateTopSitesOnDBThread(const TopSitesDelta& delta);
80 // Sets the thumbnail.
81 void SetPageThumbnailOnDBThread(const MostVisitedURL& url,
83 const Images& thumbnail);
85 // Resets the database.
86 void ResetDatabaseOnDBThread(const base::FilePath& file_path);
88 base::FilePath db_path_;
90 scoped_ptr<TopSitesDatabase> db_;
92 DISALLOW_COPY_AND_ASSIGN(TopSitesBackend);
95 } // namespace history
97 #endif // CHROME_BROWSER_HISTORY_TOP_SITES_BACKEND_H_