OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 CONTENT_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_CALLBACKS_H_ | 5 #ifndef CONTENT_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_CALLBACKS_H_ |
6 #define CONTENT_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_CALLBACKS_H_ | 6 #define CONTENT_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_CALLBACKS_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "content/browser/in_process_webkit/indexed_db_dispatcher_host.h" | 10 #include "content/browser/in_process_webkit/indexed_db_dispatcher_host.h" |
11 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBCallbacks.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBCallbacks.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBCursor.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBCursor.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabase.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabase.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabaseError.h
" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabaseError.h
" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBTransaction.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBTransaction.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
18 | 18 |
19 class IndexedDBMsg_CallbacksSuccessIDBDatabase; | |
20 class IndexedDBMsg_CallbacksSuccessIDBTransaction; | |
21 class IndexedDBMsg_CallbacksUpgradeNeeded; | |
22 | |
23 // Template magic to figure out what message to send to the renderer based on | |
24 // which (overloaded) onSuccess method we expect to be called. | |
25 template <class Type> struct WebIDBToMsgHelper { }; | |
26 template <> struct WebIDBToMsgHelper<WebKit::WebIDBDatabase> { | |
27 typedef IndexedDBMsg_CallbacksSuccessIDBDatabase MsgType; | |
28 }; | |
29 template <> struct WebIDBToMsgHelper<WebKit::WebIDBTransaction> { | |
30 typedef IndexedDBMsg_CallbacksSuccessIDBTransaction MsgType; | |
31 }; | |
32 | |
33 namespace { | |
34 int32 kDatabaseNotAdded = -1; | |
35 } | |
36 | |
37 // The code the following two classes share. | |
38 class IndexedDBCallbacksBase : public WebKit::WebIDBCallbacks { | 19 class IndexedDBCallbacksBase : public WebKit::WebIDBCallbacks { |
39 public: | 20 public: |
40 IndexedDBCallbacksBase(IndexedDBDispatcherHost* dispatcher_host, | |
41 int32 thread_id, | |
42 int32 response_id); | |
43 | |
44 virtual ~IndexedDBCallbacksBase(); | 21 virtual ~IndexedDBCallbacksBase(); |
45 | 22 |
46 virtual void onError(const WebKit::WebIDBDatabaseError& error); | 23 virtual void onError(const WebKit::WebIDBDatabaseError& error); |
47 virtual void onBlocked(); | 24 virtual void onBlocked(); |
48 virtual void onBlocked(long long old_version); | 25 virtual void onBlocked(long long old_version); |
49 | 26 |
50 protected: | 27 protected: |
| 28 IndexedDBCallbacksBase(IndexedDBDispatcherHost* dispatcher_host, |
| 29 int32 thread_id, |
| 30 int32 response_id); |
51 IndexedDBDispatcherHost* dispatcher_host() const { | 31 IndexedDBDispatcherHost* dispatcher_host() const { |
52 return dispatcher_host_.get(); | 32 return dispatcher_host_.get(); |
53 } | 33 } |
54 int32 thread_id() const { return thread_id_; } | 34 int32 thread_id() const { return thread_id_; } |
55 int32 response_id() const { return response_id_; } | 35 int32 response_id() const { return response_id_; } |
56 | 36 |
57 private: | 37 private: |
58 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_; | 38 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_; |
59 int32 response_id_; | 39 int32 response_id_; |
60 int32 thread_id_; | 40 int32 thread_id_; |
61 | 41 |
62 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacksBase); | 42 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacksBase); |
63 }; | 43 }; |
64 | 44 |
65 // A WebIDBCallbacks implementation that returns an object of WebObjectType. | 45 // TODO(dgrogan): Remove this class and change the remaining specializations |
| 46 // into subclasses of IndexedDBCallbacksBase. |
66 template <class WebObjectType> | 47 template <class WebObjectType> |
67 class IndexedDBCallbacks : public IndexedDBCallbacksBase { | 48 class IndexedDBCallbacks : public IndexedDBCallbacksBase { |
| 49 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks); |
| 50 }; |
| 51 |
| 52 class IndexedDBCallbacksTransaction : public IndexedDBCallbacksBase { |
68 public: | 53 public: |
69 IndexedDBCallbacks( | 54 IndexedDBCallbacksTransaction( |
70 IndexedDBDispatcherHost* dispatcher_host, | 55 IndexedDBDispatcherHost* dispatcher_host, |
71 int32 thread_id, | 56 int32 thread_id, |
72 int32 response_id, | 57 int32 response_id, |
73 const GURL& origin_url) | 58 const GURL& origin_url); |
74 : IndexedDBCallbacksBase(dispatcher_host, thread_id, response_id), | |
75 origin_url_(origin_url), | |
76 database_id_(kDatabaseNotAdded) { | |
77 } | |
78 | 59 |
79 virtual void onSuccess(WebObjectType* idb_object) { | 60 virtual void onSuccess(WebKit::WebIDBTransaction* idb_object); |
80 int32 object_id = database_id_; | |
81 if (object_id == kDatabaseNotAdded) { | |
82 object_id = dispatcher_host()->Add(idb_object, thread_id(), origin_url_); | |
83 } else { | |
84 // We already have this database and don't need a new copy of it. | |
85 delete idb_object; | |
86 } | |
87 | 61 |
88 dispatcher_host()->Send( | 62 private: |
89 new typename WebIDBToMsgHelper<WebObjectType>::MsgType(thread_id(), | 63 GURL origin_url_; |
90 response_id(), | 64 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacksTransaction); |
91 object_id)); | 65 }; |
92 } | |
93 | 66 |
94 void onUpgradeNeeded( | 67 class IndexedDBCallbacksDatabase : public IndexedDBCallbacksBase { |
| 68 public: |
| 69 IndexedDBCallbacksDatabase( |
| 70 IndexedDBDispatcherHost* dispatcher_host, |
| 71 int32 thread_id, |
| 72 int32 response_id, |
| 73 const GURL& origin_url); |
| 74 |
| 75 virtual void onSuccess(WebKit::WebIDBDatabase* idb_object); |
| 76 virtual void onUpgradeNeeded( |
95 long long old_version, | 77 long long old_version, |
96 WebKit::WebIDBTransaction* transaction, | 78 WebKit::WebIDBTransaction* transaction, |
97 WebKit::WebIDBDatabase* database) { | 79 WebKit::WebIDBDatabase* database); |
98 NOTREACHED(); | |
99 } | |
100 | |
101 | 80 |
102 private: | 81 private: |
103 GURL origin_url_; | 82 GURL origin_url_; |
104 int32 database_id_; | 83 int32 database_id_; |
105 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks); | 84 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacksDatabase); |
106 }; | 85 }; |
107 | 86 |
108 // WebIDBCursor uses: | 87 // WebIDBCursor uses: |
109 // * onSuccess(WebIDBCursor*, WebIDBKey, WebIDBKey, SerializedScriptValue) | 88 // * onSuccess(WebIDBCursor*, WebIDBKey, WebIDBKey, SerializedScriptValue) |
110 // when an openCursor()/openKeyCursor() call has succeeded, | 89 // when an openCursor()/openKeyCursor() call has succeeded, |
111 // * onSuccess(WebIDBKey, WebIDBKey, SerializedScriptValue) | 90 // * onSuccess(WebIDBKey, WebIDBKey, SerializedScriptValue) |
112 // when an advance()/continue() call has succeeded, or | 91 // when an advance()/continue() call has succeeded, or |
113 // * onSuccess(SerializedScriptValue::nullValue()) | 92 // * onSuccess(SerializedScriptValue::nullValue()) |
114 // to indicate it does not contain any data, i.e., there is no key within | 93 // to indicate it does not contain any data, i.e., there is no key within |
115 // the key range, or it has reached the end. | 94 // the key range, or it has reached the end. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 virtual void onSuccess(const WebKit::WebSerializedScriptValue& value); | 177 virtual void onSuccess(const WebKit::WebSerializedScriptValue& value); |
199 virtual void onSuccess(const WebKit::WebSerializedScriptValue& value, | 178 virtual void onSuccess(const WebKit::WebSerializedScriptValue& value, |
200 const WebKit::WebIDBKey& key, | 179 const WebKit::WebIDBKey& key, |
201 const WebKit::WebIDBKeyPath& keyPath); | 180 const WebKit::WebIDBKeyPath& keyPath); |
202 | 181 |
203 private: | 182 private: |
204 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks); | 183 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks); |
205 }; | 184 }; |
206 | 185 |
207 #endif // CONTENT_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_CALLBACKS_H_ | 186 #endif // CONTENT_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_CALLBACKS_H_ |
OLD | NEW |