Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / browsing_data / browsing_data_indexed_db_helper.h
blob9119cb475246fa731de2e4a341cd575cfeb515f6
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_
8 #include <list>
9 #include <set>
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"
16 #include "url/gurl.h"
18 class Profile;
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
24 // some later point.
25 class BrowsingDataIndexedDBHelper
26 : public base::RefCountedThreadSafe<BrowsingDataIndexedDBHelper> {
27 public:
28 using FetchCallback =
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);
41 protected:
42 virtual ~BrowsingDataIndexedDBHelper();
44 scoped_refptr<content::IndexedDBContext> indexed_db_context_;
46 private:
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 {
62 public:
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;
70 GURL origin;
71 base::string16 name;
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.
83 void Reset();
85 // True if no indexed databases are currently stored.
86 bool empty() const;
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;
99 private:
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_