Chromium Code Reviews| 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 |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/string16.h" | 12 #include "base/string16.h" |
| 13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
| 14 | 14 |
| 15 namespace base { | 15 namespace base { |
| 16 class MessageLoopProxy; | 16 class MessageLoopProxy; |
| 17 } | 17 } |
| 18 | 18 |
| 19 namespace webkit_database { | 19 namespace webkit_database { |
| 20 | 20 |
| 21 class DatabaseConnections { | 21 class DatabaseConnections { |
| 22 public: | 22 public: |
| 23 DatabaseConnections(); | 23 DatabaseConnections(); |
| 24 ~DatabaseConnections(); | 24 ~DatabaseConnections(); |
| 25 | 25 |
| 26 bool IsEmpty() const; | 26 bool IsEmpty() const; |
| 27 bool IsDatabaseOpened(const string16& origin_identifier, | 27 bool IsDatabaseOpened(const string16& origin_identifier, |
| 28 const string16& database_name) const; | 28 const string16& database_name) const; |
| 29 bool IsOriginUsed(const string16& origin_identifier) const; | 29 bool IsOriginUsed(const string16& origin_identifier) const; |
| 30 void AddConnection(const string16& origin_identifier, | 30 |
| 31 // Returns true of this is the first connection. | |
|
kinuko
2011/05/24 05:31:36
nit: of -> if?
michaeln
2011/05/25 01:28:06
Done.
| |
| 32 bool AddConnection(const string16& origin_identifier, | |
| 31 const string16& database_name); | 33 const string16& database_name); |
| 32 void RemoveConnection(const string16& origin_identifier, | 34 |
| 35 // Returns true if the last connection was removed. | |
| 36 bool RemoveConnection(const string16& origin_identifier, | |
| 33 const string16& database_name); | 37 const string16& database_name); |
| 38 | |
| 34 void RemoveAllConnections(); | 39 void RemoveAllConnections(); |
| 35 void RemoveConnections( | 40 void RemoveConnections( |
| 36 const DatabaseConnections& connections, | 41 const DatabaseConnections& connections, |
| 37 std::vector<std::pair<string16, string16> >* closed_dbs); | 42 std::vector<std::pair<string16, string16> >* closed_dbs); |
| 38 | 43 |
| 39 // Database sizes can be kept only if IsDatabaseOpened returns true. | 44 // Database sizes can be kept only if IsDatabaseOpened returns true. |
| 40 int64 GetOpenDatabaseSize(const string16& origin_identifier, | 45 int64 GetOpenDatabaseSize(const string16& origin_identifier, |
| 41 const string16& database_name) const; | 46 const string16& database_name) const; |
| 42 void SetOpenDatabaseSize(const string16& origin_identifier, | 47 void SetOpenDatabaseSize(const string16& origin_identifier, |
| 43 const string16& database_name, | 48 const string16& database_name, |
| 44 int64 size); | 49 int64 size); |
| 45 | 50 |
| 46 // Returns a list of the connections, <origin_id, name>. | 51 // Returns a list of the connections, <origin_id, name>. |
| 47 void ListConnections( | 52 void ListConnections( |
| 48 std::vector<std::pair<string16, string16> > *list) const; | 53 std::vector<std::pair<string16, string16> > *list) const; |
| 49 | 54 |
| 50 private: | 55 private: |
| 51 // Mapping from name to <openCount, size> | 56 // Mapping from name to <openCount, size> |
| 52 typedef std::map<string16, std::pair<int, int64> > DBConnections; | 57 typedef std::map<string16, std::pair<int, int64> > DBConnections; |
| 53 typedef std::map<string16, DBConnections> OriginConnections; | 58 typedef std::map<string16, DBConnections> OriginConnections; |
| 54 mutable OriginConnections connections_; // mutable for GetOpenDatabaseSize | 59 mutable OriginConnections connections_; // mutable for GetOpenDatabaseSize |
| 55 | 60 |
| 56 void RemoveConnectionsHelper(const string16& origin_identifier, | 61 // Returns true if the last connection was removed. |
| 62 bool RemoveConnectionsHelper(const string16& origin_identifier, | |
| 57 const string16& database_name, | 63 const string16& database_name, |
| 58 int num_connections); | 64 int num_connections); |
| 59 }; | 65 }; |
| 60 | 66 |
| 61 // A wrapper class that provides thread-safety and the | 67 // A wrapper class that provides thread-safety and the |
| 62 // ability to wait until all connections have closed. | 68 // ability to wait until all connections have closed. |
| 63 // Intended for use in renderer processes. | 69 // Intended for use in renderer processes. |
| 64 class DatabaseConnectionsWrapper | 70 class DatabaseConnectionsWrapper |
| 65 : public base::RefCountedThreadSafe<DatabaseConnectionsWrapper> { | 71 : public base::RefCountedThreadSafe<DatabaseConnectionsWrapper> { |
| 66 public: | 72 public: |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 82 | 88 |
| 83 bool waiting_for_dbs_to_close_; | 89 bool waiting_for_dbs_to_close_; |
| 84 base::Lock open_connections_lock_; | 90 base::Lock open_connections_lock_; |
| 85 DatabaseConnections open_connections_; | 91 DatabaseConnections open_connections_; |
| 86 scoped_refptr<base::MessageLoopProxy> main_thread_; | 92 scoped_refptr<base::MessageLoopProxy> main_thread_; |
| 87 }; | 93 }; |
| 88 | 94 |
| 89 } // namespace webkit_database | 95 } // namespace webkit_database |
| 90 | 96 |
| 91 #endif // WEBKIT_DATABASE_DATABASE_CONNECTIONS_H_ | 97 #endif // WEBKIT_DATABASE_DATABASE_CONNECTIONS_H_ |
| OLD | NEW |