Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_leveldb_coding.h" | 5 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h" |
| 6 | 6 |
| 7 #include <iterator> | 7 #include <iterator> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 void EncodeDouble(double value, std::string* into) { | 303 void EncodeDouble(double value, std::string* into) { |
| 304 // This always has host endianness. | 304 // This always has host endianness. |
| 305 const char* p = reinterpret_cast<char*>(&value); | 305 const char* p = reinterpret_cast<char*>(&value); |
| 306 into->insert(into->end(), p, p + sizeof(value)); | 306 into->insert(into->end(), p, p + sizeof(value)); |
| 307 } | 307 } |
| 308 | 308 |
| 309 void EncodeIDBKey(const IndexedDBKey& value, std::string* into) { | 309 void EncodeIDBKey(const IndexedDBKey& value, std::string* into) { |
| 310 size_t previous_size = into->size(); | 310 size_t previous_size = into->size(); |
| 311 DCHECK(value.IsValid()); | 311 DCHECK(value.IsValid()); |
| 312 switch (value.type()) { | 312 switch (value.type()) { |
| 313 case WebIDBKeyTypeNull: | |
| 314 case WebIDBKeyTypeInvalid: | |
| 315 case WebIDBKeyTypeMin: | |
| 316 default: { | |
| 317 NOTREACHED(); | |
| 318 EncodeByte(kIndexedDBKeyNullTypeByte, into); | |
| 319 return; | |
| 320 } | |
| 321 case WebIDBKeyTypeArray: { | 313 case WebIDBKeyTypeArray: { |
| 322 EncodeByte(kIndexedDBKeyArrayTypeByte, into); | 314 EncodeByte(kIndexedDBKeyArrayTypeByte, into); |
| 323 size_t length = value.array().size(); | 315 size_t length = value.array().size(); |
| 324 EncodeVarInt(length, into); | 316 EncodeVarInt(length, into); |
| 325 for (size_t i = 0; i < length; ++i) | 317 for (size_t i = 0; i < length; ++i) |
| 326 EncodeIDBKey(value.array()[i], into); | 318 EncodeIDBKey(value.array()[i], into); |
| 327 DCHECK_GT(into->size(), previous_size); | 319 DCHECK_GT(into->size(), previous_size); |
| 328 return; | 320 return; |
| 329 } | 321 } |
| 330 case WebIDBKeyTypeBinary: { | 322 |
|
jam
2014/03/19 16:44:36
nit: the style guide doesn't show blank lines betw
Peter Kasting
2014/03/19 21:10:57
Done.
| |
| 323 case WebIDBKeyTypeBinary: | |
| 331 EncodeByte(kIndexedDBKeyBinaryTypeByte, into); | 324 EncodeByte(kIndexedDBKeyBinaryTypeByte, into); |
| 332 EncodeBinary(value.binary(), into); | 325 EncodeBinary(value.binary(), into); |
| 333 DCHECK_GT(into->size(), previous_size); | 326 DCHECK_GT(into->size(), previous_size); |
| 334 return; | 327 return; |
| 335 } | 328 |
| 336 case WebIDBKeyTypeString: { | 329 case WebIDBKeyTypeString: |
| 337 EncodeByte(kIndexedDBKeyStringTypeByte, into); | 330 EncodeByte(kIndexedDBKeyStringTypeByte, into); |
| 338 EncodeStringWithLength(value.string(), into); | 331 EncodeStringWithLength(value.string(), into); |
| 339 DCHECK_GT(into->size(), previous_size); | 332 DCHECK_GT(into->size(), previous_size); |
| 340 return; | 333 return; |
| 341 } | 334 |
| 342 case WebIDBKeyTypeDate: { | 335 case WebIDBKeyTypeDate: |
| 343 EncodeByte(kIndexedDBKeyDateTypeByte, into); | 336 EncodeByte(kIndexedDBKeyDateTypeByte, into); |
| 344 EncodeDouble(value.date(), into); | 337 EncodeDouble(value.date(), into); |
| 345 DCHECK_EQ(9u, static_cast<size_t>(into->size() - previous_size)); | 338 DCHECK_EQ(9u, static_cast<size_t>(into->size() - previous_size)); |
| 346 return; | 339 return; |
| 347 } | 340 |
| 348 case WebIDBKeyTypeNumber: { | 341 case WebIDBKeyTypeNumber: |
| 349 EncodeByte(kIndexedDBKeyNumberTypeByte, into); | 342 EncodeByte(kIndexedDBKeyNumberTypeByte, into); |
| 350 EncodeDouble(value.number(), into); | 343 EncodeDouble(value.number(), into); |
| 351 DCHECK_EQ(9u, static_cast<size_t>(into->size() - previous_size)); | 344 DCHECK_EQ(9u, static_cast<size_t>(into->size() - previous_size)); |
| 352 return; | 345 return; |
| 353 } | 346 |
| 347 case WebIDBKeyTypeNull: | |
| 348 case WebIDBKeyTypeInvalid: | |
| 349 case WebIDBKeyTypeMin: | |
| 350 default: | |
| 351 NOTREACHED(); | |
| 352 EncodeByte(kIndexedDBKeyNullTypeByte, into); | |
| 353 return; | |
| 354 } | 354 } |
| 355 | |
| 356 NOTREACHED(); | |
| 357 } | 355 } |
| 358 | 356 |
| 359 void EncodeIDBKeyPath(const IndexedDBKeyPath& value, std::string* into) { | 357 void EncodeIDBKeyPath(const IndexedDBKeyPath& value, std::string* into) { |
| 360 // May be typed, or may be a raw string. An invalid leading | 358 // May be typed, or may be a raw string. An invalid leading |
| 361 // byte is used to identify typed coding. New records are | 359 // byte is used to identify typed coding. New records are |
| 362 // always written as typed. | 360 // always written as typed. |
| 363 EncodeByte(kIndexedDBKeyPathTypeCodedByte1, into); | 361 EncodeByte(kIndexedDBKeyPathTypeCodedByte1, into); |
| 364 EncodeByte(kIndexedDBKeyPathTypeCodedByte2, into); | 362 EncodeByte(kIndexedDBKeyPathTypeCodedByte2, into); |
| 365 EncodeByte(static_cast<char>(value.type()), into); | 363 EncodeByte(static_cast<char>(value.type()), into); |
| 366 switch (value.type()) { | 364 switch (value.type()) { |
| (...skipping 1640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2007 scoped_ptr<IndexedDBKey> IndexDataKey::primary_key() const { | 2005 scoped_ptr<IndexedDBKey> IndexDataKey::primary_key() const { |
| 2008 scoped_ptr<IndexedDBKey> key; | 2006 scoped_ptr<IndexedDBKey> key; |
| 2009 StringPiece slice(encoded_primary_key_); | 2007 StringPiece slice(encoded_primary_key_); |
| 2010 if (!DecodeIDBKey(&slice, &key)) { | 2008 if (!DecodeIDBKey(&slice, &key)) { |
| 2011 // TODO(jsbell): Return error. | 2009 // TODO(jsbell): Return error. |
| 2012 } | 2010 } |
| 2013 return key.Pass(); | 2011 return key.Pass(); |
| 2014 } | 2012 } |
| 2015 | 2013 |
| 2016 } // namespace content | 2014 } // namespace content |
| OLD | NEW |