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.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 "content/browser/indexed_db/indexed_db_backing_store.h" | 9 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
10 #include "content/browser/indexed_db/indexed_db_database.h" | 10 #include "content/browser/indexed_db/indexed_db_database.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 DCHECK(database_backend_map_.find(unique_identifier) != | 48 DCHECK(database_backend_map_.find(unique_identifier) != |
49 database_backend_map_.end()); | 49 database_backend_map_.end()); |
50 database_backend_map_.erase(unique_identifier); | 50 database_backend_map_.erase(unique_identifier); |
51 } | 51 } |
52 | 52 |
53 void IndexedDBFactory::GetDatabaseNames( | 53 void IndexedDBFactory::GetDatabaseNames( |
54 scoped_refptr<IndexedDBCallbacksWrapper> callbacks, | 54 scoped_refptr<IndexedDBCallbacksWrapper> callbacks, |
55 const string16& database_identifier, | 55 const string16& database_identifier, |
56 const base::FilePath& data_directory) { | 56 const base::FilePath& data_directory) { |
57 IDB_TRACE("IndexedDBFactory::get_database_names"); | 57 IDB_TRACE("IndexedDBFactory::get_database_names"); |
58 bool data_loss; | |
jsbell
2013/06/14 20:42:58
Add a TODO to figure out if this should be plumbed
dgrogan
2013/06/14 22:06:43
Done.
| |
58 scoped_refptr<IndexedDBBackingStore> backing_store = | 59 scoped_refptr<IndexedDBBackingStore> backing_store = |
59 OpenBackingStore(database_identifier, data_directory); | 60 OpenBackingStore(database_identifier, data_directory, &data_loss); |
60 if (!backing_store.get()) { | 61 if (!backing_store.get()) { |
61 callbacks->OnError( | 62 callbacks->OnError( |
62 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError, | 63 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError, |
63 "Internal error opening backing store for " | 64 "Internal error opening backing store for " |
64 "indexedDB.webkitGetDatabaseNames.")); | 65 "indexedDB.webkitGetDatabaseNames.")); |
65 return; | 66 return; |
66 } | 67 } |
67 | 68 |
68 callbacks->OnSuccess(backing_store->GetDatabaseNames()); | 69 callbacks->OnSuccess(backing_store->GetDatabaseNames()); |
69 } | 70 } |
(...skipping 10 matching lines...) Expand all Loading... | |
80 IndexedDBDatabaseMap::iterator it = | 81 IndexedDBDatabaseMap::iterator it = |
81 database_backend_map_.find(unique_identifier); | 82 database_backend_map_.find(unique_identifier); |
82 if (it != database_backend_map_.end()) { | 83 if (it != database_backend_map_.end()) { |
83 // If there are any connections to the database, directly delete the | 84 // If there are any connections to the database, directly delete the |
84 // database. | 85 // database. |
85 it->second->DeleteDatabase(callbacks); | 86 it->second->DeleteDatabase(callbacks); |
86 return; | 87 return; |
87 } | 88 } |
88 | 89 |
89 // TODO(jsbell): Everything from now on should be done on another thread. | 90 // TODO(jsbell): Everything from now on should be done on another thread. |
91 bool data_loss; | |
jsbell
2013/06/14 20:42:58
Also add a TODO here?
dgrogan
2013/06/14 22:06:43
Done.
| |
90 scoped_refptr<IndexedDBBackingStore> backing_store = | 92 scoped_refptr<IndexedDBBackingStore> backing_store = |
91 OpenBackingStore(database_identifier, data_directory); | 93 OpenBackingStore(database_identifier, data_directory, &data_loss); |
92 if (!backing_store.get()) { | 94 if (!backing_store.get()) { |
93 callbacks->OnError(IndexedDBDatabaseError( | 95 callbacks->OnError(IndexedDBDatabaseError( |
94 WebKit::WebIDBDatabaseExceptionUnknownError, | 96 WebKit::WebIDBDatabaseExceptionUnknownError, |
95 ASCIIToUTF16("Internal error opening backing store " | 97 ASCIIToUTF16("Internal error opening backing store " |
96 "for indexed_db.delete_database."))); | 98 "for indexed_db.delete_database."))); |
97 return; | 99 return; |
98 } | 100 } |
99 | 101 |
100 scoped_refptr<IndexedDBDatabase> database_backend = IndexedDBDatabase::Create( | 102 scoped_refptr<IndexedDBDatabase> database_backend = IndexedDBDatabase::Create( |
101 name, backing_store.get(), this, unique_identifier); | 103 name, backing_store.get(), this, unique_identifier); |
102 if (!database_backend.get()) { | 104 if (!database_backend.get()) { |
103 callbacks->OnError(IndexedDBDatabaseError( | 105 callbacks->OnError(IndexedDBDatabaseError( |
104 WebKit::WebIDBDatabaseExceptionUnknownError, | 106 WebKit::WebIDBDatabaseExceptionUnknownError, |
105 ASCIIToUTF16("Internal error creating database backend for " | 107 ASCIIToUTF16("Internal error creating database backend for " |
106 "indexed_db.delete_database."))); | 108 "indexed_db.delete_database."))); |
107 return; | 109 return; |
108 } | 110 } |
109 | 111 |
110 database_backend_map_[unique_identifier] = database_backend.get(); | 112 database_backend_map_[unique_identifier] = database_backend.get(); |
111 database_backend->DeleteDatabase(callbacks); | 113 database_backend->DeleteDatabase(callbacks); |
112 database_backend_map_.erase(unique_identifier); | 114 database_backend_map_.erase(unique_identifier); |
113 } | 115 } |
114 | 116 |
115 scoped_refptr<IndexedDBBackingStore> IndexedDBFactory::OpenBackingStore( | 117 scoped_refptr<IndexedDBBackingStore> IndexedDBFactory::OpenBackingStore( |
116 const string16& database_identifier, | 118 const string16& database_identifier, |
117 const base::FilePath& data_directory) { | 119 const base::FilePath& data_directory, |
120 bool* data_loss) { | |
118 const string16 file_identifier = ComputeFileIdentifier(database_identifier); | 121 const string16 file_identifier = ComputeFileIdentifier(database_identifier); |
119 const bool open_in_memory = data_directory.empty(); | 122 const bool open_in_memory = data_directory.empty(); |
120 | 123 |
121 IndexedDBBackingStoreMap::iterator it2 = | 124 IndexedDBBackingStoreMap::iterator it2 = |
122 backing_store_map_.find(file_identifier); | 125 backing_store_map_.find(file_identifier); |
123 if (it2 != backing_store_map_.end() && it2->second.get()) | 126 if (it2 != backing_store_map_.end() && it2->second.get()) |
124 return it2->second.get(); | 127 return it2->second.get(); |
125 | 128 |
126 scoped_refptr<IndexedDBBackingStore> backing_store; | 129 scoped_refptr<IndexedDBBackingStore> backing_store; |
127 if (open_in_memory) { | 130 if (open_in_memory) { |
128 backing_store = IndexedDBBackingStore::OpenInMemory(file_identifier); | 131 backing_store = IndexedDBBackingStore::OpenInMemory(file_identifier); |
129 } else { | 132 } else { |
130 backing_store = IndexedDBBackingStore::Open( | 133 backing_store = IndexedDBBackingStore::Open( |
131 database_identifier, data_directory, file_identifier); | 134 database_identifier, data_directory, file_identifier, data_loss); |
132 } | 135 } |
133 | 136 |
134 if (backing_store.get()) { | 137 if (backing_store.get()) { |
135 CleanWeakMap(&backing_store_map_); | 138 CleanWeakMap(&backing_store_map_); |
136 backing_store_map_[file_identifier] = backing_store->GetWeakPtr(); | 139 backing_store_map_[file_identifier] = backing_store->GetWeakPtr(); |
137 // If an in-memory database, bind lifetime to this factory instance. | 140 // If an in-memory database, bind lifetime to this factory instance. |
138 if (open_in_memory) | 141 if (open_in_memory) |
139 session_only_backing_stores_.insert(backing_store); | 142 session_only_backing_stores_.insert(backing_store); |
140 | 143 |
141 // All backing stores associated with this factory should be of the same | 144 // All backing stores associated with this factory should be of the same |
(...skipping 14 matching lines...) Expand all Loading... | |
156 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> database_callbacks, | 159 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> database_callbacks, |
157 const string16& database_identifier, | 160 const string16& database_identifier, |
158 const base::FilePath& data_directory) { | 161 const base::FilePath& data_directory) { |
159 IDB_TRACE("IndexedDBFactory::open"); | 162 IDB_TRACE("IndexedDBFactory::open"); |
160 const string16 unique_identifier = | 163 const string16 unique_identifier = |
161 ComputeUniqueIdentifier(name, database_identifier); | 164 ComputeUniqueIdentifier(name, database_identifier); |
162 | 165 |
163 scoped_refptr<IndexedDBDatabase> database_backend; | 166 scoped_refptr<IndexedDBDatabase> database_backend; |
164 IndexedDBDatabaseMap::iterator it = | 167 IndexedDBDatabaseMap::iterator it = |
165 database_backend_map_.find(unique_identifier); | 168 database_backend_map_.find(unique_identifier); |
169 bool data_loss = false; | |
166 if (it == database_backend_map_.end()) { | 170 if (it == database_backend_map_.end()) { |
167 scoped_refptr<IndexedDBBackingStore> backing_store = | 171 scoped_refptr<IndexedDBBackingStore> backing_store = |
168 OpenBackingStore(database_identifier, data_directory); | 172 OpenBackingStore(database_identifier, data_directory, &data_loss); |
169 if (!backing_store.get()) { | 173 if (!backing_store.get()) { |
170 callbacks->OnError(IndexedDBDatabaseError( | 174 callbacks->OnError(IndexedDBDatabaseError( |
171 WebKit::WebIDBDatabaseExceptionUnknownError, | 175 WebKit::WebIDBDatabaseExceptionUnknownError, |
172 ASCIIToUTF16( | 176 ASCIIToUTF16( |
173 "Internal error opening backing store for indexedDB.open."))); | 177 "Internal error opening backing store for indexedDB.open."))); |
174 return; | 178 return; |
175 } | 179 } |
176 | 180 |
177 database_backend = IndexedDBDatabase::Create( | 181 database_backend = IndexedDBDatabase::Create( |
178 name, backing_store.get(), this, unique_identifier); | 182 name, backing_store.get(), this, unique_identifier); |
179 if (!database_backend.get()) { | 183 if (!database_backend.get()) { |
180 callbacks->OnError(IndexedDBDatabaseError( | 184 callbacks->OnError(IndexedDBDatabaseError( |
181 WebKit::WebIDBDatabaseExceptionUnknownError, | 185 WebKit::WebIDBDatabaseExceptionUnknownError, |
182 ASCIIToUTF16( | 186 ASCIIToUTF16( |
183 "Internal error creating database backend for indexedDB.open."))); | 187 "Internal error creating database backend for indexedDB.open."))); |
184 return; | 188 return; |
185 } | 189 } |
186 | 190 |
187 database_backend_map_[unique_identifier] = database_backend.get(); | 191 database_backend_map_[unique_identifier] = database_backend.get(); |
188 } else { | 192 } else { |
189 database_backend = it->second; | 193 database_backend = it->second; |
190 } | 194 } |
191 | 195 |
192 database_backend->OpenConnection( | 196 database_backend->OpenConnection( |
193 callbacks, database_callbacks, transaction_id, version); | 197 callbacks, database_callbacks, transaction_id, version, data_loss); |
194 } | 198 } |
195 | 199 |
196 } // namespace content | 200 } // namespace content |
OLD | NEW |