Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / browsing_data / browsing_data_database_helper.h
blobc5cdb1863d6b24b29b99c576f8af086d90da8933
1 // Copyright (c) 2012 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_BROWSING_DATA_BROWSING_DATA_DATABASE_HELPER_H_
6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_DATABASE_HELPER_H_
8 #include <list>
9 #include <set>
10 #include <string>
12 #include "base/basictypes.h"
13 #include "base/callback_forward.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/time/time.h"
16 #include "storage/browser/database/database_tracker.h"
17 #include "storage/common/database/database_identifier.h"
18 #include "url/gurl.h"
20 class Profile;
22 // This class fetches database information in the FILE thread, and notifies
23 // the UI thread upon completion.
24 // A client of this class need to call StartFetching from the UI thread to
25 // initiate the flow, and it'll be notified by the callback in its UI
26 // thread at some later point.
27 class BrowsingDataDatabaseHelper
28 : public base::RefCountedThreadSafe<BrowsingDataDatabaseHelper> {
29 public:
30 // Contains detailed information about a web database.
31 struct DatabaseInfo {
32 DatabaseInfo(const storage::DatabaseIdentifier& identifier,
33 const std::string& database_name,
34 const std::string& description,
35 int64 size,
36 base::Time last_modified);
37 ~DatabaseInfo();
39 storage::DatabaseIdentifier identifier;
40 std::string database_name;
41 std::string description;
42 int64 size;
43 base::Time last_modified;
46 using FetchCallback = base::Callback<void(const std::list<DatabaseInfo>&)>;
48 explicit BrowsingDataDatabaseHelper(Profile* profile);
50 // Starts the fetching process, which will notify its completion via
51 // callback.
52 // This must be called only in the UI thread.
53 virtual void StartFetching(const FetchCallback& callback);
55 // Requests a single database to be deleted in the FILE thread. This must be
56 // called in the UI thread.
57 virtual void DeleteDatabase(const std::string& origin_identifier,
58 const std::string& name);
60 protected:
61 friend class base::RefCountedThreadSafe<BrowsingDataDatabaseHelper>;
62 virtual ~BrowsingDataDatabaseHelper();
64 private:
65 // Enumerates all databases. This must be called in the FILE thread.
66 void FetchDatabaseInfoOnFileThread(const FetchCallback& callback);
68 // Delete a single database file. This must be called in the FILE thread.
69 void DeleteDatabaseOnFileThread(const std::string& origin,
70 const std::string& name);
72 scoped_refptr<storage::DatabaseTracker> tracker_;
74 DISALLOW_COPY_AND_ASSIGN(BrowsingDataDatabaseHelper);
77 // This class is a thin wrapper around BrowsingDataDatabaseHelper that does not
78 // fetch its information from the database tracker, but gets them passed as
79 // a parameter during construction.
80 class CannedBrowsingDataDatabaseHelper : public BrowsingDataDatabaseHelper {
81 public:
82 struct PendingDatabaseInfo {
83 PendingDatabaseInfo(const GURL& origin,
84 const std::string& name,
85 const std::string& description);
86 ~PendingDatabaseInfo();
88 // The operator is needed to store |PendingDatabaseInfo| objects in a set.
89 bool operator<(const PendingDatabaseInfo& other) const;
91 GURL origin;
92 std::string name;
93 std::string description;
96 explicit CannedBrowsingDataDatabaseHelper(Profile* profile);
98 // Add a database to the set of canned databases that is returned by this
99 // helper.
100 void AddDatabase(const GURL& origin,
101 const std::string& name,
102 const std::string& description);
104 // Clear the list of canned databases.
105 void Reset();
107 // True if no databases are currently stored.
108 bool empty() const;
110 // Returns the number of currently stored databases.
111 size_t GetDatabaseCount() const;
113 // Returns the current list of web databases.
114 const std::set<PendingDatabaseInfo>& GetPendingDatabaseInfo();
116 // BrowsingDataDatabaseHelper implementation.
117 void StartFetching(const FetchCallback& callback) override;
118 void DeleteDatabase(const std::string& origin_identifier,
119 const std::string& name) override;
121 private:
122 ~CannedBrowsingDataDatabaseHelper() override;
124 std::set<PendingDatabaseInfo> pending_database_info_;
126 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataDatabaseHelper);
129 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_DATABASE_HELPER_H_