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::GetDatabaseNames"); | 57 IDB_TRACE("IndexedDBFactory::GetDatabaseNames"); |
| 58 // TODO(dgrogan): Plumb data_loss back to script eventually? |
| 59 WebKit::WebIDBCallbacks::DataLoss data_loss; |
58 scoped_refptr<IndexedDBBackingStore> backing_store = | 60 scoped_refptr<IndexedDBBackingStore> backing_store = |
59 OpenBackingStore(database_identifier, data_directory); | 61 OpenBackingStore(database_identifier, data_directory, &data_loss); |
60 if (!backing_store.get()) { | 62 if (!backing_store.get()) { |
61 callbacks->OnError( | 63 callbacks->OnError( |
62 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError, | 64 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError, |
63 "Internal error opening backing store for " | 65 "Internal error opening backing store for " |
64 "indexedDB.webkitGetDatabaseNames.")); | 66 "indexedDB.webkitGetDatabaseNames.")); |
65 return; | 67 return; |
66 } | 68 } |
67 | 69 |
68 callbacks->OnSuccess(backing_store->GetDatabaseNames()); | 70 callbacks->OnSuccess(backing_store->GetDatabaseNames()); |
69 } | 71 } |
70 | 72 |
71 void IndexedDBFactory::DeleteDatabase( | 73 void IndexedDBFactory::DeleteDatabase( |
72 const string16& name, | 74 const string16& name, |
73 scoped_refptr<IndexedDBCallbacksWrapper> callbacks, | 75 scoped_refptr<IndexedDBCallbacksWrapper> callbacks, |
74 const string16& database_identifier, | 76 const string16& database_identifier, |
75 const base::FilePath& data_directory) { | 77 const base::FilePath& data_directory) { |
76 IDB_TRACE("IndexedDBFactory::DeleteDatabase"); | 78 IDB_TRACE("IndexedDBFactory::DeleteDatabase"); |
77 const string16 unique_identifier = | 79 const string16 unique_identifier = |
78 ComputeUniqueIdentifier(name, database_identifier); | 80 ComputeUniqueIdentifier(name, database_identifier); |
79 | 81 |
80 IndexedDBDatabaseMap::iterator it = | 82 IndexedDBDatabaseMap::iterator it = |
81 database_backend_map_.find(unique_identifier); | 83 database_backend_map_.find(unique_identifier); |
82 if (it != database_backend_map_.end()) { | 84 if (it != database_backend_map_.end()) { |
83 // If there are any connections to the database, directly delete the | 85 // If there are any connections to the database, directly delete the |
84 // database. | 86 // database. |
85 it->second->DeleteDatabase(callbacks); | 87 it->second->DeleteDatabase(callbacks); |
86 return; | 88 return; |
87 } | 89 } |
88 | 90 |
| 91 |
| 92 // TODO(dgrogan): Plumb data_loss back to script eventually? |
| 93 WebKit::WebIDBCallbacks::DataLoss data_loss; |
89 scoped_refptr<IndexedDBBackingStore> backing_store = | 94 scoped_refptr<IndexedDBBackingStore> backing_store = |
90 OpenBackingStore(database_identifier, data_directory); | 95 OpenBackingStore(database_identifier, data_directory, &data_loss); |
91 if (!backing_store.get()) { | 96 if (!backing_store.get()) { |
92 callbacks->OnError(IndexedDBDatabaseError( | 97 callbacks->OnError(IndexedDBDatabaseError( |
93 WebKit::WebIDBDatabaseExceptionUnknownError, | 98 WebKit::WebIDBDatabaseExceptionUnknownError, |
94 ASCIIToUTF16("Internal error opening backing store " | 99 ASCIIToUTF16("Internal error opening backing store " |
95 "for indexedDB.deleteDatabase."))); | 100 "for indexedDB.deleteDatabase."))); |
96 return; | 101 return; |
97 } | 102 } |
98 | 103 |
99 scoped_refptr<IndexedDBDatabase> database_backend = IndexedDBDatabase::Create( | 104 scoped_refptr<IndexedDBDatabase> database_backend = IndexedDBDatabase::Create( |
100 name, backing_store.get(), this, unique_identifier); | 105 name, backing_store.get(), this, unique_identifier); |
101 if (!database_backend.get()) { | 106 if (!database_backend.get()) { |
102 callbacks->OnError(IndexedDBDatabaseError( | 107 callbacks->OnError(IndexedDBDatabaseError( |
103 WebKit::WebIDBDatabaseExceptionUnknownError, | 108 WebKit::WebIDBDatabaseExceptionUnknownError, |
104 ASCIIToUTF16("Internal error creating database backend for " | 109 ASCIIToUTF16("Internal error creating database backend for " |
105 "indexedDB.deleteDatabase."))); | 110 "indexedDB.deleteDatabase."))); |
106 return; | 111 return; |
107 } | 112 } |
108 | 113 |
109 database_backend_map_[unique_identifier] = database_backend.get(); | 114 database_backend_map_[unique_identifier] = database_backend.get(); |
110 database_backend->DeleteDatabase(callbacks); | 115 database_backend->DeleteDatabase(callbacks); |
111 database_backend_map_.erase(unique_identifier); | 116 database_backend_map_.erase(unique_identifier); |
112 } | 117 } |
113 | 118 |
114 scoped_refptr<IndexedDBBackingStore> IndexedDBFactory::OpenBackingStore( | 119 scoped_refptr<IndexedDBBackingStore> IndexedDBFactory::OpenBackingStore( |
115 const string16& database_identifier, | 120 const string16& database_identifier, |
116 const base::FilePath& data_directory) { | 121 const base::FilePath& data_directory, |
| 122 WebKit::WebIDBCallbacks::DataLoss* data_loss) { |
117 const string16 file_identifier = ComputeFileIdentifier(database_identifier); | 123 const string16 file_identifier = ComputeFileIdentifier(database_identifier); |
118 const bool open_in_memory = data_directory.empty(); | 124 const bool open_in_memory = data_directory.empty(); |
119 | 125 |
120 IndexedDBBackingStoreMap::iterator it2 = | 126 IndexedDBBackingStoreMap::iterator it2 = |
121 backing_store_map_.find(file_identifier); | 127 backing_store_map_.find(file_identifier); |
122 if (it2 != backing_store_map_.end() && it2->second.get()) | 128 if (it2 != backing_store_map_.end() && it2->second.get()) |
123 return it2->second.get(); | 129 return it2->second.get(); |
124 | 130 |
125 scoped_refptr<IndexedDBBackingStore> backing_store; | 131 scoped_refptr<IndexedDBBackingStore> backing_store; |
126 if (open_in_memory) { | 132 if (open_in_memory) { |
127 backing_store = IndexedDBBackingStore::OpenInMemory(file_identifier); | 133 backing_store = IndexedDBBackingStore::OpenInMemory(file_identifier); |
128 } else { | 134 } else { |
129 backing_store = IndexedDBBackingStore::Open( | 135 backing_store = IndexedDBBackingStore::Open( |
130 database_identifier, data_directory, file_identifier); | 136 database_identifier, data_directory, file_identifier, data_loss); |
131 } | 137 } |
132 | 138 |
133 if (backing_store.get()) { | 139 if (backing_store.get()) { |
134 CleanWeakMap(&backing_store_map_); | 140 CleanWeakMap(&backing_store_map_); |
135 backing_store_map_[file_identifier] = backing_store->GetWeakPtr(); | 141 backing_store_map_[file_identifier] = backing_store->GetWeakPtr(); |
136 // If an in-memory database, bind lifetime to this factory instance. | 142 // If an in-memory database, bind lifetime to this factory instance. |
137 if (open_in_memory) | 143 if (open_in_memory) |
138 session_only_backing_stores_.insert(backing_store); | 144 session_only_backing_stores_.insert(backing_store); |
139 | 145 |
140 // All backing stores associated with this factory should be of the same | 146 // All backing stores associated with this factory should be of the same |
(...skipping 14 matching lines...) Expand all Loading... |
155 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> database_callbacks, | 161 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> database_callbacks, |
156 const string16& database_identifier, | 162 const string16& database_identifier, |
157 const base::FilePath& data_directory) { | 163 const base::FilePath& data_directory) { |
158 IDB_TRACE("IndexedDBFactory::Open"); | 164 IDB_TRACE("IndexedDBFactory::Open"); |
159 const string16 unique_identifier = | 165 const string16 unique_identifier = |
160 ComputeUniqueIdentifier(name, database_identifier); | 166 ComputeUniqueIdentifier(name, database_identifier); |
161 | 167 |
162 scoped_refptr<IndexedDBDatabase> database_backend; | 168 scoped_refptr<IndexedDBDatabase> database_backend; |
163 IndexedDBDatabaseMap::iterator it = | 169 IndexedDBDatabaseMap::iterator it = |
164 database_backend_map_.find(unique_identifier); | 170 database_backend_map_.find(unique_identifier); |
| 171 WebKit::WebIDBCallbacks::DataLoss data_loss = |
| 172 WebKit::WebIDBCallbacks::DataLossNone; |
165 if (it == database_backend_map_.end()) { | 173 if (it == database_backend_map_.end()) { |
166 scoped_refptr<IndexedDBBackingStore> backing_store = | 174 scoped_refptr<IndexedDBBackingStore> backing_store = |
167 OpenBackingStore(database_identifier, data_directory); | 175 OpenBackingStore(database_identifier, data_directory, &data_loss); |
168 if (!backing_store.get()) { | 176 if (!backing_store.get()) { |
169 callbacks->OnError(IndexedDBDatabaseError( | 177 callbacks->OnError(IndexedDBDatabaseError( |
170 WebKit::WebIDBDatabaseExceptionUnknownError, | 178 WebKit::WebIDBDatabaseExceptionUnknownError, |
171 ASCIIToUTF16( | 179 ASCIIToUTF16( |
172 "Internal error opening backing store for indexedDB.open."))); | 180 "Internal error opening backing store for indexedDB.open."))); |
173 return; | 181 return; |
174 } | 182 } |
175 | 183 |
176 database_backend = IndexedDBDatabase::Create( | 184 database_backend = IndexedDBDatabase::Create( |
177 name, backing_store.get(), this, unique_identifier); | 185 name, backing_store.get(), this, unique_identifier); |
178 if (!database_backend.get()) { | 186 if (!database_backend.get()) { |
179 callbacks->OnError(IndexedDBDatabaseError( | 187 callbacks->OnError(IndexedDBDatabaseError( |
180 WebKit::WebIDBDatabaseExceptionUnknownError, | 188 WebKit::WebIDBDatabaseExceptionUnknownError, |
181 ASCIIToUTF16( | 189 ASCIIToUTF16( |
182 "Internal error creating database backend for indexedDB.open."))); | 190 "Internal error creating database backend for indexedDB.open."))); |
183 return; | 191 return; |
184 } | 192 } |
185 | 193 |
186 database_backend_map_[unique_identifier] = database_backend.get(); | 194 database_backend_map_[unique_identifier] = database_backend.get(); |
187 } else { | 195 } else { |
188 database_backend = it->second; | 196 database_backend = it->second; |
189 } | 197 } |
190 | 198 |
191 database_backend->OpenConnection( | 199 database_backend->OpenConnection( |
192 callbacks, database_callbacks, transaction_id, version); | 200 callbacks, database_callbacks, transaction_id, version, data_loss); |
193 } | 201 } |
194 | 202 |
195 } // namespace content | 203 } // namespace content |
OLD | NEW |