OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 10 #include <string> |
(...skipping 14 matching lines...) Expand all Loading... | |
25 // client of this class need to call StartFetching from the UI thread to | 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 | 26 // initiate the flow, and it'll be notified by the callback in its UI thread at |
27 // some later point. The client must call CancelNotification() if it's | 27 // some later point. The client must call CancelNotification() if it's |
28 // destroyed before the callback is notified. | 28 // destroyed before the callback is notified. |
29 class BrowsingDataIndexedDBHelper | 29 class BrowsingDataIndexedDBHelper |
30 : public base::RefCountedThreadSafe<BrowsingDataIndexedDBHelper> { | 30 : public base::RefCountedThreadSafe<BrowsingDataIndexedDBHelper> { |
31 public: | 31 public: |
32 // Contains detailed information about an indexed database. | 32 // Contains detailed information about an indexed database. |
33 struct IndexedDBInfo { | 33 struct IndexedDBInfo { |
34 IndexedDBInfo( | 34 IndexedDBInfo( |
35 const std::string& protocol, | 35 const GURL& origin_url, |
36 const std::string& host, | |
37 unsigned short port, | |
38 const std::string& database_identifier, | |
39 const std::string& origin, | |
40 const FilePath& file_path, | |
41 int64 size, | 36 int64 size, |
42 base::Time last_modified); | 37 base::Time last_modified); |
43 ~IndexedDBInfo(); | 38 ~IndexedDBInfo(); |
44 | 39 |
45 bool IsFileSchemeData() { | 40 bool IsFileSchemeData() { |
46 return protocol == chrome::kFileScheme; | 41 return origin_url.SchemeIsFile(); |
47 } | 42 } |
48 | 43 |
49 std::string protocol; | 44 GURL origin_url; |
50 std::string host; | |
51 unsigned short port; | |
52 std::string database_identifier; | |
53 std::string origin; | |
54 FilePath file_path; | |
michaeln
2011/08/23 20:39:48
Simplified this structure getting rid of duplicito
| |
55 int64 size; | 45 int64 size; |
56 base::Time last_modified; | 46 base::Time last_modified; |
57 }; | 47 }; |
58 | 48 |
59 // Create a BrowsingDataIndexedDBHelper instance for the indexed databases | 49 // Create a BrowsingDataIndexedDBHelper instance for the indexed databases |
60 // stored in |profile|'s user data directory. | 50 // stored in |profile|'s user data directory. |
61 static BrowsingDataIndexedDBHelper* Create(Profile* profile); | 51 static BrowsingDataIndexedDBHelper* Create(Profile* profile); |
62 | 52 |
63 // Starts the fetching process, which will notify its completion via | 53 // Starts the fetching process, which will notify its completion via |
64 // callback. | 54 // callback. |
65 // This must be called only in the UI thread. | 55 // This must be called only in the UI thread. |
66 virtual void StartFetching( | 56 virtual void StartFetching( |
67 Callback1<const std::list<IndexedDBInfo>& >::Type* callback) = 0; | 57 Callback1<const std::list<IndexedDBInfo>& >::Type* callback) = 0; |
68 // Cancels the notification callback (i.e., the window that created it no | 58 // Cancels the notification callback (i.e., the window that created it no |
69 // longer exists). | 59 // longer exists). |
70 // This must be called only in the UI thread. | 60 // This must be called only in the UI thread. |
71 virtual void CancelNotification() = 0; | 61 virtual void CancelNotification() = 0; |
72 // Requests a single indexed database file to be deleted in the WEBKIT thread. | 62 // Requests a single indexed database file to be deleted in the WEBKIT thread. |
73 virtual void DeleteIndexedDBFile(const FilePath& file_path) = 0; | 63 virtual void DeleteIndexedDB(const GURL& origin_url) = 0; |
74 | 64 |
75 protected: | 65 protected: |
76 friend class base::RefCountedThreadSafe<BrowsingDataIndexedDBHelper>; | 66 friend class base::RefCountedThreadSafe<BrowsingDataIndexedDBHelper>; |
77 virtual ~BrowsingDataIndexedDBHelper() {} | 67 virtual ~BrowsingDataIndexedDBHelper() {} |
78 }; | 68 }; |
79 | 69 |
80 // This class is an implementation of BrowsingDataIndexedDBHelper that does | 70 // This class is an implementation of BrowsingDataIndexedDBHelper that does |
81 // not fetch its information from the indexed database tracker, but gets them | 71 // not fetch its information from the indexed database tracker, but gets them |
82 // passed as a parameter. | 72 // passed as a parameter. |
83 class CannedBrowsingDataIndexedDBHelper | 73 class CannedBrowsingDataIndexedDBHelper |
84 : public BrowsingDataIndexedDBHelper { | 74 : public BrowsingDataIndexedDBHelper { |
85 public: | 75 public: |
86 explicit CannedBrowsingDataIndexedDBHelper(Profile* profile); | 76 CannedBrowsingDataIndexedDBHelper(); |
87 | 77 |
88 // Return a copy of the IndexedDB helper. Only one consumer can use the | 78 // Return a copy of the IndexedDB helper. Only one consumer can use the |
89 // StartFetching method at a time, so we need to create a copy of the helper | 79 // StartFetching method at a time, so we need to create a copy of the helper |
90 // everytime we instantiate a cookies tree model for it. | 80 // everytime we instantiate a cookies tree model for it. |
91 CannedBrowsingDataIndexedDBHelper* Clone(); | 81 CannedBrowsingDataIndexedDBHelper* Clone(); |
92 | 82 |
93 // Add a indexed database to the set of canned indexed databases that is | 83 // Add a indexed database to the set of canned indexed databases that is |
94 // returned by this helper. | 84 // returned by this helper. |
95 void AddIndexedDB(const GURL& origin, | 85 void AddIndexedDB(const GURL& origin, |
96 const string16& description); | 86 const string16& description); |
97 | 87 |
98 // Clear the list of canned indexed databases. | 88 // Clear the list of canned indexed databases. |
99 void Reset(); | 89 void Reset(); |
100 | 90 |
101 // True if no indexed databases are currently stored. | 91 // True if no indexed databases are currently stored. |
102 bool empty() const; | 92 bool empty() const; |
103 | 93 |
104 // BrowsingDataIndexedDBHelper methods. | 94 // BrowsingDataIndexedDBHelper methods. |
105 virtual void StartFetching( | 95 virtual void StartFetching( |
106 Callback1<const std::list<IndexedDBInfo>& >::Type* callback); | 96 Callback1<const std::list<IndexedDBInfo>& >::Type* callback); |
107 virtual void CancelNotification(); | 97 virtual void CancelNotification(); |
108 virtual void DeleteIndexedDBFile(const FilePath& file_path) {} | 98 virtual void DeleteIndexedDB(const GURL& origin_url) {} |
109 | 99 |
110 private: | 100 private: |
111 struct PendingIndexedDBInfo { | 101 struct PendingIndexedDBInfo { |
112 PendingIndexedDBInfo(); | 102 PendingIndexedDBInfo(); |
113 PendingIndexedDBInfo(const GURL& origin, const string16& description); | 103 PendingIndexedDBInfo(const GURL& origin, const string16& description); |
114 ~PendingIndexedDBInfo(); | 104 ~PendingIndexedDBInfo(); |
115 | 105 |
116 GURL origin; | 106 GURL origin; |
117 string16 description; | 107 string16 description; |
118 }; | 108 }; |
119 | 109 |
120 virtual ~CannedBrowsingDataIndexedDBHelper(); | 110 virtual ~CannedBrowsingDataIndexedDBHelper(); |
121 | 111 |
122 // Convert the pending indexed db info to indexed db info objects. | 112 // Convert the pending indexed db info to indexed db info objects. |
123 void ConvertPendingInfoInWebKitThread(); | 113 void ConvertPendingInfoInWebKitThread(); |
124 | 114 |
125 void NotifyInUIThread(); | 115 void NotifyInUIThread(); |
126 | 116 |
127 Profile* profile_; | |
128 | |
129 // Lock to protect access to pending_indexed_db_info_; | 117 // Lock to protect access to pending_indexed_db_info_; |
130 mutable base::Lock lock_; | 118 mutable base::Lock lock_; |
131 | 119 |
132 // This may mutate on WEBKIT and UI threads. | 120 // This may mutate on WEBKIT and UI threads. |
133 std::list<PendingIndexedDBInfo> pending_indexed_db_info_; | 121 std::list<PendingIndexedDBInfo> pending_indexed_db_info_; |
134 | 122 |
135 // This only mutates on the WEBKIT thread. | 123 // This only mutates on the WEBKIT thread. |
136 std::list<IndexedDBInfo> indexed_db_info_; | 124 std::list<IndexedDBInfo> indexed_db_info_; |
137 | 125 |
138 // This only mutates on the UI thread. | 126 // This only mutates on the UI thread. |
139 scoped_ptr<Callback1<const std::list<IndexedDBInfo>& >::Type > | 127 scoped_ptr<Callback1<const std::list<IndexedDBInfo>& >::Type > |
140 completion_callback_; | 128 completion_callback_; |
141 | 129 |
142 // Indicates whether or not we're currently fetching information: | 130 // Indicates whether or not we're currently fetching information: |
143 // it's true when StartFetching() is called in the UI thread, and it's reset | 131 // it's true when StartFetching() is called in the UI thread, and it's reset |
144 // after we notified the callback in the UI thread. | 132 // after we notified the callback in the UI thread. |
145 // This only mutates on the UI thread. | 133 // This only mutates on the UI thread. |
146 bool is_fetching_; | 134 bool is_fetching_; |
147 | 135 |
148 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataIndexedDBHelper); | 136 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataIndexedDBHelper); |
149 }; | 137 }; |
150 | 138 |
151 #endif // CHROME_BROWSER_BROWSING_DATA_INDEXED_DB_HELPER_H_ | 139 #endif // CHROME_BROWSER_BROWSING_DATA_INDEXED_DB_HELPER_H_ |
OLD | NEW |