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

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

Issue 1549113002: Switch to standard integer types in content/browser/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 12 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
OLDNEW
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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 static const unsigned char kObjectStoreFreeListTypeByte = 150; 216 static const unsigned char kObjectStoreFreeListTypeByte = 150;
217 static const unsigned char kIndexFreeListTypeByte = 151; 217 static const unsigned char kIndexFreeListTypeByte = 151;
218 static const unsigned char kObjectStoreNamesTypeByte = 200; 218 static const unsigned char kObjectStoreNamesTypeByte = 200;
219 static const unsigned char kIndexNamesKeyTypeByte = 201; 219 static const unsigned char kIndexNamesKeyTypeByte = 201;
220 220
221 static const unsigned char kObjectMetaDataTypeMaximum = 255; 221 static const unsigned char kObjectMetaDataTypeMaximum = 255;
222 static const unsigned char kIndexMetaDataTypeMaximum = 255; 222 static const unsigned char kIndexMetaDataTypeMaximum = 255;
223 223
224 const unsigned char kMinimumIndexId = 30; 224 const unsigned char kMinimumIndexId = 30;
225 225
226 inline void EncodeIntSafely(int64 value, int64 max, std::string* into) { 226 inline void EncodeIntSafely(int64_t value, int64_t max, std::string* into) {
227 DCHECK_LE(value, max); 227 DCHECK_LE(value, max);
228 return EncodeInt(value, into); 228 return EncodeInt(value, into);
229 } 229 }
230 230
231 std::string MaxIDBKey() { 231 std::string MaxIDBKey() {
232 std::string ret; 232 std::string ret;
233 EncodeByte(kIndexedDBKeyNullTypeByte, &ret); 233 EncodeByte(kIndexedDBKeyNullTypeByte, &ret);
234 return ret; 234 return ret;
235 } 235 }
236 236
237 std::string MinIDBKey() { 237 std::string MinIDBKey() {
238 std::string ret; 238 std::string ret;
239 EncodeByte(kIndexedDBKeyMinKeyTypeByte, &ret); 239 EncodeByte(kIndexedDBKeyMinKeyTypeByte, &ret);
240 return ret; 240 return ret;
241 } 241 }
242 242
243 void EncodeByte(unsigned char value, std::string* into) { 243 void EncodeByte(unsigned char value, std::string* into) {
244 into->push_back(value); 244 into->push_back(value);
245 } 245 }
246 246
247 void EncodeBool(bool value, std::string* into) { 247 void EncodeBool(bool value, std::string* into) {
248 into->push_back(value ? 1 : 0); 248 into->push_back(value ? 1 : 0);
249 } 249 }
250 250
251 void EncodeInt(int64 value, std::string* into) { 251 void EncodeInt(int64_t value, std::string* into) {
252 #ifndef NDEBUG 252 #ifndef NDEBUG
253 // Exercised by unit tests in debug only. 253 // Exercised by unit tests in debug only.
254 DCHECK_GE(value, 0); 254 DCHECK_GE(value, 0);
255 #endif 255 #endif
256 uint64 n = static_cast<uint64>(value); 256 uint64_t n = static_cast<uint64_t>(value);
257 257
258 do { 258 do {
259 unsigned char c = n; 259 unsigned char c = n;
260 into->push_back(c); 260 into->push_back(c);
261 n >>= 8; 261 n >>= 8;
262 } while (n); 262 } while (n);
263 } 263 }
264 264
265 void EncodeVarInt(int64 value, std::string* into) { 265 void EncodeVarInt(int64_t value, std::string* into) {
266 #ifndef NDEBUG 266 #ifndef NDEBUG
267 // Exercised by unit tests in debug only. 267 // Exercised by unit tests in debug only.
268 DCHECK_GE(value, 0); 268 DCHECK_GE(value, 0);
269 #endif 269 #endif
270 uint64 n = static_cast<uint64>(value); 270 uint64_t n = static_cast<uint64_t>(value);
271 271
272 do { 272 do {
273 unsigned char c = n & 0x7f; 273 unsigned char c = n & 0x7f;
274 n >>= 7; 274 n >>= 7;
275 if (n) 275 if (n)
276 c |= 0x80; 276 c |= 0x80;
277 into->push_back(c); 277 into->push_back(c);
278 } while (n); 278 } while (n);
279 } 279 }
280 280
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 397
398 bool DecodeBool(StringPiece* slice, bool* value) { 398 bool DecodeBool(StringPiece* slice, bool* value) {
399 if (slice->empty()) 399 if (slice->empty())
400 return false; 400 return false;
401 401
402 *value = !!(*slice)[0]; 402 *value = !!(*slice)[0];
403 slice->remove_prefix(1); 403 slice->remove_prefix(1);
404 return true; 404 return true;
405 } 405 }
406 406
407 bool DecodeInt(StringPiece* slice, int64* value) { 407 bool DecodeInt(StringPiece* slice, int64_t* value) {
408 if (slice->empty()) 408 if (slice->empty())
409 return false; 409 return false;
410 410
411 StringPiece::const_iterator it = slice->begin(); 411 StringPiece::const_iterator it = slice->begin();
412 int shift = 0; 412 int shift = 0;
413 int64 ret = 0; 413 int64_t ret = 0;
414 while (it != slice->end()) { 414 while (it != slice->end()) {
415 unsigned char c = *it++; 415 unsigned char c = *it++;
416 ret |= static_cast<int64>(c) << shift; 416 ret |= static_cast<int64_t>(c) << shift;
417 shift += 8; 417 shift += 8;
418 } 418 }
419 *value = ret; 419 *value = ret;
420 slice->remove_prefix(it - slice->begin()); 420 slice->remove_prefix(it - slice->begin());
421 return true; 421 return true;
422 } 422 }
423 423
424 bool DecodeVarInt(StringPiece* slice, int64* value) { 424 bool DecodeVarInt(StringPiece* slice, int64_t* value) {
425 if (slice->empty()) 425 if (slice->empty())
426 return false; 426 return false;
427 427
428 StringPiece::const_iterator it = slice->begin(); 428 StringPiece::const_iterator it = slice->begin();
429 int shift = 0; 429 int shift = 0;
430 int64 ret = 0; 430 int64_t ret = 0;
431 do { 431 do {
432 if (it == slice->end()) 432 if (it == slice->end())
433 return false; 433 return false;
434 434
435 unsigned char c = *it; 435 unsigned char c = *it;
436 ret |= static_cast<int64>(c & 0x7f) << shift; 436 ret |= static_cast<int64_t>(c & 0x7f) << shift;
437 shift += 7; 437 shift += 7;
438 } while (*it++ & 0x80); 438 } while (*it++ & 0x80);
439 *value = ret; 439 *value = ret;
440 slice->remove_prefix(it - slice->begin()); 440 slice->remove_prefix(it - slice->begin());
441 return true; 441 return true;
442 } 442 }
443 443
444 bool DecodeString(StringPiece* slice, base::string16* value) { 444 bool DecodeString(StringPiece* slice, base::string16* value) {
445 if (slice->empty()) { 445 if (slice->empty()) {
446 value->clear(); 446 value->clear();
(...skipping 12 matching lines...) Expand all
459 459
460 *value = decoded; 460 *value = decoded;
461 slice->remove_prefix(length * sizeof(base::char16)); 461 slice->remove_prefix(length * sizeof(base::char16));
462 return true; 462 return true;
463 } 463 }
464 464
465 bool DecodeStringWithLength(StringPiece* slice, base::string16* value) { 465 bool DecodeStringWithLength(StringPiece* slice, base::string16* value) {
466 if (slice->empty()) 466 if (slice->empty())
467 return false; 467 return false;
468 468
469 int64 length = 0; 469 int64_t length = 0;
470 if (!DecodeVarInt(slice, &length) || length < 0) 470 if (!DecodeVarInt(slice, &length) || length < 0)
471 return false; 471 return false;
472 size_t bytes = length * sizeof(base::char16); 472 size_t bytes = length * sizeof(base::char16);
473 if (slice->size() < bytes) 473 if (slice->size() < bytes)
474 return false; 474 return false;
475 475
476 StringPiece subpiece(slice->begin(), bytes); 476 StringPiece subpiece(slice->begin(), bytes);
477 slice->remove_prefix(bytes); 477 slice->remove_prefix(bytes);
478 if (!DecodeString(&subpiece, value)) 478 if (!DecodeString(&subpiece, value))
479 return false; 479 return false;
480 480
481 return true; 481 return true;
482 } 482 }
483 483
484 bool DecodeBinary(StringPiece* slice, std::string* value) { 484 bool DecodeBinary(StringPiece* slice, std::string* value) {
485 if (slice->empty()) 485 if (slice->empty())
486 return false; 486 return false;
487 487
488 int64 length = 0; 488 int64_t length = 0;
489 if (!DecodeVarInt(slice, &length) || length < 0) 489 if (!DecodeVarInt(slice, &length) || length < 0)
490 return false; 490 return false;
491 size_t size = length; 491 size_t size = length;
492 if (slice->size() < size) 492 if (slice->size() < size)
493 return false; 493 return false;
494 494
495 value->assign(slice->begin(), size); 495 value->assign(slice->begin(), size);
496 slice->remove_prefix(size); 496 slice->remove_prefix(size);
497 return true; 497 return true;
498 } 498 }
499 499
500 bool DecodeIDBKey(StringPiece* slice, scoped_ptr<IndexedDBKey>* value) { 500 bool DecodeIDBKey(StringPiece* slice, scoped_ptr<IndexedDBKey>* value) {
501 if (slice->empty()) 501 if (slice->empty())
502 return false; 502 return false;
503 503
504 unsigned char type = (*slice)[0]; 504 unsigned char type = (*slice)[0];
505 slice->remove_prefix(1); 505 slice->remove_prefix(1);
506 506
507 switch (type) { 507 switch (type) {
508 case kIndexedDBKeyNullTypeByte: 508 case kIndexedDBKeyNullTypeByte:
509 *value = make_scoped_ptr(new IndexedDBKey()); 509 *value = make_scoped_ptr(new IndexedDBKey());
510 return true; 510 return true;
511 511
512 case kIndexedDBKeyArrayTypeByte: { 512 case kIndexedDBKeyArrayTypeByte: {
513 int64 length = 0; 513 int64_t length = 0;
514 if (!DecodeVarInt(slice, &length) || length < 0) 514 if (!DecodeVarInt(slice, &length) || length < 0)
515 return false; 515 return false;
516 IndexedDBKey::KeyArray array; 516 IndexedDBKey::KeyArray array;
517 while (length--) { 517 while (length--) {
518 scoped_ptr<IndexedDBKey> key; 518 scoped_ptr<IndexedDBKey> key;
519 if (!DecodeIDBKey(slice, &key)) 519 if (!DecodeIDBKey(slice, &key))
520 return false; 520 return false;
521 array.push_back(*key); 521 array.push_back(*key);
522 } 522 }
523 *value = make_scoped_ptr(new IndexedDBKey(array)); 523 *value = make_scoped_ptr(new IndexedDBKey(array));
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 case WebIDBKeyPathTypeString: { 592 case WebIDBKeyPathTypeString: {
593 base::string16 string; 593 base::string16 string;
594 if (!DecodeStringWithLength(slice, &string)) 594 if (!DecodeStringWithLength(slice, &string))
595 return false; 595 return false;
596 DCHECK(slice->empty()); 596 DCHECK(slice->empty());
597 *value = IndexedDBKeyPath(string); 597 *value = IndexedDBKeyPath(string);
598 return true; 598 return true;
599 } 599 }
600 case WebIDBKeyPathTypeArray: { 600 case WebIDBKeyPathTypeArray: {
601 std::vector<base::string16> array; 601 std::vector<base::string16> array;
602 int64 count; 602 int64_t count;
603 if (!DecodeVarInt(slice, &count)) 603 if (!DecodeVarInt(slice, &count))
604 return false; 604 return false;
605 DCHECK_GE(count, 0); 605 DCHECK_GE(count, 0);
606 while (count--) { 606 while (count--) {
607 base::string16 string; 607 base::string16 string;
608 if (!DecodeStringWithLength(slice, &string)) 608 if (!DecodeStringWithLength(slice, &string))
609 return false; 609 return false;
610 array.push_back(string); 610 array.push_back(string);
611 } 611 }
612 DCHECK(slice->empty()); 612 DCHECK(slice->empty());
613 *value = IndexedDBKeyPath(array); 613 *value = IndexedDBKeyPath(array);
614 return true; 614 return true;
615 } 615 }
616 } 616 }
617 NOTREACHED(); 617 NOTREACHED();
618 return false; 618 return false;
619 } 619 }
620 620
621 bool DecodeBlobJournal(StringPiece* slice, BlobJournalType* journal) { 621 bool DecodeBlobJournal(StringPiece* slice, BlobJournalType* journal) {
622 BlobJournalType output; 622 BlobJournalType output;
623 while (!slice->empty()) { 623 while (!slice->empty()) {
624 int64 database_id = -1; 624 int64_t database_id = -1;
625 int64 blob_key = -1; 625 int64_t blob_key = -1;
626 if (!DecodeVarInt(slice, &database_id)) 626 if (!DecodeVarInt(slice, &database_id))
627 return false; 627 return false;
628 if (!KeyPrefix::IsValidDatabaseId(database_id)) 628 if (!KeyPrefix::IsValidDatabaseId(database_id))
629 return false; 629 return false;
630 if (!DecodeVarInt(slice, &blob_key)) 630 if (!DecodeVarInt(slice, &blob_key))
631 return false; 631 return false;
632 if (!DatabaseMetaDataKey::IsValidBlobKey(blob_key) && 632 if (!DatabaseMetaDataKey::IsValidBlobKey(blob_key) &&
633 (blob_key != DatabaseMetaDataKey::kAllBlobsKey)) { 633 (blob_key != DatabaseMetaDataKey::kAllBlobsKey)) {
634 return false; 634 return false;
635 } 635 }
636 output.push_back(std::make_pair(database_id, blob_key)); 636 output.push_back(std::make_pair(database_id, blob_key));
637 } 637 }
638 journal->swap(output); 638 journal->swap(output);
639 return true; 639 return true;
640 } 640 }
641 641
642 bool ConsumeEncodedIDBKey(StringPiece* slice) { 642 bool ConsumeEncodedIDBKey(StringPiece* slice) {
643 unsigned char type = (*slice)[0]; 643 unsigned char type = (*slice)[0];
644 slice->remove_prefix(1); 644 slice->remove_prefix(1);
645 645
646 switch (type) { 646 switch (type) {
647 case kIndexedDBKeyNullTypeByte: 647 case kIndexedDBKeyNullTypeByte:
648 case kIndexedDBKeyMinKeyTypeByte: 648 case kIndexedDBKeyMinKeyTypeByte:
649 return true; 649 return true;
650 case kIndexedDBKeyArrayTypeByte: { 650 case kIndexedDBKeyArrayTypeByte: {
651 int64 length; 651 int64_t length;
652 if (!DecodeVarInt(slice, &length)) 652 if (!DecodeVarInt(slice, &length))
653 return false; 653 return false;
654 while (length--) { 654 while (length--) {
655 if (!ConsumeEncodedIDBKey(slice)) 655 if (!ConsumeEncodedIDBKey(slice))
656 return false; 656 return false;
657 } 657 }
658 return true; 658 return true;
659 } 659 }
660 case kIndexedDBKeyBinaryTypeByte: { 660 case kIndexedDBKeyBinaryTypeByte: {
661 int64 length = 0; 661 int64_t length = 0;
662 if (!DecodeVarInt(slice, &length) || length < 0) 662 if (!DecodeVarInt(slice, &length) || length < 0)
663 return false; 663 return false;
664 if (slice->size() < static_cast<size_t>(length)) 664 if (slice->size() < static_cast<size_t>(length))
665 return false; 665 return false;
666 slice->remove_prefix(length); 666 slice->remove_prefix(length);
667 return true; 667 return true;
668 } 668 }
669 case kIndexedDBKeyStringTypeByte: { 669 case kIndexedDBKeyStringTypeByte: {
670 int64 length = 0; 670 int64_t length = 0;
671 if (!DecodeVarInt(slice, &length) || length < 0) 671 if (!DecodeVarInt(slice, &length) || length < 0)
672 return false; 672 return false;
673 if (slice->size() < static_cast<size_t>(length) * sizeof(base::char16)) 673 if (slice->size() < static_cast<size_t>(length) * sizeof(base::char16))
674 return false; 674 return false;
675 slice->remove_prefix(length * sizeof(base::char16)); 675 slice->remove_prefix(length * sizeof(base::char16));
676 return true; 676 return true;
677 } 677 }
678 case kIndexedDBKeyDateTypeByte: 678 case kIndexedDBKeyDateTypeByte:
679 case kIndexedDBKeyNumberTypeByte: 679 case kIndexedDBKeyNumberTypeByte:
680 if (slice->size() < sizeof(double)) 680 if (slice->size() < sizeof(double))
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 return WebIDBKeyTypeMin; 714 return WebIDBKeyTypeMin;
715 } 715 }
716 716
717 NOTREACHED(); 717 NOTREACHED();
718 return WebIDBKeyTypeInvalid; 718 return WebIDBKeyTypeInvalid;
719 } 719 }
720 720
721 int CompareEncodedStringsWithLength(StringPiece* slice1, 721 int CompareEncodedStringsWithLength(StringPiece* slice1,
722 StringPiece* slice2, 722 StringPiece* slice2,
723 bool* ok) { 723 bool* ok) {
724 int64 len1, len2; 724 int64_t len1, len2;
725 if (!DecodeVarInt(slice1, &len1) || !DecodeVarInt(slice2, &len2)) { 725 if (!DecodeVarInt(slice1, &len1) || !DecodeVarInt(slice2, &len2)) {
726 *ok = false; 726 *ok = false;
727 return 0; 727 return 0;
728 } 728 }
729 DCHECK_GE(len1, 0); 729 DCHECK_GE(len1, 0);
730 DCHECK_GE(len2, 0); 730 DCHECK_GE(len2, 0);
731 if (len1 < 0 || len2 < 0) { 731 if (len1 < 0 || len2 < 0) {
732 *ok = false; 732 *ok = false;
733 return 0; 733 return 0;
734 } 734 }
(...skipping 12 matching lines...) Expand all
747 slice2->remove_prefix(len2 * sizeof(base::char16)); 747 slice2->remove_prefix(len2 * sizeof(base::char16));
748 748
749 *ok = true; 749 *ok = true;
750 // Strings are UTF-16BE encoded, so a simple memcmp is sufficient. 750 // Strings are UTF-16BE encoded, so a simple memcmp is sufficient.
751 return string1.compare(string2); 751 return string1.compare(string2);
752 } 752 }
753 753
754 int CompareEncodedBinary(StringPiece* slice1, 754 int CompareEncodedBinary(StringPiece* slice1,
755 StringPiece* slice2, 755 StringPiece* slice2,
756 bool* ok) { 756 bool* ok) {
757 int64 len1, len2; 757 int64_t len1, len2;
758 if (!DecodeVarInt(slice1, &len1) || !DecodeVarInt(slice2, &len2)) { 758 if (!DecodeVarInt(slice1, &len1) || !DecodeVarInt(slice2, &len2)) {
759 *ok = false; 759 *ok = false;
760 return 0; 760 return 0;
761 } 761 }
762 DCHECK_GE(len1, 0); 762 DCHECK_GE(len1, 0);
763 DCHECK_GE(len2, 0); 763 DCHECK_GE(len2, 0);
764 if (len1 < 0 || len2 < 0) { 764 if (len1 < 0 || len2 < 0) {
765 *ok = false; 765 *ok = false;
766 return 0; 766 return 0;
767 } 767 }
(...skipping 11 matching lines...) Expand all
779 StringPiece binary1(slice1->begin(), size1); 779 StringPiece binary1(slice1->begin(), size1);
780 StringPiece binary2(slice2->begin(), size2); 780 StringPiece binary2(slice2->begin(), size2);
781 slice1->remove_prefix(size1); 781 slice1->remove_prefix(size1);
782 slice2->remove_prefix(size2); 782 slice2->remove_prefix(size2);
783 783
784 *ok = true; 784 *ok = true;
785 // This is the same as a memcmp() 785 // This is the same as a memcmp()
786 return binary1.compare(binary2); 786 return binary1.compare(binary2);
787 } 787 }
788 788
789 static int CompareInts(int64 a, int64 b) { 789 static int CompareInts(int64_t a, int64_t b) {
790 #ifndef NDEBUG 790 #ifndef NDEBUG
791 // Exercised by unit tests in debug only. 791 // Exercised by unit tests in debug only.
792 DCHECK_GE(a, 0); 792 DCHECK_GE(a, 0);
793 DCHECK_GE(b, 0); 793 DCHECK_GE(b, 0);
794 #endif 794 #endif
795 int64 diff = a - b; 795 int64_t diff = a - b;
796 if (diff < 0) 796 if (diff < 0)
797 return -1; 797 return -1;
798 if (diff > 0) 798 if (diff > 0)
799 return 1; 799 return 1;
800 return 0; 800 return 0;
801 } 801 }
802 802
803 static inline int CompareSizes(size_t a, size_t b) { 803 static inline int CompareSizes(size_t a, size_t b) {
804 if (a > b) 804 if (a > b)
805 return 1; 805 return 1;
(...skipping 18 matching lines...) Expand all
824 if (int x = CompareTypes(KeyTypeByteToKeyType(type_a), 824 if (int x = CompareTypes(KeyTypeByteToKeyType(type_a),
825 KeyTypeByteToKeyType(type_b))) 825 KeyTypeByteToKeyType(type_b)))
826 return x; 826 return x;
827 827
828 switch (type_a) { 828 switch (type_a) {
829 case kIndexedDBKeyNullTypeByte: 829 case kIndexedDBKeyNullTypeByte:
830 case kIndexedDBKeyMinKeyTypeByte: 830 case kIndexedDBKeyMinKeyTypeByte:
831 // Null type or max type; no payload to compare. 831 // Null type or max type; no payload to compare.
832 return 0; 832 return 0;
833 case kIndexedDBKeyArrayTypeByte: { 833 case kIndexedDBKeyArrayTypeByte: {
834 int64 length_a, length_b; 834 int64_t length_a, length_b;
835 if (!DecodeVarInt(slice_a, &length_a) || 835 if (!DecodeVarInt(slice_a, &length_a) ||
836 !DecodeVarInt(slice_b, &length_b)) { 836 !DecodeVarInt(slice_b, &length_b)) {
837 *ok = false; 837 *ok = false;
838 return 0; 838 return 0;
839 } 839 }
840 for (int64 i = 0; i < length_a && i < length_b; ++i) { 840 for (int64_t i = 0; i < length_a && i < length_b; ++i) {
841 int result = CompareEncodedIDBKeys(slice_a, slice_b, ok); 841 int result = CompareEncodedIDBKeys(slice_a, slice_b, ok);
842 if (!*ok || result) 842 if (!*ok || result)
843 return result; 843 return result;
844 } 844 }
845 return length_a - length_b; 845 return length_a - length_b;
846 } 846 }
847 case kIndexedDBKeyBinaryTypeByte: 847 case kIndexedDBKeyBinaryTypeByte:
848 return CompareEncodedBinary(slice_a, slice_b, ok); 848 return CompareEncodedBinary(slice_a, slice_b, ok);
849 case kIndexedDBKeyStringTypeByte: 849 case kIndexedDBKeyStringTypeByte:
850 return CompareEncodedStringsWithLength(slice_a, slice_b, ok); 850 return CompareEncodedStringsWithLength(slice_a, slice_b, ok);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 bool only_compare_index_keys, 933 bool only_compare_index_keys,
934 bool* ok) { 934 bool* ok) {
935 // index key 935 // index key
936 int result = CompareEncodedIDBKeys(slice_a, slice_b, ok); 936 int result = CompareEncodedIDBKeys(slice_a, slice_b, ok);
937 if (!*ok || result) 937 if (!*ok || result)
938 return result; 938 return result;
939 if (only_compare_index_keys) 939 if (only_compare_index_keys)
940 return 0; 940 return 0;
941 941
942 // sequence number [optional] 942 // sequence number [optional]
943 int64 sequence_number_a = -1; 943 int64_t sequence_number_a = -1;
944 int64 sequence_number_b = -1; 944 int64_t sequence_number_b = -1;
945 if (!slice_a->empty() && !DecodeVarInt(slice_a, &sequence_number_a)) 945 if (!slice_a->empty() && !DecodeVarInt(slice_a, &sequence_number_a))
946 return 0; 946 return 0;
947 if (!slice_b->empty() && !DecodeVarInt(slice_b, &sequence_number_b)) 947 if (!slice_b->empty() && !DecodeVarInt(slice_b, &sequence_number_b))
948 return 0; 948 return 0;
949 949
950 if (slice_a->empty() || slice_b->empty()) 950 if (slice_a->empty() || slice_b->empty())
951 return CompareSizes(slice_a->size(), slice_b->size()); 951 return CompareSizes(slice_a->size(), slice_b->size());
952 952
953 // primary key [optional] 953 // primary key [optional]
954 result = CompareEncodedIDBKeys(slice_a, slice_b, ok); 954 result = CompareEncodedIDBKeys(slice_a, slice_b, ok);
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 if (!ok) 1126 if (!ok)
1127 return 0; 1127 return 0;
1128 return result; 1128 return result;
1129 } 1129 }
1130 1130
1131 KeyPrefix::KeyPrefix() 1131 KeyPrefix::KeyPrefix()
1132 : database_id_(INVALID_TYPE), 1132 : database_id_(INVALID_TYPE),
1133 object_store_id_(INVALID_TYPE), 1133 object_store_id_(INVALID_TYPE),
1134 index_id_(INVALID_TYPE) {} 1134 index_id_(INVALID_TYPE) {}
1135 1135
1136 KeyPrefix::KeyPrefix(int64 database_id) 1136 KeyPrefix::KeyPrefix(int64_t database_id)
1137 : database_id_(database_id), object_store_id_(0), index_id_(0) { 1137 : database_id_(database_id), object_store_id_(0), index_id_(0) {
1138 DCHECK(KeyPrefix::IsValidDatabaseId(database_id)); 1138 DCHECK(KeyPrefix::IsValidDatabaseId(database_id));
1139 } 1139 }
1140 1140
1141 KeyPrefix::KeyPrefix(int64 database_id, int64 object_store_id) 1141 KeyPrefix::KeyPrefix(int64_t database_id, int64_t object_store_id)
1142 : database_id_(database_id), 1142 : database_id_(database_id),
1143 object_store_id_(object_store_id), 1143 object_store_id_(object_store_id),
1144 index_id_(0) { 1144 index_id_(0) {
1145 DCHECK(KeyPrefix::IsValidDatabaseId(database_id)); 1145 DCHECK(KeyPrefix::IsValidDatabaseId(database_id));
1146 DCHECK(KeyPrefix::IsValidObjectStoreId(object_store_id)); 1146 DCHECK(KeyPrefix::IsValidObjectStoreId(object_store_id));
1147 } 1147 }
1148 1148
1149 KeyPrefix::KeyPrefix(int64 database_id, int64 object_store_id, int64 index_id) 1149 KeyPrefix::KeyPrefix(int64_t database_id,
1150 int64_t object_store_id,
1151 int64_t index_id)
1150 : database_id_(database_id), 1152 : database_id_(database_id),
1151 object_store_id_(object_store_id), 1153 object_store_id_(object_store_id),
1152 index_id_(index_id) { 1154 index_id_(index_id) {
1153 DCHECK(KeyPrefix::IsValidDatabaseId(database_id)); 1155 DCHECK(KeyPrefix::IsValidDatabaseId(database_id));
1154 DCHECK(KeyPrefix::IsValidObjectStoreId(object_store_id)); 1156 DCHECK(KeyPrefix::IsValidObjectStoreId(object_store_id));
1155 DCHECK(KeyPrefix::IsValidIndexId(index_id)); 1157 DCHECK(KeyPrefix::IsValidIndexId(index_id));
1156 } 1158 }
1157 1159
1158 KeyPrefix::KeyPrefix(enum Type type, 1160 KeyPrefix::KeyPrefix(enum Type type,
1159 int64 database_id, 1161 int64_t database_id,
1160 int64 object_store_id, 1162 int64_t object_store_id,
1161 int64 index_id) 1163 int64_t index_id)
1162 : database_id_(database_id), 1164 : database_id_(database_id),
1163 object_store_id_(object_store_id), 1165 object_store_id_(object_store_id),
1164 index_id_(index_id) { 1166 index_id_(index_id) {
1165 DCHECK_EQ(type, INVALID_TYPE); 1167 DCHECK_EQ(type, INVALID_TYPE);
1166 DCHECK(KeyPrefix::IsValidDatabaseId(database_id)); 1168 DCHECK(KeyPrefix::IsValidDatabaseId(database_id));
1167 DCHECK(KeyPrefix::IsValidObjectStoreId(object_store_id)); 1169 DCHECK(KeyPrefix::IsValidObjectStoreId(object_store_id));
1168 } 1170 }
1169 1171
1170 KeyPrefix KeyPrefix::CreateWithSpecialIndex(int64 database_id, 1172 KeyPrefix KeyPrefix::CreateWithSpecialIndex(int64_t database_id,
1171 int64 object_store_id, 1173 int64_t object_store_id,
1172 int64 index_id) { 1174 int64_t index_id) {
1173 DCHECK(KeyPrefix::IsValidDatabaseId(database_id)); 1175 DCHECK(KeyPrefix::IsValidDatabaseId(database_id));
1174 DCHECK(KeyPrefix::IsValidObjectStoreId(object_store_id)); 1176 DCHECK(KeyPrefix::IsValidObjectStoreId(object_store_id));
1175 DCHECK(index_id); 1177 DCHECK(index_id);
1176 return KeyPrefix(INVALID_TYPE, database_id, object_store_id, index_id); 1178 return KeyPrefix(INVALID_TYPE, database_id, object_store_id, index_id);
1177 } 1179 }
1178 1180
1179 bool KeyPrefix::IsValidDatabaseId(int64 database_id) { 1181 bool KeyPrefix::IsValidDatabaseId(int64_t database_id) {
1180 return (database_id > 0) && (database_id < KeyPrefix::kMaxDatabaseId); 1182 return (database_id > 0) && (database_id < KeyPrefix::kMaxDatabaseId);
1181 } 1183 }
1182 1184
1183 bool KeyPrefix::IsValidObjectStoreId(int64 object_store_id) { 1185 bool KeyPrefix::IsValidObjectStoreId(int64_t object_store_id) {
1184 return (object_store_id > 0) && 1186 return (object_store_id > 0) &&
1185 (object_store_id < KeyPrefix::kMaxObjectStoreId); 1187 (object_store_id < KeyPrefix::kMaxObjectStoreId);
1186 } 1188 }
1187 1189
1188 bool KeyPrefix::IsValidIndexId(int64 index_id) { 1190 bool KeyPrefix::IsValidIndexId(int64_t index_id) {
1189 return (index_id >= kMinimumIndexId) && (index_id < KeyPrefix::kMaxIndexId); 1191 return (index_id >= kMinimumIndexId) && (index_id < KeyPrefix::kMaxIndexId);
1190 } 1192 }
1191 1193
1192 bool KeyPrefix::Decode(StringPiece* slice, KeyPrefix* result) { 1194 bool KeyPrefix::Decode(StringPiece* slice, KeyPrefix* result) {
1193 unsigned char first_byte; 1195 unsigned char first_byte;
1194 if (!DecodeByte(slice, &first_byte)) 1196 if (!DecodeByte(slice, &first_byte))
1195 return false; 1197 return false;
1196 1198
1197 size_t database_id_bytes = ((first_byte >> 5) & 0x7) + 1; 1199 size_t database_id_bytes = ((first_byte >> 5) & 0x7) + 1;
1198 size_t object_store_id_bytes = ((first_byte >> 2) & 0x7) + 1; 1200 size_t object_store_id_bytes = ((first_byte >> 2) & 0x7) + 1;
(...skipping 30 matching lines...) Expand all
1229 return result; 1231 return result;
1230 } 1232 }
1231 1233
1232 std::string KeyPrefix::Encode() const { 1234 std::string KeyPrefix::Encode() const {
1233 DCHECK(database_id_ != kInvalidId); 1235 DCHECK(database_id_ != kInvalidId);
1234 DCHECK(object_store_id_ != kInvalidId); 1236 DCHECK(object_store_id_ != kInvalidId);
1235 DCHECK(index_id_ != kInvalidId); 1237 DCHECK(index_id_ != kInvalidId);
1236 return EncodeInternal(database_id_, object_store_id_, index_id_); 1238 return EncodeInternal(database_id_, object_store_id_, index_id_);
1237 } 1239 }
1238 1240
1239 std::string KeyPrefix::EncodeInternal(int64 database_id, 1241 std::string KeyPrefix::EncodeInternal(int64_t database_id,
1240 int64 object_store_id, 1242 int64_t object_store_id,
1241 int64 index_id) { 1243 int64_t index_id) {
1242 std::string database_id_string; 1244 std::string database_id_string;
1243 std::string object_store_id_string; 1245 std::string object_store_id_string;
1244 std::string index_id_string; 1246 std::string index_id_string;
1245 1247
1246 EncodeIntSafely(database_id, kMaxDatabaseId, &database_id_string); 1248 EncodeIntSafely(database_id, kMaxDatabaseId, &database_id_string);
1247 EncodeIntSafely(object_store_id, kMaxObjectStoreId, &object_store_id_string); 1249 EncodeIntSafely(object_store_id, kMaxObjectStoreId, &object_store_id_string);
1248 EncodeIntSafely(index_id, kMaxIndexId, &index_id_string); 1250 EncodeIntSafely(index_id, kMaxIndexId, &index_id_string);
1249 1251
1250 DCHECK(database_id_string.size() <= kMaxDatabaseIdSizeBytes); 1252 DCHECK(database_id_string.size() <= kMaxDatabaseIdSizeBytes);
1251 DCHECK(object_store_id_string.size() <= kMaxObjectStoreIdSizeBytes); 1253 DCHECK(object_store_id_string.size() <= kMaxObjectStoreIdSizeBytes);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1349 DCHECK(!prefix.index_id_); 1351 DCHECK(!prefix.index_id_);
1350 unsigned char type_byte = 0; 1352 unsigned char type_byte = 0;
1351 if (!DecodeByte(slice, &type_byte)) 1353 if (!DecodeByte(slice, &type_byte))
1352 return false; 1354 return false;
1353 DCHECK_EQ(type_byte, kDatabaseFreeListTypeByte); 1355 DCHECK_EQ(type_byte, kDatabaseFreeListTypeByte);
1354 if (!DecodeVarInt(slice, &result->database_id_)) 1356 if (!DecodeVarInt(slice, &result->database_id_))
1355 return false; 1357 return false;
1356 return true; 1358 return true;
1357 } 1359 }
1358 1360
1359 std::string DatabaseFreeListKey::Encode(int64 database_id) { 1361 std::string DatabaseFreeListKey::Encode(int64_t database_id) {
1360 std::string ret = KeyPrefix::EncodeEmpty(); 1362 std::string ret = KeyPrefix::EncodeEmpty();
1361 ret.push_back(kDatabaseFreeListTypeByte); 1363 ret.push_back(kDatabaseFreeListTypeByte);
1362 EncodeVarInt(database_id, &ret); 1364 EncodeVarInt(database_id, &ret);
1363 return ret; 1365 return ret;
1364 } 1366 }
1365 1367
1366 std::string DatabaseFreeListKey::EncodeMaxKey() { 1368 std::string DatabaseFreeListKey::EncodeMaxKey() {
1367 return Encode(std::numeric_limits<int64>::max()); 1369 return Encode(std::numeric_limits<int64_t>::max());
1368 } 1370 }
1369 1371
1370 int64 DatabaseFreeListKey::DatabaseId() const { 1372 int64_t DatabaseFreeListKey::DatabaseId() const {
1371 DCHECK_GE(database_id_, 0); 1373 DCHECK_GE(database_id_, 0);
1372 return database_id_; 1374 return database_id_;
1373 } 1375 }
1374 1376
1375 int DatabaseFreeListKey::Compare(const DatabaseFreeListKey& other) const { 1377 int DatabaseFreeListKey::Compare(const DatabaseFreeListKey& other) const {
1376 DCHECK_GE(database_id_, 0); 1378 DCHECK_GE(database_id_, 0);
1377 return CompareInts(database_id_, other.database_id_); 1379 return CompareInts(database_id_, other.database_id_);
1378 } 1380 }
1379 1381
1380 bool DatabaseNameKey::Decode(StringPiece* slice, DatabaseNameKey* result) { 1382 bool DatabaseNameKey::Decode(StringPiece* slice, DatabaseNameKey* result) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1414 // just after origin in collation order 1416 // just after origin in collation order
1415 return EncodeMinKeyForOrigin(origin_identifier + '\x01'); 1417 return EncodeMinKeyForOrigin(origin_identifier + '\x01');
1416 } 1418 }
1417 1419
1418 int DatabaseNameKey::Compare(const DatabaseNameKey& other) { 1420 int DatabaseNameKey::Compare(const DatabaseNameKey& other) {
1419 if (int x = origin_.compare(other.origin_)) 1421 if (int x = origin_.compare(other.origin_))
1420 return x; 1422 return x;
1421 return database_name_.compare(other.database_name_); 1423 return database_name_.compare(other.database_name_);
1422 } 1424 }
1423 1425
1424 bool DatabaseMetaDataKey::IsValidBlobKey(int64 blob_key) { 1426 bool DatabaseMetaDataKey::IsValidBlobKey(int64_t blob_key) {
1425 return blob_key >= kBlobKeyGeneratorInitialNumber; 1427 return blob_key >= kBlobKeyGeneratorInitialNumber;
1426 } 1428 }
1427 1429
1428 const int64 DatabaseMetaDataKey::kAllBlobsKey = 1; 1430 const int64_t DatabaseMetaDataKey::kAllBlobsKey = 1;
1429 const int64 DatabaseMetaDataKey::kBlobKeyGeneratorInitialNumber = 2; 1431 const int64_t DatabaseMetaDataKey::kBlobKeyGeneratorInitialNumber = 2;
1430 const int64 DatabaseMetaDataKey::kInvalidBlobKey = -1; 1432 const int64_t DatabaseMetaDataKey::kInvalidBlobKey = -1;
1431 1433
1432 std::string DatabaseMetaDataKey::Encode(int64 database_id, 1434 std::string DatabaseMetaDataKey::Encode(int64_t database_id,
1433 MetaDataType meta_data_type) { 1435 MetaDataType meta_data_type) {
1434 KeyPrefix prefix(database_id); 1436 KeyPrefix prefix(database_id);
1435 std::string ret = prefix.Encode(); 1437 std::string ret = prefix.Encode();
1436 ret.push_back(meta_data_type); 1438 ret.push_back(meta_data_type);
1437 return ret; 1439 return ret;
1438 } 1440 }
1439 1441
1440 ObjectStoreMetaDataKey::ObjectStoreMetaDataKey() 1442 ObjectStoreMetaDataKey::ObjectStoreMetaDataKey()
1441 : object_store_id_(-1), meta_data_type_(0xFF) {} 1443 : object_store_id_(-1), meta_data_type_(0xFF) {}
1442 1444
(...skipping 10 matching lines...) Expand all
1453 return false; 1455 return false;
1454 DCHECK_EQ(type_byte, kObjectStoreMetaDataTypeByte); 1456 DCHECK_EQ(type_byte, kObjectStoreMetaDataTypeByte);
1455 if (!DecodeVarInt(slice, &result->object_store_id_)) 1457 if (!DecodeVarInt(slice, &result->object_store_id_))
1456 return false; 1458 return false;
1457 DCHECK(result->object_store_id_); 1459 DCHECK(result->object_store_id_);
1458 if (!DecodeByte(slice, &result->meta_data_type_)) 1460 if (!DecodeByte(slice, &result->meta_data_type_))
1459 return false; 1461 return false;
1460 return true; 1462 return true;
1461 } 1463 }
1462 1464
1463 std::string ObjectStoreMetaDataKey::Encode(int64 database_id, 1465 std::string ObjectStoreMetaDataKey::Encode(int64_t database_id,
1464 int64 object_store_id, 1466 int64_t object_store_id,
1465 unsigned char meta_data_type) { 1467 unsigned char meta_data_type) {
1466 KeyPrefix prefix(database_id); 1468 KeyPrefix prefix(database_id);
1467 std::string ret = prefix.Encode(); 1469 std::string ret = prefix.Encode();
1468 ret.push_back(kObjectStoreMetaDataTypeByte); 1470 ret.push_back(kObjectStoreMetaDataTypeByte);
1469 EncodeVarInt(object_store_id, &ret); 1471 EncodeVarInt(object_store_id, &ret);
1470 ret.push_back(meta_data_type); 1472 ret.push_back(meta_data_type);
1471 return ret; 1473 return ret;
1472 } 1474 }
1473 1475
1474 std::string ObjectStoreMetaDataKey::EncodeMaxKey(int64 database_id) { 1476 std::string ObjectStoreMetaDataKey::EncodeMaxKey(int64_t database_id) {
1475 return Encode(database_id, 1477 return Encode(database_id, std::numeric_limits<int64_t>::max(),
1476 std::numeric_limits<int64>::max(),
1477 kObjectMetaDataTypeMaximum); 1478 kObjectMetaDataTypeMaximum);
1478 } 1479 }
1479 1480
1480 std::string ObjectStoreMetaDataKey::EncodeMaxKey(int64 database_id, 1481 std::string ObjectStoreMetaDataKey::EncodeMaxKey(int64_t database_id,
1481 int64 object_store_id) { 1482 int64_t object_store_id) {
1482 return Encode(database_id, object_store_id, kObjectMetaDataTypeMaximum); 1483 return Encode(database_id, object_store_id, kObjectMetaDataTypeMaximum);
1483 } 1484 }
1484 1485
1485 int64 ObjectStoreMetaDataKey::ObjectStoreId() const { 1486 int64_t ObjectStoreMetaDataKey::ObjectStoreId() const {
1486 DCHECK_GE(object_store_id_, 0); 1487 DCHECK_GE(object_store_id_, 0);
1487 return object_store_id_; 1488 return object_store_id_;
1488 } 1489 }
1489 unsigned char ObjectStoreMetaDataKey::MetaDataType() const { 1490 unsigned char ObjectStoreMetaDataKey::MetaDataType() const {
1490 return meta_data_type_; 1491 return meta_data_type_;
1491 } 1492 }
1492 1493
1493 int ObjectStoreMetaDataKey::Compare(const ObjectStoreMetaDataKey& other) { 1494 int ObjectStoreMetaDataKey::Compare(const ObjectStoreMetaDataKey& other) {
1494 DCHECK_GE(object_store_id_, 0); 1495 DCHECK_GE(object_store_id_, 0);
1495 if (int x = CompareInts(object_store_id_, other.object_store_id_)) 1496 if (int x = CompareInts(object_store_id_, other.object_store_id_))
(...skipping 17 matching lines...) Expand all
1513 DCHECK_EQ(type_byte, kIndexMetaDataTypeByte); 1514 DCHECK_EQ(type_byte, kIndexMetaDataTypeByte);
1514 if (!DecodeVarInt(slice, &result->object_store_id_)) 1515 if (!DecodeVarInt(slice, &result->object_store_id_))
1515 return false; 1516 return false;
1516 if (!DecodeVarInt(slice, &result->index_id_)) 1517 if (!DecodeVarInt(slice, &result->index_id_))
1517 return false; 1518 return false;
1518 if (!DecodeByte(slice, &result->meta_data_type_)) 1519 if (!DecodeByte(slice, &result->meta_data_type_))
1519 return false; 1520 return false;
1520 return true; 1521 return true;
1521 } 1522 }
1522 1523
1523 std::string IndexMetaDataKey::Encode(int64 database_id, 1524 std::string IndexMetaDataKey::Encode(int64_t database_id,
1524 int64 object_store_id, 1525 int64_t object_store_id,
1525 int64 index_id, 1526 int64_t index_id,
1526 unsigned char meta_data_type) { 1527 unsigned char meta_data_type) {
1527 KeyPrefix prefix(database_id); 1528 KeyPrefix prefix(database_id);
1528 std::string ret = prefix.Encode(); 1529 std::string ret = prefix.Encode();
1529 ret.push_back(kIndexMetaDataTypeByte); 1530 ret.push_back(kIndexMetaDataTypeByte);
1530 EncodeVarInt(object_store_id, &ret); 1531 EncodeVarInt(object_store_id, &ret);
1531 EncodeVarInt(index_id, &ret); 1532 EncodeVarInt(index_id, &ret);
1532 EncodeByte(meta_data_type, &ret); 1533 EncodeByte(meta_data_type, &ret);
1533 return ret; 1534 return ret;
1534 } 1535 }
1535 1536
1536 std::string IndexMetaDataKey::EncodeMaxKey(int64 database_id, 1537 std::string IndexMetaDataKey::EncodeMaxKey(int64_t database_id,
1537 int64 object_store_id) { 1538 int64_t object_store_id) {
1538 return Encode(database_id, 1539 return Encode(database_id, object_store_id,
1539 object_store_id, 1540 std::numeric_limits<int64_t>::max(), kIndexMetaDataTypeMaximum);
1540 std::numeric_limits<int64>::max(),
1541 kIndexMetaDataTypeMaximum);
1542 } 1541 }
1543 1542
1544 std::string IndexMetaDataKey::EncodeMaxKey(int64 database_id, 1543 std::string IndexMetaDataKey::EncodeMaxKey(int64_t database_id,
1545 int64 object_store_id, 1544 int64_t object_store_id,
1546 int64 index_id) { 1545 int64_t index_id) {
1547 return Encode( 1546 return Encode(
1548 database_id, object_store_id, index_id, kIndexMetaDataTypeMaximum); 1547 database_id, object_store_id, index_id, kIndexMetaDataTypeMaximum);
1549 } 1548 }
1550 1549
1551 int IndexMetaDataKey::Compare(const IndexMetaDataKey& other) { 1550 int IndexMetaDataKey::Compare(const IndexMetaDataKey& other) {
1552 DCHECK_GE(object_store_id_, 0); 1551 DCHECK_GE(object_store_id_, 0);
1553 DCHECK_GE(index_id_, 0); 1552 DCHECK_GE(index_id_, 0);
1554 1553
1555 if (int x = CompareInts(object_store_id_, other.object_store_id_)) 1554 if (int x = CompareInts(object_store_id_, other.object_store_id_))
1556 return x; 1555 return x;
1557 if (int x = CompareInts(index_id_, other.index_id_)) 1556 if (int x = CompareInts(index_id_, other.index_id_))
1558 return x; 1557 return x;
1559 return meta_data_type_ - other.meta_data_type_; 1558 return meta_data_type_ - other.meta_data_type_;
1560 } 1559 }
1561 1560
1562 int64 IndexMetaDataKey::IndexId() const { 1561 int64_t IndexMetaDataKey::IndexId() const {
1563 DCHECK_GE(index_id_, 0); 1562 DCHECK_GE(index_id_, 0);
1564 return index_id_; 1563 return index_id_;
1565 } 1564 }
1566 1565
1567 ObjectStoreFreeListKey::ObjectStoreFreeListKey() : object_store_id_(-1) {} 1566 ObjectStoreFreeListKey::ObjectStoreFreeListKey() : object_store_id_(-1) {}
1568 1567
1569 bool ObjectStoreFreeListKey::Decode(StringPiece* slice, 1568 bool ObjectStoreFreeListKey::Decode(StringPiece* slice,
1570 ObjectStoreFreeListKey* result) { 1569 ObjectStoreFreeListKey* result) {
1571 KeyPrefix prefix; 1570 KeyPrefix prefix;
1572 if (!KeyPrefix::Decode(slice, &prefix)) 1571 if (!KeyPrefix::Decode(slice, &prefix))
1573 return false; 1572 return false;
1574 DCHECK(prefix.database_id_); 1573 DCHECK(prefix.database_id_);
1575 DCHECK(!prefix.object_store_id_); 1574 DCHECK(!prefix.object_store_id_);
1576 DCHECK(!prefix.index_id_); 1575 DCHECK(!prefix.index_id_);
1577 unsigned char type_byte = 0; 1576 unsigned char type_byte = 0;
1578 if (!DecodeByte(slice, &type_byte)) 1577 if (!DecodeByte(slice, &type_byte))
1579 return false; 1578 return false;
1580 DCHECK_EQ(type_byte, kObjectStoreFreeListTypeByte); 1579 DCHECK_EQ(type_byte, kObjectStoreFreeListTypeByte);
1581 if (!DecodeVarInt(slice, &result->object_store_id_)) 1580 if (!DecodeVarInt(slice, &result->object_store_id_))
1582 return false; 1581 return false;
1583 return true; 1582 return true;
1584 } 1583 }
1585 1584
1586 std::string ObjectStoreFreeListKey::Encode(int64 database_id, 1585 std::string ObjectStoreFreeListKey::Encode(int64_t database_id,
1587 int64 object_store_id) { 1586 int64_t object_store_id) {
1588 KeyPrefix prefix(database_id); 1587 KeyPrefix prefix(database_id);
1589 std::string ret = prefix.Encode(); 1588 std::string ret = prefix.Encode();
1590 ret.push_back(kObjectStoreFreeListTypeByte); 1589 ret.push_back(kObjectStoreFreeListTypeByte);
1591 EncodeVarInt(object_store_id, &ret); 1590 EncodeVarInt(object_store_id, &ret);
1592 return ret; 1591 return ret;
1593 } 1592 }
1594 1593
1595 std::string ObjectStoreFreeListKey::EncodeMaxKey(int64 database_id) { 1594 std::string ObjectStoreFreeListKey::EncodeMaxKey(int64_t database_id) {
1596 return Encode(database_id, std::numeric_limits<int64>::max()); 1595 return Encode(database_id, std::numeric_limits<int64_t>::max());
1597 } 1596 }
1598 1597
1599 int64 ObjectStoreFreeListKey::ObjectStoreId() const { 1598 int64_t ObjectStoreFreeListKey::ObjectStoreId() const {
1600 DCHECK_GE(object_store_id_, 0); 1599 DCHECK_GE(object_store_id_, 0);
1601 return object_store_id_; 1600 return object_store_id_;
1602 } 1601 }
1603 1602
1604 int ObjectStoreFreeListKey::Compare(const ObjectStoreFreeListKey& other) { 1603 int ObjectStoreFreeListKey::Compare(const ObjectStoreFreeListKey& other) {
1605 // TODO(jsbell): It may seem strange that we're not comparing database id's, 1604 // TODO(jsbell): It may seem strange that we're not comparing database id's,
1606 // but that comparison will have been made earlier. 1605 // but that comparison will have been made earlier.
1607 // We should probably make this more clear, though... 1606 // We should probably make this more clear, though...
1608 DCHECK_GE(object_store_id_, 0); 1607 DCHECK_GE(object_store_id_, 0);
1609 return CompareInts(object_store_id_, other.object_store_id_); 1608 return CompareInts(object_store_id_, other.object_store_id_);
(...skipping 12 matching lines...) Expand all
1622 if (!DecodeByte(slice, &type_byte)) 1621 if (!DecodeByte(slice, &type_byte))
1623 return false; 1622 return false;
1624 DCHECK_EQ(type_byte, kIndexFreeListTypeByte); 1623 DCHECK_EQ(type_byte, kIndexFreeListTypeByte);
1625 if (!DecodeVarInt(slice, &result->object_store_id_)) 1624 if (!DecodeVarInt(slice, &result->object_store_id_))
1626 return false; 1625 return false;
1627 if (!DecodeVarInt(slice, &result->index_id_)) 1626 if (!DecodeVarInt(slice, &result->index_id_))
1628 return false; 1627 return false;
1629 return true; 1628 return true;
1630 } 1629 }
1631 1630
1632 std::string IndexFreeListKey::Encode(int64 database_id, 1631 std::string IndexFreeListKey::Encode(int64_t database_id,
1633 int64 object_store_id, 1632 int64_t object_store_id,
1634 int64 index_id) { 1633 int64_t index_id) {
1635 KeyPrefix prefix(database_id); 1634 KeyPrefix prefix(database_id);
1636 std::string ret = prefix.Encode(); 1635 std::string ret = prefix.Encode();
1637 ret.push_back(kIndexFreeListTypeByte); 1636 ret.push_back(kIndexFreeListTypeByte);
1638 EncodeVarInt(object_store_id, &ret); 1637 EncodeVarInt(object_store_id, &ret);
1639 EncodeVarInt(index_id, &ret); 1638 EncodeVarInt(index_id, &ret);
1640 return ret; 1639 return ret;
1641 } 1640 }
1642 1641
1643 std::string IndexFreeListKey::EncodeMaxKey(int64 database_id, 1642 std::string IndexFreeListKey::EncodeMaxKey(int64_t database_id,
1644 int64 object_store_id) { 1643 int64_t object_store_id) {
1645 return Encode( 1644 return Encode(database_id, object_store_id,
1646 database_id, object_store_id, std::numeric_limits<int64>::max()); 1645 std::numeric_limits<int64_t>::max());
1647 } 1646 }
1648 1647
1649 int IndexFreeListKey::Compare(const IndexFreeListKey& other) { 1648 int IndexFreeListKey::Compare(const IndexFreeListKey& other) {
1650 DCHECK_GE(object_store_id_, 0); 1649 DCHECK_GE(object_store_id_, 0);
1651 DCHECK_GE(index_id_, 0); 1650 DCHECK_GE(index_id_, 0);
1652 if (int x = CompareInts(object_store_id_, other.object_store_id_)) 1651 if (int x = CompareInts(object_store_id_, other.object_store_id_))
1653 return x; 1652 return x;
1654 return CompareInts(index_id_, other.index_id_); 1653 return CompareInts(index_id_, other.index_id_);
1655 } 1654 }
1656 1655
1657 int64 IndexFreeListKey::ObjectStoreId() const { 1656 int64_t IndexFreeListKey::ObjectStoreId() const {
1658 DCHECK_GE(object_store_id_, 0); 1657 DCHECK_GE(object_store_id_, 0);
1659 return object_store_id_; 1658 return object_store_id_;
1660 } 1659 }
1661 1660
1662 int64 IndexFreeListKey::IndexId() const { 1661 int64_t IndexFreeListKey::IndexId() const {
1663 DCHECK_GE(index_id_, 0); 1662 DCHECK_GE(index_id_, 0);
1664 return index_id_; 1663 return index_id_;
1665 } 1664 }
1666 1665
1667 // TODO(jsbell): We never use this to look up object store ids, 1666 // TODO(jsbell): We never use this to look up object store ids,
1668 // because a mapping is kept in the IndexedDBDatabase. Can the 1667 // because a mapping is kept in the IndexedDBDatabase. Can the
1669 // mapping become unreliable? Can we remove this? 1668 // mapping become unreliable? Can we remove this?
1670 bool ObjectStoreNamesKey::Decode(StringPiece* slice, 1669 bool ObjectStoreNamesKey::Decode(StringPiece* slice,
1671 ObjectStoreNamesKey* result) { 1670 ObjectStoreNamesKey* result) {
1672 KeyPrefix prefix; 1671 KeyPrefix prefix;
1673 if (!KeyPrefix::Decode(slice, &prefix)) 1672 if (!KeyPrefix::Decode(slice, &prefix))
1674 return false; 1673 return false;
1675 DCHECK(prefix.database_id_); 1674 DCHECK(prefix.database_id_);
1676 DCHECK(!prefix.object_store_id_); 1675 DCHECK(!prefix.object_store_id_);
1677 DCHECK(!prefix.index_id_); 1676 DCHECK(!prefix.index_id_);
1678 unsigned char type_byte = 0; 1677 unsigned char type_byte = 0;
1679 if (!DecodeByte(slice, &type_byte)) 1678 if (!DecodeByte(slice, &type_byte))
1680 return false; 1679 return false;
1681 DCHECK_EQ(type_byte, kObjectStoreNamesTypeByte); 1680 DCHECK_EQ(type_byte, kObjectStoreNamesTypeByte);
1682 if (!DecodeStringWithLength(slice, &result->object_store_name_)) 1681 if (!DecodeStringWithLength(slice, &result->object_store_name_))
1683 return false; 1682 return false;
1684 return true; 1683 return true;
1685 } 1684 }
1686 1685
1687 std::string ObjectStoreNamesKey::Encode( 1686 std::string ObjectStoreNamesKey::Encode(
1688 int64 database_id, 1687 int64_t database_id,
1689 const base::string16& object_store_name) { 1688 const base::string16& object_store_name) {
1690 KeyPrefix prefix(database_id); 1689 KeyPrefix prefix(database_id);
1691 std::string ret = prefix.Encode(); 1690 std::string ret = prefix.Encode();
1692 ret.push_back(kObjectStoreNamesTypeByte); 1691 ret.push_back(kObjectStoreNamesTypeByte);
1693 EncodeStringWithLength(object_store_name, &ret); 1692 EncodeStringWithLength(object_store_name, &ret);
1694 return ret; 1693 return ret;
1695 } 1694 }
1696 1695
1697 int ObjectStoreNamesKey::Compare(const ObjectStoreNamesKey& other) { 1696 int ObjectStoreNamesKey::Compare(const ObjectStoreNamesKey& other) {
1698 return object_store_name_.compare(other.object_store_name_); 1697 return object_store_name_.compare(other.object_store_name_);
(...skipping 14 matching lines...) Expand all
1713 if (!DecodeByte(slice, &type_byte)) 1712 if (!DecodeByte(slice, &type_byte))
1714 return false; 1713 return false;
1715 DCHECK_EQ(type_byte, kIndexNamesKeyTypeByte); 1714 DCHECK_EQ(type_byte, kIndexNamesKeyTypeByte);
1716 if (!DecodeVarInt(slice, &result->object_store_id_)) 1715 if (!DecodeVarInt(slice, &result->object_store_id_))
1717 return false; 1716 return false;
1718 if (!DecodeStringWithLength(slice, &result->index_name_)) 1717 if (!DecodeStringWithLength(slice, &result->index_name_))
1719 return false; 1718 return false;
1720 return true; 1719 return true;
1721 } 1720 }
1722 1721
1723 std::string IndexNamesKey::Encode(int64 database_id, 1722 std::string IndexNamesKey::Encode(int64_t database_id,
1724 int64 object_store_id, 1723 int64_t object_store_id,
1725 const base::string16& index_name) { 1724 const base::string16& index_name) {
1726 KeyPrefix prefix(database_id); 1725 KeyPrefix prefix(database_id);
1727 std::string ret = prefix.Encode(); 1726 std::string ret = prefix.Encode();
1728 ret.push_back(kIndexNamesKeyTypeByte); 1727 ret.push_back(kIndexNamesKeyTypeByte);
1729 EncodeVarInt(object_store_id, &ret); 1728 EncodeVarInt(object_store_id, &ret);
1730 EncodeStringWithLength(index_name, &ret); 1729 EncodeStringWithLength(index_name, &ret);
1731 return ret; 1730 return ret;
1732 } 1731 }
1733 1732
1734 int IndexNamesKey::Compare(const IndexNamesKey& other) { 1733 int IndexNamesKey::Compare(const IndexNamesKey& other) {
(...skipping 12 matching lines...) Expand all
1747 if (!KeyPrefix::Decode(slice, &prefix)) 1746 if (!KeyPrefix::Decode(slice, &prefix))
1748 return false; 1747 return false;
1749 DCHECK(prefix.database_id_); 1748 DCHECK(prefix.database_id_);
1750 DCHECK(prefix.object_store_id_); 1749 DCHECK(prefix.object_store_id_);
1751 DCHECK_EQ(prefix.index_id_, kSpecialIndexNumber); 1750 DCHECK_EQ(prefix.index_id_, kSpecialIndexNumber);
1752 if (!ExtractEncodedIDBKey(slice, &result->encoded_user_key_)) 1751 if (!ExtractEncodedIDBKey(slice, &result->encoded_user_key_))
1753 return false; 1752 return false;
1754 return true; 1753 return true;
1755 } 1754 }
1756 1755
1757 std::string ObjectStoreDataKey::Encode(int64 database_id, 1756 std::string ObjectStoreDataKey::Encode(int64_t database_id,
1758 int64 object_store_id, 1757 int64_t object_store_id,
1759 const std::string encoded_user_key) { 1758 const std::string encoded_user_key) {
1760 KeyPrefix prefix(KeyPrefix::CreateWithSpecialIndex( 1759 KeyPrefix prefix(KeyPrefix::CreateWithSpecialIndex(
1761 database_id, object_store_id, kSpecialIndexNumber)); 1760 database_id, object_store_id, kSpecialIndexNumber));
1762 std::string ret = prefix.Encode(); 1761 std::string ret = prefix.Encode();
1763 ret.append(encoded_user_key); 1762 ret.append(encoded_user_key);
1764 1763
1765 return ret; 1764 return ret;
1766 } 1765 }
1767 1766
1768 std::string ObjectStoreDataKey::Encode(int64 database_id, 1767 std::string ObjectStoreDataKey::Encode(int64_t database_id,
1769 int64 object_store_id, 1768 int64_t object_store_id,
1770 const IndexedDBKey& user_key) { 1769 const IndexedDBKey& user_key) {
1771 std::string encoded_key; 1770 std::string encoded_key;
1772 EncodeIDBKey(user_key, &encoded_key); 1771 EncodeIDBKey(user_key, &encoded_key);
1773 return Encode(database_id, object_store_id, encoded_key); 1772 return Encode(database_id, object_store_id, encoded_key);
1774 } 1773 }
1775 1774
1776 scoped_ptr<IndexedDBKey> ObjectStoreDataKey::user_key() const { 1775 scoped_ptr<IndexedDBKey> ObjectStoreDataKey::user_key() const {
1777 scoped_ptr<IndexedDBKey> key; 1776 scoped_ptr<IndexedDBKey> key;
1778 StringPiece slice(encoded_user_key_); 1777 StringPiece slice(encoded_user_key_);
1779 if (!DecodeIDBKey(&slice, &key)) { 1778 if (!DecodeIDBKey(&slice, &key)) {
1780 // TODO(jsbell): Return error. 1779 // TODO(jsbell): Return error.
1781 } 1780 }
1782 return key.Pass(); 1781 return key.Pass();
1783 } 1782 }
1784 1783
1785 const int64 ObjectStoreDataKey::kSpecialIndexNumber = kObjectStoreDataIndexId; 1784 const int64_t ObjectStoreDataKey::kSpecialIndexNumber = kObjectStoreDataIndexId;
1786 1785
1787 ExistsEntryKey::ExistsEntryKey() {} 1786 ExistsEntryKey::ExistsEntryKey() {}
1788 ExistsEntryKey::~ExistsEntryKey() {} 1787 ExistsEntryKey::~ExistsEntryKey() {}
1789 1788
1790 bool ExistsEntryKey::Decode(StringPiece* slice, ExistsEntryKey* result) { 1789 bool ExistsEntryKey::Decode(StringPiece* slice, ExistsEntryKey* result) {
1791 KeyPrefix prefix; 1790 KeyPrefix prefix;
1792 if (!KeyPrefix::Decode(slice, &prefix)) 1791 if (!KeyPrefix::Decode(slice, &prefix))
1793 return false; 1792 return false;
1794 DCHECK(prefix.database_id_); 1793 DCHECK(prefix.database_id_);
1795 DCHECK(prefix.object_store_id_); 1794 DCHECK(prefix.object_store_id_);
1796 DCHECK_EQ(prefix.index_id_, kSpecialIndexNumber); 1795 DCHECK_EQ(prefix.index_id_, kSpecialIndexNumber);
1797 if (!ExtractEncodedIDBKey(slice, &result->encoded_user_key_)) 1796 if (!ExtractEncodedIDBKey(slice, &result->encoded_user_key_))
1798 return false; 1797 return false;
1799 return true; 1798 return true;
1800 } 1799 }
1801 1800
1802 std::string ExistsEntryKey::Encode(int64 database_id, 1801 std::string ExistsEntryKey::Encode(int64_t database_id,
1803 int64 object_store_id, 1802 int64_t object_store_id,
1804 const std::string& encoded_key) { 1803 const std::string& encoded_key) {
1805 KeyPrefix prefix(KeyPrefix::CreateWithSpecialIndex( 1804 KeyPrefix prefix(KeyPrefix::CreateWithSpecialIndex(
1806 database_id, object_store_id, kSpecialIndexNumber)); 1805 database_id, object_store_id, kSpecialIndexNumber));
1807 std::string ret = prefix.Encode(); 1806 std::string ret = prefix.Encode();
1808 ret.append(encoded_key); 1807 ret.append(encoded_key);
1809 return ret; 1808 return ret;
1810 } 1809 }
1811 1810
1812 std::string ExistsEntryKey::Encode(int64 database_id, 1811 std::string ExistsEntryKey::Encode(int64_t database_id,
1813 int64 object_store_id, 1812 int64_t object_store_id,
1814 const IndexedDBKey& user_key) { 1813 const IndexedDBKey& user_key) {
1815 std::string encoded_key; 1814 std::string encoded_key;
1816 EncodeIDBKey(user_key, &encoded_key); 1815 EncodeIDBKey(user_key, &encoded_key);
1817 return Encode(database_id, object_store_id, encoded_key); 1816 return Encode(database_id, object_store_id, encoded_key);
1818 } 1817 }
1819 1818
1820 scoped_ptr<IndexedDBKey> ExistsEntryKey::user_key() const { 1819 scoped_ptr<IndexedDBKey> ExistsEntryKey::user_key() const {
1821 scoped_ptr<IndexedDBKey> key; 1820 scoped_ptr<IndexedDBKey> key;
1822 StringPiece slice(encoded_user_key_); 1821 StringPiece slice(encoded_user_key_);
1823 if (!DecodeIDBKey(&slice, &key)) { 1822 if (!DecodeIDBKey(&slice, &key)) {
1824 // TODO(jsbell): Return error. 1823 // TODO(jsbell): Return error.
1825 } 1824 }
1826 return key.Pass(); 1825 return key.Pass();
1827 } 1826 }
1828 1827
1829 const int64 ExistsEntryKey::kSpecialIndexNumber = kExistsEntryIndexId; 1828 const int64_t ExistsEntryKey::kSpecialIndexNumber = kExistsEntryIndexId;
1830 1829
1831 bool BlobEntryKey::Decode(StringPiece* slice, BlobEntryKey* result) { 1830 bool BlobEntryKey::Decode(StringPiece* slice, BlobEntryKey* result) {
1832 KeyPrefix prefix; 1831 KeyPrefix prefix;
1833 if (!KeyPrefix::Decode(slice, &prefix)) 1832 if (!KeyPrefix::Decode(slice, &prefix))
1834 return false; 1833 return false;
1835 DCHECK(prefix.database_id_); 1834 DCHECK(prefix.database_id_);
1836 DCHECK(prefix.object_store_id_); 1835 DCHECK(prefix.object_store_id_);
1837 DCHECK_EQ(prefix.index_id_, kSpecialIndexNumber); 1836 DCHECK_EQ(prefix.index_id_, kSpecialIndexNumber);
1838 1837
1839 if (!ExtractEncodedIDBKey(slice, &result->encoded_user_key_)) 1838 if (!ExtractEncodedIDBKey(slice, &result->encoded_user_key_))
(...skipping 23 matching lines...) Expand all
1863 std::string BlobEntryKey::ReencodeToObjectStoreDataKey(StringPiece* slice) { 1862 std::string BlobEntryKey::ReencodeToObjectStoreDataKey(StringPiece* slice) {
1864 // TODO(ericu): We could be more efficient here, since the suffix is the same. 1863 // TODO(ericu): We could be more efficient here, since the suffix is the same.
1865 BlobEntryKey key; 1864 BlobEntryKey key;
1866 if (!Decode(slice, &key)) 1865 if (!Decode(slice, &key))
1867 return std::string(); 1866 return std::string();
1868 1867
1869 return ObjectStoreDataKey::Encode( 1868 return ObjectStoreDataKey::Encode(
1870 key.database_id_, key.object_store_id_, key.encoded_user_key_); 1869 key.database_id_, key.object_store_id_, key.encoded_user_key_);
1871 } 1870 }
1872 1871
1873 std::string BlobEntryKey::EncodeMinKeyForObjectStore(int64 database_id, 1872 std::string BlobEntryKey::EncodeMinKeyForObjectStore(int64_t database_id,
1874 int64 object_store_id) { 1873 int64_t object_store_id) {
1875 // Our implied encoded_user_key_ here is empty, the lowest possible key. 1874 // Our implied encoded_user_key_ here is empty, the lowest possible key.
1876 return Encode(database_id, object_store_id, std::string()); 1875 return Encode(database_id, object_store_id, std::string());
1877 } 1876 }
1878 1877
1879 std::string BlobEntryKey::EncodeStopKeyForObjectStore(int64 database_id, 1878 std::string BlobEntryKey::EncodeStopKeyForObjectStore(int64_t database_id,
1880 int64 object_store_id) { 1879 int64_t object_store_id) {
1881 DCHECK(KeyPrefix::ValidIds(database_id, object_store_id)); 1880 DCHECK(KeyPrefix::ValidIds(database_id, object_store_id));
1882 KeyPrefix prefix(KeyPrefix::CreateWithSpecialIndex( 1881 KeyPrefix prefix(KeyPrefix::CreateWithSpecialIndex(
1883 database_id, object_store_id, kSpecialIndexNumber + 1)); 1882 database_id, object_store_id, kSpecialIndexNumber + 1));
1884 return prefix.Encode(); 1883 return prefix.Encode();
1885 } 1884 }
1886 1885
1887 std::string BlobEntryKey::Encode() const { 1886 std::string BlobEntryKey::Encode() const {
1888 DCHECK(!encoded_user_key_.empty()); 1887 DCHECK(!encoded_user_key_.empty());
1889 return Encode(database_id_, object_store_id_, encoded_user_key_); 1888 return Encode(database_id_, object_store_id_, encoded_user_key_);
1890 } 1889 }
1891 1890
1892 std::string BlobEntryKey::Encode(int64 database_id, 1891 std::string BlobEntryKey::Encode(int64_t database_id,
1893 int64 object_store_id, 1892 int64_t object_store_id,
1894 const IndexedDBKey& user_key) { 1893 const IndexedDBKey& user_key) {
1895 std::string encoded_key; 1894 std::string encoded_key;
1896 EncodeIDBKey(user_key, &encoded_key); 1895 EncodeIDBKey(user_key, &encoded_key);
1897 return Encode(database_id, object_store_id, encoded_key); 1896 return Encode(database_id, object_store_id, encoded_key);
1898 } 1897 }
1899 1898
1900 std::string BlobEntryKey::Encode(int64 database_id, 1899 std::string BlobEntryKey::Encode(int64_t database_id,
1901 int64 object_store_id, 1900 int64_t object_store_id,
1902 const std::string& encoded_user_key) { 1901 const std::string& encoded_user_key) {
1903 DCHECK(KeyPrefix::ValidIds(database_id, object_store_id)); 1902 DCHECK(KeyPrefix::ValidIds(database_id, object_store_id));
1904 KeyPrefix prefix(KeyPrefix::CreateWithSpecialIndex( 1903 KeyPrefix prefix(KeyPrefix::CreateWithSpecialIndex(
1905 database_id, object_store_id, kSpecialIndexNumber)); 1904 database_id, object_store_id, kSpecialIndexNumber));
1906 return prefix.Encode() + encoded_user_key; 1905 return prefix.Encode() + encoded_user_key;
1907 } 1906 }
1908 1907
1909 const int64 BlobEntryKey::kSpecialIndexNumber = kBlobEntryIndexId; 1908 const int64_t BlobEntryKey::kSpecialIndexNumber = kBlobEntryIndexId;
1910 1909
1911 IndexDataKey::IndexDataKey() 1910 IndexDataKey::IndexDataKey()
1912 : database_id_(-1), 1911 : database_id_(-1),
1913 object_store_id_(-1), 1912 object_store_id_(-1),
1914 index_id_(-1), 1913 index_id_(-1),
1915 sequence_number_(-1) {} 1914 sequence_number_(-1) {}
1916 1915
1917 IndexDataKey::~IndexDataKey() {} 1916 IndexDataKey::~IndexDataKey() {}
1918 1917
1919 bool IndexDataKey::Decode(StringPiece* slice, IndexDataKey* result) { 1918 bool IndexDataKey::Decode(StringPiece* slice, IndexDataKey* result) {
(...skipping 19 matching lines...) Expand all
1939 return false; 1938 return false;
1940 1939
1941 // [optional] primary key 1940 // [optional] primary key
1942 if (slice->empty()) 1941 if (slice->empty())
1943 return true; 1942 return true;
1944 if (!ExtractEncodedIDBKey(slice, &result->encoded_primary_key_)) 1943 if (!ExtractEncodedIDBKey(slice, &result->encoded_primary_key_))
1945 return false; 1944 return false;
1946 return true; 1945 return true;
1947 } 1946 }
1948 1947
1949 std::string IndexDataKey::Encode(int64 database_id, 1948 std::string IndexDataKey::Encode(int64_t database_id,
1950 int64 object_store_id, 1949 int64_t object_store_id,
1951 int64 index_id, 1950 int64_t index_id,
1952 const std::string& encoded_user_key, 1951 const std::string& encoded_user_key,
1953 const std::string& encoded_primary_key, 1952 const std::string& encoded_primary_key,
1954 int64 sequence_number) { 1953 int64_t sequence_number) {
1955 KeyPrefix prefix(database_id, object_store_id, index_id); 1954 KeyPrefix prefix(database_id, object_store_id, index_id);
1956 std::string ret = prefix.Encode(); 1955 std::string ret = prefix.Encode();
1957 ret.append(encoded_user_key); 1956 ret.append(encoded_user_key);
1958 EncodeVarInt(sequence_number, &ret); 1957 EncodeVarInt(sequence_number, &ret);
1959 ret.append(encoded_primary_key); 1958 ret.append(encoded_primary_key);
1960 return ret; 1959 return ret;
1961 } 1960 }
1962 1961
1963 std::string IndexDataKey::Encode(int64 database_id, 1962 std::string IndexDataKey::Encode(int64_t database_id,
1964 int64 object_store_id, 1963 int64_t object_store_id,
1965 int64 index_id, 1964 int64_t index_id,
1966 const IndexedDBKey& user_key) { 1965 const IndexedDBKey& user_key) {
1967 std::string encoded_key; 1966 std::string encoded_key;
1968 EncodeIDBKey(user_key, &encoded_key); 1967 EncodeIDBKey(user_key, &encoded_key);
1969 return Encode( 1968 return Encode(
1970 database_id, object_store_id, index_id, encoded_key, MinIDBKey(), 0); 1969 database_id, object_store_id, index_id, encoded_key, MinIDBKey(), 0);
1971 } 1970 }
1972 1971
1973 std::string IndexDataKey::Encode(int64 database_id, 1972 std::string IndexDataKey::Encode(int64_t database_id,
1974 int64 object_store_id, 1973 int64_t object_store_id,
1975 int64 index_id, 1974 int64_t index_id,
1976 const IndexedDBKey& user_key, 1975 const IndexedDBKey& user_key,
1977 const IndexedDBKey& user_primary_key) { 1976 const IndexedDBKey& user_primary_key) {
1978 std::string encoded_key; 1977 std::string encoded_key;
1979 EncodeIDBKey(user_key, &encoded_key); 1978 EncodeIDBKey(user_key, &encoded_key);
1980 std::string encoded_primary_key; 1979 std::string encoded_primary_key;
1981 EncodeIDBKey(user_primary_key, &encoded_primary_key); 1980 EncodeIDBKey(user_primary_key, &encoded_primary_key);
1982 return Encode(database_id, 1981 return Encode(database_id,
1983 object_store_id, 1982 object_store_id,
1984 index_id, 1983 index_id,
1985 encoded_key, 1984 encoded_key,
1986 encoded_primary_key, 1985 encoded_primary_key,
1987 0); 1986 0);
1988 } 1987 }
1989 1988
1990 std::string IndexDataKey::EncodeMinKey(int64 database_id, 1989 std::string IndexDataKey::EncodeMinKey(int64_t database_id,
1991 int64 object_store_id, 1990 int64_t object_store_id,
1992 int64 index_id) { 1991 int64_t index_id) {
1993 return Encode( 1992 return Encode(
1994 database_id, object_store_id, index_id, MinIDBKey(), MinIDBKey(), 0); 1993 database_id, object_store_id, index_id, MinIDBKey(), MinIDBKey(), 0);
1995 } 1994 }
1996 1995
1997 std::string IndexDataKey::EncodeMaxKey(int64 database_id, 1996 std::string IndexDataKey::EncodeMaxKey(int64_t database_id,
1998 int64 object_store_id, 1997 int64_t object_store_id,
1999 int64 index_id) { 1998 int64_t index_id) {
2000 return Encode(database_id, 1999 return Encode(database_id, object_store_id, index_id, MaxIDBKey(),
2001 object_store_id, 2000 MaxIDBKey(), std::numeric_limits<int64_t>::max());
2002 index_id,
2003 MaxIDBKey(),
2004 MaxIDBKey(),
2005 std::numeric_limits<int64>::max());
2006 } 2001 }
2007 2002
2008 int64 IndexDataKey::DatabaseId() const { 2003 int64_t IndexDataKey::DatabaseId() const {
2009 DCHECK_GE(database_id_, 0); 2004 DCHECK_GE(database_id_, 0);
2010 return database_id_; 2005 return database_id_;
2011 } 2006 }
2012 2007
2013 int64 IndexDataKey::ObjectStoreId() const { 2008 int64_t IndexDataKey::ObjectStoreId() const {
2014 DCHECK_GE(object_store_id_, 0); 2009 DCHECK_GE(object_store_id_, 0);
2015 return object_store_id_; 2010 return object_store_id_;
2016 } 2011 }
2017 2012
2018 int64 IndexDataKey::IndexId() const { 2013 int64_t IndexDataKey::IndexId() const {
2019 DCHECK_GE(index_id_, 0); 2014 DCHECK_GE(index_id_, 0);
2020 return index_id_; 2015 return index_id_;
2021 } 2016 }
2022 2017
2023 scoped_ptr<IndexedDBKey> IndexDataKey::user_key() const { 2018 scoped_ptr<IndexedDBKey> IndexDataKey::user_key() const {
2024 scoped_ptr<IndexedDBKey> key; 2019 scoped_ptr<IndexedDBKey> key;
2025 StringPiece slice(encoded_user_key_); 2020 StringPiece slice(encoded_user_key_);
2026 if (!DecodeIDBKey(&slice, &key)) { 2021 if (!DecodeIDBKey(&slice, &key)) {
2027 // TODO(jsbell): Return error. 2022 // TODO(jsbell): Return error.
2028 } 2023 }
2029 return key.Pass(); 2024 return key.Pass();
2030 } 2025 }
2031 2026
2032 scoped_ptr<IndexedDBKey> IndexDataKey::primary_key() const { 2027 scoped_ptr<IndexedDBKey> IndexDataKey::primary_key() const {
2033 scoped_ptr<IndexedDBKey> key; 2028 scoped_ptr<IndexedDBKey> key;
2034 StringPiece slice(encoded_primary_key_); 2029 StringPiece slice(encoded_primary_key_);
2035 if (!DecodeIDBKey(&slice, &key)) { 2030 if (!DecodeIDBKey(&slice, &key)) {
2036 // TODO(jsbell): Return error. 2031 // TODO(jsbell): Return error.
2037 } 2032 }
2038 return key.Pass(); 2033 return key.Pass();
2039 } 2034 }
2040 2035
2041 } // namespace content 2036 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698