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_
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"
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
> {
30 // Contains detailed information about a web database.
32 DatabaseInfo(const storage::DatabaseIdentifier
& identifier
,
33 const std::string
& database_name
,
34 const std::string
& description
,
36 base::Time last_modified
);
39 storage::DatabaseIdentifier identifier
;
40 std::string database_name
;
41 std::string description
;
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
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
);
61 friend class base::RefCountedThreadSafe
<BrowsingDataDatabaseHelper
>;
62 virtual ~BrowsingDataDatabaseHelper();
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
{
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;
93 std::string description
;
96 explicit CannedBrowsingDataDatabaseHelper(Profile
* profile
);
98 // Add a database to the set of canned databases that is returned by this
100 void AddDatabase(const GURL
& origin
,
101 const std::string
& name
,
102 const std::string
& description
);
104 // Clear the list of canned databases.
107 // True if no databases are currently stored.
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
;
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_