summaryrefslogtreecommitdiffstats
path: root/webkit/database/database_connections.cc
diff options
context:
space:
mode:
authordumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-06 21:15:55 +0000
committerdumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-06 21:15:55 +0000
commit3ccfe535658c8852c1cc1df01372ecc602f376cd (patch)
tree47582af5ba2a4f0658126d564d618c18a93173cf /webkit/database/database_connections.cc
parent6d8e2a64b6961331816689850192a8ee864f9a97 (diff)
downloadchromium_src-3ccfe535658c8852c1cc1df01372ecc602f376cd.zip
chromium_src-3ccfe535658c8852c1cc1df01372ecc602f376cd.tar.gz
chromium_src-3ccfe535658c8852c1cc1df01372ecc602f376cd.tar.bz2
Adding methods that will be used by the quota management UI.
TEST=none BUG=none Review URL: http://codereview.chromium.org/507014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35651 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/database/database_connections.cc')
-rw-r--r--webkit/database/database_connections.cc78
1 files changed, 78 insertions, 0 deletions
diff --git a/webkit/database/database_connections.cc b/webkit/database/database_connections.cc
new file mode 100644
index 0000000..a6e6d3d
--- /dev/null
+++ b/webkit/database/database_connections.cc
@@ -0,0 +1,78 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/database/database_connections.h"
+
+#include "base/logging.h"
+
+namespace webkit_database {
+
+DatabaseConnections::DatabaseConnections() {
+}
+
+DatabaseConnections::~DatabaseConnections() {
+ DCHECK(connections_.empty());
+}
+
+bool DatabaseConnections::IsDatabaseOpened(const string16& origin_identifier,
+ const string16& database_name) {
+ OriginConnections::const_iterator origin_it =
+ connections_.find(origin_identifier);
+ if (origin_it == connections_.end())
+ return false;
+ const DBConnections& origin_connections = origin_it->second;
+ return (origin_connections.find(database_name) != origin_connections.end());
+}
+
+bool DatabaseConnections::IsOriginUsed(const string16& origin_identifier) {
+ return (connections_.find(origin_identifier) != connections_.end());
+}
+
+void DatabaseConnections::AddConnection(const string16& origin_identifier,
+ const string16& database_name) {
+ connections_[origin_identifier][database_name]++;
+}
+
+void DatabaseConnections::RemoveConnection(const string16& origin_identifier,
+ const string16& database_name) {
+ RemoveConnectionsHelper(origin_identifier, database_name, 1);
+}
+
+void DatabaseConnections::RemoveAllConnections() {
+ connections_.clear();
+}
+
+void DatabaseConnections::RemoveConnections(
+ const DatabaseConnections& connections) {
+ for (OriginConnections::const_iterator origin_it =
+ connections.connections_.begin();
+ origin_it != connections.connections_.end();
+ origin_it++) {
+ const DBConnections& db_connections = origin_it->second;
+ for (DBConnections::const_iterator db_it = db_connections.begin();
+ db_it != db_connections.end(); db_it++) {
+ RemoveConnectionsHelper(origin_it->first, db_it->first, db_it->second);
+ }
+ }
+}
+
+void DatabaseConnections::RemoveConnectionsHelper(
+ const string16& origin_identifier,
+ const string16& database_name,
+ int num_connections) {
+ OriginConnections::iterator origin_iterator =
+ connections_.find(origin_identifier);
+ DCHECK(origin_iterator != connections_.end());
+ DBConnections& db_connections = origin_iterator->second;
+ int& count = db_connections[database_name];
+ DCHECK(count >= num_connections);
+ count -= num_connections;
+ if (!count) {
+ db_connections.erase(database_name);
+ if (db_connections.empty())
+ connections_.erase(origin_iterator);
+ }
+}
+
+} // namespace webkit_database