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 | 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 15 matching lines...) Expand all Loading... |
26 #include "modules/indexeddb/IDBOpenDBRequest.h" | 26 #include "modules/indexeddb/IDBOpenDBRequest.h" |
27 | 27 |
28 #include "bindings/core/v8/Nullable.h" | 28 #include "bindings/core/v8/Nullable.h" |
29 #include "core/dom/DOMException.h" | 29 #include "core/dom/DOMException.h" |
30 #include "core/dom/ExceptionCode.h" | 30 #include "core/dom/ExceptionCode.h" |
31 #include "core/dom/ExecutionContext.h" | 31 #include "core/dom/ExecutionContext.h" |
32 #include "modules/indexeddb/IDBDatabase.h" | 32 #include "modules/indexeddb/IDBDatabase.h" |
33 #include "modules/indexeddb/IDBDatabaseCallbacks.h" | 33 #include "modules/indexeddb/IDBDatabaseCallbacks.h" |
34 #include "modules/indexeddb/IDBTracing.h" | 34 #include "modules/indexeddb/IDBTracing.h" |
35 #include "modules/indexeddb/IDBVersionChangeEvent.h" | 35 #include "modules/indexeddb/IDBVersionChangeEvent.h" |
36 #include <memory> | |
37 | 36 |
38 using blink::WebIDBDatabase; | 37 using blink::WebIDBDatabase; |
39 | 38 |
40 namespace blink { | 39 namespace blink { |
41 | 40 |
42 IDBOpenDBRequest* IDBOpenDBRequest::create(ScriptState* scriptState, IDBDatabase
Callbacks* callbacks, int64_t transactionId, int64_t version) | 41 IDBOpenDBRequest* IDBOpenDBRequest::create(ScriptState* scriptState, IDBDatabase
Callbacks* callbacks, int64_t transactionId, int64_t version) |
43 { | 42 { |
44 IDBOpenDBRequest* request = new IDBOpenDBRequest(scriptState, callbacks, tra
nsactionId, version); | 43 IDBOpenDBRequest* request = new IDBOpenDBRequest(scriptState, callbacks, tra
nsactionId, version); |
45 request->suspendIfNeeded(); | 44 request->suspendIfNeeded(); |
46 return request; | 45 return request; |
(...skipping 25 matching lines...) Expand all Loading... |
72 | 71 |
73 void IDBOpenDBRequest::onBlocked(int64_t oldVersion) | 72 void IDBOpenDBRequest::onBlocked(int64_t oldVersion) |
74 { | 73 { |
75 IDB_TRACE("IDBOpenDBRequest::onBlocked()"); | 74 IDB_TRACE("IDBOpenDBRequest::onBlocked()"); |
76 if (!shouldEnqueueEvent()) | 75 if (!shouldEnqueueEvent()) |
77 return; | 76 return; |
78 Nullable<unsigned long long> newVersionNullable = (m_version == IDBDatabaseM
etadata::DefaultVersion) ? Nullable<unsigned long long>() : Nullable<unsigned lo
ng long>(m_version); | 77 Nullable<unsigned long long> newVersionNullable = (m_version == IDBDatabaseM
etadata::DefaultVersion) ? Nullable<unsigned long long>() : Nullable<unsigned lo
ng long>(m_version); |
79 enqueueEvent(IDBVersionChangeEvent::create(EventTypeNames::blocked, oldVersi
on, newVersionNullable)); | 78 enqueueEvent(IDBVersionChangeEvent::create(EventTypeNames::blocked, oldVersi
on, newVersionNullable)); |
80 } | 79 } |
81 | 80 |
82 void IDBOpenDBRequest::onUpgradeNeeded(int64_t oldVersion, std::unique_ptr<WebID
BDatabase> backend, const IDBDatabaseMetadata& metadata, WebIDBDataLoss dataLoss
, String dataLossMessage) | 81 void IDBOpenDBRequest::onUpgradeNeeded(int64_t oldVersion, PassOwnPtr<WebIDBData
base> backend, const IDBDatabaseMetadata& metadata, WebIDBDataLoss dataLoss, Str
ing dataLossMessage) |
83 { | 82 { |
84 IDB_TRACE("IDBOpenDBRequest::onUpgradeNeeded()"); | 83 IDB_TRACE("IDBOpenDBRequest::onUpgradeNeeded()"); |
85 if (m_contextStopped || !getExecutionContext()) { | 84 if (m_contextStopped || !getExecutionContext()) { |
86 std::unique_ptr<WebIDBDatabase> db = std::move(backend); | 85 OwnPtr<WebIDBDatabase> db = std::move(backend); |
87 db->abort(m_transactionId); | 86 db->abort(m_transactionId); |
88 db->close(); | 87 db->close(); |
89 return; | 88 return; |
90 } | 89 } |
91 if (!shouldEnqueueEvent()) | 90 if (!shouldEnqueueEvent()) |
92 return; | 91 return; |
93 | 92 |
94 ASSERT(m_databaseCallbacks); | 93 ASSERT(m_databaseCallbacks); |
95 | 94 |
96 IDBDatabase* idbDatabase = IDBDatabase::create(getExecutionContext(), std::m
ove(backend), m_databaseCallbacks.release()); | 95 IDBDatabase* idbDatabase = IDBDatabase::create(getExecutionContext(), std::m
ove(backend), m_databaseCallbacks.release()); |
97 idbDatabase->setMetadata(metadata); | 96 idbDatabase->setMetadata(metadata); |
98 | 97 |
99 if (oldVersion == IDBDatabaseMetadata::NoVersion) { | 98 if (oldVersion == IDBDatabaseMetadata::NoVersion) { |
100 // This database hasn't had a version before. | 99 // This database hasn't had a version before. |
101 oldVersion = IDBDatabaseMetadata::DefaultVersion; | 100 oldVersion = IDBDatabaseMetadata::DefaultVersion; |
102 } | 101 } |
103 IDBDatabaseMetadata oldMetadata(metadata); | 102 IDBDatabaseMetadata oldMetadata(metadata); |
104 oldMetadata.version = oldVersion; | 103 oldMetadata.version = oldVersion; |
105 | 104 |
106 m_transaction = IDBTransaction::create(getScriptState(), m_transactionId, id
bDatabase, this, oldMetadata); | 105 m_transaction = IDBTransaction::create(getScriptState(), m_transactionId, id
bDatabase, this, oldMetadata); |
107 setResult(IDBAny::create(idbDatabase)); | 106 setResult(IDBAny::create(idbDatabase)); |
108 | 107 |
109 if (m_version == IDBDatabaseMetadata::NoVersion) | 108 if (m_version == IDBDatabaseMetadata::NoVersion) |
110 m_version = 1; | 109 m_version = 1; |
111 enqueueEvent(IDBVersionChangeEvent::create(EventTypeNames::upgradeneeded, ol
dVersion, m_version, dataLoss, dataLossMessage)); | 110 enqueueEvent(IDBVersionChangeEvent::create(EventTypeNames::upgradeneeded, ol
dVersion, m_version, dataLoss, dataLossMessage)); |
112 } | 111 } |
113 | 112 |
114 void IDBOpenDBRequest::onSuccess(std::unique_ptr<WebIDBDatabase> backend, const
IDBDatabaseMetadata& metadata) | 113 void IDBOpenDBRequest::onSuccess(PassOwnPtr<WebIDBDatabase> backend, const IDBDa
tabaseMetadata& metadata) |
115 { | 114 { |
116 IDB_TRACE("IDBOpenDBRequest::onSuccess()"); | 115 IDB_TRACE("IDBOpenDBRequest::onSuccess()"); |
117 if (m_contextStopped || !getExecutionContext()) { | 116 if (m_contextStopped || !getExecutionContext()) { |
118 std::unique_ptr<WebIDBDatabase> db = std::move(backend); | 117 OwnPtr<WebIDBDatabase> db = std::move(backend); |
119 if (db) | 118 if (db) |
120 db->close(); | 119 db->close(); |
121 return; | 120 return; |
122 } | 121 } |
123 if (!shouldEnqueueEvent()) | 122 if (!shouldEnqueueEvent()) |
124 return; | 123 return; |
125 | 124 |
126 IDBDatabase* idbDatabase = nullptr; | 125 IDBDatabase* idbDatabase = nullptr; |
127 if (resultAsAny()) { | 126 if (resultAsAny()) { |
128 // Previous onUpgradeNeeded call delivered the backend. | 127 // Previous onUpgradeNeeded call delivered the backend. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 dequeueEvent(event); | 170 dequeueEvent(event); |
172 setResult(nullptr); | 171 setResult(nullptr); |
173 onError(DOMException::create(AbortError, "The connection was closed.")); | 172 onError(DOMException::create(AbortError, "The connection was closed.")); |
174 return DispatchEventResult::CanceledBeforeDispatch; | 173 return DispatchEventResult::CanceledBeforeDispatch; |
175 } | 174 } |
176 | 175 |
177 return IDBRequest::dispatchEventInternal(event); | 176 return IDBRequest::dispatchEventInternal(event); |
178 } | 177 } |
179 | 178 |
180 } // namespace blink | 179 } // namespace blink |
OLD | NEW |