OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_BROWSING_DATA_INDEXED_DB_HELPER_H_ | 5 #ifndef CHROME_BROWSER_BROWSING_DATA_INDEXED_DB_HELPER_H_ |
6 #define CHROME_BROWSER_BROWSING_DATA_INDEXED_DB_HELPER_H_ | 6 #define CHROME_BROWSER_BROWSING_DATA_INDEXED_DB_HELPER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <list> | 9 #include <list> |
10 #include <set> | |
10 #include <string> | 11 #include <string> |
11 | 12 |
12 #include "base/callback.h" | 13 #include "base/callback.h" |
13 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
14 #include "base/file_path.h" | 15 #include "base/file_path.h" |
15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
16 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
17 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
18 #include "base/time.h" | 19 #include "base/time.h" |
19 #include "chrome/common/url_constants.h" | |
20 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
21 | 21 |
22 class Profile; | 22 class Profile; |
23 | 23 |
24 // BrowsingDataIndexedDBHelper is an interface for classes dealing with | 24 // BrowsingDataIndexedDBHelper is an interface for classes dealing with |
25 // aggregating and deleting browsing data stored in indexed databases. A | 25 // aggregating and deleting browsing data stored in indexed databases. A |
26 // client of this class need to call StartFetching from the UI thread to | 26 // client of this class need to call StartFetching from the UI thread to |
27 // initiate the flow, and it'll be notified by the callback in its UI thread at | 27 // initiate the flow, and it'll be notified by the callback in its UI thread at |
28 // some later point. | 28 // some later point. |
29 class BrowsingDataIndexedDBHelper | 29 class BrowsingDataIndexedDBHelper |
(...skipping 29 matching lines...) Expand all Loading... | |
59 friend class base::RefCountedThreadSafe<BrowsingDataIndexedDBHelper>; | 59 friend class base::RefCountedThreadSafe<BrowsingDataIndexedDBHelper>; |
60 virtual ~BrowsingDataIndexedDBHelper() {} | 60 virtual ~BrowsingDataIndexedDBHelper() {} |
61 }; | 61 }; |
62 | 62 |
63 // This class is an implementation of BrowsingDataIndexedDBHelper that does | 63 // This class is an implementation of BrowsingDataIndexedDBHelper that does |
64 // not fetch its information from the indexed database tracker, but gets them | 64 // not fetch its information from the indexed database tracker, but gets them |
65 // passed as a parameter. | 65 // passed as a parameter. |
66 class CannedBrowsingDataIndexedDBHelper | 66 class CannedBrowsingDataIndexedDBHelper |
67 : public BrowsingDataIndexedDBHelper { | 67 : public BrowsingDataIndexedDBHelper { |
68 public: | 68 public: |
69 // Contains information about an indexed database. | |
70 struct PendingIndexedDBInfo { | |
71 PendingIndexedDBInfo(const GURL& origin, const string16& name); | |
72 ~PendingIndexedDBInfo(); | |
73 | |
74 bool operator<(const PendingIndexedDBInfo& other) const; | |
75 | |
76 GURL origin; | |
77 string16 name; | |
78 }; | |
79 | |
69 CannedBrowsingDataIndexedDBHelper(); | 80 CannedBrowsingDataIndexedDBHelper(); |
70 | 81 |
71 // Return a copy of the IndexedDB helper. Only one consumer can use the | 82 // Return a copy of the IndexedDB helper. Only one consumer can use the |
72 // StartFetching method at a time, so we need to create a copy of the helper | 83 // StartFetching method at a time, so we need to create a copy of the helper |
73 // every time we instantiate a cookies tree model for it. | 84 // every time we instantiate a cookies tree model for it. |
74 CannedBrowsingDataIndexedDBHelper* Clone(); | 85 CannedBrowsingDataIndexedDBHelper* Clone(); |
75 | 86 |
76 // Add a indexed database to the set of canned indexed databases that is | 87 // Add a indexed database to the set of canned indexed databases that is |
77 // returned by this helper. | 88 // returned by this helper. |
78 void AddIndexedDB(const GURL& origin, | 89 void AddIndexedDB(const GURL& origin, |
79 const string16& description); | 90 const string16& name); |
80 | 91 |
81 // Clear the list of canned indexed databases. | 92 // Clear the list of canned indexed databases. |
82 void Reset(); | 93 void Reset(); |
83 | 94 |
84 // True if no indexed databases are currently stored. | 95 // True if no indexed databases are currently stored. |
85 bool empty() const; | 96 bool empty() const; |
86 | 97 |
87 // Returns the number of currently stored indexed databases. | 98 // Returns the number of currently stored indexed databases. |
88 size_t GetIndexedDBCount() const; | 99 size_t GetIndexedDBCount() const; |
89 | 100 |
101 // Returns the current list of indexed data bases. | |
102 const std::set<CannedBrowsingDataIndexedDBHelper::PendingIndexedDBInfo>& | |
103 GetIndexedDBInfo() const; | |
104 | |
90 // BrowsingDataIndexedDBHelper methods. | 105 // BrowsingDataIndexedDBHelper methods. |
91 virtual void StartFetching( | 106 virtual void StartFetching( |
92 const base::Callback<void(const std::list<IndexedDBInfo>&)>& | 107 const base::Callback<void(const std::list<IndexedDBInfo>&)>& |
93 callback) OVERRIDE; | 108 callback) OVERRIDE; |
109 | |
94 virtual void DeleteIndexedDB(const GURL& origin) OVERRIDE {} | 110 virtual void DeleteIndexedDB(const GURL& origin) OVERRIDE {} |
95 | 111 |
96 private: | 112 private: |
97 struct PendingIndexedDBInfo { | |
98 PendingIndexedDBInfo(); | |
99 PendingIndexedDBInfo(const GURL& origin, const string16& description); | |
100 ~PendingIndexedDBInfo(); | |
101 | |
102 GURL origin; | |
103 string16 description; | |
104 }; | |
105 | |
106 virtual ~CannedBrowsingDataIndexedDBHelper(); | 113 virtual ~CannedBrowsingDataIndexedDBHelper(); |
107 | 114 |
108 // Convert the pending indexed db info to indexed db info objects. | 115 // Convert the pending indexed db info to indexed db info objects. |
109 void ConvertPendingInfoInWebKitThread(); | 116 void ConvertPendingInfoInWebKitThread(); |
110 | 117 |
111 void NotifyInUIThread(); | 118 void NotifyInUIThread(); |
112 | 119 |
113 // Lock to protect access to pending_indexed_db_info_; | 120 // Lock to protect access to pending_indexed_db_info_; |
114 mutable base::Lock lock_; | 121 mutable base::Lock lock_; |
115 | 122 |
116 // This may mutate on WEBKIT and UI threads. | 123 // This only mutates on the UI thread. But it is read on the Webkit thread. |
Bernhard Bauer
2012/05/14 17:14:07
If you're changing this comment, could you simplif
markusheintz_
2012/05/14 18:18:06
Done.
| |
117 std::list<PendingIndexedDBInfo> pending_indexed_db_info_; | 124 std::set<PendingIndexedDBInfo> pending_indexed_db_info_; |
118 | 125 |
119 // This only mutates on the WEBKIT thread. | 126 // Access to |indexed_db_info_| is triggered indirectly via the UI thread and |
127 // guarded by |is_fetching_|. This means |indexed_db_info_| is only accessed | |
128 // while |is_fetching_| is true. The flag |is_fetching_| is only accessed on | |
129 // the UI thread. | |
130 // In the context of this class |indexed_db_info_| is only accessed on the UI | |
131 // thread. | |
120 std::list<IndexedDBInfo> indexed_db_info_; | 132 std::list<IndexedDBInfo> indexed_db_info_; |
121 | 133 |
122 // This only mutates on the UI thread. | 134 // This only mutates on the UI thread. |
123 base::Callback<void(const std::list<IndexedDBInfo>&)> completion_callback_; | 135 base::Callback<void(const std::list<IndexedDBInfo>&)> completion_callback_; |
124 | 136 |
125 // Indicates whether or not we're currently fetching information: | 137 // Indicates whether or not we're currently fetching information: |
126 // it's true when StartFetching() is called in the UI thread, and it's reset | 138 // it's true when StartFetching() is called in the UI thread, and it's reset |
127 // after we notified the callback in the UI thread. | 139 // after we notified the callback in the UI thread. |
128 // This only mutates on the UI thread. | 140 // This only mutates on the UI thread. |
129 bool is_fetching_; | 141 bool is_fetching_; |
130 | 142 |
131 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataIndexedDBHelper); | 143 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataIndexedDBHelper); |
132 }; | 144 }; |
133 | 145 |
134 #endif // CHROME_BROWSER_BROWSING_DATA_INDEXED_DB_HELPER_H_ | 146 #endif // CHROME_BROWSER_BROWSING_DATA_INDEXED_DB_HELPER_H_ |
OLD | NEW |