| 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/public/platform/WebData.h" | 12 #include "third_party/WebKit/public/platform/WebData.h" |
| 13 #include "third_party/WebKit/public/platform/WebIDBCallbacks.h" | |
| 14 #include "third_party/WebKit/public/platform/WebIDBCursor.h" | |
| 15 #include "third_party/WebKit/public/platform/WebIDBDatabase.h" | 13 #include "third_party/WebKit/public/platform/WebIDBDatabase.h" |
| 16 #include "third_party/WebKit/public/platform/WebIDBDatabaseError.h" | 14 #include "third_party/WebKit/public/platform/WebIDBDatabaseError.h" |
| 17 #include "third_party/WebKit/public/platform/WebString.h" | 15 #include "third_party/WebKit/public/platform/WebString.h" |
| 18 | 16 |
| 19 namespace content { | 17 namespace content { |
| 18 class WebIDBCursorImpl; |
| 19 class WebIDBDatabaseImpl; |
| 20 | 20 |
| 21 class IndexedDBCallbacksBase : public WebKit::WebIDBCallbacks { | 21 class IndexedDBCallbacksBase { |
| 22 public: | 22 public: |
| 23 virtual ~IndexedDBCallbacksBase(); | 23 virtual ~IndexedDBCallbacksBase(); |
| 24 | 24 |
| 25 virtual void onError(const WebKit::WebIDBDatabaseError& error); | 25 virtual void onError(const WebKit::WebIDBDatabaseError& error); |
| 26 virtual void onBlocked(long long old_version); | 26 virtual void onBlocked(long long old_version); |
| 27 | 27 |
| 28 // implemented by subclasses, but need to be called later |
| 29 virtual void onSuccess(const WebKit::WebVector<WebKit::WebString>& value); |
| 30 virtual void onSuccess(WebIDBDatabaseImpl* idb_object, |
| 31 const WebKit::WebIDBMetadata& metadata); |
| 32 virtual void onUpgradeNeeded(long long old_version, |
| 33 WebIDBDatabaseImpl* database, |
| 34 const WebKit::WebIDBMetadata&); |
| 35 virtual void onSuccess(WebIDBCursorImpl* idb_object, |
| 36 const WebKit::WebIDBKey& key, |
| 37 const WebKit::WebIDBKey& primaryKey, |
| 38 const WebKit::WebData& value); |
| 39 virtual void onSuccess(const WebKit::WebIDBKey& key, |
| 40 const WebKit::WebIDBKey& primaryKey, |
| 41 const WebKit::WebData& value); |
| 42 virtual void onSuccess(const WebKit::WebData& value); |
| 43 virtual void onSuccessWithPrefetch( |
| 44 const WebKit::WebVector<WebKit::WebIDBKey>& keys, |
| 45 const WebKit::WebVector<WebKit::WebIDBKey>& primaryKeys, |
| 46 const WebKit::WebVector<WebKit::WebData>& values); |
| 47 virtual void onSuccess(const WebKit::WebIDBKey& value); |
| 48 virtual void onSuccess(const WebKit::WebData& value, |
| 49 const WebKit::WebIDBKey& key, |
| 50 const WebKit::WebIDBKeyPath& keyPath); |
| 51 virtual void onSuccess(long long value); |
| 52 virtual void onSuccess(); |
| 53 |
| 28 protected: | 54 protected: |
| 29 IndexedDBCallbacksBase(IndexedDBDispatcherHost* dispatcher_host, | 55 IndexedDBCallbacksBase(IndexedDBDispatcherHost* dispatcher_host, |
| 30 int32 ipc_thread_id, | 56 int32 ipc_thread_id, |
| 31 int32 ipc_callbacks_id); | 57 int32 ipc_callbacks_id); |
| 32 IndexedDBDispatcherHost* dispatcher_host() const { | 58 IndexedDBDispatcherHost* dispatcher_host() const { |
| 33 return dispatcher_host_.get(); | 59 return dispatcher_host_.get(); |
| 34 } | 60 } |
| 35 int32 ipc_thread_id() const { return ipc_thread_id_; } | 61 int32 ipc_thread_id() const { return ipc_thread_id_; } |
| 36 int32 ipc_callbacks_id() const { return ipc_callbacks_id_; } | 62 int32 ipc_callbacks_id() const { return ipc_callbacks_id_; } |
| 37 | 63 |
| 38 private: | 64 private: |
| 39 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_; | 65 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_; |
| 40 int32 ipc_callbacks_id_; | 66 int32 ipc_callbacks_id_; |
| 41 int32 ipc_thread_id_; | 67 int32 ipc_thread_id_; |
| 42 | 68 |
| 43 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacksBase); | 69 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacksBase); |
| 44 }; | 70 }; |
| 45 | 71 |
| 46 // TODO(dgrogan): Remove this class and change the remaining specializations | 72 // TODO(dgrogan): Remove this class and change the remaining specializations |
| 47 // into subclasses of IndexedDBCallbacksBase. | 73 // into subclasses of IndexedDBCallbacksBase. |
| 48 template <class WebObjectType> | 74 template <class WebObjectType> |
| 49 class IndexedDBCallbacks : public IndexedDBCallbacksBase { | 75 class IndexedDBCallbacks : public IndexedDBCallbacksBase { |
| 50 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks); | 76 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks); |
| 51 }; | 77 }; |
| 52 | 78 |
| 53 class IndexedDBCallbacksDatabase : public IndexedDBCallbacksBase { | 79 class IndexedDBCallbacksDatabase : public IndexedDBCallbacksBase { |
| 54 public: | 80 public: |
| 55 IndexedDBCallbacksDatabase( | 81 IndexedDBCallbacksDatabase(IndexedDBDispatcherHost* dispatcher_host, |
| 56 IndexedDBDispatcherHost* dispatcher_host, | 82 int32 ipc_thread_id, |
| 57 int32 ipc_thread_id, | 83 int32 ipc_callbacks_id, |
| 58 int32 ipc_callbacks_id, | 84 int32 ipc_database_callbacks_id, |
| 59 int32 ipc_database_callbacks_id, | 85 int64 host_transaction_id, |
| 60 int64 host_transaction_id, | 86 const GURL& origin_url); |
| 61 const GURL& origin_url); | |
| 62 | 87 |
| 63 virtual void onSuccess( | 88 virtual void onSuccess(WebIDBDatabaseImpl* idb_object, |
| 64 WebKit::WebIDBDatabase* idb_object, | 89 const WebKit::WebIDBMetadata& metadata) OVERRIDE; |
| 65 const WebKit::WebIDBMetadata& metadata); | 90 virtual void onUpgradeNeeded(long long old_version, |
| 66 virtual void onUpgradeNeeded( | 91 WebIDBDatabaseImpl* database, |
| 67 long long old_version, | 92 const WebKit::WebIDBMetadata&) OVERRIDE; |
| 68 WebKit::WebIDBDatabase* database, | |
| 69 const WebKit::WebIDBMetadata&); | |
| 70 | 93 |
| 71 private: | 94 private: |
| 72 int64 host_transaction_id_; | 95 int64 host_transaction_id_; |
| 73 GURL origin_url_; | 96 GURL origin_url_; |
| 74 int32 ipc_database_id_; | 97 int32 ipc_database_id_; |
| 75 int32 ipc_database_callbacks_id_; | 98 int32 ipc_database_callbacks_id_; |
| 76 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacksDatabase); | 99 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacksDatabase); |
| 77 }; | 100 }; |
| 78 | 101 |
| 79 // WebIDBCursor uses: | 102 // WebIDBCursorImpl uses: |
| 80 // * onSuccess(WebIDBCursor*, WebIDBKey, WebIDBKey, WebData) | 103 // * onSuccess(WebIDBCursorImpl*, WebIDBKey, WebIDBKey, WebData) |
| 81 // when an openCursor()/openKeyCursor() call has succeeded, | 104 // when an openCursor()/openKeyCursor() call has succeeded, |
| 82 // * onSuccess(WebIDBKey, WebIDBKey, WebData) | 105 // * onSuccess(WebIDBKey, WebIDBKey, WebData) |
| 83 // when an advance()/continue() call has succeeded, or | 106 // when an advance()/continue() call has succeeded, or |
| 84 // * onSuccess() | 107 // * onSuccess() |
| 85 // to indicate it does not contain any data, i.e., there is no key within | 108 // to indicate it does not contain any data, i.e., there is no key within |
| 86 // the key range, or it has reached the end. | 109 // the key range, or it has reached the end. |
| 87 template <> | 110 template <> |
| 88 class IndexedDBCallbacks<WebKit::WebIDBCursor> | 111 class IndexedDBCallbacks<WebIDBCursorImpl> : public IndexedDBCallbacksBase { |
| 89 : public IndexedDBCallbacksBase { | |
| 90 public: | 112 public: |
| 91 IndexedDBCallbacks( | 113 IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host, |
| 92 IndexedDBDispatcherHost* dispatcher_host, | 114 int32 ipc_thread_id, |
| 93 int32 ipc_thread_id, | 115 int32 ipc_callbacks_id, |
| 94 int32 ipc_callbacks_id, | 116 int32 ipc_cursor_id) |
| 95 int32 ipc_cursor_id) | 117 : IndexedDBCallbacksBase(dispatcher_host, |
| 96 : IndexedDBCallbacksBase(dispatcher_host, ipc_thread_id, | 118 ipc_thread_id, |
| 97 ipc_callbacks_id), | 119 ipc_callbacks_id), |
| 98 ipc_cursor_id_(ipc_cursor_id) { } | 120 ipc_cursor_id_(ipc_cursor_id) {} |
| 99 | 121 |
| 100 virtual void onSuccess(WebKit::WebIDBCursor* idb_object, | 122 virtual void onSuccess(WebIDBCursorImpl* idb_object, |
| 101 const WebKit::WebIDBKey& key, | 123 const WebKit::WebIDBKey& key, |
| 102 const WebKit::WebIDBKey& primaryKey, | 124 const WebKit::WebIDBKey& primaryKey, |
| 103 const WebKit::WebData& value); | 125 const WebKit::WebData& value); |
| 104 virtual void onSuccess(const WebKit::WebIDBKey& key, | 126 virtual void onSuccess(const WebKit::WebIDBKey& key, |
| 105 const WebKit::WebIDBKey& primaryKey, | 127 const WebKit::WebIDBKey& primaryKey, |
| 106 const WebKit::WebData& value); | 128 const WebKit::WebData& value); |
| 107 virtual void onSuccess(const WebKit::WebData& value); | 129 virtual void onSuccess(const WebKit::WebData& value); |
| 108 virtual void onSuccessWithPrefetch( | 130 virtual void onSuccessWithPrefetch( |
| 109 const WebKit::WebVector<WebKit::WebIDBKey>& keys, | 131 const WebKit::WebVector<WebKit::WebIDBKey>& keys, |
| 110 const WebKit::WebVector<WebKit::WebIDBKey>& primaryKeys, | 132 const WebKit::WebVector<WebKit::WebIDBKey>& primaryKeys, |
| 111 const WebKit::WebVector<WebKit::WebData>& values); | 133 const WebKit::WebVector<WebKit::WebData>& values); |
| 112 | 134 |
| 113 private: | 135 private: |
| 114 // The id of the cursor this callback concerns, or -1 if the cursor | 136 // The id of the cursor this callback concerns, or -1 if the cursor |
| 115 // does not exist yet. | 137 // does not exist yet. |
| 116 int32 ipc_cursor_id_; | 138 int32 ipc_cursor_id_; |
| 117 | 139 |
| 118 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks); | 140 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks); |
| 119 }; | 141 }; |
| 120 | 142 |
| 121 // WebIDBKey is implemented in WebKit as opposed to being an interface Chromium | 143 // WebIDBKey is implemented in WebKit as opposed to being an interface Chromium |
| 122 // implements. Thus we pass a const ___& version and thus we need this | 144 // implements. Thus we pass a const ___& version and thus we need this |
| 123 // specialization. | 145 // specialization. |
| 124 template <> | 146 template <> |
| 125 class IndexedDBCallbacks<WebKit::WebIDBKey> | 147 class IndexedDBCallbacks<WebKit::WebIDBKey> : public IndexedDBCallbacksBase { |
| 126 : public IndexedDBCallbacksBase { | |
| 127 public: | 148 public: |
| 128 IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host, | 149 IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host, |
| 129 int32 ipc_thread_id, | 150 int32 ipc_thread_id, |
| 130 int32 ipc_callbacks_id) | 151 int32 ipc_callbacks_id) |
| 131 : IndexedDBCallbacksBase(dispatcher_host, ipc_thread_id, | 152 : IndexedDBCallbacksBase(dispatcher_host, |
| 132 ipc_callbacks_id) { } | 153 ipc_thread_id, |
| 154 ipc_callbacks_id) {} |
| 133 | 155 |
| 134 virtual void onSuccess(const WebKit::WebIDBKey& value); | 156 virtual void onSuccess(const WebKit::WebIDBKey& value); |
| 135 | 157 |
| 136 private: | 158 private: |
| 137 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks); | 159 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks); |
| 138 }; | 160 }; |
| 139 | 161 |
| 140 // WebVector is implemented in WebKit as opposed to being an | 162 // WebVector is implemented in WebKit as opposed to being an |
| 141 // interface Chromium implements. Thus we pass a const ___& version and thus | 163 // interface Chromium implements. Thus we pass a const ___& version and thus |
| 142 // we need this specialization. | 164 // we need this specialization. |
| 143 template <> | 165 template <> |
| 144 class IndexedDBCallbacks<WebKit::WebVector<WebKit::WebString> > | 166 class IndexedDBCallbacks< |
| 145 : public IndexedDBCallbacksBase { | 167 WebKit::WebVector<WebKit::WebString> > : public IndexedDBCallbacksBase { |
| 146 public: | 168 public: |
| 147 IndexedDBCallbacks( | 169 IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host, |
| 148 IndexedDBDispatcherHost* dispatcher_host, | 170 int32 ipc_thread_id, |
| 149 int32 ipc_thread_id, | 171 int32 ipc_callbacks_id) |
| 150 int32 ipc_callbacks_id) | 172 : IndexedDBCallbacksBase(dispatcher_host, |
| 151 : IndexedDBCallbacksBase(dispatcher_host, ipc_thread_id, | 173 ipc_thread_id, |
| 152 ipc_callbacks_id) { } | 174 ipc_callbacks_id) {} |
| 153 | 175 |
| 154 virtual void onSuccess(const WebKit::WebVector<WebKit::WebString>& value); | 176 virtual void onSuccess(const WebKit::WebVector<WebKit::WebString>& value); |
| 155 | 177 |
| 156 private: | 178 private: |
| 157 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks); | 179 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks); |
| 158 }; | 180 }; |
| 159 | 181 |
| 160 // WebData is implemented in WebKit as opposed to being an interface | 182 // WebData is implemented in WebKit as opposed to being an interface |
| 161 // Chromium implements. Thus we pass a const ___& version and thus we | 183 // Chromium implements. Thus we pass a const ___& version and thus we |
| 162 // need this specialization. | 184 // need this specialization. |
| 163 template <> | 185 template <> |
| 164 class IndexedDBCallbacks<WebKit::WebData> | 186 class IndexedDBCallbacks<WebKit::WebData> : public IndexedDBCallbacksBase { |
| 165 : public IndexedDBCallbacksBase { | |
| 166 public: | 187 public: |
| 167 IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host, | 188 IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host, |
| 168 int32 ipc_thread_id, | 189 int32 ipc_thread_id, |
| 169 int32 ipc_callbacks_id) | 190 int32 ipc_callbacks_id) |
| 170 : IndexedDBCallbacksBase(dispatcher_host, ipc_thread_id, | 191 : IndexedDBCallbacksBase(dispatcher_host, |
| 171 ipc_callbacks_id) { } | 192 ipc_thread_id, |
| 193 ipc_callbacks_id) {} |
| 172 | 194 |
| 173 virtual void onSuccess(const WebKit::WebData& value); | 195 virtual void onSuccess(const WebKit::WebData& value); |
| 174 virtual void onSuccess(const WebKit::WebData& value, | 196 virtual void onSuccess(const WebKit::WebData& value, |
| 175 const WebKit::WebIDBKey& key, | 197 const WebKit::WebIDBKey& key, |
| 176 const WebKit::WebIDBKeyPath& keyPath); | 198 const WebKit::WebIDBKeyPath& keyPath); |
| 177 virtual void onSuccess(long long value); | 199 virtual void onSuccess(long long value); |
| 178 virtual void onSuccess(); | 200 virtual void onSuccess(); |
| 179 virtual void onSuccess(const WebKit::WebIDBKey& value); | 201 virtual void onSuccess(const WebKit::WebIDBKey& value); |
| 180 | 202 |
| 181 private: | 203 private: |
| 182 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks); | 204 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks); |
| 183 }; | 205 }; |
| 184 | 206 |
| 185 } // namespace content | 207 } // namespace content |
| 186 | 208 |
| 187 #endif // CONTENT_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_CALLBACKS_H_ | 209 #endif // CONTENT_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_CALLBACKS_H_ |
| OLD | NEW |