OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_CALLBACKS_H_ | 5 #ifndef CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_CALLBACKS_H_ |
6 #define CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_CALLBACKS_H_ | 6 #define CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_CALLBACKS_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/logging.h" |
9 #include "base/ref_counted.h" | 10 #include "base/ref_counted.h" |
| 11 #include "chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h" |
10 #include "third_party/WebKit/WebKit/chromium/public/WebIDBCallbacks.h" | 12 #include "third_party/WebKit/WebKit/chromium/public/WebIDBCallbacks.h" |
| 13 #include "third_party/WebKit/WebKit/chromium/public/WebIDBDatabaseError.h" |
11 | 14 |
12 class IndexedDBDispatcherHost; | |
13 | 15 |
| 16 template <class WebObjectType, typename SuccessMsgType, typename ErrorMsgType> |
14 class IndexedDBCallbacks : public WebKit::WebIDBCallbacks { | 17 class IndexedDBCallbacks : public WebKit::WebIDBCallbacks { |
15 public: | 18 public: |
16 IndexedDBCallbacks(IndexedDBDispatcherHost* parent, int32 response_id); | 19 IndexedDBCallbacks( |
17 virtual ~IndexedDBCallbacks(); | 20 IndexedDBDispatcherHost* dispatcher_host, int32 response_id) |
| 21 : dispatcher_host_(dispatcher_host), response_id_(response_id) { } |
18 | 22 |
19 // We define default versions of these functions which simply DCHECK. | 23 virtual void onError(const WebKit::WebIDBDatabaseError& error) { |
20 // For each WebIDBCallbacks implementation, there should only be one success | 24 dispatcher_host_->Send(new ErrorMsgType( |
21 // callback that can possibly be called. | 25 response_id_, error.code(), error.message())); |
22 virtual void onSuccess(WebKit::WebIDBDatabase* idb_database); | 26 } |
23 virtual void onSuccess(const WebKit::WebSerializedScriptValue& value); | |
24 | 27 |
25 protected: | 28 virtual void onSuccess(WebObjectType* idb_object) { |
26 IndexedDBDispatcherHost* parent() { return parent_.get(); } | 29 int32 object_id = dispatcher_host_->Add(idb_object); |
27 int32 response_id() const { return response_id_; } | 30 dispatcher_host_->Send(new SuccessMsgType(response_id_, object_id)); |
| 31 } |
28 | 32 |
29 private: | 33 private: |
30 scoped_refptr<IndexedDBDispatcherHost> parent_; | 34 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_; |
31 int32 response_id_; | 35 int32 response_id_; |
32 | 36 |
33 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks); | 37 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks); |
34 }; | 38 }; |
35 | 39 |
36 #endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_CALLBACKS_H_ | 40 #endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_CALLBACKS_H_ |
37 | 41 |
OLD | NEW |