Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / browsing_data / browsing_data_indexed_db_helper.h
blob6476848c9ca7629b011c29ae41c08d6196aefd3f
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>
10 #include <string>
12 #include "base/callback.h"
13 #include "base/compiler_specific.h"
14 #include "base/files/file_path.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/synchronization/lock.h"
17 #include "base/time/time.h"
18 #include "content/public/browser/indexed_db_context.h"
19 #include "url/gurl.h"
21 class Profile;
23 // BrowsingDataIndexedDBHelper is an interface for classes dealing with
24 // aggregating and deleting browsing data stored in indexed databases. A
25 // client of this class need to call StartFetching from the UI thread to
26 // initiate the flow, and it'll be notified by the callback in its UI thread at
27 // some later point.
28 class BrowsingDataIndexedDBHelper
29 : public base::RefCountedThreadSafe<BrowsingDataIndexedDBHelper> {
30 public:
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(
38 const base::Callback<void(const std::list<content::IndexedDBInfo>&)>&
39 callback);
40 // Requests a single indexed database to be deleted in the IndexedDB thread.
41 virtual void DeleteIndexedDB(const GURL& origin);
43 protected:
44 virtual ~BrowsingDataIndexedDBHelper();
46 scoped_refptr<content::IndexedDBContext> indexed_db_context_;
48 // Access to |indexed_db_info_| is triggered indirectly via the UI thread and
49 // guarded by |is_fetching_|. This means |indexed_db_info_| is only accessed
50 // while |is_fetching_| is true. The flag |is_fetching_| is only accessed on
51 // the UI thread.
52 // In the context of this class |indexed_db_info_| is only accessed on the
53 // context's IndexedDB thread.
54 std::list<content::IndexedDBInfo> indexed_db_info_;
56 // This member is only mutated on the UI thread.
57 base::Callback<void(const std::list<content::IndexedDBInfo>&)>
58 completion_callback_;
60 // Indicates whether or not we're currently fetching information:
61 // it's true when StartFetching() is called in the UI thread, and it's reset
62 // after we notified the callback in the UI thread.
63 // This member is only mutated on the UI thread.
64 bool is_fetching_;
66 private:
67 friend class base::RefCountedThreadSafe<BrowsingDataIndexedDBHelper>;
69 // Enumerates all indexed database files in the IndexedDB thread.
70 void FetchIndexedDBInfoInIndexedDBThread();
71 // Notifies the completion callback in the UI thread.
72 void NotifyInUIThread();
73 // Delete a single indexed database in the IndexedDB thread.
74 void DeleteIndexedDBInIndexedDBThread(const GURL& origin);
76 DISALLOW_COPY_AND_ASSIGN(BrowsingDataIndexedDBHelper);
79 // This class is an implementation of BrowsingDataIndexedDBHelper that does
80 // not fetch its information from the indexed database tracker, but gets them
81 // passed as a parameter.
82 class CannedBrowsingDataIndexedDBHelper
83 : public BrowsingDataIndexedDBHelper {
84 public:
85 // Contains information about an indexed database.
86 struct PendingIndexedDBInfo {
87 PendingIndexedDBInfo(const GURL& origin, const base::string16& name);
88 ~PendingIndexedDBInfo();
90 bool operator<(const PendingIndexedDBInfo& other) const;
92 GURL origin;
93 base::string16 name;
96 explicit CannedBrowsingDataIndexedDBHelper(
97 content::IndexedDBContext* context);
99 // Add a indexed database to the set of canned indexed databases that is
100 // returned by this helper.
101 void AddIndexedDB(const GURL& origin,
102 const base::string16& name);
104 // Clear the list of canned indexed databases.
105 void Reset();
107 // True if no indexed databases are currently stored.
108 bool empty() const;
110 // Returns the number of currently stored indexed databases.
111 size_t GetIndexedDBCount() const;
113 // Returns the current list of indexed data bases.
114 const std::set<CannedBrowsingDataIndexedDBHelper::PendingIndexedDBInfo>&
115 GetIndexedDBInfo() const;
117 // BrowsingDataIndexedDBHelper methods.
118 void StartFetching(const base::Callback<
119 void(const std::list<content::IndexedDBInfo>&)>& callback) override;
120 void DeleteIndexedDB(const GURL& origin) override;
122 private:
123 ~CannedBrowsingDataIndexedDBHelper() override;
125 std::set<PendingIndexedDBInfo> pending_indexed_db_info_;
127 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataIndexedDBHelper);
130 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_INDEXED_DB_HELPER_H_