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_INDEXED_DB_HELPER_H_
6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_INDEXED_DB_HELPER_H_
11 #include "base/callback.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/strings/string16.h"
14 #include "content/public/browser/indexed_db_context.h"
15 #include "content/public/browser/indexed_db_info.h"
20 // BrowsingDataIndexedDBHelper is an interface for classes dealing with
21 // aggregating and deleting browsing data stored in indexed databases. A
22 // client of this class need to call StartFetching from the UI thread to
23 // initiate the flow, and it'll be notified by the callback in its UI thread at
25 class BrowsingDataIndexedDBHelper
26 : public base::RefCountedThreadSafe
<BrowsingDataIndexedDBHelper
> {
29 base::Callback
<void(const std::list
<content::IndexedDBInfo
>&)>;
31 // Create a BrowsingDataIndexedDBHelper instance for the indexed databases
32 // stored in |context|'s associated profile's user data directory.
33 explicit BrowsingDataIndexedDBHelper(content::IndexedDBContext
* context
);
35 // Starts the fetching process, which will notify its completion via
36 // |callback|. This must be called only on the UI thread.
37 virtual void StartFetching(const FetchCallback
& callback
);
38 // Requests a single indexed database to be deleted in the IndexedDB thread.
39 virtual void DeleteIndexedDB(const GURL
& origin
);
42 virtual ~BrowsingDataIndexedDBHelper();
44 scoped_refptr
<content::IndexedDBContext
> indexed_db_context_
;
47 friend class base::RefCountedThreadSafe
<BrowsingDataIndexedDBHelper
>;
49 // Enumerates all indexed database files in the IndexedDB thread.
50 void FetchIndexedDBInfoInIndexedDBThread(const FetchCallback
& callback
);
51 // Delete a single indexed database in the IndexedDB thread.
52 void DeleteIndexedDBInIndexedDBThread(const GURL
& origin
);
54 DISALLOW_COPY_AND_ASSIGN(BrowsingDataIndexedDBHelper
);
57 // This class is an implementation of BrowsingDataIndexedDBHelper that does
58 // not fetch its information from the indexed database tracker, but gets them
59 // passed as a parameter.
60 class CannedBrowsingDataIndexedDBHelper
61 : public BrowsingDataIndexedDBHelper
{
63 // Contains information about an indexed database.
64 struct PendingIndexedDBInfo
{
65 PendingIndexedDBInfo(const GURL
& origin
, const base::string16
& name
);
66 ~PendingIndexedDBInfo();
68 bool operator<(const PendingIndexedDBInfo
& other
) const;
74 explicit CannedBrowsingDataIndexedDBHelper(
75 content::IndexedDBContext
* context
);
77 // Add a indexed database to the set of canned indexed databases that is
78 // returned by this helper.
79 void AddIndexedDB(const GURL
& origin
,
80 const base::string16
& name
);
82 // Clear the list of canned indexed databases.
85 // True if no indexed databases are currently stored.
88 // Returns the number of currently stored indexed databases.
89 size_t GetIndexedDBCount() const;
91 // Returns the current list of indexed data bases.
92 const std::set
<CannedBrowsingDataIndexedDBHelper::PendingIndexedDBInfo
>&
93 GetIndexedDBInfo() const;
95 // BrowsingDataIndexedDBHelper methods.
96 void StartFetching(const FetchCallback
& callback
) override
;
97 void DeleteIndexedDB(const GURL
& origin
) override
;
100 ~CannedBrowsingDataIndexedDBHelper() override
;
102 std::set
<PendingIndexedDBInfo
> pending_indexed_db_info_
;
104 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataIndexedDBHelper
);
107 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_INDEXED_DB_HELPER_H_