OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "storage/common/database/database_connections.h" | 5 #include "storage/common/database/database_connections.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/message_loop/message_loop_proxy.h" | 11 #include "base/thread_task_runner_handle.h" |
12 | 12 |
13 namespace storage { | 13 namespace storage { |
14 | 14 |
15 DatabaseConnections::DatabaseConnections() { | 15 DatabaseConnections::DatabaseConnections() { |
16 } | 16 } |
17 | 17 |
18 DatabaseConnections::~DatabaseConnections() { | 18 DatabaseConnections::~DatabaseConnections() { |
19 DCHECK(connections_.empty()); | 19 DCHECK(connections_.empty()); |
20 } | 20 } |
21 | 21 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 if (count) | 116 if (count) |
117 return false; | 117 return false; |
118 db_connections.erase(database_name); | 118 db_connections.erase(database_name); |
119 if (db_connections.empty()) | 119 if (db_connections.empty()) |
120 connections_.erase(origin_iterator); | 120 connections_.erase(origin_iterator); |
121 return true; | 121 return true; |
122 } | 122 } |
123 | 123 |
124 DatabaseConnectionsWrapper::DatabaseConnectionsWrapper() | 124 DatabaseConnectionsWrapper::DatabaseConnectionsWrapper() |
125 : waiting_for_dbs_to_close_(false), | 125 : waiting_for_dbs_to_close_(false), |
126 main_thread_(base::MessageLoopProxy::current()) { | 126 main_thread_(base::ThreadTaskRunnerHandle::Get()) { |
127 } | 127 } |
128 | 128 |
129 DatabaseConnectionsWrapper::~DatabaseConnectionsWrapper() { | 129 DatabaseConnectionsWrapper::~DatabaseConnectionsWrapper() { |
130 } | 130 } |
131 | 131 |
132 void DatabaseConnectionsWrapper::WaitForAllDatabasesToClose() { | 132 void DatabaseConnectionsWrapper::WaitForAllDatabasesToClose() { |
133 // We assume that new databases won't be open while we're waiting. | 133 // We assume that new databases won't be open while we're waiting. |
134 DCHECK(main_thread_->BelongsToCurrentThread()); | 134 DCHECK(main_thread_->BelongsToCurrentThread()); |
135 if (HasOpenConnections()) { | 135 if (HasOpenConnections()) { |
136 base::AutoReset<bool> auto_reset(&waiting_for_dbs_to_close_, true); | 136 base::AutoReset<bool> auto_reset(&waiting_for_dbs_to_close_, true); |
(...skipping 29 matching lines...) Expand all Loading... |
166 origin_identifier, database_name)); | 166 origin_identifier, database_name)); |
167 return; | 167 return; |
168 } | 168 } |
169 base::AutoLock auto_lock(open_connections_lock_); | 169 base::AutoLock auto_lock(open_connections_lock_); |
170 open_connections_.RemoveConnection(origin_identifier, database_name); | 170 open_connections_.RemoveConnection(origin_identifier, database_name); |
171 if (waiting_for_dbs_to_close_ && open_connections_.IsEmpty()) | 171 if (waiting_for_dbs_to_close_ && open_connections_.IsEmpty()) |
172 base::MessageLoop::current()->Quit(); | 172 base::MessageLoop::current()->Quit(); |
173 } | 173 } |
174 | 174 |
175 } // namespace storage | 175 } // namespace storage |
OLD | NEW |