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

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

Issue 2870803002: Rename IDBRequest::On* callbacks to IDBRequest::Enqueue*. (Closed)
Patch Set: De-virtualized one more callback. Created 3 years, 7 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 void IDBOpenDBRequest::ContextDestroyed(ExecutionContext* destroyed_context) { 70 void IDBOpenDBRequest::ContextDestroyed(ExecutionContext* destroyed_context) {
71 IDBRequest::ContextDestroyed(destroyed_context); 71 IDBRequest::ContextDestroyed(destroyed_context);
72 if (database_callbacks_) 72 if (database_callbacks_)
73 database_callbacks_->DetachWebCallbacks(); 73 database_callbacks_->DetachWebCallbacks();
74 } 74 }
75 75
76 const AtomicString& IDBOpenDBRequest::InterfaceName() const { 76 const AtomicString& IDBOpenDBRequest::InterfaceName() const {
77 return EventTargetNames::IDBOpenDBRequest; 77 return EventTargetNames::IDBOpenDBRequest;
78 } 78 }
79 79
80 void IDBOpenDBRequest::OnBlocked(int64_t old_version) { 80 void IDBOpenDBRequest::EnqueueBlocked(int64_t old_version) {
81 IDB_TRACE("IDBOpenDBRequest::onBlocked()"); 81 IDB_TRACE("IDBOpenDBRequest::onBlocked()");
82 if (!ShouldEnqueueEvent()) 82 if (!ShouldEnqueueEvent())
83 return; 83 return;
84 Nullable<unsigned long long> new_version_nullable = 84 Nullable<unsigned long long> new_version_nullable =
85 (version_ == IDBDatabaseMetadata::kDefaultVersion) 85 (version_ == IDBDatabaseMetadata::kDefaultVersion)
86 ? Nullable<unsigned long long>() 86 ? Nullable<unsigned long long>()
87 : Nullable<unsigned long long>(version_); 87 : Nullable<unsigned long long>(version_);
88 EnqueueEvent(IDBVersionChangeEvent::Create( 88 EnqueueEvent(IDBVersionChangeEvent::Create(
89 EventTypeNames::blocked, old_version, new_version_nullable)); 89 EventTypeNames::blocked, old_version, new_version_nullable));
90 } 90 }
91 91
92 void IDBOpenDBRequest::OnUpgradeNeeded(int64_t old_version, 92 void IDBOpenDBRequest::EnqueueUpgradeNeeded(
93 std::unique_ptr<WebIDBDatabase> backend, 93 int64_t old_version,
94 const IDBDatabaseMetadata& metadata, 94 std::unique_ptr<WebIDBDatabase> backend,
95 WebIDBDataLoss data_loss, 95 const IDBDatabaseMetadata& metadata,
96 String data_loss_message) { 96 WebIDBDataLoss data_loss,
97 String data_loss_message) {
97 IDB_TRACE("IDBOpenDBRequest::onUpgradeNeeded()"); 98 IDB_TRACE("IDBOpenDBRequest::onUpgradeNeeded()");
98 if (!ShouldEnqueueEvent()) 99 if (!ShouldEnqueueEvent())
99 return; 100 return;
100 101
101 DCHECK(database_callbacks_); 102 DCHECK(database_callbacks_);
102 103
103 IDBDatabase* idb_database = 104 IDBDatabase* idb_database =
104 IDBDatabase::Create(GetExecutionContext(), std::move(backend), 105 IDBDatabase::Create(GetExecutionContext(), std::move(backend),
105 database_callbacks_.Release(), isolate_); 106 database_callbacks_.Release(), isolate_);
106 idb_database->SetMetadata(metadata); 107 idb_database->SetMetadata(metadata);
(...skipping 10 matching lines...) Expand all
117 old_database_metadata); 118 old_database_metadata);
118 SetResult(IDBAny::Create(idb_database)); 119 SetResult(IDBAny::Create(idb_database));
119 120
120 if (version_ == IDBDatabaseMetadata::kNoVersion) 121 if (version_ == IDBDatabaseMetadata::kNoVersion)
121 version_ = 1; 122 version_ = 1;
122 EnqueueEvent(IDBVersionChangeEvent::Create(EventTypeNames::upgradeneeded, 123 EnqueueEvent(IDBVersionChangeEvent::Create(EventTypeNames::upgradeneeded,
123 old_version, version_, data_loss, 124 old_version, version_, data_loss,
124 data_loss_message)); 125 data_loss_message));
125 } 126 }
126 127
127 void IDBOpenDBRequest::OnSuccess(std::unique_ptr<WebIDBDatabase> backend, 128 void IDBOpenDBRequest::EnqueueResponse(std::unique_ptr<WebIDBDatabase> backend,
128 const IDBDatabaseMetadata& metadata) { 129 const IDBDatabaseMetadata& metadata) {
129 IDB_TRACE("IDBOpenDBRequest::onSuccess()"); 130 IDB_TRACE("IDBOpenDBRequest::onSuccess()");
130 if (!ShouldEnqueueEvent()) 131 if (!ShouldEnqueueEvent())
131 return; 132 return;
132 133
133 IDBDatabase* idb_database = nullptr; 134 IDBDatabase* idb_database = nullptr;
134 if (ResultAsAny()) { 135 if (ResultAsAny()) {
135 // Previous OnUpgradeNeeded call delivered the backend. 136 // Previous OnUpgradeNeeded call delivered the backend.
136 DCHECK(!backend.get()); 137 DCHECK(!backend.get());
137 idb_database = ResultAsAny()->IdbDatabase(); 138 idb_database = ResultAsAny()->IdbDatabase();
138 DCHECK(idb_database); 139 DCHECK(idb_database);
139 DCHECK(!database_callbacks_); 140 DCHECK(!database_callbacks_);
140 } else { 141 } else {
141 DCHECK(backend.get()); 142 DCHECK(backend.get());
142 DCHECK(database_callbacks_); 143 DCHECK(database_callbacks_);
143 idb_database = 144 idb_database =
144 IDBDatabase::Create(GetExecutionContext(), std::move(backend), 145 IDBDatabase::Create(GetExecutionContext(), std::move(backend),
145 database_callbacks_.Release(), isolate_); 146 database_callbacks_.Release(), isolate_);
146 SetResult(IDBAny::Create(idb_database)); 147 SetResult(IDBAny::Create(idb_database));
147 } 148 }
148 idb_database->SetMetadata(metadata); 149 idb_database->SetMetadata(metadata);
149 EnqueueEvent(Event::Create(EventTypeNames::success)); 150 EnqueueEvent(Event::Create(EventTypeNames::success));
150 } 151 }
151 152
152 void IDBOpenDBRequest::OnSuccess(int64_t old_version) { 153 void IDBOpenDBRequest::EnqueueResponse(int64_t old_version) {
153 IDB_TRACE("IDBOpenDBRequest::onSuccess()"); 154 IDB_TRACE("IDBOpenDBRequest::onSuccess()");
154 if (!ShouldEnqueueEvent()) 155 if (!ShouldEnqueueEvent())
155 return; 156 return;
156 if (old_version == IDBDatabaseMetadata::kNoVersion) { 157 if (old_version == IDBDatabaseMetadata::kNoVersion) {
157 // This database hasn't had an integer version before. 158 // This database hasn't had an integer version before.
158 old_version = IDBDatabaseMetadata::kDefaultVersion; 159 old_version = IDBDatabaseMetadata::kDefaultVersion;
159 } 160 }
160 SetResult(IDBAny::CreateUndefined()); 161 SetResult(IDBAny::CreateUndefined());
161 EnqueueEvent(IDBVersionChangeEvent::Create( 162 EnqueueEvent(IDBVersionChangeEvent::Create(
162 EventTypeNames::success, old_version, Nullable<unsigned long long>())); 163 EventTypeNames::success, old_version, Nullable<unsigned long long>()));
163 } 164 }
164 165
165 bool IDBOpenDBRequest::ShouldEnqueueEvent() const { 166 bool IDBOpenDBRequest::ShouldEnqueueEvent() const {
166 if (!GetExecutionContext()) 167 if (!GetExecutionContext())
167 return false; 168 return false;
168 DCHECK(ready_state_ == PENDING || ready_state_ == DONE); 169 DCHECK(ready_state_ == PENDING || ready_state_ == DONE);
169 if (request_aborted_) 170 if (request_aborted_)
170 return false; 171 return false;
171 return true; 172 return true;
172 } 173 }
173 174
174 DispatchEventResult IDBOpenDBRequest::DispatchEventInternal(Event* event) { 175 DispatchEventResult IDBOpenDBRequest::DispatchEventInternal(Event* event) {
175 // If the connection closed between onUpgradeNeeded and the delivery of the 176 // If the connection closed between onUpgradeNeeded and the delivery of the
176 // "success" event, an "error" event should be fired instead. 177 // "success" event, an "error" event should be fired instead.
177 if (event->type() == EventTypeNames::success && 178 if (event->type() == EventTypeNames::success &&
178 ResultAsAny()->GetType() == IDBAny::kIDBDatabaseType && 179 ResultAsAny()->GetType() == IDBAny::kIDBDatabaseType &&
179 ResultAsAny()->IdbDatabase()->IsClosePending()) { 180 ResultAsAny()->IdbDatabase()->IsClosePending()) {
180 DequeueEvent(event); 181 DequeueEvent(event);
181 SetResult(nullptr); 182 SetResult(nullptr);
182 OnError(DOMException::Create(kAbortError, "The connection was closed.")); 183 EnqueueResponse(
184 DOMException::Create(kAbortError, "The connection was closed."));
183 return DispatchEventResult::kCanceledBeforeDispatch; 185 return DispatchEventResult::kCanceledBeforeDispatch;
184 } 186 }
185 187
186 return IDBRequest::DispatchEventInternal(event); 188 return IDBRequest::DispatchEventInternal(event);
187 } 189 }
188 190
189 } // namespace blink 191 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698