OLD | NEW |
| (Empty) |
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 "modules/indexeddb/WebIDBCallbacksImpl.h" | |
30 | |
31 #include "core/dom/DOMException.h" | |
32 #include "core/inspector/InspectorInstrumentation.h" | |
33 #include "modules/IndexedDBNames.h" | |
34 #include "modules/indexeddb/IDBMetadata.h" | |
35 #include "modules/indexeddb/IDBRequest.h" | |
36 #include "modules/indexeddb/IDBValue.h" | |
37 #include "platform/SharedBuffer.h" | |
38 #include "public/platform/modules/indexeddb/WebIDBCursor.h" | |
39 #include "public/platform/modules/indexeddb/WebIDBDatabase.h" | |
40 #include "public/platform/modules/indexeddb/WebIDBDatabaseError.h" | |
41 #include "public/platform/modules/indexeddb/WebIDBKey.h" | |
42 #include "public/platform/modules/indexeddb/WebIDBValue.h" | |
43 #include "wtf/PtrUtil.h" | |
44 #include <memory> | |
45 | |
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::WebIDBValue; | |
53 using blink::WebVector; | |
54 | |
55 namespace blink { | |
56 | |
57 // static | |
58 std::unique_ptr<WebIDBCallbacksImpl> WebIDBCallbacksImpl::create(IDBRequest* req
uest) | |
59 { | |
60 return wrapUnique(new WebIDBCallbacksImpl(request)); | |
61 } | |
62 | |
63 WebIDBCallbacksImpl::WebIDBCallbacksImpl(IDBRequest* request) | |
64 : m_request(request) | |
65 { | |
66 InspectorInstrumentation::asyncTaskScheduled(m_request->getExecutionContext(
), IndexedDBNames::IndexedDB, this, true); | |
67 } | |
68 | |
69 WebIDBCallbacksImpl::~WebIDBCallbacksImpl() | |
70 { | |
71 InspectorInstrumentation::asyncTaskCanceled(m_request->getExecutionContext()
, this); | |
72 } | |
73 | |
74 void WebIDBCallbacksImpl::onError(const WebIDBDatabaseError& error) | |
75 { | |
76 InspectorInstrumentation::AsyncTask asyncTask(m_request->getExecutionContext
(), this); | |
77 m_request->onError(DOMException::create(error.code(), error.message())); | |
78 } | |
79 | |
80 void WebIDBCallbacksImpl::onSuccess(const WebVector<WebString>& webStringList) | |
81 { | |
82 Vector<String> stringList; | |
83 for (size_t i = 0; i < webStringList.size(); ++i) | |
84 stringList.append(webStringList[i]); | |
85 InspectorInstrumentation::AsyncTask asyncTask(m_request->getExecutionContext
(), this); | |
86 m_request->onSuccess(stringList); | |
87 } | |
88 | |
89 void WebIDBCallbacksImpl::onSuccess(WebIDBCursor* cursor, const WebIDBKey& key,
const WebIDBKey& primaryKey, const WebIDBValue& value) | |
90 { | |
91 InspectorInstrumentation::AsyncTask asyncTask(m_request->getExecutionContext
(), this); | |
92 m_request->onSuccess(wrapUnique(cursor), key, primaryKey, IDBValue::create(v
alue)); | |
93 } | |
94 | |
95 void WebIDBCallbacksImpl::onSuccess(WebIDBDatabase* backend, const WebIDBMetadat
a& metadata) | |
96 { | |
97 InspectorInstrumentation::AsyncTask asyncTask(m_request->getExecutionContext
(), this); | |
98 m_request->onSuccess(wrapUnique(backend), IDBDatabaseMetadata(metadata)); | |
99 } | |
100 | |
101 void WebIDBCallbacksImpl::onSuccess(const WebIDBKey& key) | |
102 { | |
103 InspectorInstrumentation::AsyncTask asyncTask(m_request->getExecutionContext
(), this); | |
104 m_request->onSuccess(key); | |
105 } | |
106 | |
107 void WebIDBCallbacksImpl::onSuccess(const WebIDBValue& value) | |
108 { | |
109 InspectorInstrumentation::AsyncTask asyncTask(m_request->getExecutionContext
(), this); | |
110 m_request->onSuccess(IDBValue::create(value)); | |
111 } | |
112 | |
113 void WebIDBCallbacksImpl::onSuccess(const WebVector<WebIDBValue>& values) | |
114 { | |
115 InspectorInstrumentation::AsyncTask asyncTask(m_request->getExecutionContext
(), this); | |
116 Vector<RefPtr<IDBValue>> idbValues(values.size()); | |
117 for (size_t i = 0; i < values.size(); ++i) | |
118 idbValues[i] = IDBValue::create(values[i]); | |
119 m_request->onSuccess(idbValues); | |
120 } | |
121 | |
122 void WebIDBCallbacksImpl::onSuccess(long long value) | |
123 { | |
124 InspectorInstrumentation::AsyncTask asyncTask(m_request->getExecutionContext
(), this); | |
125 m_request->onSuccess(value); | |
126 } | |
127 | |
128 void WebIDBCallbacksImpl::onSuccess() | |
129 { | |
130 InspectorInstrumentation::AsyncTask asyncTask(m_request->getExecutionContext
(), this); | |
131 m_request->onSuccess(); | |
132 } | |
133 | |
134 void WebIDBCallbacksImpl::onSuccess(const WebIDBKey& key, const WebIDBKey& prima
ryKey, const WebIDBValue& value) | |
135 { | |
136 InspectorInstrumentation::AsyncTask asyncTask(m_request->getExecutionContext
(), this); | |
137 m_request->onSuccess(key, primaryKey, IDBValue::create(value)); | |
138 } | |
139 | |
140 void WebIDBCallbacksImpl::onBlocked(long long oldVersion) | |
141 { | |
142 InspectorInstrumentation::AsyncTask asyncTask(m_request->getExecutionContext
(), this); | |
143 m_request->onBlocked(oldVersion); | |
144 } | |
145 | |
146 void WebIDBCallbacksImpl::onUpgradeNeeded(long long oldVersion, WebIDBDatabase*
database, const WebIDBMetadata& metadata, unsigned short dataLoss, WebString dat
aLossMessage) | |
147 { | |
148 InspectorInstrumentation::AsyncTask asyncTask(m_request->getExecutionContext
(), this); | |
149 m_request->onUpgradeNeeded(oldVersion, wrapUnique(database), IDBDatabaseMeta
data(metadata), static_cast<WebIDBDataLoss>(dataLoss), dataLossMessage); | |
150 } | |
151 | |
152 } // namespace blink | |
OLD | NEW |