| 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 WEBKIT_DATABASE_DATABASE_CONNECTIONS_H_ | 5 #ifndef WEBKIT_DATABASE_DATABASE_CONNECTIONS_H_ |
| 6 #define WEBKIT_DATABASE_DATABASE_CONNECTIONS_H_ | 6 #define WEBKIT_DATABASE_DATABASE_CONNECTIONS_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 bool IsOriginUsed(const string16& origin_identifier) const; | 29 bool IsOriginUsed(const string16& origin_identifier) const; |
| 30 void AddConnection(const string16& origin_identifier, | 30 void AddConnection(const string16& origin_identifier, |
| 31 const string16& database_name); | 31 const string16& database_name); |
| 32 void RemoveConnection(const string16& origin_identifier, | 32 void RemoveConnection(const string16& origin_identifier, |
| 33 const string16& database_name); | 33 const string16& database_name); |
| 34 void RemoveAllConnections(); | 34 void RemoveAllConnections(); |
| 35 void RemoveConnections( | 35 void RemoveConnections( |
| 36 const DatabaseConnections& connections, | 36 const DatabaseConnections& connections, |
| 37 std::vector<std::pair<string16, string16> >* closed_dbs); | 37 std::vector<std::pair<string16, string16> >* closed_dbs); |
| 38 | 38 |
| 39 // Database sizes can be kept only if IsDatabaseOpened returns true. |
| 40 int64 GetOpenDatabaseSize(const string16& origin_identifier, |
| 41 const string16& database_name) const; |
| 42 void SetOpenDatabaseSize(const string16& origin_identifier, |
| 43 const string16& database_name, |
| 44 int64 size); |
| 45 |
| 46 // Returns a list of the connections, <origin_id, name>. |
| 47 void ListConnections( |
| 48 std::vector<std::pair<string16, string16> > *list) const; |
| 49 |
| 39 private: | 50 private: |
| 40 typedef std::map<string16, int> DBConnections; | 51 // Mapping from name to <openCount, size> |
| 52 typedef std::map<string16, std::pair<int, int64> > DBConnections; |
| 41 typedef std::map<string16, DBConnections> OriginConnections; | 53 typedef std::map<string16, DBConnections> OriginConnections; |
| 42 OriginConnections connections_; | 54 mutable OriginConnections connections_; // mutable for GetOpenDatabaseSize |
| 43 | 55 |
| 44 void RemoveConnectionsHelper(const string16& origin_identifier, | 56 void RemoveConnectionsHelper(const string16& origin_identifier, |
| 45 const string16& database_name, | 57 const string16& database_name, |
| 46 int num_connections); | 58 int num_connections); |
| 47 }; | 59 }; |
| 48 | 60 |
| 49 // A wrapper class that provides thread-safety and the | 61 // A wrapper class that provides thread-safety and the |
| 50 // ability to wait until all connections have closed. | 62 // ability to wait until all connections have closed. |
| 51 // Intended for use in renderer processes. | 63 // Intended for use in renderer processes. |
| 52 class DatabaseConnectionsWrapper | 64 class DatabaseConnectionsWrapper |
| (...skipping 17 matching lines...) Expand all Loading... |
| 70 | 82 |
| 71 bool waiting_for_dbs_to_close_; | 83 bool waiting_for_dbs_to_close_; |
| 72 base::Lock open_connections_lock_; | 84 base::Lock open_connections_lock_; |
| 73 DatabaseConnections open_connections_; | 85 DatabaseConnections open_connections_; |
| 74 scoped_refptr<base::MessageLoopProxy> main_thread_; | 86 scoped_refptr<base::MessageLoopProxy> main_thread_; |
| 75 }; | 87 }; |
| 76 | 88 |
| 77 } // namespace webkit_database | 89 } // namespace webkit_database |
| 78 | 90 |
| 79 #endif // WEBKIT_DATABASE_DATABASE_CONNECTIONS_H_ | 91 #endif // WEBKIT_DATABASE_DATABASE_CONNECTIONS_H_ |
| OLD | NEW |