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

Side by Side Diff: third_party/WebKit/Source/modules/indexeddb/IDBRequest.h

Issue 2822453003: Wrap large IndexedDB values into Blobs before writing to LevelDB. (Closed)
Patch Set: Fixed compilation errors on Windows and no-DCHECKs. 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) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 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 22 matching lines...) Expand all
33 33
34 #include "bindings/core/v8/ScriptValue.h" 34 #include "bindings/core/v8/ScriptValue.h"
35 #include "core/dom/DOMStringList.h" 35 #include "core/dom/DOMStringList.h"
36 #include "core/dom/SuspendableObject.h" 36 #include "core/dom/SuspendableObject.h"
37 #include "core/events/EventListener.h" 37 #include "core/events/EventListener.h"
38 #include "core/events/EventTarget.h" 38 #include "core/events/EventTarget.h"
39 #include "modules/EventModules.h" 39 #include "modules/EventModules.h"
40 #include "modules/ModulesExport.h" 40 #include "modules/ModulesExport.h"
41 #include "modules/indexeddb/IDBAny.h" 41 #include "modules/indexeddb/IDBAny.h"
42 #include "modules/indexeddb/IDBTransaction.h" 42 #include "modules/indexeddb/IDBTransaction.h"
43 #include "modules/indexeddb/IDBValueWrapper.h"
43 #include "modules/indexeddb/IndexedDB.h" 44 #include "modules/indexeddb/IndexedDB.h"
44 #include "platform/bindings/ActiveScriptWrappable.h" 45 #include "platform/bindings/ActiveScriptWrappable.h"
45 #include "platform/bindings/ScriptState.h" 46 #include "platform/bindings/ScriptState.h"
46 #include "platform/blob/BlobData.h" 47 #include "platform/blob/BlobData.h"
47 #include "platform/heap/Handle.h" 48 #include "platform/heap/Handle.h"
48 #include "platform/wtf/HashMap.h" 49 #include "platform/wtf/HashMap.h"
49 #include "public/platform/WebBlobInfo.h" 50 #include "public/platform/WebBlobInfo.h"
50 #include "public/platform/modules/indexeddb/WebIDBCursor.h" 51 #include "public/platform/modules/indexeddb/WebIDBCursor.h"
51 #include "public/platform/modules/indexeddb/WebIDBTypes.h" 52 #include "public/platform/modules/indexeddb/WebIDBTypes.h"
52 53
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 std::unique_ptr<WebIDBCallbacks> CreateWebCallbacks(); 92 std::unique_ptr<WebIDBCallbacks> CreateWebCallbacks();
92 void WebCallbacksDestroyed(); 93 void WebCallbacksDestroyed();
93 94
94 DEFINE_ATTRIBUTE_EVENT_LISTENER(success); 95 DEFINE_ATTRIBUTE_EVENT_LISTENER(success);
95 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); 96 DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
96 97
97 void SetCursorDetails(IndexedDB::CursorType, WebIDBCursorDirection); 98 void SetCursorDetails(IndexedDB::CursorType, WebIDBCursorDirection);
98 void SetPendingCursor(IDBCursor*); 99 void SetPendingCursor(IDBCursor*);
99 void Abort(); 100 void Abort();
100 101
102 void QueueResult(DOMException*);
103 void QueueResult(IDBKey*);
104 void QueueResult(std::unique_ptr<WebIDBCursor>,
105 IDBKey*,
106 IDBKey* primary_key,
107 PassRefPtr<IDBValue>);
108 void QueueResult(PassRefPtr<IDBValue>);
109 void QueueResult(const Vector<RefPtr<IDBValue>>&);
110 void QueueResult(IDBKey*, IDBKey* primary_key, PassRefPtr<IDBValue>);
111
101 virtual void OnError(DOMException*); 112 virtual void OnError(DOMException*);
jsbell 2017/05/05 00:29:37 WDYT about making most of the OnXXXX methods prote
pwnall 2017/05/11 23:54:23 Done. Can't say no to de-virtualizing :)
113 virtual void OnSuccess(IDBKey*);
102 virtual void OnSuccess(const Vector<String>&); 114 virtual void OnSuccess(const Vector<String>&);
103 virtual void OnSuccess(std::unique_ptr<WebIDBCursor>, 115 virtual void OnSuccess(std::unique_ptr<WebIDBCursor>,
104 IDBKey*, 116 IDBKey*,
105 IDBKey* primary_key, 117 IDBKey* primary_key,
106 PassRefPtr<IDBValue>); 118 PassRefPtr<IDBValue>);
107 virtual void OnSuccess(IDBKey*);
108 virtual void OnSuccess(PassRefPtr<IDBValue>); 119 virtual void OnSuccess(PassRefPtr<IDBValue>);
109 virtual void OnSuccess(const Vector<RefPtr<IDBValue>>&); 120 virtual void OnSuccess(const Vector<RefPtr<IDBValue>>&);
110 virtual void OnSuccess(int64_t); 121 virtual void OnSuccess(int64_t);
111 virtual void OnSuccess(); 122 virtual void OnSuccess();
jsbell 2017/05/05 00:29:37 Doesn't this one need a QueueResult() ? if not, ca
pwnall 2017/05/11 23:54:23 Done. Thank you very much for catching this!! FW
112 virtual void OnSuccess(IDBKey*, IDBKey* primary_key, PassRefPtr<IDBValue>); 123 virtual void OnSuccess(IDBKey*, IDBKey* primary_key, PassRefPtr<IDBValue>);
113 124
114 // Only IDBOpenDBRequest instances should receive these: 125 // Only IDBOpenDBRequest instances should receive these:
115 virtual void OnBlocked(int64_t old_version) { NOTREACHED(); } 126 virtual void OnBlocked(int64_t old_version) { NOTREACHED(); }
116 virtual void OnUpgradeNeeded(int64_t old_version, 127 virtual void OnUpgradeNeeded(int64_t old_version,
117 std::unique_ptr<WebIDBDatabase>, 128 std::unique_ptr<WebIDBDatabase>,
118 const IDBDatabaseMetadata&, 129 const IDBDatabaseMetadata&,
119 WebIDBDataLoss, 130 WebIDBDataLoss,
120 String data_loss_message) { 131 String data_loss_message) {
121 NOTREACHED(); 132 NOTREACHED();
122 } 133 }
123 virtual void OnSuccess(std::unique_ptr<WebIDBDatabase>, 134 virtual void OnSuccess(std::unique_ptr<WebIDBDatabase>,
124 const IDBDatabaseMetadata&) { 135 const IDBDatabaseMetadata&) {
125 NOTREACHED(); 136 NOTREACHED();
126 } 137 }
127 138
139 inline void ExtractOutgoingBlobHandlesFrom(IDBValueWrapper* value_wrapper) {
dmurph 2017/05/04 22:27:07 I'd prefer we don't include and depend on the valu
pwnall 2017/05/11 23:54:23 Done.
140 value_wrapper->ExtractBlobDataHandles(&outgoing_blob_handles_);
141 }
142
128 // ScriptWrappable 143 // ScriptWrappable
129 bool HasPendingActivity() const final; 144 bool HasPendingActivity() const final;
130 145
131 // SuspendableObject 146 // SuspendableObject
132 void ContextDestroyed(ExecutionContext*) override; 147 void ContextDestroyed(ExecutionContext*) override;
133 148
134 // EventTarget 149 // EventTarget
135 const AtomicString& InterfaceName() const override; 150 const AtomicString& InterfaceName() const override;
136 ExecutionContext* GetExecutionContext() const final; 151 ExecutionContext* GetExecutionContext() const final;
137 void UncaughtExceptionInEventHandler() final; 152 void UncaughtExceptionInEventHandler() final;
138 153
139 // Called by a version change transaction that has finished to set this 154 // Called by a version change transaction that has finished to set this
140 // request back from DONE (following "upgradeneeded") back to PENDING (for 155 // request back from DONE (following "upgradeneeded") back to PENDING (for
141 // the upcoming "success" or "error"). 156 // the upcoming "success" or "error").
142 void TransactionDidFinishAndDispatch(); 157 void TransactionDidFinishAndDispatch();
143 158
144 IDBCursor* GetResultCursor() const; 159 IDBCursor* GetResultCursor() const;
145 160
146 void StorePutOperationBlobs(
147 HashMap<String, RefPtr<BlobDataHandle>> blob_handles) {
148 transit_blob_handles_ = std::move(blob_handles);
149 }
150
151 protected: 161 protected:
152 IDBRequest(ScriptState*, IDBAny* source, IDBTransaction*); 162 IDBRequest(ScriptState*, IDBAny* source, IDBTransaction*);
153 void EnqueueEvent(Event*); 163 void EnqueueEvent(Event*);
154 void DequeueEvent(Event*); 164 void DequeueEvent(Event*);
155 virtual bool ShouldEnqueueEvent() const; 165 virtual bool ShouldEnqueueEvent() const;
156 void OnSuccessInternal(IDBAny*); 166 void OnSuccessInternal(IDBAny*);
157 void SetResult(IDBAny*); 167 void SetResult(IDBAny*);
158 168
159 // EventTarget 169 // EventTarget
160 DispatchEventResult DispatchEventInternal(Event*) override; 170 DispatchEventResult DispatchEventInternal(Event*) override;
161 171
172 // Can be nullptr for requests that are not associated with a transaction,
173 // i.e. delete requests and unsuccessful open requests.
jsbell 2017/05/05 00:29:37 And completed open requests, IIRC?
pwnall 2017/05/11 23:54:23 Done. Case added. The "i.e." there was intended t
162 Member<IDBTransaction> transaction_; 174 Member<IDBTransaction> transaction_;
175
163 ReadyState ready_state_ = PENDING; 176 ReadyState ready_state_ = PENDING;
164 bool request_aborted_ = false; // May be aborted by transaction then receive 177 bool request_aborted_ = false; // May be aborted by transaction then receive
165 // async onsuccess; ignore vs. assert. 178 // async onsuccess; ignore vs. assert.
166 // Maintain the isolate so that all externally allocated memory can be 179 // Maintain the isolate so that all externally allocated memory can be
167 // registered against it. 180 // registered against it.
168 v8::Isolate* isolate_; 181 v8::Isolate* isolate_;
169 182
170 private: 183 private:
171 void SetResultCursor(IDBCursor*, 184 void SetResultCursor(IDBCursor*,
172 IDBKey*, 185 IDBKey*,
173 IDBKey* primary_key, 186 IDBKey* primary_key,
174 PassRefPtr<IDBValue>); 187 PassRefPtr<IDBValue>);
175 void AckReceivedBlobs(const IDBValue*); 188 void AckReceivedBlobs(const IDBValue*);
176 void AckReceivedBlobs(const Vector<RefPtr<IDBValue>>&); 189 void AckReceivedBlobs(const Vector<RefPtr<IDBValue>>&);
177 190
178 void ClearPutOperationBlobs() { transit_blob_handles_.clear(); }
dmurph 2017/05/04 22:27:07 Requests can take forever for a GC, so please try
pwnall 2017/05/11 23:54:23 I think I was doing that. See the "outgoing_blob_h
179
180 Member<IDBAny> source_; 191 Member<IDBAny> source_;
181 Member<IDBAny> result_; 192 Member<IDBAny> result_;
182 Member<DOMException> error_; 193 Member<DOMException> error_;
183 194
184 bool has_pending_activity_ = true; 195 bool has_pending_activity_ = true;
185 HeapVector<Member<Event>> enqueued_events_; 196 HeapVector<Member<Event>> enqueued_events_;
186 197
187 // Only used if the result type will be a cursor. 198 // Only used if the result type will be a cursor.
188 IndexedDB::CursorType cursor_type_ = IndexedDB::kCursorKeyAndValue; 199 IndexedDB::CursorType cursor_type_ = IndexedDB::kCursorKeyAndValue;
189 WebIDBCursorDirection cursor_direction_ = kWebIDBCursorDirectionNext; 200 WebIDBCursorDirection cursor_direction_ = kWebIDBCursorDirectionNext;
190 // When a cursor is continued/advanced, |result_| is cleared and 201 // When a cursor is continued/advanced, |result_| is cleared and
191 // |pendingCursor_| holds it. 202 // |pendingCursor_| holds it.
192 Member<IDBCursor> pending_cursor_; 203 Member<IDBCursor> pending_cursor_;
193 // New state is not applied to the cursor object until the event is 204 // New state is not applied to the cursor object until the event is
194 // dispatched. 205 // dispatched.
195 Member<IDBKey> cursor_key_; 206 Member<IDBKey> cursor_key_;
196 Member<IDBKey> cursor_primary_key_; 207 Member<IDBKey> cursor_primary_key_;
197 RefPtr<IDBValue> cursor_value_; 208 RefPtr<IDBValue> cursor_value_;
198 209
199 HashMap<String, RefPtr<BlobDataHandle>> transit_blob_handles_; 210 // Keeps blobs alive while they are sent to the browser process.
dmurph 2017/05/04 22:27:07 Any reason for the name change? I like 'transit' b
pwnall 2017/05/11 23:54:23 Done. (switched it back) "transit" seemed generic
211 Vector<RefPtr<BlobDataHandle>> outgoing_blob_handles_;
200 212
201 bool did_fire_upgrade_needed_event_ = false; 213 bool did_fire_upgrade_needed_event_ = false;
202 bool prevent_propagation_ = false; 214 bool prevent_propagation_ = false;
203 bool result_dirty_ = true; 215 bool result_dirty_ = true;
204 216
205 // Transactions should be aborted after event dispatch if an exception was 217 // Transactions should be aborted after event dispatch if an exception was
206 // not caught. This is cleared before dispatch, set by a call to 218 // not caught. This is cleared before dispatch, set by a call to
207 // UncaughtExceptionInEventHandler() during dispatch, and checked afterwards 219 // UncaughtExceptionInEventHandler() during dispatch, and checked afterwards
208 // to abort if necessary. 220 // to abort if necessary.
209 bool did_throw_in_event_handler_ = false; 221 bool did_throw_in_event_handler_ = false;
210 222
211 // Pointer back to the WebIDBCallbacks that holds a persistent reference to 223 // Pointer back to the WebIDBCallbacks that holds a persistent reference to
212 // this object. 224 // this object.
213 WebIDBCallbacks* web_callbacks_ = nullptr; 225 WebIDBCallbacks* web_callbacks_ = nullptr;
214 }; 226 };
215 227
216 } // namespace blink 228 } // namespace blink
217 229
218 #endif // IDBRequest_h 230 #endif // IDBRequest_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698