Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 13 matching lines...) Expand all Loading... | |
| 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #ifndef IDBRequest_h | 29 #ifndef IDBRequest_h |
| 30 #define IDBRequest_h | 30 #define IDBRequest_h |
| 31 | 31 |
| 32 #include <memory> | 32 #include <memory> |
| 33 | 33 |
| 34 #include "base/macros.h" | |
| 34 #include "bindings/core/v8/ScriptValue.h" | 35 #include "bindings/core/v8/ScriptValue.h" |
| 35 #include "core/dom/DOMStringList.h" | 36 #include "core/dom/DOMStringList.h" |
| 36 #include "core/dom/SuspendableObject.h" | 37 #include "core/dom/SuspendableObject.h" |
| 37 #include "core/events/EventListener.h" | 38 #include "core/events/EventListener.h" |
| 38 #include "core/events/EventTarget.h" | 39 #include "core/events/EventTarget.h" |
| 39 #include "modules/EventModules.h" | 40 #include "modules/EventModules.h" |
| 40 #include "modules/ModulesExport.h" | 41 #include "modules/ModulesExport.h" |
| 41 #include "modules/indexeddb/IDBAny.h" | 42 #include "modules/indexeddb/IDBAny.h" |
| 42 #include "modules/indexeddb/IDBTransaction.h" | 43 #include "modules/indexeddb/IDBTransaction.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" |
| 50 #include "platform/wtf/Time.h" | |
| 49 #include "public/platform/WebBlobInfo.h" | 51 #include "public/platform/WebBlobInfo.h" |
| 50 #include "public/platform/modules/indexeddb/WebIDBCursor.h" | 52 #include "public/platform/modules/indexeddb/WebIDBCursor.h" |
| 51 #include "public/platform/modules/indexeddb/WebIDBTypes.h" | 53 #include "public/platform/modules/indexeddb/WebIDBTypes.h" |
| 52 | 54 |
| 53 namespace blink { | 55 namespace blink { |
| 54 | 56 |
| 55 class DOMException; | 57 class DOMException; |
| 56 class ExceptionState; | 58 class ExceptionState; |
| 57 class IDBCursor; | 59 class IDBCursor; |
| 58 struct IDBDatabaseMetadata; | 60 struct IDBDatabaseMetadata; |
| 59 class IDBValue; | 61 class IDBValue; |
| 60 | 62 |
| 61 class MODULES_EXPORT IDBRequest : public EventTargetWithInlineData, | 63 class MODULES_EXPORT IDBRequest : public EventTargetWithInlineData, |
| 62 public ActiveScriptWrappable<IDBRequest>, | 64 public ActiveScriptWrappable<IDBRequest>, |
| 63 public SuspendableObject { | 65 public SuspendableObject { |
| 64 DEFINE_WRAPPERTYPEINFO(); | 66 DEFINE_WRAPPERTYPEINFO(); |
| 65 USING_GARBAGE_COLLECTED_MIXIN(IDBRequest); | 67 USING_GARBAGE_COLLECTED_MIXIN(IDBRequest); |
| 66 | 68 |
| 67 public: | 69 public: |
| 68 static IDBRequest* Create(ScriptState*, IDBAny* source, IDBTransaction*); | 70 // Records async tracing, starting oncontruction and ending on destruction. |
|
pwnall
2017/05/18 22:14:32
onconstruction -> missing space?
dmurph
2017/05/18 23:51:15
Done.
| |
| 71 // UMA timing metrics are recorded on RecordUMAMetrics. | |
| 72 class ScopedMetricsTracker { | |
| 73 public: | |
| 74 ScopedMetricsTracker(const char* uma_name, const char* tracing_name, void*); | |
| 75 ~ScopedMetricsTracker(); | |
| 76 | |
| 77 void RecordUMAMetrics() const; | |
| 78 | |
| 79 private: | |
| 80 const char* uma_name_ = nullptr; | |
| 81 const char* tracing_name_ = nullptr; | |
| 82 void* id_; | |
| 83 WTF::TimeTicks start_; | |
| 84 | |
| 85 DISALLOW_COPY_AND_ASSIGN(ScopedMetricsTracker); | |
| 86 }; | |
| 87 | |
| 88 static IDBRequest* Create(ScriptState*, | |
| 89 IDBAny* source, | |
| 90 IDBTransaction*, | |
| 91 std::unique_ptr<ScopedMetricsTracker>); | |
| 69 ~IDBRequest() override; | 92 ~IDBRequest() override; |
| 70 DECLARE_VIRTUAL_TRACE(); | 93 DECLARE_VIRTUAL_TRACE(); |
| 71 | 94 |
| 72 v8::Isolate* GetIsolate() const { return isolate_; } | 95 v8::Isolate* GetIsolate() const { return isolate_; } |
| 73 ScriptValue result(ScriptState*, ExceptionState&); | 96 ScriptValue result(ScriptState*, ExceptionState&); |
| 74 DOMException* error(ExceptionState&) const; | 97 DOMException* error(ExceptionState&) const; |
| 75 ScriptValue source(ScriptState*) const; | 98 ScriptValue source(ScriptState*) const; |
| 76 IDBTransaction* transaction() const { return transaction_.Get(); } | 99 IDBTransaction* transaction() const { return transaction_.Get(); } |
| 77 | 100 |
| 78 bool isResultDirty() const { return result_dirty_; } | 101 bool isResultDirty() const { return result_dirty_; } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 // the upcoming "success" or "error"). | 169 // the upcoming "success" or "error"). |
| 147 void TransactionDidFinishAndDispatch(); | 170 void TransactionDidFinishAndDispatch(); |
| 148 | 171 |
| 149 IDBCursor* GetResultCursor() const; | 172 IDBCursor* GetResultCursor() const; |
| 150 | 173 |
| 151 void StorePutOperationBlobs( | 174 void StorePutOperationBlobs( |
| 152 HashMap<String, RefPtr<BlobDataHandle>> blob_handles) { | 175 HashMap<String, RefPtr<BlobDataHandle>> blob_handles) { |
| 153 transit_blob_handles_ = std::move(blob_handles); | 176 transit_blob_handles_ = std::move(blob_handles); |
| 154 } | 177 } |
| 155 | 178 |
| 179 void AssignNewMetrics(std::unique_ptr<ScopedMetricsTracker> metrics) { | |
| 180 DCHECK(!metrics_); | |
| 181 metrics_ = std::move(metrics); | |
| 182 } | |
| 183 | |
| 156 protected: | 184 protected: |
| 157 IDBRequest(ScriptState*, IDBAny* source, IDBTransaction*); | 185 IDBRequest(ScriptState*, |
| 186 IDBAny* source, | |
| 187 IDBTransaction*, | |
| 188 std::unique_ptr<ScopedMetricsTracker>); | |
| 158 void EnqueueEvent(Event*); | 189 void EnqueueEvent(Event*); |
| 159 void DequeueEvent(Event*); | 190 void DequeueEvent(Event*); |
| 160 virtual bool ShouldEnqueueEvent() const; | 191 virtual bool ShouldEnqueueEvent() const; |
| 161 void EnqueueResultInternal(IDBAny*); | 192 void EnqueueResultInternal(IDBAny*); |
| 162 void SetResult(IDBAny*); | 193 void SetResult(IDBAny*); |
| 163 | 194 |
| 164 // EventTarget | 195 // EventTarget |
| 165 DispatchEventResult DispatchEventInternal(Event*) override; | 196 DispatchEventResult DispatchEventInternal(Event*) override; |
| 166 | 197 |
| 167 Member<IDBTransaction> transaction_; | 198 Member<IDBTransaction> transaction_; |
| 168 ReadyState ready_state_ = PENDING; | 199 ReadyState ready_state_ = PENDING; |
| 169 bool request_aborted_ = false; // May be aborted by transaction then receive | 200 bool request_aborted_ = false; // May be aborted by transaction then receive |
| 170 // async onsuccess; ignore vs. assert. | 201 // async onsuccess; ignore vs. assert. |
| 171 // Maintain the isolate so that all externally allocated memory can be | 202 // Maintain the isolate so that all externally allocated memory can be |
| 172 // registered against it. | 203 // registered against it. |
| 173 v8::Isolate* isolate_; | 204 v8::Isolate* isolate_; |
| 174 | 205 |
| 175 private: | 206 private: |
| 176 void SetResultCursor(IDBCursor*, | 207 void SetResultCursor(IDBCursor*, |
| 177 IDBKey*, | 208 IDBKey*, |
| 178 IDBKey* primary_key, | 209 IDBKey* primary_key, |
| 179 PassRefPtr<IDBValue>); | 210 PassRefPtr<IDBValue>); |
| 180 void AckReceivedBlobs(const IDBValue*); | 211 void AckReceivedBlobs(const IDBValue*); |
| 181 void AckReceivedBlobs(const Vector<RefPtr<IDBValue>>&); | 212 void AckReceivedBlobs(const Vector<RefPtr<IDBValue>>&); |
| 182 | 213 |
| 214 void MaybeRecordMetrics() { | |
|
pwnall
2017/05/18 22:14:32
metrics_ only seems to be null in testing.
1) Can
dmurph
2017/05/18 23:51:15
Done.
| |
| 215 if (metrics_) { | |
| 216 metrics_->RecordUMAMetrics(); | |
| 217 metrics_.reset(); | |
| 218 } | |
| 219 } | |
| 220 | |
| 183 void ClearPutOperationBlobs() { transit_blob_handles_.clear(); } | 221 void ClearPutOperationBlobs() { transit_blob_handles_.clear(); } |
| 184 | 222 |
| 185 Member<IDBAny> source_; | 223 Member<IDBAny> source_; |
| 186 Member<IDBAny> result_; | 224 Member<IDBAny> result_; |
| 187 Member<DOMException> error_; | 225 Member<DOMException> error_; |
| 188 | 226 |
| 227 std::unique_ptr<ScopedMetricsTracker> metrics_; | |
| 228 | |
| 189 bool has_pending_activity_ = true; | 229 bool has_pending_activity_ = true; |
| 190 HeapVector<Member<Event>> enqueued_events_; | 230 HeapVector<Member<Event>> enqueued_events_; |
| 191 | 231 |
| 192 // Only used if the result type will be a cursor. | 232 // Only used if the result type will be a cursor. |
| 193 IndexedDB::CursorType cursor_type_ = IndexedDB::kCursorKeyAndValue; | 233 IndexedDB::CursorType cursor_type_ = IndexedDB::kCursorKeyAndValue; |
| 194 WebIDBCursorDirection cursor_direction_ = kWebIDBCursorDirectionNext; | 234 WebIDBCursorDirection cursor_direction_ = kWebIDBCursorDirectionNext; |
| 195 // When a cursor is continued/advanced, |result_| is cleared and | 235 // When a cursor is continued/advanced, |result_| is cleared and |
| 196 // |pendingCursor_| holds it. | 236 // |pendingCursor_| holds it. |
| 197 Member<IDBCursor> pending_cursor_; | 237 Member<IDBCursor> pending_cursor_; |
| 198 // New state is not applied to the cursor object until the event is | 238 // New state is not applied to the cursor object until the event is |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 214 bool did_throw_in_event_handler_ = false; | 254 bool did_throw_in_event_handler_ = false; |
| 215 | 255 |
| 216 // Pointer back to the WebIDBCallbacks that holds a persistent reference to | 256 // Pointer back to the WebIDBCallbacks that holds a persistent reference to |
| 217 // this object. | 257 // this object. |
| 218 WebIDBCallbacks* web_callbacks_ = nullptr; | 258 WebIDBCallbacks* web_callbacks_ = nullptr; |
| 219 }; | 259 }; |
| 220 | 260 |
| 221 } // namespace blink | 261 } // namespace blink |
| 222 | 262 |
| 223 #endif // IDBRequest_h | 263 #endif // IDBRequest_h |
| OLD | NEW |