diff options
author | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-01 20:40:35 +0000 |
---|---|---|
committer | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-01 20:40:35 +0000 |
commit | 1d4dbdeaa23f3459fb710c8b2fe4d444266d952a (patch) | |
tree | 94064bd57faaba18d1ee7a9fe514628f58a6be55 /webkit/database/database_connections.cc | |
parent | 228d0659a51d0581c743b5b81921d43c7fd81e35 (diff) | |
download | chromium_src-1d4dbdeaa23f3459fb710c8b2fe4d444266d952a.zip chromium_src-1d4dbdeaa23f3459fb710c8b2fe4d444266d952a.tar.gz chromium_src-1d4dbdeaa23f3459fb710c8b2fe4d444266d952a.tar.bz2 |
Changes to WebDatabaseObserverImpl and SimpleDatabaseSystem required to have a chance of working properly with v8 isolates. With isolates the database related interfaces will be called on multiple threads and the previous impl was not put together with that in mind.
BUG=none
TEST=existing tests pass (no way to test with isolates yet)
Review URL: http://codereview.chromium.org/6677088
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80218 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/database/database_connections.cc')
-rw-r--r-- | webkit/database/database_connections.cc | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/webkit/database/database_connections.cc b/webkit/database/database_connections.cc index 05efb1e..612f73b4 100644 --- a/webkit/database/database_connections.cc +++ b/webkit/database/database_connections.cc @@ -1,10 +1,13 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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/auto_reset.h" #include "base/logging.h" +#include "base/message_loop.h" +#include "base/message_loop_proxy.h" namespace webkit_database { @@ -84,4 +87,53 @@ void DatabaseConnections::RemoveConnectionsHelper( } } +DatabaseConnectionsWrapper::DatabaseConnectionsWrapper() + : waiting_for_dbs_to_close_(false), + main_thread_(base::MessageLoopProxy::CreateForCurrentThread()) { +} + +DatabaseConnectionsWrapper::~DatabaseConnectionsWrapper() { +} + +void DatabaseConnectionsWrapper::WaitForAllDatabasesToClose() { + // We assume that new databases won't be open while we're waiting. + DCHECK(main_thread_->BelongsToCurrentThread()); + if (HasOpenConnections()) { + AutoReset<bool> auto_reset(&waiting_for_dbs_to_close_, true); + MessageLoop::ScopedNestableTaskAllower nestable(MessageLoop::current()); + MessageLoop::current()->Run(); + } +} + +bool DatabaseConnectionsWrapper::HasOpenConnections() { + DCHECK(main_thread_->BelongsToCurrentThread()); + base::AutoLock auto_lock(open_connections_lock_); + return !open_connections_.IsEmpty(); +} + +void DatabaseConnectionsWrapper::AddOpenConnection( + const string16& origin_identifier, + const string16& database_name) { + // We add to the collection immediately on any thread. + base::AutoLock auto_lock(open_connections_lock_); + open_connections_.AddConnection(origin_identifier, database_name); +} + +void DatabaseConnectionsWrapper::RemoveOpenConnection( + const string16& origin_identifier, + const string16& database_name) { + // But only remove from the collection on the main thread + // so we can handle the waiting_for_dbs_to_close_ case. + if (!main_thread_->BelongsToCurrentThread()) { + main_thread_->PostTask(FROM_HERE, NewRunnableMethod( + this, &DatabaseConnectionsWrapper::RemoveOpenConnection, + origin_identifier, database_name)); + return; + } + base::AutoLock auto_lock(open_connections_lock_); + open_connections_.RemoveConnection(origin_identifier, database_name); + if (waiting_for_dbs_to_close_ && open_connections_.IsEmpty()) + MessageLoop::current()->Quit(); +} + } // namespace webkit_database |