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_DATABASE_HELPER_H_ | 5 #ifndef CHROME_BROWSER_BROWSING_DATA_DATABASE_HELPER_H_ |
6 #define CHROME_BROWSER_BROWSING_DATA_DATABASE_HELPER_H_ | 6 #define CHROME_BROWSER_BROWSING_DATA_DATABASE_HELPER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <list> | 9 #include <list> |
10 #include <string> | 10 #include <string> |
(...skipping 11 matching lines...) Expand all Loading... |
22 // This class fetches database information in the FILE thread, and notifies | 22 // This class fetches database information in the FILE thread, and notifies |
23 // the UI thread upon completion. | 23 // the UI thread upon completion. |
24 // A client of this class need to call StartFetching from the UI thread to | 24 // A 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 | 25 // initiate the flow, and it'll be notified by the callback in its UI |
26 // thread at some later point. | 26 // thread at some later point. |
27 class BrowsingDataDatabaseHelper | 27 class BrowsingDataDatabaseHelper |
28 : public base::RefCountedThreadSafe<BrowsingDataDatabaseHelper> { | 28 : public base::RefCountedThreadSafe<BrowsingDataDatabaseHelper> { |
29 public: | 29 public: |
30 // Contains detailed information about a web database. | 30 // Contains detailed information about a web database. |
31 struct DatabaseInfo { | 31 struct DatabaseInfo { |
32 DatabaseInfo(); | |
33 DatabaseInfo(const std::string& host, | 32 DatabaseInfo(const std::string& host, |
34 const std::string& database_name, | 33 const std::string& database_name, |
35 const std::string& origin_identifier, | 34 const std::string& origin_identifier, |
36 const std::string& description, | 35 const std::string& description, |
37 const std::string& origin, | 36 const std::string& origin, |
38 int64 size, | 37 int64 size, |
39 base::Time last_modified); | 38 base::Time last_modified); |
40 ~DatabaseInfo(); | 39 ~DatabaseInfo(); |
41 | 40 |
42 std::string host; | 41 std::string host; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 scoped_refptr<webkit_database::DatabaseTracker> tracker_; | 90 scoped_refptr<webkit_database::DatabaseTracker> tracker_; |
92 | 91 |
93 DISALLOW_COPY_AND_ASSIGN(BrowsingDataDatabaseHelper); | 92 DISALLOW_COPY_AND_ASSIGN(BrowsingDataDatabaseHelper); |
94 }; | 93 }; |
95 | 94 |
96 // This class is a thin wrapper around BrowsingDataDatabaseHelper that does not | 95 // This class is a thin wrapper around BrowsingDataDatabaseHelper that does not |
97 // fetch its information from the database tracker, but gets them passed as | 96 // fetch its information from the database tracker, but gets them passed as |
98 // a parameter during construction. | 97 // a parameter during construction. |
99 class CannedBrowsingDataDatabaseHelper : public BrowsingDataDatabaseHelper { | 98 class CannedBrowsingDataDatabaseHelper : public BrowsingDataDatabaseHelper { |
100 public: | 99 public: |
| 100 struct PendingDatabaseInfo { |
| 101 PendingDatabaseInfo(const GURL& origin, |
| 102 const std::string& name, |
| 103 const std::string& description); |
| 104 ~PendingDatabaseInfo(); |
| 105 |
| 106 GURL origin; |
| 107 std::string name; |
| 108 std::string description; |
| 109 }; |
| 110 |
101 explicit CannedBrowsingDataDatabaseHelper(Profile* profile); | 111 explicit CannedBrowsingDataDatabaseHelper(Profile* profile); |
102 | 112 |
103 // Return a copy of the database helper. Only one consumer can use the | 113 // Return a copy of the database helper. Only one consumer can use the |
104 // StartFetching method at a time, so we need to create a copy of the helper | 114 // StartFetching method at a time, so we need to create a copy of the helper |
105 // everytime we instantiate a cookies tree model for it. | 115 // everytime we instantiate a cookies tree model for it. |
106 CannedBrowsingDataDatabaseHelper* Clone(); | 116 CannedBrowsingDataDatabaseHelper* Clone(); |
107 | 117 |
108 // Add a database to the set of canned databases that is returned by this | 118 // Add a database to the set of canned databases that is returned by this |
109 // helper. | 119 // helper. |
110 void AddDatabase(const GURL& origin, | 120 void AddDatabase(const GURL& origin, |
111 const std::string& name, | 121 const std::string& name, |
112 const std::string& description); | 122 const std::string& description); |
113 | 123 |
114 // Clear the list of canned databases. | 124 // Clear the list of canned databases. |
115 void Reset(); | 125 void Reset(); |
116 | 126 |
117 // True if no databases are currently stored. | 127 // True if no databases are currently stored. |
118 bool empty() const; | 128 bool empty() const; |
119 | 129 |
120 // Returns the number of currently stored databases. | 130 // Returns the number of currently stored databases. |
121 size_t GetDatabaseCount() const; | 131 size_t GetDatabaseCount() const; |
122 | 132 |
| 133 // Returns the current list of web databases. |
| 134 const std::list<PendingDatabaseInfo>& pending_database_info() { |
| 135 return pending_database_info_; |
| 136 } |
| 137 |
123 // BrowsingDataDatabaseHelper implementation. | 138 // BrowsingDataDatabaseHelper implementation. |
124 virtual void StartFetching( | 139 virtual void StartFetching( |
125 const base::Callback<void(const std::list<DatabaseInfo>&)>& callback) | 140 const base::Callback<void(const std::list<DatabaseInfo>&)>& callback) |
126 OVERRIDE; | 141 OVERRIDE; |
127 | 142 |
128 private: | 143 private: |
129 struct PendingDatabaseInfo { | |
130 PendingDatabaseInfo(); | |
131 PendingDatabaseInfo(const GURL& origin, | |
132 const std::string& name, | |
133 const std::string& description); | |
134 ~PendingDatabaseInfo(); | |
135 | |
136 GURL origin; | |
137 std::string name; | |
138 std::string description; | |
139 }; | |
140 | |
141 virtual ~CannedBrowsingDataDatabaseHelper(); | 144 virtual ~CannedBrowsingDataDatabaseHelper(); |
142 | 145 |
143 // Converts the pending database info structs to database info structs. | 146 // Converts the pending database info structs to database info structs. |
144 void ConvertInfoInWebKitThread(); | 147 void ConvertInfoInWebKitThread(); |
145 | 148 |
146 // Used to protect access to pending_database_info_. | 149 // Used to protect access to pending_database_info_. |
147 mutable base::Lock lock_; | 150 mutable base::Lock lock_; |
148 | 151 |
149 // This may mutate on WEBKIT and UI threads. | 152 // This may mutate only on the UI thread. |
150 std::list<PendingDatabaseInfo> pending_database_info_; | 153 std::list<PendingDatabaseInfo> pending_database_info_; |
151 | 154 |
152 Profile* profile_; | 155 Profile* profile_; |
153 | 156 |
154 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataDatabaseHelper); | 157 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataDatabaseHelper); |
155 }; | 158 }; |
156 | 159 |
157 #endif // CHROME_BROWSER_BROWSING_DATA_DATABASE_HELPER_H_ | 160 #endif // CHROME_BROWSER_BROWSING_DATA_DATABASE_HELPER_H_ |
OLD | NEW |