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