| 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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 void EncodeDouble(double value, std::string* into) { | 286 void EncodeDouble(double value, std::string* into) { |
| 287 // This always has host endianness. | 287 // This always has host endianness. |
| 288 const char* p = reinterpret_cast<char*>(&value); | 288 const char* p = reinterpret_cast<char*>(&value); |
| 289 into->insert(into->end(), p, p + sizeof(value)); | 289 into->insert(into->end(), p, p + sizeof(value)); |
| 290 } | 290 } |
| 291 | 291 |
| 292 void EncodeIDBKey(const IndexedDBKey& value, std::string* into) { | 292 void EncodeIDBKey(const IndexedDBKey& value, std::string* into) { |
| 293 size_t previous_size = into->size(); | 293 size_t previous_size = into->size(); |
| 294 DCHECK(value.IsValid()); | 294 DCHECK(value.IsValid()); |
| 295 switch (value.type()) { | 295 switch (value.type()) { |
| 296 case WebIDBKeyTypeNull: | |
| 297 case WebIDBKeyTypeInvalid: | |
| 298 case WebIDBKeyTypeMin: | |
| 299 default: { | |
| 300 NOTREACHED(); | |
| 301 EncodeByte(kIndexedDBKeyNullTypeByte, into); | |
| 302 return; | |
| 303 } | |
| 304 case WebIDBKeyTypeArray: { | 296 case WebIDBKeyTypeArray: { |
| 305 EncodeByte(kIndexedDBKeyArrayTypeByte, into); | 297 EncodeByte(kIndexedDBKeyArrayTypeByte, into); |
| 306 size_t length = value.array().size(); | 298 size_t length = value.array().size(); |
| 307 EncodeVarInt(length, into); | 299 EncodeVarInt(length, into); |
| 308 for (size_t i = 0; i < length; ++i) | 300 for (size_t i = 0; i < length; ++i) |
| 309 EncodeIDBKey(value.array()[i], into); | 301 EncodeIDBKey(value.array()[i], into); |
| 310 DCHECK_GT(into->size(), previous_size); | 302 DCHECK_GT(into->size(), previous_size); |
| 311 return; | 303 return; |
| 312 } | 304 } |
| 313 case WebIDBKeyTypeBinary: { | 305 |
| 306 case WebIDBKeyTypeBinary: |
| 314 EncodeByte(kIndexedDBKeyBinaryTypeByte, into); | 307 EncodeByte(kIndexedDBKeyBinaryTypeByte, into); |
| 315 EncodeBinary(value.binary(), into); | 308 EncodeBinary(value.binary(), into); |
| 316 DCHECK_GT(into->size(), previous_size); | 309 DCHECK_GT(into->size(), previous_size); |
| 317 return; | 310 return; |
| 318 } | 311 |
| 319 case WebIDBKeyTypeString: { | 312 case WebIDBKeyTypeString: |
| 320 EncodeByte(kIndexedDBKeyStringTypeByte, into); | 313 EncodeByte(kIndexedDBKeyStringTypeByte, into); |
| 321 EncodeStringWithLength(value.string(), into); | 314 EncodeStringWithLength(value.string(), into); |
| 322 DCHECK_GT(into->size(), previous_size); | 315 DCHECK_GT(into->size(), previous_size); |
| 323 return; | 316 return; |
| 324 } | 317 |
| 325 case WebIDBKeyTypeDate: { | 318 case WebIDBKeyTypeDate: |
| 326 EncodeByte(kIndexedDBKeyDateTypeByte, into); | 319 EncodeByte(kIndexedDBKeyDateTypeByte, into); |
| 327 EncodeDouble(value.date(), into); | 320 EncodeDouble(value.date(), into); |
| 328 DCHECK_EQ(9u, static_cast<size_t>(into->size() - previous_size)); | 321 DCHECK_EQ(9u, static_cast<size_t>(into->size() - previous_size)); |
| 329 return; | 322 return; |
| 330 } | 323 |
| 331 case WebIDBKeyTypeNumber: { | 324 case WebIDBKeyTypeNumber: |
| 332 EncodeByte(kIndexedDBKeyNumberTypeByte, into); | 325 EncodeByte(kIndexedDBKeyNumberTypeByte, into); |
| 333 EncodeDouble(value.number(), into); | 326 EncodeDouble(value.number(), into); |
| 334 DCHECK_EQ(9u, static_cast<size_t>(into->size() - previous_size)); | 327 DCHECK_EQ(9u, static_cast<size_t>(into->size() - previous_size)); |
| 335 return; | 328 return; |
| 336 } | 329 |
| 330 case WebIDBKeyTypeNull: |
| 331 case WebIDBKeyTypeInvalid: |
| 332 case WebIDBKeyTypeMin: |
| 333 default: |
| 334 NOTREACHED(); |
| 335 EncodeByte(kIndexedDBKeyNullTypeByte, into); |
| 336 return; |
| 337 } | 337 } |
| 338 | |
| 339 NOTREACHED(); | |
| 340 } | 338 } |
| 341 | 339 |
| 342 void EncodeIDBKeyPath(const IndexedDBKeyPath& value, std::string* into) { | 340 void EncodeIDBKeyPath(const IndexedDBKeyPath& value, std::string* into) { |
| 343 // May be typed, or may be a raw string. An invalid leading | 341 // May be typed, or may be a raw string. An invalid leading |
| 344 // byte is used to identify typed coding. New records are | 342 // byte is used to identify typed coding. New records are |
| 345 // always written as typed. | 343 // always written as typed. |
| 346 EncodeByte(kIndexedDBKeyPathTypeCodedByte1, into); | 344 EncodeByte(kIndexedDBKeyPathTypeCodedByte1, into); |
| 347 EncodeByte(kIndexedDBKeyPathTypeCodedByte2, into); | 345 EncodeByte(kIndexedDBKeyPathTypeCodedByte2, into); |
| 348 EncodeByte(static_cast<char>(value.type()), into); | 346 EncodeByte(static_cast<char>(value.type()), into); |
| 349 switch (value.type()) { | 347 switch (value.type()) { |
| (...skipping 1521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1871 scoped_ptr<IndexedDBKey> IndexDataKey::primary_key() const { | 1869 scoped_ptr<IndexedDBKey> IndexDataKey::primary_key() const { |
| 1872 scoped_ptr<IndexedDBKey> key; | 1870 scoped_ptr<IndexedDBKey> key; |
| 1873 StringPiece slice(encoded_primary_key_); | 1871 StringPiece slice(encoded_primary_key_); |
| 1874 if (!DecodeIDBKey(&slice, &key)) { | 1872 if (!DecodeIDBKey(&slice, &key)) { |
| 1875 // TODO(jsbell): Return error. | 1873 // TODO(jsbell): Return error. |
| 1876 } | 1874 } |
| 1877 return key.Pass(); | 1875 return key.Pass(); |
| 1878 } | 1876 } |
| 1879 | 1877 |
| 1880 } // namespace content | 1878 } // namespace content |
| OLD | NEW |