Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(654)

Side by Side Diff: storage/common/database/database_connections.h

Issue 442383002: Move storage-related files from webkit/ to new top-level directory storage/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « storage/common/data_element.cc ('k') | storage/common/database/database_connections.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_COMMON_DATABASE_DATABASE_CONNECTIONS_H_ 5 #ifndef WEBKIT_COMMON_DATABASE_DATABASE_CONNECTIONS_H_
6 #define WEBKIT_COMMON_DATABASE_DATABASE_CONNECTIONS_H_ 6 #define WEBKIT_COMMON_DATABASE_DATABASE_CONNECTIONS_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
14 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
15 #include "webkit/common/webkit_storage_common_export.h" 15 #include "storage/common/storage_export.h"
16 16
17 namespace base { 17 namespace base {
18 class MessageLoopProxy; 18 class MessageLoopProxy;
19 } 19 }
20 20
21 namespace webkit_database { 21 namespace webkit_database {
22 22
23 class WEBKIT_STORAGE_COMMON_EXPORT DatabaseConnections { 23 class STORAGE_EXPORT DatabaseConnections {
24 public: 24 public:
25 DatabaseConnections(); 25 DatabaseConnections();
26 ~DatabaseConnections(); 26 ~DatabaseConnections();
27 27
28 bool IsEmpty() const; 28 bool IsEmpty() const;
29 bool IsDatabaseOpened(const std::string& origin_identifier, 29 bool IsDatabaseOpened(const std::string& origin_identifier,
30 const base::string16& database_name) const; 30 const base::string16& database_name) const;
31 bool IsOriginUsed(const std::string& origin_identifier) const; 31 bool IsOriginUsed(const std::string& origin_identifier) const;
32 32
33 // Returns true if this is the first connection. 33 // Returns true if this is the first connection.
(...skipping 11 matching lines...) Expand all
45 45
46 // Database sizes can be kept only if IsDatabaseOpened returns true. 46 // Database sizes can be kept only if IsDatabaseOpened returns true.
47 int64 GetOpenDatabaseSize(const std::string& origin_identifier, 47 int64 GetOpenDatabaseSize(const std::string& origin_identifier,
48 const base::string16& database_name) const; 48 const base::string16& database_name) const;
49 void SetOpenDatabaseSize(const std::string& origin_identifier, 49 void SetOpenDatabaseSize(const std::string& origin_identifier,
50 const base::string16& database_name, 50 const base::string16& database_name,
51 int64 size); 51 int64 size);
52 52
53 // Returns a list of the connections, <origin_id, name>. 53 // Returns a list of the connections, <origin_id, name>.
54 void ListConnections( 54 void ListConnections(
55 std::vector<std::pair<std::string, base::string16> > *list) const; 55 std::vector<std::pair<std::string, base::string16> >* list) const;
56 56
57 private: 57 private:
58 // Mapping from name to <openCount, size> 58 // Mapping from name to <openCount, size>
59 typedef std::map<base::string16, std::pair<int, int64> > DBConnections; 59 typedef std::map<base::string16, std::pair<int, int64> > DBConnections;
60 typedef std::map<std::string, DBConnections> OriginConnections; 60 typedef std::map<std::string, DBConnections> OriginConnections;
61 mutable OriginConnections connections_; // mutable for GetOpenDatabaseSize 61 mutable OriginConnections connections_; // mutable for GetOpenDatabaseSize
62 62
63 // Returns true if the last connection was removed. 63 // Returns true if the last connection was removed.
64 bool RemoveConnectionsHelper(const std::string& origin_identifier, 64 bool RemoveConnectionsHelper(const std::string& origin_identifier,
65 const base::string16& database_name, 65 const base::string16& database_name,
66 int num_connections); 66 int num_connections);
67 }; 67 };
68 68
69 // A wrapper class that provides thread-safety and the 69 // A wrapper class that provides thread-safety and the
70 // ability to wait until all connections have closed. 70 // ability to wait until all connections have closed.
71 // Intended for use in renderer processes. 71 // Intended for use in renderer processes.
72 class WEBKIT_STORAGE_COMMON_EXPORT DatabaseConnectionsWrapper 72 class STORAGE_EXPORT DatabaseConnectionsWrapper
73 : public base::RefCountedThreadSafe<DatabaseConnectionsWrapper> { 73 : public base::RefCountedThreadSafe<DatabaseConnectionsWrapper> {
74 public: 74 public:
75 DatabaseConnectionsWrapper(); 75 DatabaseConnectionsWrapper();
76 76
77 // The Wait and Has methods should only be called on the 77 // The Wait and Has methods should only be called on the
78 // main thread (the thread on which the wrapper is constructed). 78 // main thread (the thread on which the wrapper is constructed).
79 void WaitForAllDatabasesToClose(); 79 void WaitForAllDatabasesToClose();
80 bool HasOpenConnections(); 80 bool HasOpenConnections();
81 81
82 // Add and Remove may be called on any thread. 82 // Add and Remove may be called on any thread.
83 void AddOpenConnection(const std::string& origin_identifier, 83 void AddOpenConnection(const std::string& origin_identifier,
84 const base::string16& database_name); 84 const base::string16& database_name);
85 void RemoveOpenConnection(const std::string& origin_identifier, 85 void RemoveOpenConnection(const std::string& origin_identifier,
86 const base::string16& database_name); 86 const base::string16& database_name);
87
87 private: 88 private:
88 ~DatabaseConnectionsWrapper(); 89 ~DatabaseConnectionsWrapper();
89 friend class base::RefCountedThreadSafe<DatabaseConnectionsWrapper>; 90 friend class base::RefCountedThreadSafe<DatabaseConnectionsWrapper>;
90 91
91 bool waiting_for_dbs_to_close_; 92 bool waiting_for_dbs_to_close_;
92 base::Lock open_connections_lock_; 93 base::Lock open_connections_lock_;
93 DatabaseConnections open_connections_; 94 DatabaseConnections open_connections_;
94 scoped_refptr<base::MessageLoopProxy> main_thread_; 95 scoped_refptr<base::MessageLoopProxy> main_thread_;
95 }; 96 };
96 97
97 } // namespace webkit_database 98 } // namespace webkit_database
98 99
99 #endif // WEBKIT_COMMON_DATABASE_DATABASE_CONNECTIONS_H_ 100 #endif // WEBKIT_COMMON_DATABASE_DATABASE_CONNECTIONS_H_
OLDNEW
« no previous file with comments | « storage/common/data_element.cc ('k') | storage/common/database/database_connections.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698