2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
16 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC.
20 * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "modules/indexeddb/WebIDBCallbacksImpl.h"
32 #include "core/dom/DOMError.h"
33 #include "core/inspector/InspectorInstrumentation.h"
34 #include "modules/indexeddb/IDBMetadata.h"
35 #include "modules/indexeddb/IDBRequest.h"
36 #include "platform/SharedBuffer.h"
37 #include "public/platform/WebBlobInfo.h"
38 #include "public/platform/WebData.h"
39 #include "public/platform/WebIDBCursor.h"
40 #include "public/platform/WebIDBDatabase.h"
41 #include "public/platform/WebIDBDatabaseError.h"
42 #include "public/platform/WebIDBKey.h"
44 using blink::WebBlobInfo;
46 using blink::WebIDBCursor;
47 using blink::WebIDBDatabase;
48 using blink::WebIDBDatabaseError;
49 using blink::WebIDBKey;
50 using blink::WebIDBKeyPath;
51 using blink::WebIDBMetadata;
52 using blink::WebVector;
57 PassOwnPtr<WebIDBCallbacksImpl> WebIDBCallbacksImpl::create(IDBRequest* request)
59 return adoptPtr(new WebIDBCallbacksImpl(request));
62 WebIDBCallbacksImpl::WebIDBCallbacksImpl(IDBRequest* request)
65 m_asyncOperationId = InspectorInstrumentation::traceAsyncOperationStarting(m_request->executionContext(), "IndexedDB");
68 WebIDBCallbacksImpl::~WebIDBCallbacksImpl()
70 InspectorInstrumentation::traceAsyncOperationCompleted(m_request->executionContext(), m_asyncOperationId);
73 static PassOwnPtr<Vector<WebBlobInfo> > ConvertBlobInfo(const WebVector<WebBlobInfo>& webBlobInfo)
75 OwnPtr<Vector<WebBlobInfo> > blobInfo = adoptPtr(new Vector<WebBlobInfo>(webBlobInfo.size()));
76 for (size_t i = 0; i < webBlobInfo.size(); ++i)
77 (*blobInfo)[i] = webBlobInfo[i];
78 return blobInfo.release();
81 void WebIDBCallbacksImpl::onError(const WebIDBDatabaseError& error)
83 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsyncCallbackStarting(m_request->executionContext(), m_asyncOperationId);
84 m_request->onError(error);
85 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
88 void WebIDBCallbacksImpl::onSuccess(const WebVector<blink::WebString>& webStringList)
90 Vector<String> stringList;
91 for (size_t i = 0; i < webStringList.size(); ++i)
92 stringList.append(webStringList[i]);
93 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsyncCallbackStarting(m_request->executionContext(), m_asyncOperationId);
94 m_request->onSuccess(stringList);
95 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
98 void WebIDBCallbacksImpl::onSuccess(WebIDBCursor* cursor, const WebIDBKey& key, const WebIDBKey& primaryKey, const WebData& value, const WebVector<WebBlobInfo>& webBlobInfo)
100 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsyncCallbackStarting(m_request->executionContext(), m_asyncOperationId);
101 m_request->onSuccess(adoptPtr(cursor), key, primaryKey, value, ConvertBlobInfo(webBlobInfo));
102 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
105 void WebIDBCallbacksImpl::onSuccess(WebIDBDatabase* backend, const WebIDBMetadata& metadata)
107 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsyncCallbackStarting(m_request->executionContext(), m_asyncOperationId);
108 m_request->onSuccess(adoptPtr(backend), metadata);
109 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
112 void WebIDBCallbacksImpl::onSuccess(const WebIDBKey& key)
114 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsyncCallbackStarting(m_request->executionContext(), m_asyncOperationId);
115 m_request->onSuccess(key);
116 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
119 void WebIDBCallbacksImpl::onSuccess(const WebData& value, const WebVector<WebBlobInfo>& webBlobInfo)
121 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsyncCallbackStarting(m_request->executionContext(), m_asyncOperationId);
122 m_request->onSuccess(value, ConvertBlobInfo(webBlobInfo));
123 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
126 void WebIDBCallbacksImpl::onSuccess(const WebData& value, const WebVector<WebBlobInfo>& webBlobInfo, const WebIDBKey& key, const WebIDBKeyPath& keyPath)
128 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsyncCallbackStarting(m_request->executionContext(), m_asyncOperationId);
129 m_request->onSuccess(value, ConvertBlobInfo(webBlobInfo), key, keyPath);
130 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
133 void WebIDBCallbacksImpl::onSuccess(long long value)
135 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsyncCallbackStarting(m_request->executionContext(), m_asyncOperationId);
136 m_request->onSuccess(value);
137 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
140 void WebIDBCallbacksImpl::onSuccess()
142 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsyncCallbackStarting(m_request->executionContext(), m_asyncOperationId);
143 m_request->onSuccess();
144 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
147 void WebIDBCallbacksImpl::onSuccess(const WebIDBKey& key, const WebIDBKey& primaryKey, const WebData& value, const WebVector<WebBlobInfo>& webBlobInfo)
149 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsyncCallbackStarting(m_request->executionContext(), m_asyncOperationId);
150 m_request->onSuccess(key, primaryKey, value, ConvertBlobInfo(webBlobInfo));
151 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
154 void WebIDBCallbacksImpl::onBlocked(long long oldVersion)
156 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsyncCallbackStarting(m_request->executionContext(), m_asyncOperationId);
157 m_request->onBlocked(oldVersion);
158 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
161 void WebIDBCallbacksImpl::onUpgradeNeeded(long long oldVersion, WebIDBDatabase* database, const WebIDBMetadata& metadata, unsigned short dataLoss, blink::WebString dataLossMessage)
163 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsyncCallbackStarting(m_request->executionContext(), m_asyncOperationId);
164 m_request->onUpgradeNeeded(oldVersion, adoptPtr(database), metadata, static_cast<blink::WebIDBDataLoss>(dataLoss), dataLossMessage);
165 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);