OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 : m_version(version) | 86 : m_version(version) |
87 , m_callbacks(callbacks) | 87 , m_callbacks(callbacks) |
88 , m_databaseCallbacks(databaseCallbacks) | 88 , m_databaseCallbacks(databaseCallbacks) |
89 { | 89 { |
90 } | 90 } |
91 String m_version; | 91 String m_version; |
92 RefPtr<IDBCallbacks> m_callbacks; | 92 RefPtr<IDBCallbacks> m_callbacks; |
93 RefPtr<IDBDatabaseCallbacks> m_databaseCallbacks; | 93 RefPtr<IDBDatabaseCallbacks> m_databaseCallbacks; |
94 }; | 94 }; |
95 | 95 |
96 PassRefPtr<IDBDatabaseBackendImpl> IDBDatabaseBackendImpl::create(const String&
name, IDBBackingStore* database, IDBTransactionCoordinator* coordinator, IDBFact
oryBackendImpl* factory, const String& uniqueIdentifier) | |
97 { | |
98 RefPtr<IDBDatabaseBackendImpl> backend = adoptRef(new IDBDatabaseBackendImpl
(name, database, coordinator, factory, uniqueIdentifier)); | |
99 if (!backend->openInternal()) | |
100 return 0; | |
101 return backend.release(); | |
102 } | |
103 | |
104 IDBDatabaseBackendImpl::IDBDatabaseBackendImpl(const String& name, IDBBackingSto
re* backingStore, IDBTransactionCoordinator* coordinator, IDBFactoryBackendImpl*
factory, const String& uniqueIdentifier) | 96 IDBDatabaseBackendImpl::IDBDatabaseBackendImpl(const String& name, IDBBackingSto
re* backingStore, IDBTransactionCoordinator* coordinator, IDBFactoryBackendImpl*
factory, const String& uniqueIdentifier) |
105 : m_backingStore(backingStore) | 97 : m_backingStore(backingStore) |
106 , m_id(InvalidId) | 98 , m_id(InvalidId) |
107 , m_name(name) | 99 , m_name(name) |
108 , m_version("") | 100 , m_version("") |
109 , m_identifier(uniqueIdentifier) | 101 , m_identifier(uniqueIdentifier) |
110 , m_factory(factory) | 102 , m_factory(factory) |
111 , m_transactionCoordinator(coordinator) | 103 , m_transactionCoordinator(coordinator) |
112 { | 104 { |
113 ASSERT(!m_name.isNull()); | 105 ASSERT(!m_name.isNull()); |
| 106 openInternal(); |
114 } | 107 } |
115 | 108 |
116 bool IDBDatabaseBackendImpl::openInternal() | 109 void IDBDatabaseBackendImpl::openInternal() |
117 { | 110 { |
118 bool success = m_backingStore->getIDBDatabaseMetaData(m_name, m_version, m_i
d); | 111 bool success = m_backingStore->getIDBDatabaseMetaData(m_name, m_version, m_i
d); |
119 ASSERT(success == (m_id != InvalidId)); | 112 ASSERT(success == (m_id != InvalidId)); |
120 if (success) { | 113 if (success) { |
121 loadObjectStores(); | 114 loadObjectStores(); |
122 return true; | 115 return; |
123 } | 116 } |
124 return m_backingStore->createIDBDatabaseMetaData(m_name, m_version, m_id); | 117 if (!m_backingStore->createIDBDatabaseMetaData(m_name, m_version, m_id)) |
| 118 ASSERT_NOT_REACHED(); // FIXME: Need better error handling. |
125 } | 119 } |
126 | 120 |
127 IDBDatabaseBackendImpl::~IDBDatabaseBackendImpl() | 121 IDBDatabaseBackendImpl::~IDBDatabaseBackendImpl() |
128 { | 122 { |
129 m_factory->removeIDBDatabaseBackend(m_identifier); | 123 m_factory->removeIDBDatabaseBackend(m_identifier); |
130 } | 124 } |
131 | 125 |
132 PassRefPtr<IDBBackingStore> IDBDatabaseBackendImpl::backingStore() const | 126 PassRefPtr<IDBBackingStore> IDBDatabaseBackendImpl::backingStore() const |
133 { | 127 { |
134 return m_backingStore; | 128 return m_backingStore; |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 void IDBDatabaseBackendImpl::open(PassRefPtr<IDBDatabaseCallbacks> callbacks) | 318 void IDBDatabaseBackendImpl::open(PassRefPtr<IDBDatabaseCallbacks> callbacks) |
325 { | 319 { |
326 m_databaseCallbacksSet.add(RefPtr<IDBDatabaseCallbacks>(callbacks)); | 320 m_databaseCallbacksSet.add(RefPtr<IDBDatabaseCallbacks>(callbacks)); |
327 } | 321 } |
328 | 322 |
329 void IDBDatabaseBackendImpl::openConnection(PassRefPtr<IDBCallbacks> callbacks) | 323 void IDBDatabaseBackendImpl::openConnection(PassRefPtr<IDBCallbacks> callbacks) |
330 { | 324 { |
331 if (!m_pendingDeleteCalls.isEmpty() || m_runningVersionChangeTransaction ||
!m_pendingSetVersionCalls.isEmpty()) | 325 if (!m_pendingDeleteCalls.isEmpty() || m_runningVersionChangeTransaction ||
!m_pendingSetVersionCalls.isEmpty()) |
332 m_pendingOpenCalls.append(PendingOpenCall::create(callbacks)); | 326 m_pendingOpenCalls.append(PendingOpenCall::create(callbacks)); |
333 else { | 327 else { |
334 if (m_id == InvalidId && !openInternal()) | 328 if (m_id == InvalidId) |
335 callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UN
KNOWN_ERR, "Internal error.")); | 329 openInternal(); |
336 else | 330 callbacks->onSuccess(this); |
337 callbacks->onSuccess(this); | |
338 } | 331 } |
339 } | 332 } |
340 | 333 |
341 void IDBDatabaseBackendImpl::deleteDatabase(PassRefPtr<IDBCallbacks> prpCallback
s) | 334 void IDBDatabaseBackendImpl::deleteDatabase(PassRefPtr<IDBCallbacks> prpCallback
s) |
342 { | 335 { |
343 if (m_runningVersionChangeTransaction || !m_pendingSetVersionCalls.isEmpty()
) { | 336 if (m_runningVersionChangeTransaction || !m_pendingSetVersionCalls.isEmpty()
) { |
344 m_pendingDeleteCalls.append(PendingDeleteCall::create(prpCallbacks)); | 337 m_pendingDeleteCalls.append(PendingDeleteCall::create(prpCallbacks)); |
345 return; | 338 return; |
346 } | 339 } |
347 RefPtr<IDBCallbacks> callbacks = prpCallbacks; | 340 RefPtr<IDBCallbacks> callbacks = prpCallbacks; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 | 403 |
411 void IDBDatabaseBackendImpl::resetVersion(ScriptExecutionContext*, PassRefPtr<ID
BDatabaseBackendImpl> database, const String& version) | 404 void IDBDatabaseBackendImpl::resetVersion(ScriptExecutionContext*, PassRefPtr<ID
BDatabaseBackendImpl> database, const String& version) |
412 { | 405 { |
413 database->m_version = version; | 406 database->m_version = version; |
414 } | 407 } |
415 | 408 |
416 | 409 |
417 } // namespace WebCore | 410 } // namespace WebCore |
418 | 411 |
419 #endif // ENABLE(INDEXED_DATABASE) | 412 #endif // ENABLE(INDEXED_DATABASE) |
OLD | NEW |