Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / modules / indexeddb / WebIDBCallbacksImpl.cpp
1 /*
2  * Copyright (C) 2013 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
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
14  * distribution.
15  *
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.
27  */
28
29 #include "config.h"
30 #include "modules/indexeddb/WebIDBCallbacksImpl.h"
31
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"
43
44 using blink::WebBlobInfo;
45 using blink::WebData;
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;
53
54 namespace blink {
55
56 // static
57 PassOwnPtr<WebIDBCallbacksImpl> WebIDBCallbacksImpl::create(IDBRequest* request)
58 {
59     return adoptPtr(new WebIDBCallbacksImpl(request));
60 }
61
62 WebIDBCallbacksImpl::WebIDBCallbacksImpl(IDBRequest* request)
63     : m_request(request)
64 {
65     m_asyncOperationId = InspectorInstrumentation::traceAsyncOperationStarting(m_request->executionContext(), "IndexedDB");
66 }
67
68 WebIDBCallbacksImpl::~WebIDBCallbacksImpl()
69 {
70     InspectorInstrumentation::traceAsyncOperationCompleted(m_request->executionContext(), m_asyncOperationId);
71 }
72
73 static PassOwnPtr<Vector<WebBlobInfo> > ConvertBlobInfo(const WebVector<WebBlobInfo>& webBlobInfo)
74 {
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();
79 }
80
81 void WebIDBCallbacksImpl::onError(const WebIDBDatabaseError& error)
82 {
83     InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsyncCallbackStarting(m_request->executionContext(), m_asyncOperationId);
84     m_request->onError(error);
85     InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
86 }
87
88 void WebIDBCallbacksImpl::onSuccess(const WebVector<blink::WebString>& webStringList)
89 {
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);
96 }
97
98 void WebIDBCallbacksImpl::onSuccess(WebIDBCursor* cursor, const WebIDBKey& key, const WebIDBKey& primaryKey, const WebData& value, const WebVector<WebBlobInfo>& webBlobInfo)
99 {
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);
103 }
104
105 void WebIDBCallbacksImpl::onSuccess(WebIDBDatabase* backend, const WebIDBMetadata& metadata)
106 {
107     InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsyncCallbackStarting(m_request->executionContext(), m_asyncOperationId);
108     m_request->onSuccess(adoptPtr(backend), metadata);
109     InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
110 }
111
112 void WebIDBCallbacksImpl::onSuccess(const WebIDBKey& key)
113 {
114     InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsyncCallbackStarting(m_request->executionContext(), m_asyncOperationId);
115     m_request->onSuccess(key);
116     InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
117 }
118
119 void WebIDBCallbacksImpl::onSuccess(const WebData& value, const WebVector<WebBlobInfo>& webBlobInfo)
120 {
121     InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsyncCallbackStarting(m_request->executionContext(), m_asyncOperationId);
122     m_request->onSuccess(value, ConvertBlobInfo(webBlobInfo));
123     InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
124 }
125
126 void WebIDBCallbacksImpl::onSuccess(const WebData& value, const WebVector<WebBlobInfo>& webBlobInfo, const WebIDBKey& key, const WebIDBKeyPath& keyPath)
127 {
128     InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsyncCallbackStarting(m_request->executionContext(), m_asyncOperationId);
129     m_request->onSuccess(value, ConvertBlobInfo(webBlobInfo), key, keyPath);
130     InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
131 }
132
133 void WebIDBCallbacksImpl::onSuccess(long long value)
134 {
135     InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsyncCallbackStarting(m_request->executionContext(), m_asyncOperationId);
136     m_request->onSuccess(value);
137     InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
138 }
139
140 void WebIDBCallbacksImpl::onSuccess()
141 {
142     InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsyncCallbackStarting(m_request->executionContext(), m_asyncOperationId);
143     m_request->onSuccess();
144     InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
145 }
146
147 void WebIDBCallbacksImpl::onSuccess(const WebIDBKey& key, const WebIDBKey& primaryKey, const WebData& value, const WebVector<WebBlobInfo>& webBlobInfo)
148 {
149     InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsyncCallbackStarting(m_request->executionContext(), m_asyncOperationId);
150     m_request->onSuccess(key, primaryKey, value, ConvertBlobInfo(webBlobInfo));
151     InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
152 }
153
154 void WebIDBCallbacksImpl::onBlocked(long long oldVersion)
155 {
156     InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsyncCallbackStarting(m_request->executionContext(), m_asyncOperationId);
157     m_request->onBlocked(oldVersion);
158     InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
159 }
160
161 void WebIDBCallbacksImpl::onUpgradeNeeded(long long oldVersion, WebIDBDatabase* database, const WebIDBMetadata& metadata, unsigned short dataLoss, blink::WebString dataLossMessage)
162 {
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);
166 }
167
168 } // namespace blink