Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(985)

Side by Side Diff: third_party/WebKit/Source/modules/indexeddb/IDBFactory.cpp

Issue 2642943002: Allow closing IndexedDB database before deleting (Closed)
Patch Set: Allow closing IndexedDB database before deleting Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 const String& name, 145 const String& name,
146 ExceptionState& exceptionState) { 146 ExceptionState& exceptionState) {
147 IDB_TRACE("IDBFactory::open"); 147 IDB_TRACE("IDBFactory::open");
148 return openInternal(scriptState, name, IDBDatabaseMetadata::NoVersion, 148 return openInternal(scriptState, name, IDBDatabaseMetadata::NoVersion,
149 exceptionState); 149 exceptionState);
150 } 150 }
151 151
152 IDBOpenDBRequest* IDBFactory::deleteDatabase(ScriptState* scriptState, 152 IDBOpenDBRequest* IDBFactory::deleteDatabase(ScriptState* scriptState,
153 const String& name, 153 const String& name,
154 ExceptionState& exceptionState) { 154 ExceptionState& exceptionState) {
155 return deleteDatabaseInternal(scriptState, name, exceptionState,
156 false /* force_close */);
157 }
158
159 IDBOpenDBRequest* IDBFactory::closeConnectionsAndDeleteDatabase(
160 ScriptState* scriptState,
161 const String& name,
162 ExceptionState& exceptionState) {
163 return deleteDatabaseInternal(scriptState, name, exceptionState,
164 true /* force_close */);
165 }
166
167 IDBOpenDBRequest* IDBFactory::deleteDatabaseInternal(
168 ScriptState* scriptState,
169 const String& name,
170 ExceptionState& exceptionState,
171 bool forceClose) {
155 IDB_TRACE("IDBFactory::deleteDatabase"); 172 IDB_TRACE("IDBFactory::deleteDatabase");
156 IDBDatabase::recordApiCallsHistogram(IDBDeleteDatabaseCall); 173 IDBDatabase::recordApiCallsHistogram(IDBDeleteDatabaseCall);
157 if (!isContextValid(scriptState->getExecutionContext())) 174 if (!isContextValid(scriptState->getExecutionContext()))
158 return nullptr; 175 return nullptr;
159 if (!scriptState->getExecutionContext() 176 if (!scriptState->getExecutionContext()
160 ->getSecurityOrigin() 177 ->getSecurityOrigin()
161 ->canAccessDatabase()) { 178 ->canAccessDatabase()) {
162 exceptionState.throwSecurityError( 179 exceptionState.throwSecurityError(
163 "access to the Indexed Database API is denied in this context."); 180 "access to the Indexed Database API is denied in this context.");
164 return nullptr; 181 return nullptr;
165 } 182 }
166 183
167 IDBOpenDBRequest* request = IDBOpenDBRequest::create( 184 IDBOpenDBRequest* request = IDBOpenDBRequest::create(
168 scriptState, nullptr, 0, IDBDatabaseMetadata::DefaultVersion); 185 scriptState, nullptr, 0, IDBDatabaseMetadata::DefaultVersion);
169 186
170 if (!IndexedDBClient::from(scriptState->getExecutionContext()) 187 if (!IndexedDBClient::from(scriptState->getExecutionContext())
171 ->allowIndexedDB(scriptState->getExecutionContext(), name)) { 188 ->allowIndexedDB(scriptState->getExecutionContext(), name)) {
172 request->onError( 189 request->onError(
173 DOMException::create(UnknownError, permissionDeniedErrorMessage)); 190 DOMException::create(UnknownError, permissionDeniedErrorMessage));
174 return request; 191 return request;
175 } 192 }
176 193
177 Platform::current()->idbFactory()->deleteDatabase( 194 Platform::current()->idbFactory()->deleteDatabase(
178 name, request->createWebCallbacks().release(), 195 name, request->createWebCallbacks().release(),
179 WebSecurityOrigin( 196 WebSecurityOrigin(
180 scriptState->getExecutionContext()->getSecurityOrigin())); 197 scriptState->getExecutionContext()->getSecurityOrigin()),
198 forceClose);
181 return request; 199 return request;
182 } 200 }
183 201
184 short IDBFactory::cmp(ScriptState* scriptState, 202 short IDBFactory::cmp(ScriptState* scriptState,
185 const ScriptValue& firstValue, 203 const ScriptValue& firstValue,
186 const ScriptValue& secondValue, 204 const ScriptValue& secondValue,
187 ExceptionState& exceptionState) { 205 ExceptionState& exceptionState) {
188 IDBKey* first = ScriptValue::to<IDBKey*>(scriptState->isolate(), firstValue, 206 IDBKey* first = ScriptValue::to<IDBKey*>(scriptState->isolate(), firstValue,
189 exceptionState); 207 exceptionState);
190 if (exceptionState.hadException()) 208 if (exceptionState.hadException())
(...skipping 13 matching lines...) Expand all
204 if (!second->isValid()) { 222 if (!second->isValid()) {
205 exceptionState.throwDOMException(DataError, 223 exceptionState.throwDOMException(DataError,
206 IDBDatabase::notValidKeyErrorMessage); 224 IDBDatabase::notValidKeyErrorMessage);
207 return 0; 225 return 0;
208 } 226 }
209 227
210 return static_cast<short>(first->compare(second)); 228 return static_cast<short>(first->compare(second));
211 } 229 }
212 230
213 } // namespace blink 231 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698