OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "content/browser/indexed_db/indexed_db_factory.h" | 5 #include "content/browser/indexed_db/indexed_db_factory_impl.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "content/browser/indexed_db/indexed_db_backing_store.h" | 12 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
13 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 13 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
14 #include "content/browser/indexed_db/indexed_db_database_error.h" | 14 #include "content/browser/indexed_db/indexed_db_database_error.h" |
15 #include "content/browser/indexed_db/indexed_db_tracing.h" | 15 #include "content/browser/indexed_db/indexed_db_tracing.h" |
16 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h" | 16 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h" |
17 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" | 17 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" |
18 #include "third_party/leveldatabase/env_chromium.h" | 18 #include "third_party/leveldatabase/env_chromium.h" |
19 #include "webkit/common/database/database_identifier.h" | 19 #include "webkit/common/database/database_identifier.h" |
20 | 20 |
21 using base::ASCIIToUTF16; | 21 using base::ASCIIToUTF16; |
22 | 22 |
23 namespace content { | 23 namespace content { |
24 | 24 |
25 const int64 kBackingStoreGracePeriodMs = 2000; | 25 const int64 kBackingStoreGracePeriodMs = 2000; |
26 | 26 |
27 IndexedDBFactory::IndexedDBFactory(IndexedDBContextImpl* context) | 27 IndexedDBFactoryImpl::IndexedDBFactoryImpl(IndexedDBContextImpl* context) |
28 : context_(context) {} | 28 : context_(context) { |
| 29 } |
29 | 30 |
30 IndexedDBFactory::~IndexedDBFactory() {} | 31 IndexedDBFactoryImpl::~IndexedDBFactoryImpl() { |
| 32 } |
31 | 33 |
32 void IndexedDBFactory::RemoveDatabaseFromMaps( | 34 void IndexedDBFactoryImpl::RemoveDatabaseFromMaps( |
33 const IndexedDBDatabase::Identifier& identifier) { | 35 const IndexedDBDatabase::Identifier& identifier) { |
34 IndexedDBDatabaseMap::iterator it = database_map_.find(identifier); | 36 IndexedDBDatabaseMap::iterator it = database_map_.find(identifier); |
35 DCHECK(it != database_map_.end()); | 37 DCHECK(it != database_map_.end()); |
36 IndexedDBDatabase* database = it->second; | 38 IndexedDBDatabase* database = it->second; |
37 database_map_.erase(it); | 39 database_map_.erase(it); |
38 | 40 |
39 std::pair<OriginDBMap::iterator, OriginDBMap::iterator> range = | 41 std::pair<OriginDBMap::iterator, OriginDBMap::iterator> range = |
40 origin_dbs_.equal_range(database->identifier().first); | 42 origin_dbs_.equal_range(database->identifier().first); |
41 DCHECK(range.first != range.second); | 43 DCHECK(range.first != range.second); |
42 for (OriginDBMap::iterator it2 = range.first; it2 != range.second; ++it2) { | 44 for (OriginDBMap::iterator it2 = range.first; it2 != range.second; ++it2) { |
43 if (it2->second == database) { | 45 if (it2->second == database) { |
44 origin_dbs_.erase(it2); | 46 origin_dbs_.erase(it2); |
45 break; | 47 break; |
46 } | 48 } |
47 } | 49 } |
48 } | 50 } |
49 | 51 |
50 void IndexedDBFactory::ReleaseDatabase( | 52 void IndexedDBFactoryImpl::ReleaseDatabase( |
51 const IndexedDBDatabase::Identifier& identifier, | 53 const IndexedDBDatabase::Identifier& identifier, |
52 bool forcedClose) { | 54 bool forcedClose) { |
53 | |
54 DCHECK(!database_map_.find(identifier)->second->backing_store()); | 55 DCHECK(!database_map_.find(identifier)->second->backing_store()); |
55 | 56 |
56 RemoveDatabaseFromMaps(identifier); | 57 RemoveDatabaseFromMaps(identifier); |
57 | 58 |
58 // No grace period on a forced-close, as the initiator is | 59 // No grace period on a forced-close, as the initiator is |
59 // assuming the backing store will be released once all | 60 // assuming the backing store will be released once all |
60 // connections are closed. | 61 // connections are closed. |
61 ReleaseBackingStore(identifier.first, forcedClose); | 62 ReleaseBackingStore(identifier.first, forcedClose); |
62 } | 63 } |
63 | 64 |
64 void IndexedDBFactory::ReleaseBackingStore(const GURL& origin_url, | 65 void IndexedDBFactoryImpl::ReleaseBackingStore(const GURL& origin_url, |
65 bool immediate) { | 66 bool immediate) { |
66 if (immediate) { | 67 if (immediate) { |
67 IndexedDBBackingStoreMap::iterator it = | 68 IndexedDBBackingStoreMap::iterator it = |
68 backing_stores_with_active_blobs_.find(origin_url); | 69 backing_stores_with_active_blobs_.find(origin_url); |
69 if (it != backing_stores_with_active_blobs_.end()) { | 70 if (it != backing_stores_with_active_blobs_.end()) { |
70 it->second->active_blob_registry()->ForceShutdown(); | 71 it->second->active_blob_registry()->ForceShutdown(); |
71 backing_stores_with_active_blobs_.erase(it); | 72 backing_stores_with_active_blobs_.erase(it); |
72 } | 73 } |
73 } | 74 } |
74 | 75 |
75 // Only close if this is the last reference. | 76 // Only close if this is the last reference. |
76 if (!HasLastBackingStoreReference(origin_url)) | 77 if (!HasLastBackingStoreReference(origin_url)) |
77 return; | 78 return; |
78 | 79 |
79 // If this factory does hold the last reference to the backing store, it can | 80 // If this factory does hold the last reference to the backing store, it can |
80 // be closed - but unless requested to close it immediately, keep it around | 81 // be closed - but unless requested to close it immediately, keep it around |
81 // for a short period so that a re-open is fast. | 82 // for a short period so that a re-open is fast. |
82 if (immediate) { | 83 if (immediate) { |
83 CloseBackingStore(origin_url); | 84 CloseBackingStore(origin_url); |
84 return; | 85 return; |
85 } | 86 } |
86 | 87 |
87 // Start a timer to close the backing store, unless something else opens it | 88 // Start a timer to close the backing store, unless something else opens it |
88 // in the mean time. | 89 // in the mean time. |
89 DCHECK(!backing_store_map_[origin_url]->close_timer()->IsRunning()); | 90 DCHECK(!backing_store_map_[origin_url]->close_timer()->IsRunning()); |
90 backing_store_map_[origin_url]->close_timer()->Start( | 91 backing_store_map_[origin_url]->close_timer()->Start( |
91 FROM_HERE, | 92 FROM_HERE, |
92 base::TimeDelta::FromMilliseconds(kBackingStoreGracePeriodMs), | 93 base::TimeDelta::FromMilliseconds(kBackingStoreGracePeriodMs), |
93 base::Bind(&IndexedDBFactory::MaybeCloseBackingStore, this, origin_url)); | 94 base::Bind( |
| 95 &IndexedDBFactoryImpl::MaybeCloseBackingStore, this, origin_url)); |
94 } | 96 } |
95 | 97 |
96 void IndexedDBFactory::MaybeCloseBackingStore(const GURL& origin_url) { | 98 void IndexedDBFactoryImpl::MaybeCloseBackingStore(const GURL& origin_url) { |
97 // Another reference may have opened since the maybe-close was posted, so it | 99 // Another reference may have opened since the maybe-close was posted, so it |
98 // is necessary to check again. | 100 // is necessary to check again. |
99 if (HasLastBackingStoreReference(origin_url)) | 101 if (HasLastBackingStoreReference(origin_url)) |
100 CloseBackingStore(origin_url); | 102 CloseBackingStore(origin_url); |
101 } | 103 } |
102 | 104 |
103 void IndexedDBFactory::CloseBackingStore(const GURL& origin_url) { | 105 void IndexedDBFactoryImpl::CloseBackingStore(const GURL& origin_url) { |
104 IndexedDBBackingStoreMap::iterator it = backing_store_map_.find(origin_url); | 106 IndexedDBBackingStoreMap::iterator it = backing_store_map_.find(origin_url); |
105 DCHECK(it != backing_store_map_.end()); | 107 DCHECK(it != backing_store_map_.end()); |
106 // Stop the timer (if it's running) - this may happen if the timer was started | 108 // Stop the timer (if it's running) - this may happen if the timer was started |
107 // and then a forced close occurs. | 109 // and then a forced close occurs. |
108 it->second->close_timer()->Stop(); | 110 it->second->close_timer()->Stop(); |
109 backing_store_map_.erase(it); | 111 backing_store_map_.erase(it); |
110 } | 112 } |
111 | 113 |
112 bool IndexedDBFactory::HasLastBackingStoreReference(const GURL& origin_url) | 114 bool IndexedDBFactoryImpl::HasLastBackingStoreReference( |
113 const { | 115 const GURL& origin_url) const { |
114 IndexedDBBackingStore* ptr; | 116 IndexedDBBackingStore* ptr; |
115 { | 117 { |
116 // Scope so that the implicit scoped_refptr<> is freed. | 118 // Scope so that the implicit scoped_refptr<> is freed. |
117 IndexedDBBackingStoreMap::const_iterator it = | 119 IndexedDBBackingStoreMap::const_iterator it = |
118 backing_store_map_.find(origin_url); | 120 backing_store_map_.find(origin_url); |
119 DCHECK(it != backing_store_map_.end()); | 121 DCHECK(it != backing_store_map_.end()); |
120 ptr = it->second.get(); | 122 ptr = it->second.get(); |
121 } | 123 } |
122 return ptr->HasOneRef(); | 124 return ptr->HasOneRef(); |
123 } | 125 } |
124 | 126 |
125 void IndexedDBFactory::ForceClose(const GURL& origin_url) { | 127 void IndexedDBFactoryImpl::ForceClose(const GURL& origin_url) { |
126 std::pair<OriginDBMapIterator, OriginDBMapIterator> range = | 128 std::pair<OriginDBMapIterator, OriginDBMapIterator> range = |
127 GetOpenDatabasesForOrigin(origin_url); | 129 GetOpenDatabasesForOrigin(origin_url); |
128 | 130 |
129 while (range.first != range.second) { | 131 while (range.first != range.second) { |
130 IndexedDBDatabase* db = range.first->second; | 132 IndexedDBDatabase* db = range.first->second; |
131 ++range.first; | 133 ++range.first; |
132 db->ForceClose(); | 134 db->ForceClose(); |
133 } | 135 } |
134 | 136 |
135 if (backing_store_map_.find(origin_url) != backing_store_map_.end()) | 137 if (backing_store_map_.find(origin_url) != backing_store_map_.end()) |
136 ReleaseBackingStore(origin_url, true /* immediate */); | 138 ReleaseBackingStore(origin_url, true /* immediate */); |
137 } | 139 } |
138 | 140 |
139 void IndexedDBFactory::ContextDestroyed() { | 141 void IndexedDBFactoryImpl::ContextDestroyed() { |
140 // Timers on backing stores hold a reference to this factory. When the | 142 // Timers on backing stores hold a reference to this factory. When the |
141 // context (which nominally owns this factory) is destroyed during thread | 143 // context (which nominally owns this factory) is destroyed during thread |
142 // termination the timers must be stopped so that this factory and the | 144 // termination the timers must be stopped so that this factory and the |
143 // stores can be disposed of. | 145 // stores can be disposed of. |
144 for (IndexedDBBackingStoreMap::iterator it = backing_store_map_.begin(); | 146 for (IndexedDBBackingStoreMap::iterator it = backing_store_map_.begin(); |
145 it != backing_store_map_.end(); | 147 it != backing_store_map_.end(); |
146 ++it) | 148 ++it) |
147 it->second->close_timer()->Stop(); | 149 it->second->close_timer()->Stop(); |
148 backing_store_map_.clear(); | 150 backing_store_map_.clear(); |
149 backing_stores_with_active_blobs_.clear(); | 151 backing_stores_with_active_blobs_.clear(); |
150 context_ = NULL; | 152 context_ = NULL; |
151 } | 153 } |
152 | 154 |
153 void IndexedDBFactory::ReportOutstandingBlobs(const GURL& origin_url, | 155 void IndexedDBFactoryImpl::ReportOutstandingBlobs(const GURL& origin_url, |
154 bool blobs_outstanding) { | 156 bool blobs_outstanding) { |
155 if (!context_) | 157 if (!context_) |
156 return; | 158 return; |
157 if (blobs_outstanding) { | 159 if (blobs_outstanding) { |
158 DCHECK(!backing_stores_with_active_blobs_.count(origin_url)); | 160 DCHECK(!backing_stores_with_active_blobs_.count(origin_url)); |
159 IndexedDBBackingStoreMap::iterator it = backing_store_map_.find(origin_url); | 161 IndexedDBBackingStoreMap::iterator it = backing_store_map_.find(origin_url); |
160 if (it != backing_store_map_.end()) | 162 if (it != backing_store_map_.end()) |
161 backing_stores_with_active_blobs_.insert(*it); | 163 backing_stores_with_active_blobs_.insert(*it); |
162 else | 164 else |
163 DCHECK(false); | 165 DCHECK(false); |
164 } else { | 166 } else { |
165 IndexedDBBackingStoreMap::iterator it = | 167 IndexedDBBackingStoreMap::iterator it = |
166 backing_stores_with_active_blobs_.find(origin_url); | 168 backing_stores_with_active_blobs_.find(origin_url); |
167 if (it != backing_stores_with_active_blobs_.end()) { | 169 if (it != backing_stores_with_active_blobs_.end()) { |
168 backing_stores_with_active_blobs_.erase(it); | 170 backing_stores_with_active_blobs_.erase(it); |
169 ReleaseBackingStore(origin_url, false /* immediate */); | 171 ReleaseBackingStore(origin_url, false /* immediate */); |
170 } | 172 } |
171 } | 173 } |
172 } | 174 } |
173 | 175 |
174 void IndexedDBFactory::GetDatabaseNames( | 176 void IndexedDBFactoryImpl::GetDatabaseNames( |
175 scoped_refptr<IndexedDBCallbacks> callbacks, | 177 scoped_refptr<IndexedDBCallbacks> callbacks, |
176 const GURL& origin_url, | 178 const GURL& origin_url, |
177 const base::FilePath& data_directory, | 179 const base::FilePath& data_directory, |
178 net::URLRequestContext* request_context) { | 180 net::URLRequestContext* request_context) { |
179 IDB_TRACE("IndexedDBFactory::GetDatabaseNames"); | 181 IDB_TRACE("IndexedDBFactoryImpl::GetDatabaseNames"); |
180 // TODO(dgrogan): Plumb data_loss back to script eventually? | 182 // TODO(dgrogan): Plumb data_loss back to script eventually? |
181 blink::WebIDBDataLoss data_loss; | 183 blink::WebIDBDataLoss data_loss; |
182 std::string data_loss_message; | 184 std::string data_loss_message; |
183 bool disk_full; | 185 bool disk_full; |
184 scoped_refptr<IndexedDBBackingStore> backing_store = | 186 scoped_refptr<IndexedDBBackingStore> backing_store = |
185 OpenBackingStore(origin_url, | 187 OpenBackingStore(origin_url, |
186 data_directory, | 188 data_directory, |
187 request_context, | 189 request_context, |
188 &data_loss, | 190 &data_loss, |
189 &data_loss_message, | 191 &data_loss_message, |
(...skipping 10 matching lines...) Expand all Loading... |
200 std::vector<base::string16> names = backing_store->GetDatabaseNames(&s); | 202 std::vector<base::string16> names = backing_store->GetDatabaseNames(&s); |
201 if (!s.ok()) { | 203 if (!s.ok()) { |
202 // TODO(cmumford): Handle this error | 204 // TODO(cmumford): Handle this error |
203 DLOG(ERROR) << "Internal error getting database names"; | 205 DLOG(ERROR) << "Internal error getting database names"; |
204 } | 206 } |
205 callbacks->OnSuccess(names); | 207 callbacks->OnSuccess(names); |
206 backing_store = NULL; | 208 backing_store = NULL; |
207 ReleaseBackingStore(origin_url, false /* immediate */); | 209 ReleaseBackingStore(origin_url, false /* immediate */); |
208 } | 210 } |
209 | 211 |
210 void IndexedDBFactory::DeleteDatabase( | 212 void IndexedDBFactoryImpl::DeleteDatabase( |
211 const base::string16& name, | 213 const base::string16& name, |
212 net::URLRequestContext* request_context, | 214 net::URLRequestContext* request_context, |
213 scoped_refptr<IndexedDBCallbacks> callbacks, | 215 scoped_refptr<IndexedDBCallbacks> callbacks, |
214 const GURL& origin_url, | 216 const GURL& origin_url, |
215 const base::FilePath& data_directory) { | 217 const base::FilePath& data_directory) { |
216 IDB_TRACE("IndexedDBFactory::DeleteDatabase"); | 218 IDB_TRACE("IndexedDBFactoryImpl::DeleteDatabase"); |
217 IndexedDBDatabase::Identifier unique_identifier(origin_url, name); | 219 IndexedDBDatabase::Identifier unique_identifier(origin_url, name); |
218 IndexedDBDatabaseMap::iterator it = database_map_.find(unique_identifier); | 220 IndexedDBDatabaseMap::iterator it = database_map_.find(unique_identifier); |
219 if (it != database_map_.end()) { | 221 if (it != database_map_.end()) { |
220 // If there are any connections to the database, directly delete the | 222 // If there are any connections to the database, directly delete the |
221 // database. | 223 // database. |
222 it->second->DeleteDatabase(callbacks); | 224 it->second->DeleteDatabase(callbacks); |
223 return; | 225 return; |
224 } | 226 } |
225 | 227 |
226 // TODO(dgrogan): Plumb data_loss back to script eventually? | 228 // TODO(dgrogan): Plumb data_loss back to script eventually? |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 | 262 |
261 database_map_[unique_identifier] = database; | 263 database_map_[unique_identifier] = database; |
262 origin_dbs_.insert(std::make_pair(origin_url, database)); | 264 origin_dbs_.insert(std::make_pair(origin_url, database)); |
263 database->DeleteDatabase(callbacks); | 265 database->DeleteDatabase(callbacks); |
264 RemoveDatabaseFromMaps(unique_identifier); | 266 RemoveDatabaseFromMaps(unique_identifier); |
265 database = NULL; | 267 database = NULL; |
266 backing_store = NULL; | 268 backing_store = NULL; |
267 ReleaseBackingStore(origin_url, false /* immediate */); | 269 ReleaseBackingStore(origin_url, false /* immediate */); |
268 } | 270 } |
269 | 271 |
270 void IndexedDBFactory::DatabaseDeleted( | 272 void IndexedDBFactoryImpl::DatabaseDeleted( |
271 const IndexedDBDatabase::Identifier& identifier) { | 273 const IndexedDBDatabase::Identifier& identifier) { |
272 // NULL after ContextDestroyed() called, and in some unit tests. | 274 // NULL after ContextDestroyed() called, and in some unit tests. |
273 if (!context_) | 275 if (!context_) |
274 return; | 276 return; |
275 context_->DatabaseDeleted(identifier.first); | 277 context_->DatabaseDeleted(identifier.first); |
276 } | 278 } |
277 | 279 |
278 void IndexedDBFactory::HandleBackingStoreFailure(const GURL& origin_url) { | 280 void IndexedDBFactoryImpl::HandleBackingStoreFailure(const GURL& origin_url) { |
279 // NULL after ContextDestroyed() called, and in some unit tests. | 281 // NULL after ContextDestroyed() called, and in some unit tests. |
280 if (!context_) | 282 if (!context_) |
281 return; | 283 return; |
282 context_->ForceClose(origin_url, | 284 context_->ForceClose(origin_url, |
283 IndexedDBContextImpl::FORCE_CLOSE_BACKING_STORE_FAILURE); | 285 IndexedDBContextImpl::FORCE_CLOSE_BACKING_STORE_FAILURE); |
284 } | 286 } |
285 | 287 |
286 void IndexedDBFactory::HandleBackingStoreCorruption( | 288 void IndexedDBFactoryImpl::HandleBackingStoreCorruption( |
287 const GURL& origin_url, | 289 const GURL& origin_url, |
288 const IndexedDBDatabaseError& error) { | 290 const IndexedDBDatabaseError& error) { |
289 // Make a copy of origin_url as this is likely a reference to a member of a | 291 // Make a copy of origin_url as this is likely a reference to a member of a |
290 // backing store which this function will be deleting. | 292 // backing store which this function will be deleting. |
291 GURL saved_origin_url(origin_url); | 293 GURL saved_origin_url(origin_url); |
292 DCHECK(context_); | 294 DCHECK(context_); |
293 base::FilePath path_base = context_->data_path(); | 295 base::FilePath path_base = context_->data_path(); |
294 IndexedDBBackingStore::RecordCorruptionInfo( | 296 IndexedDBBackingStore::RecordCorruptionInfo( |
295 path_base, saved_origin_url, base::UTF16ToUTF8(error.message())); | 297 path_base, saved_origin_url, base::UTF16ToUTF8(error.message())); |
296 HandleBackingStoreFailure(saved_origin_url); | 298 HandleBackingStoreFailure(saved_origin_url); |
297 // Note: DestroyBackingStore only deletes LevelDB files, leaving all others, | 299 // Note: DestroyBackingStore only deletes LevelDB files, leaving all others, |
298 // so our corruption info file will remain. | 300 // so our corruption info file will remain. |
299 leveldb::Status s = | 301 leveldb::Status s = |
300 IndexedDBBackingStore::DestroyBackingStore(path_base, saved_origin_url); | 302 IndexedDBBackingStore::DestroyBackingStore(path_base, saved_origin_url); |
301 if (!s.ok()) | 303 if (!s.ok()) |
302 DLOG(ERROR) << "Unable to delete backing store: " << s.ToString(); | 304 DLOG(ERROR) << "Unable to delete backing store: " << s.ToString(); |
303 } | 305 } |
304 | 306 |
305 bool IndexedDBFactory::IsDatabaseOpen(const GURL& origin_url, | 307 bool IndexedDBFactoryImpl::IsDatabaseOpen(const GURL& origin_url, |
306 const base::string16& name) const { | 308 const base::string16& name) const { |
307 return !!database_map_.count(IndexedDBDatabase::Identifier(origin_url, name)); | 309 return !!database_map_.count(IndexedDBDatabase::Identifier(origin_url, name)); |
308 } | 310 } |
309 | 311 |
310 bool IndexedDBFactory::IsBackingStoreOpen(const GURL& origin_url) const { | 312 bool IndexedDBFactoryImpl::IsBackingStoreOpen(const GURL& origin_url) const { |
311 return backing_store_map_.find(origin_url) != backing_store_map_.end(); | 313 return backing_store_map_.find(origin_url) != backing_store_map_.end(); |
312 } | 314 } |
313 | 315 |
314 bool IndexedDBFactory::IsBackingStorePendingClose(const GURL& origin_url) | 316 bool IndexedDBFactoryImpl::IsBackingStorePendingClose( |
315 const { | 317 const GURL& origin_url) const { |
316 IndexedDBBackingStoreMap::const_iterator it = | 318 IndexedDBBackingStoreMap::const_iterator it = |
317 backing_store_map_.find(origin_url); | 319 backing_store_map_.find(origin_url); |
318 if (it == backing_store_map_.end()) | 320 if (it == backing_store_map_.end()) |
319 return false; | 321 return false; |
320 return it->second->close_timer()->IsRunning(); | 322 return it->second->close_timer()->IsRunning(); |
321 } | 323 } |
322 | 324 |
323 scoped_refptr<IndexedDBBackingStore> IndexedDBFactory::OpenBackingStoreHelper( | 325 scoped_refptr<IndexedDBBackingStore> |
| 326 IndexedDBFactoryImpl::OpenBackingStoreHelper( |
324 const GURL& origin_url, | 327 const GURL& origin_url, |
325 const base::FilePath& data_directory, | 328 const base::FilePath& data_directory, |
326 net::URLRequestContext* request_context, | 329 net::URLRequestContext* request_context, |
327 blink::WebIDBDataLoss* data_loss, | 330 blink::WebIDBDataLoss* data_loss, |
328 std::string* data_loss_message, | 331 std::string* data_loss_message, |
329 bool* disk_full, | 332 bool* disk_full, |
330 bool first_time) { | 333 bool first_time) { |
331 return IndexedDBBackingStore::Open(this, | 334 return IndexedDBBackingStore::Open(this, |
332 origin_url, | 335 origin_url, |
333 data_directory, | 336 data_directory, |
334 request_context, | 337 request_context, |
335 data_loss, | 338 data_loss, |
336 data_loss_message, | 339 data_loss_message, |
337 disk_full, | 340 disk_full, |
338 context_->TaskRunner(), | 341 context_->TaskRunner(), |
339 first_time); | 342 first_time); |
340 } | 343 } |
341 | 344 |
342 scoped_refptr<IndexedDBBackingStore> IndexedDBFactory::OpenBackingStore( | 345 scoped_refptr<IndexedDBBackingStore> IndexedDBFactoryImpl::OpenBackingStore( |
343 const GURL& origin_url, | 346 const GURL& origin_url, |
344 const base::FilePath& data_directory, | 347 const base::FilePath& data_directory, |
345 net::URLRequestContext* request_context, | 348 net::URLRequestContext* request_context, |
346 blink::WebIDBDataLoss* data_loss, | 349 blink::WebIDBDataLoss* data_loss, |
347 std::string* data_loss_message, | 350 std::string* data_loss_message, |
348 bool* disk_full) { | 351 bool* disk_full) { |
349 const bool open_in_memory = data_directory.empty(); | 352 const bool open_in_memory = data_directory.empty(); |
350 | 353 |
351 IndexedDBBackingStoreMap::iterator it2 = backing_store_map_.find(origin_url); | 354 IndexedDBBackingStoreMap::iterator it2 = backing_store_map_.find(origin_url); |
352 if (it2 != backing_store_map_.end()) { | 355 if (it2 != backing_store_map_.end()) { |
(...skipping 29 matching lines...) Expand all Loading... |
382 // All backing stores associated with this factory should be of the same | 385 // All backing stores associated with this factory should be of the same |
383 // type. | 386 // type. |
384 DCHECK_NE(session_only_backing_stores_.empty(), open_in_memory); | 387 DCHECK_NE(session_only_backing_stores_.empty(), open_in_memory); |
385 | 388 |
386 return backing_store; | 389 return backing_store; |
387 } | 390 } |
388 | 391 |
389 return 0; | 392 return 0; |
390 } | 393 } |
391 | 394 |
392 void IndexedDBFactory::Open(const base::string16& name, | 395 void IndexedDBFactoryImpl::Open(const base::string16& name, |
393 const IndexedDBPendingConnection& connection, | 396 const IndexedDBPendingConnection& connection, |
394 net::URLRequestContext* request_context, | 397 net::URLRequestContext* request_context, |
395 const GURL& origin_url, | 398 const GURL& origin_url, |
396 const base::FilePath& data_directory) { | 399 const base::FilePath& data_directory) { |
397 IDB_TRACE("IndexedDBFactory::Open"); | 400 IDB_TRACE("IndexedDBFactoryImpl::Open"); |
398 scoped_refptr<IndexedDBDatabase> database; | 401 scoped_refptr<IndexedDBDatabase> database; |
399 IndexedDBDatabase::Identifier unique_identifier(origin_url, name); | 402 IndexedDBDatabase::Identifier unique_identifier(origin_url, name); |
400 IndexedDBDatabaseMap::iterator it = database_map_.find(unique_identifier); | 403 IndexedDBDatabaseMap::iterator it = database_map_.find(unique_identifier); |
401 blink::WebIDBDataLoss data_loss = | 404 blink::WebIDBDataLoss data_loss = |
402 blink::WebIDBDataLossNone; | 405 blink::WebIDBDataLossNone; |
403 std::string data_loss_message; | 406 std::string data_loss_message; |
404 bool disk_full = false; | 407 bool disk_full = false; |
405 bool was_open = (it != database_map_.end()); | 408 bool was_open = (it != database_map_.end()); |
406 if (!was_open) { | 409 if (!was_open) { |
407 scoped_refptr<IndexedDBBackingStore> backing_store = | 410 scoped_refptr<IndexedDBBackingStore> backing_store = |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 connection.callbacks->OnDataLoss(data_loss, data_loss_message); | 455 connection.callbacks->OnDataLoss(data_loss, data_loss_message); |
453 | 456 |
454 database->OpenConnection(connection); | 457 database->OpenConnection(connection); |
455 | 458 |
456 if (!was_open && database->ConnectionCount() > 0) { | 459 if (!was_open && database->ConnectionCount() > 0) { |
457 database_map_[unique_identifier] = database; | 460 database_map_[unique_identifier] = database; |
458 origin_dbs_.insert(std::make_pair(origin_url, database)); | 461 origin_dbs_.insert(std::make_pair(origin_url, database)); |
459 } | 462 } |
460 } | 463 } |
461 | 464 |
462 std::pair<IndexedDBFactory::OriginDBMapIterator, | 465 std::pair<IndexedDBFactoryImpl::OriginDBMapIterator, |
463 IndexedDBFactory::OriginDBMapIterator> | 466 IndexedDBFactoryImpl::OriginDBMapIterator> |
464 IndexedDBFactory::GetOpenDatabasesForOrigin(const GURL& origin_url) const { | 467 IndexedDBFactoryImpl::GetOpenDatabasesForOrigin(const GURL& origin_url) const { |
465 return origin_dbs_.equal_range(origin_url); | 468 return origin_dbs_.equal_range(origin_url); |
466 } | 469 } |
467 | 470 |
468 size_t IndexedDBFactory::GetConnectionCount(const GURL& origin_url) const { | 471 size_t IndexedDBFactoryImpl::GetConnectionCount(const GURL& origin_url) const { |
469 size_t count(0); | 472 size_t count(0); |
470 | 473 |
471 std::pair<OriginDBMapIterator, OriginDBMapIterator> range = | 474 std::pair<OriginDBMapIterator, OriginDBMapIterator> range = |
472 GetOpenDatabasesForOrigin(origin_url); | 475 GetOpenDatabasesForOrigin(origin_url); |
473 for (OriginDBMapIterator it = range.first; it != range.second; ++it) | 476 for (OriginDBMapIterator it = range.first; it != range.second; ++it) |
474 count += it->second->ConnectionCount(); | 477 count += it->second->ConnectionCount(); |
475 | 478 |
476 return count; | 479 return count; |
477 } | 480 } |
478 | 481 |
479 } // namespace content | 482 } // namespace content |
OLD | NEW |