OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CHROME_BROWSER_BROWSING_DATA_INDEXED_DB_HELPER_H_ | |
6 #define CHROME_BROWSER_BROWSING_DATA_INDEXED_DB_HELPER_H_ | |
7 | |
8 #include <list> | |
9 #include <set> | |
10 #include <string> | |
11 | |
12 #include "base/callback.h" | |
13 #include "base/compiler_specific.h" | |
14 #include "base/file_path.h" | |
15 #include "base/memory/ref_counted.h" | |
16 #include "base/synchronization/lock.h" | |
17 #include "base/time.h" | |
18 #include "googleurl/src/gurl.h" | |
19 | |
20 class Profile; | |
21 | |
22 // BrowsingDataIndexedDBHelper is an interface for classes dealing with | |
23 // aggregating and deleting browsing data stored in indexed databases. A | |
24 // 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 thread at | |
26 // some later point. | |
27 class BrowsingDataIndexedDBHelper | |
28 : public base::RefCountedThreadSafe<BrowsingDataIndexedDBHelper> { | |
29 public: | |
30 // Contains detailed information about an indexed database. | |
31 struct IndexedDBInfo { | |
32 IndexedDBInfo( | |
33 const GURL& origin, | |
34 int64 size, | |
35 base::Time last_modified); | |
36 ~IndexedDBInfo(); | |
37 | |
38 GURL origin; | |
39 int64 size; | |
40 base::Time last_modified; | |
41 }; | |
42 | |
43 // Create a BrowsingDataIndexedDBHelper instance for the indexed databases | |
44 // stored in |profile|'s user data directory. | |
45 static BrowsingDataIndexedDBHelper* Create(Profile* profile); | |
46 | |
47 // Starts the fetching process, which will notify its completion via | |
48 // callback. | |
49 // This must be called only in the UI thread. | |
50 virtual void StartFetching( | |
51 const base::Callback<void(const std::list<IndexedDBInfo>&)>& | |
52 callback) = 0; | |
53 // Requests a single indexed database to be deleted in the WEBKIT thread. | |
54 virtual void DeleteIndexedDB(const GURL& origin) = 0; | |
55 | |
56 protected: | |
57 friend class base::RefCountedThreadSafe<BrowsingDataIndexedDBHelper>; | |
58 virtual ~BrowsingDataIndexedDBHelper() {} | |
59 }; | |
60 | |
61 // This class is an implementation of BrowsingDataIndexedDBHelper that does | |
62 // not fetch its information from the indexed database tracker, but gets them | |
63 // passed as a parameter. | |
64 class CannedBrowsingDataIndexedDBHelper | |
65 : public BrowsingDataIndexedDBHelper { | |
66 public: | |
67 // Contains information about an indexed database. | |
68 struct PendingIndexedDBInfo { | |
69 PendingIndexedDBInfo(const GURL& origin, const string16& name); | |
70 ~PendingIndexedDBInfo(); | |
71 | |
72 bool operator<(const PendingIndexedDBInfo& other) const; | |
73 | |
74 GURL origin; | |
75 string16 name; | |
76 }; | |
77 | |
78 CannedBrowsingDataIndexedDBHelper(); | |
79 | |
80 // Return a copy of the IndexedDB helper. Only one consumer can use the | |
81 // StartFetching method at a time, so we need to create a copy of the helper | |
82 // every time we instantiate a cookies tree model for it. | |
83 CannedBrowsingDataIndexedDBHelper* Clone(); | |
84 | |
85 // Add a indexed database to the set of canned indexed databases that is | |
86 // returned by this helper. | |
87 void AddIndexedDB(const GURL& origin, | |
88 const string16& name); | |
89 | |
90 // Clear the list of canned indexed databases. | |
91 void Reset(); | |
92 | |
93 // True if no indexed databases are currently stored. | |
94 bool empty() const; | |
95 | |
96 // Returns the number of currently stored indexed databases. | |
97 size_t GetIndexedDBCount() const; | |
98 | |
99 // Returns the current list of indexed data bases. | |
100 const std::set<CannedBrowsingDataIndexedDBHelper::PendingIndexedDBInfo>& | |
101 GetIndexedDBInfo() const; | |
102 | |
103 // BrowsingDataIndexedDBHelper methods. | |
104 virtual void StartFetching( | |
105 const base::Callback<void(const std::list<IndexedDBInfo>&)>& | |
106 callback) OVERRIDE; | |
107 | |
108 virtual void DeleteIndexedDB(const GURL& origin) OVERRIDE {} | |
109 | |
110 private: | |
111 virtual ~CannedBrowsingDataIndexedDBHelper(); | |
112 | |
113 // Convert the pending indexed db info to indexed db info objects. | |
114 void ConvertPendingInfoInWebKitThread(); | |
115 | |
116 void NotifyInUIThread(); | |
117 | |
118 // Lock to protect access to pending_indexed_db_info_; | |
119 mutable base::Lock lock_; | |
120 | |
121 // Access to |pending_indexed_db_info_| is protected by |lock_| since it can | |
122 // be accessed on the UI and on the WEBKIT thread. | |
123 std::set<PendingIndexedDBInfo> pending_indexed_db_info_; | |
124 | |
125 // Access to |indexed_db_info_| is triggered indirectly via the UI thread and | |
126 // guarded by |is_fetching_|. This means |indexed_db_info_| is only accessed | |
127 // while |is_fetching_| is true. The flag |is_fetching_| is only accessed on | |
128 // the UI thread. | |
129 // In the context of this class |indexed_db_info_| is only accessed on the UI | |
130 // thread. | |
131 std::list<IndexedDBInfo> indexed_db_info_; | |
132 | |
133 // This only mutates on the UI thread. | |
134 base::Callback<void(const std::list<IndexedDBInfo>&)> completion_callback_; | |
135 | |
136 // Indicates whether or not we're currently fetching information: | |
137 // it's true when StartFetching() is called in the UI thread, and it's reset | |
138 // after we notified the callback in the UI thread. | |
139 // This only mutates on the UI thread. | |
140 bool is_fetching_; | |
141 | |
142 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataIndexedDBHelper); | |
143 }; | |
144 | |
145 #endif // CHROME_BROWSER_BROWSING_DATA_INDEXED_DB_HELPER_H_ | |
OLD | NEW |