1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_CALLBACKS_H_
6 #define CONTENT_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_CALLBACKS_H_
8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h"
10 #include "content/browser/in_process_webkit/indexed_db_dispatcher_host.h"
11 #include "googleurl/src/gurl.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBCallbacks.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBCursor.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabase.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabaseError.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBTransaction.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
21 class IndexedDBCallbacksBase
: public WebKit::WebIDBCallbacks
{
23 virtual ~IndexedDBCallbacksBase();
25 virtual void onError(const WebKit::WebIDBDatabaseError
& error
);
26 virtual void onBlocked();
27 virtual void onBlocked(long long old_version
);
30 IndexedDBCallbacksBase(IndexedDBDispatcherHost
* dispatcher_host
,
32 int32 ipc_response_id
);
33 IndexedDBDispatcherHost
* dispatcher_host() const {
34 return dispatcher_host_
.get();
36 int32
ipc_thread_id() const { return ipc_thread_id_
; }
37 int32
ipc_response_id() const { return ipc_response_id_
; }
40 scoped_refptr
<IndexedDBDispatcherHost
> dispatcher_host_
;
41 int32 ipc_response_id_
;
44 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacksBase
);
47 // TODO(dgrogan): Remove this class and change the remaining specializations
48 // into subclasses of IndexedDBCallbacksBase.
49 template <class WebObjectType
>
50 class IndexedDBCallbacks
: public IndexedDBCallbacksBase
{
51 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks
);
54 class IndexedDBCallbacksDatabase
: public IndexedDBCallbacksBase
{
56 IndexedDBCallbacksDatabase(
57 IndexedDBDispatcherHost
* dispatcher_host
,
59 int32 ipc_response_id
,
60 const GURL
& origin_url
);
62 virtual void onSuccess(WebKit::WebIDBDatabase
* idb_object
);
63 virtual void onUpgradeNeeded(
64 long long old_version
,
65 WebKit::WebIDBTransaction
* transaction
,
66 WebKit::WebIDBDatabase
* database
);
70 int32 ipc_database_id_
;
71 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacksDatabase
);
75 // * onSuccess(WebIDBCursor*, WebIDBKey, WebIDBKey, SerializedScriptValue)
76 // when an openCursor()/openKeyCursor() call has succeeded,
77 // * onSuccess(WebIDBKey, WebIDBKey, SerializedScriptValue)
78 // when an advance()/continue() call has succeeded, or
79 // * onSuccess(SerializedScriptValue::nullValue())
80 // to indicate it does not contain any data, i.e., there is no key within
81 // the key range, or it has reached the end.
83 class IndexedDBCallbacks
<WebKit::WebIDBCursor
>
84 : public IndexedDBCallbacksBase
{
87 IndexedDBDispatcherHost
* dispatcher_host
,
89 int32 ipc_response_id
,
91 : IndexedDBCallbacksBase(dispatcher_host
, ipc_thread_id
, ipc_response_id
),
92 ipc_cursor_id_(ipc_cursor_id
) { }
94 virtual void onSuccess(WebKit::WebIDBCursor
* idb_object
,
95 const WebKit::WebIDBKey
& key
,
96 const WebKit::WebIDBKey
& primaryKey
,
97 const WebKit::WebSerializedScriptValue
& value
);
98 virtual void onSuccess(const WebKit::WebIDBKey
& key
,
99 const WebKit::WebIDBKey
& primaryKey
,
100 const WebKit::WebSerializedScriptValue
& value
);
101 virtual void onSuccess(const WebKit::WebSerializedScriptValue
& value
);
102 virtual void onSuccessWithPrefetch(
103 const WebKit::WebVector
<WebKit::WebIDBKey
>& keys
,
104 const WebKit::WebVector
<WebKit::WebIDBKey
>& primaryKeys
,
105 const WebKit::WebVector
<WebKit::WebSerializedScriptValue
>& values
);
108 // The id of the cursor this callback concerns, or -1 if the cursor
109 // does not exist yet.
110 int32 ipc_cursor_id_
;
112 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks
);
115 // WebIDBKey is implemented in WebKit as opposed to being an interface Chromium
116 // implements. Thus we pass a const ___& version and thus we need this
119 class IndexedDBCallbacks
<WebKit::WebIDBKey
>
120 : public IndexedDBCallbacksBase
{
122 IndexedDBCallbacks(IndexedDBDispatcherHost
* dispatcher_host
,
124 int32 ipc_response_id
)
125 : IndexedDBCallbacksBase(dispatcher_host
, ipc_thread_id
,
128 virtual void onSuccess(const WebKit::WebIDBKey
& value
);
131 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks
);
134 // WebDOMStringList is implemented in WebKit as opposed to being an
135 // interface Chromium implements. Thus we pass a const ___& version and thus
136 // we need this specialization.
138 class IndexedDBCallbacks
<WebKit::WebDOMStringList
>
139 : public IndexedDBCallbacksBase
{
142 IndexedDBDispatcherHost
* dispatcher_host
,
144 int32 ipc_response_id
)
145 : IndexedDBCallbacksBase(dispatcher_host
, ipc_thread_id
,
148 virtual void onSuccess(const WebKit::WebDOMStringList
& value
);
151 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks
);
154 // WebSerializedScriptValue is implemented in WebKit as opposed to being an
155 // interface Chromium implements. Thus we pass a const ___& version and thus
156 // we need this specialization.
158 class IndexedDBCallbacks
<WebKit::WebSerializedScriptValue
>
159 : public IndexedDBCallbacksBase
{
161 IndexedDBCallbacks(IndexedDBDispatcherHost
* dispatcher_host
,
163 int32 ipc_response_id
)
164 : IndexedDBCallbacksBase(dispatcher_host
, ipc_thread_id
,
167 virtual void onSuccess(const WebKit::WebSerializedScriptValue
& value
);
168 virtual void onSuccess(const WebKit::WebSerializedScriptValue
& value
,
169 const WebKit::WebIDBKey
& key
,
170 const WebKit::WebIDBKeyPath
& keyPath
);
171 virtual void onSuccess(long long value
);
172 virtual void onSuccess();
175 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks
);
178 } // namespace content
180 #endif // CONTENT_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_CALLBACKS_H_