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

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

Issue 2349413002: Minor IndexedDB refactorings. (Closed)
Patch Set: Rebased Created 4 years, 2 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) 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 request->suspendIfNeeded(); 45 request->suspendIfNeeded();
46 return request; 46 return request;
47 } 47 }
48 48
49 IDBOpenDBRequest::IDBOpenDBRequest(ScriptState* scriptState, IDBDatabaseCallback s* callbacks, int64_t transactionId, int64_t version) 49 IDBOpenDBRequest::IDBOpenDBRequest(ScriptState* scriptState, IDBDatabaseCallback s* callbacks, int64_t transactionId, int64_t version)
50 : IDBRequest(scriptState, IDBAny::createNull(), nullptr) 50 : IDBRequest(scriptState, IDBAny::createNull(), nullptr)
51 , m_databaseCallbacks(callbacks) 51 , m_databaseCallbacks(callbacks)
52 , m_transactionId(transactionId) 52 , m_transactionId(transactionId)
53 , m_version(version) 53 , m_version(version)
54 { 54 {
55 ASSERT(!resultAsAny()); 55 DCHECK(!resultAsAny());
56 } 56 }
57 57
58 IDBOpenDBRequest::~IDBOpenDBRequest() 58 IDBOpenDBRequest::~IDBOpenDBRequest()
59 { 59 {
60 } 60 }
61 61
62 DEFINE_TRACE(IDBOpenDBRequest) 62 DEFINE_TRACE(IDBOpenDBRequest)
63 { 63 {
64 visitor->trace(m_databaseCallbacks); 64 visitor->trace(m_databaseCallbacks);
65 IDBRequest::trace(visitor); 65 IDBRequest::trace(visitor);
(...skipping 18 matching lines...) Expand all
84 IDB_TRACE("IDBOpenDBRequest::onUpgradeNeeded()"); 84 IDB_TRACE("IDBOpenDBRequest::onUpgradeNeeded()");
85 if (m_contextStopped || !getExecutionContext()) { 85 if (m_contextStopped || !getExecutionContext()) {
86 std::unique_ptr<WebIDBDatabase> db = std::move(backend); 86 std::unique_ptr<WebIDBDatabase> db = std::move(backend);
87 db->abort(m_transactionId); 87 db->abort(m_transactionId);
88 db->close(); 88 db->close();
89 return; 89 return;
90 } 90 }
91 if (!shouldEnqueueEvent()) 91 if (!shouldEnqueueEvent())
92 return; 92 return;
93 93
94 ASSERT(m_databaseCallbacks); 94 DCHECK(m_databaseCallbacks);
95 95
96 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());
97 idbDatabase->setMetadata(metadata); 97 idbDatabase->setMetadata(metadata);
98 98
99 if (oldVersion == IDBDatabaseMetadata::NoVersion) { 99 if (oldVersion == IDBDatabaseMetadata::NoVersion) {
100 // This database hasn't had a version before. 100 // This database hasn't had a version before.
101 oldVersion = IDBDatabaseMetadata::DefaultVersion; 101 oldVersion = IDBDatabaseMetadata::DefaultVersion;
102 } 102 }
103 IDBDatabaseMetadata oldMetadata(metadata); 103 IDBDatabaseMetadata oldMetadata(metadata);
104 oldMetadata.version = oldVersion; 104 oldMetadata.version = oldVersion;
105 105
106 m_transaction = IDBTransaction::create(getScriptState(), m_transactionId, id bDatabase, this, oldMetadata); 106 m_transaction = IDBTransaction::createVersionChange(getScriptState(), m_tran sactionId, idbDatabase, this, oldMetadata);
107 setResult(IDBAny::create(idbDatabase)); 107 setResult(IDBAny::create(idbDatabase));
108 108
109 if (m_version == IDBDatabaseMetadata::NoVersion) 109 if (m_version == IDBDatabaseMetadata::NoVersion)
110 m_version = 1; 110 m_version = 1;
111 enqueueEvent(IDBVersionChangeEvent::create(EventTypeNames::upgradeneeded, ol dVersion, m_version, dataLoss, dataLossMessage)); 111 enqueueEvent(IDBVersionChangeEvent::create(EventTypeNames::upgradeneeded, ol dVersion, m_version, dataLoss, dataLossMessage));
112 } 112 }
113 113
114 void IDBOpenDBRequest::onSuccess(std::unique_ptr<WebIDBDatabase> backend, const IDBDatabaseMetadata& metadata) 114 void IDBOpenDBRequest::onSuccess(std::unique_ptr<WebIDBDatabase> backend, const IDBDatabaseMetadata& metadata)
115 { 115 {
116 IDB_TRACE("IDBOpenDBRequest::onSuccess()"); 116 IDB_TRACE("IDBOpenDBRequest::onSuccess()");
117 if (m_contextStopped || !getExecutionContext()) { 117 if (m_contextStopped || !getExecutionContext()) {
118 std::unique_ptr<WebIDBDatabase> db = std::move(backend); 118 std::unique_ptr<WebIDBDatabase> db = std::move(backend);
119 if (db) 119 if (db)
120 db->close(); 120 db->close();
121 return; 121 return;
122 } 122 }
123 if (!shouldEnqueueEvent()) 123 if (!shouldEnqueueEvent())
124 return; 124 return;
125 125
126 IDBDatabase* idbDatabase = nullptr; 126 IDBDatabase* idbDatabase = nullptr;
127 if (resultAsAny()) { 127 if (resultAsAny()) {
128 // Previous onUpgradeNeeded call delivered the backend. 128 // Previous onUpgradeNeeded call delivered the backend.
129 ASSERT(!backend.get()); 129 DCHECK(!backend.get());
130 idbDatabase = resultAsAny()->idbDatabase(); 130 idbDatabase = resultAsAny()->idbDatabase();
131 ASSERT(idbDatabase); 131 DCHECK(idbDatabase);
132 ASSERT(!m_databaseCallbacks); 132 DCHECK(!m_databaseCallbacks);
133 } else { 133 } else {
134 ASSERT(backend.get()); 134 DCHECK(backend.get());
135 ASSERT(m_databaseCallbacks); 135 DCHECK(m_databaseCallbacks);
136 idbDatabase = IDBDatabase::create(getExecutionContext(), std::move(backe nd), m_databaseCallbacks.release()); 136 idbDatabase = IDBDatabase::create(getExecutionContext(), std::move(backe nd), m_databaseCallbacks.release());
137 setResult(IDBAny::create(idbDatabase)); 137 setResult(IDBAny::create(idbDatabase));
138 } 138 }
139 idbDatabase->setMetadata(metadata); 139 idbDatabase->setMetadata(metadata);
140 enqueueEvent(Event::create(EventTypeNames::success)); 140 enqueueEvent(Event::create(EventTypeNames::success));
141 } 141 }
142 142
143 void IDBOpenDBRequest::onSuccess(int64_t oldVersion) 143 void IDBOpenDBRequest::onSuccess(int64_t oldVersion)
144 { 144 {
145 IDB_TRACE("IDBOpenDBRequest::onSuccess()"); 145 IDB_TRACE("IDBOpenDBRequest::onSuccess()");
146 if (!shouldEnqueueEvent()) 146 if (!shouldEnqueueEvent())
147 return; 147 return;
148 if (oldVersion == IDBDatabaseMetadata::NoVersion) { 148 if (oldVersion == IDBDatabaseMetadata::NoVersion) {
149 // This database hasn't had an integer version before. 149 // This database hasn't had an integer version before.
150 oldVersion = IDBDatabaseMetadata::DefaultVersion; 150 oldVersion = IDBDatabaseMetadata::DefaultVersion;
151 } 151 }
152 setResult(IDBAny::createUndefined()); 152 setResult(IDBAny::createUndefined());
153 enqueueEvent(IDBVersionChangeEvent::create(EventTypeNames::success, oldVersi on, Nullable<unsigned long long>())); 153 enqueueEvent(IDBVersionChangeEvent::create(EventTypeNames::success, oldVersi on, Nullable<unsigned long long>()));
154 } 154 }
155 155
156 bool IDBOpenDBRequest::shouldEnqueueEvent() const 156 bool IDBOpenDBRequest::shouldEnqueueEvent() const
157 { 157 {
158 if (m_contextStopped || !getExecutionContext()) 158 if (m_contextStopped || !getExecutionContext())
159 return false; 159 return false;
160 ASSERT(m_readyState == PENDING || m_readyState == DONE); 160 DCHECK(m_readyState == PENDING || m_readyState == DONE);
161 if (m_requestAborted) 161 if (m_requestAborted)
162 return false; 162 return false;
163 return true; 163 return true;
164 } 164 }
165 165
166 DispatchEventResult IDBOpenDBRequest::dispatchEventInternal(Event* event) 166 DispatchEventResult IDBOpenDBRequest::dispatchEventInternal(Event* event)
167 { 167 {
168 // If the connection closed between onUpgradeNeeded and the delivery of the "success" event, 168 // If the connection closed between onUpgradeNeeded and the delivery of the "success" event,
169 // an "error" event should be fired instead. 169 // an "error" event should be fired instead.
170 if (event->type() == EventTypeNames::success && resultAsAny()->getType() == IDBAny::IDBDatabaseType && resultAsAny()->idbDatabase()->isClosePending()) { 170 if (event->type() == EventTypeNames::success && resultAsAny()->getType() == IDBAny::IDBDatabaseType && resultAsAny()->idbDatabase()->isClosePending()) {
171 dequeueEvent(event); 171 dequeueEvent(event);
172 setResult(nullptr); 172 setResult(nullptr);
173 onError(DOMException::create(AbortError, "The connection was closed.")); 173 onError(DOMException::create(AbortError, "The connection was closed."));
174 return DispatchEventResult::CanceledBeforeDispatch; 174 return DispatchEventResult::CanceledBeforeDispatch;
175 } 175 }
176 176
177 return IDBRequest::dispatchEventInternal(event); 177 return IDBRequest::dispatchEventInternal(event);
178 } 178 }
179 179
180 } // namespace blink 180 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698