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