Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: content/browser/indexed_db/indexed_db_callbacks.cc

Issue 18075008: IndexedDB: Switch key/value handling from vector<char> to std::string (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "content/browser/indexed_db/indexed_db_callbacks.h" 5 #include "content/browser/indexed_db/indexed_db_callbacks.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector>
9 8
10 #include "content/browser/indexed_db/indexed_db_connection.h" 9 #include "content/browser/indexed_db/indexed_db_connection.h"
11 #include "content/browser/indexed_db/indexed_db_cursor.h" 10 #include "content/browser/indexed_db/indexed_db_cursor.h"
12 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" 11 #include "content/browser/indexed_db/indexed_db_database_callbacks.h"
13 #include "content/browser/indexed_db/indexed_db_database_error.h" 12 #include "content/browser/indexed_db/indexed_db_database_error.h"
14 #include "content/browser/indexed_db/indexed_db_metadata.h" 13 #include "content/browser/indexed_db/indexed_db_metadata.h"
15 #include "content/common/indexed_db/indexed_db_messages.h" 14 #include "content/common/indexed_db/indexed_db_messages.h"
16 #include "webkit/browser/quota/quota_manager.h" 15 #include "webkit/browser/quota/quota_manager.h"
17 16
18 using WebKit::WebIDBCallbacks; 17 using WebKit::WebIDBCallbacks;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 ipc_callbacks_id_, 152 ipc_callbacks_id_,
154 ipc_database_callbacks_id_, 153 ipc_database_callbacks_id_,
155 ipc_object_id, 154 ipc_object_id,
156 IndexedDBDispatcherHost::ConvertMetadata(metadata))); 155 IndexedDBDispatcherHost::ConvertMetadata(metadata)));
157 dispatcher_host_ = NULL; 156 dispatcher_host_ = NULL;
158 } 157 }
159 158
160 void IndexedDBCallbacks::OnSuccess(scoped_refptr<IndexedDBCursor> cursor, 159 void IndexedDBCallbacks::OnSuccess(scoped_refptr<IndexedDBCursor> cursor,
161 const IndexedDBKey& key, 160 const IndexedDBKey& key,
162 const IndexedDBKey& primary_key, 161 const IndexedDBKey& primary_key,
163 std::vector<char>* value) { 162 std::string* value) {
164 DCHECK(dispatcher_host_.get()); 163 DCHECK(dispatcher_host_.get());
165 164
166 DCHECK_EQ(kNoCursor, ipc_cursor_id_); 165 DCHECK_EQ(kNoCursor, ipc_cursor_id_);
167 DCHECK_EQ(kNoTransaction, host_transaction_id_); 166 DCHECK_EQ(kNoTransaction, host_transaction_id_);
168 DCHECK_EQ(kNoDatabase, ipc_database_id_); 167 DCHECK_EQ(kNoDatabase, ipc_database_id_);
169 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); 168 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_);
170 169
171 int32 ipc_object_id = dispatcher_host_->Add(cursor.get()); 170 int32 ipc_object_id = dispatcher_host_->Add(cursor.get());
172 IndexedDBMsg_CallbacksSuccessIDBCursor_Params params; 171 IndexedDBMsg_CallbacksSuccessIDBCursor_Params params;
173 params.ipc_thread_id = ipc_thread_id_; 172 params.ipc_thread_id = ipc_thread_id_;
174 params.ipc_callbacks_id = ipc_callbacks_id_; 173 params.ipc_callbacks_id = ipc_callbacks_id_;
175 params.ipc_cursor_id = ipc_object_id; 174 params.ipc_cursor_id = ipc_object_id;
176 params.key = key; 175 params.key = key;
177 params.primary_key = primary_key; 176 params.primary_key = primary_key;
178 if (value && !value->empty()) 177 if (value && !value->empty())
179 std::swap(params.value, *value); 178 std::swap(params.value, *value);
180 // TODO(alecflett): Avoid a copy here: the whole params object is 179 // TODO(alecflett): Avoid a copy here: the whole params object is
181 // being copied into the message. 180 // being copied into the message.
182 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessIDBCursor(params)); 181 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessIDBCursor(params));
183 182
184 dispatcher_host_ = NULL; 183 dispatcher_host_ = NULL;
185 } 184 }
186 185
187 void IndexedDBCallbacks::OnSuccess(const IndexedDBKey& key, 186 void IndexedDBCallbacks::OnSuccess(const IndexedDBKey& key,
188 const IndexedDBKey& primary_key, 187 const IndexedDBKey& primary_key,
189 std::vector<char>* value) { 188 std::string* value) {
190 DCHECK(dispatcher_host_.get()); 189 DCHECK(dispatcher_host_.get());
191 190
192 DCHECK_NE(kNoCursor, ipc_cursor_id_); 191 DCHECK_NE(kNoCursor, ipc_cursor_id_);
193 DCHECK_EQ(kNoTransaction, host_transaction_id_); 192 DCHECK_EQ(kNoTransaction, host_transaction_id_);
194 DCHECK_EQ(kNoDatabase, ipc_database_id_); 193 DCHECK_EQ(kNoDatabase, ipc_database_id_);
195 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); 194 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_);
196 195
197 IndexedDBCursor* idb_cursor = 196 IndexedDBCursor* idb_cursor =
198 dispatcher_host_->GetCursorFromId(ipc_cursor_id_); 197 dispatcher_host_->GetCursorFromId(ipc_cursor_id_);
199 198
(...skipping 11 matching lines...) Expand all
211 // TODO(alecflett): Avoid a copy here: the whole params object is 210 // TODO(alecflett): Avoid a copy here: the whole params object is
212 // being copied into the message. 211 // being copied into the message.
213 dispatcher_host_->Send( 212 dispatcher_host_->Send(
214 new IndexedDBMsg_CallbacksSuccessCursorContinue(params)); 213 new IndexedDBMsg_CallbacksSuccessCursorContinue(params));
215 dispatcher_host_ = NULL; 214 dispatcher_host_ = NULL;
216 } 215 }
217 216
218 void IndexedDBCallbacks::OnSuccessWithPrefetch( 217 void IndexedDBCallbacks::OnSuccessWithPrefetch(
219 const std::vector<IndexedDBKey>& keys, 218 const std::vector<IndexedDBKey>& keys,
220 const std::vector<IndexedDBKey>& primary_keys, 219 const std::vector<IndexedDBKey>& primary_keys,
221 const std::vector<std::vector<char> >& values) { 220 const std::vector<std::string>& values) {
222 DCHECK_EQ(keys.size(), primary_keys.size()); 221 DCHECK_EQ(keys.size(), primary_keys.size());
223 DCHECK_EQ(keys.size(), values.size()); 222 DCHECK_EQ(keys.size(), values.size());
224 223
225 DCHECK(dispatcher_host_.get()); 224 DCHECK(dispatcher_host_.get());
226 225
227 DCHECK_NE(kNoCursor, ipc_cursor_id_); 226 DCHECK_NE(kNoCursor, ipc_cursor_id_);
228 DCHECK_EQ(kNoTransaction, host_transaction_id_); 227 DCHECK_EQ(kNoTransaction, host_transaction_id_);
229 DCHECK_EQ(kNoDatabase, ipc_database_id_); 228 DCHECK_EQ(kNoDatabase, ipc_database_id_);
230 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); 229 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_);
231 230
(...skipping 10 matching lines...) Expand all
242 params.ipc_callbacks_id = ipc_callbacks_id_; 241 params.ipc_callbacks_id = ipc_callbacks_id_;
243 params.ipc_cursor_id = ipc_cursor_id_; 242 params.ipc_cursor_id = ipc_cursor_id_;
244 params.keys = msgKeys; 243 params.keys = msgKeys;
245 params.primary_keys = msgPrimaryKeys; 244 params.primary_keys = msgPrimaryKeys;
246 params.values = values; 245 params.values = values;
247 dispatcher_host_->Send( 246 dispatcher_host_->Send(
248 new IndexedDBMsg_CallbacksSuccessCursorPrefetch(params)); 247 new IndexedDBMsg_CallbacksSuccessCursorPrefetch(params));
249 dispatcher_host_ = NULL; 248 dispatcher_host_ = NULL;
250 } 249 }
251 250
252 void IndexedDBCallbacks::OnSuccess(std::vector<char>* value, 251 void IndexedDBCallbacks::OnSuccess(std::string* value,
253 const IndexedDBKey& key, 252 const IndexedDBKey& key,
254 const IndexedDBKeyPath& key_path) { 253 const IndexedDBKeyPath& key_path) {
255 DCHECK(dispatcher_host_.get()); 254 DCHECK(dispatcher_host_.get());
256 255
257 DCHECK_EQ(kNoCursor, ipc_cursor_id_); 256 DCHECK_EQ(kNoCursor, ipc_cursor_id_);
258 DCHECK_EQ(kNoTransaction, host_transaction_id_); 257 DCHECK_EQ(kNoTransaction, host_transaction_id_);
259 DCHECK_EQ(kNoDatabase, ipc_database_id_); 258 DCHECK_EQ(kNoDatabase, ipc_database_id_);
260 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); 259 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_);
261 260
262 std::vector<char> value_copy; 261 std::string value_copy;
263 if (value && !value->empty()) 262 if (value && !value->empty())
264 std::swap(value_copy, *value); 263 std::swap(value_copy, *value);
264
265 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessValueWithKey( 265 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessValueWithKey(
266 ipc_thread_id_, 266 ipc_thread_id_,
267 ipc_callbacks_id_, 267 ipc_callbacks_id_,
268 // TODO(alecflett): Avoid a copy here. 268 // TODO(alecflett): Avoid a copy here.
269 value_copy, 269 value_copy,
270 key, 270 key,
271 key_path)); 271 key_path));
272 dispatcher_host_ = NULL; 272 dispatcher_host_ = NULL;
273 } 273 }
274 274
275 void IndexedDBCallbacks::OnSuccess(std::vector<char>* value) { 275 void IndexedDBCallbacks::OnSuccess(std::string* value) {
276 DCHECK(dispatcher_host_.get()); 276 DCHECK(dispatcher_host_.get());
277 277
278 DCHECK(kNoCursor == ipc_cursor_id_ || value == NULL); 278 DCHECK(kNoCursor == ipc_cursor_id_ || value == NULL);
279 DCHECK_EQ(kNoTransaction, host_transaction_id_); 279 DCHECK_EQ(kNoTransaction, host_transaction_id_);
280 DCHECK_EQ(kNoDatabase, ipc_database_id_); 280 DCHECK_EQ(kNoDatabase, ipc_database_id_);
281 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); 281 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_);
282 282
283 std::vector<char> value_copy; 283 std::string value_copy;
284 if (value && !value->empty()) 284 if (value && !value->empty())
285 std::swap(value_copy, *value); 285 std::swap(value_copy, *value);
286
286 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessValue( 287 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessValue(
287 ipc_thread_id_, 288 ipc_thread_id_,
288 ipc_callbacks_id_, 289 ipc_callbacks_id_,
289 // TODO(alecflett): avoid a copy here. 290 // TODO(alecflett): avoid a copy here.
290 value_copy)); 291 value_copy));
291 dispatcher_host_ = NULL; 292 dispatcher_host_ = NULL;
292 } 293 }
293 294
294 void IndexedDBCallbacks::OnSuccess(const IndexedDBKey& value) { 295 void IndexedDBCallbacks::OnSuccess(const IndexedDBKey& value) {
295 DCHECK(dispatcher_host_.get()); 296 DCHECK(dispatcher_host_.get());
(...skipping 28 matching lines...) Expand all
324 DCHECK_EQ(kNoTransaction, host_transaction_id_); 325 DCHECK_EQ(kNoTransaction, host_transaction_id_);
325 DCHECK_EQ(kNoDatabase, ipc_database_id_); 326 DCHECK_EQ(kNoDatabase, ipc_database_id_);
326 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); 327 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_);
327 328
328 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessUndefined( 329 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessUndefined(
329 ipc_thread_id_, ipc_callbacks_id_)); 330 ipc_thread_id_, ipc_callbacks_id_));
330 dispatcher_host_ = NULL; 331 dispatcher_host_ = NULL;
331 } 332 }
332 333
333 } // namespace content 334 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698