OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 idbDatabase->close(); | 187 idbDatabase->close(); |
188 } | 188 } |
189 | 189 |
190 private: | 190 private: |
191 OpenDatabaseCallback(ExecutableWithDatabase* executableWithDatabase) | 191 OpenDatabaseCallback(ExecutableWithDatabase* executableWithDatabase) |
192 : EventListener(EventListener::CPPEventListenerType) | 192 : EventListener(EventListener::CPPEventListenerType) |
193 , m_executableWithDatabase(executableWithDatabase) { } | 193 , m_executableWithDatabase(executableWithDatabase) { } |
194 RefPtr<ExecutableWithDatabase> m_executableWithDatabase; | 194 RefPtr<ExecutableWithDatabase> m_executableWithDatabase; |
195 }; | 195 }; |
196 | 196 |
197 class UpgradeDatabaseCallback final : public EventListener { | |
198 public: | |
199 static PassRefPtrWillBeRawPtr<UpgradeDatabaseCallback> create(ExecutableWith Database* executableWithDatabase) | |
200 { | |
201 return adoptRefWillBeNoop(new UpgradeDatabaseCallback(executableWithData base)); | |
202 } | |
203 | |
204 ~UpgradeDatabaseCallback() override { } | |
205 | |
206 bool operator==(const EventListener& other) override | |
207 { | |
208 return this == &other; | |
209 } | |
210 | |
211 void handleEvent(ExecutionContext* context, Event* event) override | |
212 { | |
213 if (event->type() != EventTypeNames::upgradeneeded) { | |
cmumford
2015/10/22 16:10:43
Why not just an ASSERT for this as we're only obse
jsbell
2015/10/22 19:57:31
I'm leaving this as-is (copy/pasta from other hand
| |
214 m_executableWithDatabase->requestCallback()->sendFailure("Unexpected event type."); | |
215 return; | |
216 } | |
217 | |
218 // If an "upgradeneeded" event comes through then the database that | |
219 // had previously been enumerate was deleted. We don't want to | |
cmumford
2015/10/22 16:10:43
s/enumerate/enumerated/
jsbell
2015/10/22 19:57:31
Done.
| |
220 // implicitly re-create it here, so abort the transaction. | |
221 IDBOpenDBRequest* idbOpenDBRequest = static_cast<IDBOpenDBRequest*>(even t->target()); | |
222 NonThrowableExceptionState exceptionState; | |
223 idbOpenDBRequest->transaction()->abort(exceptionState); | |
224 } | |
225 | |
226 private: | |
227 UpgradeDatabaseCallback(ExecutableWithDatabase* executableWithDatabase) | |
228 : EventListener(EventListener::CPPEventListenerType) | |
229 , m_executableWithDatabase(executableWithDatabase) { } | |
230 RefPtr<ExecutableWithDatabase> m_executableWithDatabase; | |
231 }; | |
232 | |
197 void ExecutableWithDatabase::start(IDBFactory* idbFactory, SecurityOrigin*, cons t String& databaseName) | 233 void ExecutableWithDatabase::start(IDBFactory* idbFactory, SecurityOrigin*, cons t String& databaseName) |
198 { | 234 { |
199 RefPtrWillBeRawPtr<OpenDatabaseCallback> callback = OpenDatabaseCallback::cr eate(this); | 235 RefPtrWillBeRawPtr<OpenDatabaseCallback> openCallback = OpenDatabaseCallback ::create(this); |
236 RefPtrWillBeRawPtr<UpgradeDatabaseCallback> upgradeCallback = UpgradeDatabas eCallback::create(this); | |
200 TrackExceptionState exceptionState; | 237 TrackExceptionState exceptionState; |
201 IDBOpenDBRequest* idbOpenDBRequest = idbFactory->open(scriptState(), databas eName, exceptionState); | 238 IDBOpenDBRequest* idbOpenDBRequest = idbFactory->open(scriptState(), databas eName, exceptionState); |
202 if (exceptionState.hadException()) { | 239 if (exceptionState.hadException()) { |
203 requestCallback()->sendFailure("Could not open database."); | 240 requestCallback()->sendFailure("Could not open database."); |
204 return; | 241 return; |
205 } | 242 } |
206 idbOpenDBRequest->addEventListener(EventTypeNames::success, callback, false) ; | 243 idbOpenDBRequest->addEventListener(EventTypeNames::success, openCallback, fa lse); |
244 idbOpenDBRequest->addEventListener(EventTypeNames::upgradeneeded, upgradeCal lback, false); | |
207 } | 245 } |
208 | 246 |
209 static IDBTransaction* transactionForDatabase(ScriptState* scriptState, IDBDatab ase* idbDatabase, const String& objectStoreName, const String& mode = IndexedDBN ames::readonly) | 247 static IDBTransaction* transactionForDatabase(ScriptState* scriptState, IDBDatab ase* idbDatabase, const String& objectStoreName, const String& mode = IndexedDBN ames::readonly) |
210 { | 248 { |
211 TrackExceptionState exceptionState; | 249 TrackExceptionState exceptionState; |
212 StringOrStringSequenceOrDOMStringList scope; | 250 StringOrStringSequenceOrDOMStringList scope; |
213 scope.setString(objectStoreName); | 251 scope.setString(objectStoreName); |
214 IDBTransaction* idbTransaction = idbDatabase->transaction(scriptState, scope , mode, exceptionState); | 252 IDBTransaction* idbTransaction = idbDatabase->transaction(scriptState, scope , mode, exceptionState); |
215 if (exceptionState.hadException()) | 253 if (exceptionState.hadException()) |
216 return nullptr; | 254 return nullptr; |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
789 RefPtr<ClearObjectStore> clearObjectStore = ClearObjectStore::create(scriptS tate, objectStoreName, requestCallback); | 827 RefPtr<ClearObjectStore> clearObjectStore = ClearObjectStore::create(scriptS tate, objectStoreName, requestCallback); |
790 clearObjectStore->start(idbFactory, document->securityOrigin(), databaseName ); | 828 clearObjectStore->start(idbFactory, document->securityOrigin(), databaseName ); |
791 } | 829 } |
792 | 830 |
793 DEFINE_TRACE(InspectorIndexedDBAgent) | 831 DEFINE_TRACE(InspectorIndexedDBAgent) |
794 { | 832 { |
795 InspectorBaseAgent::trace(visitor); | 833 InspectorBaseAgent::trace(visitor); |
796 } | 834 } |
797 | 835 |
798 } // namespace blink | 836 } // namespace blink |
OLD | NEW |