indexed_db_leveldb_coding.h revision 7dbb3d5cf0c15f500944d211057644d6a2f37371
1868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// found in the LICENSE file.
4868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
5868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_LEVELDB_CODING_H_
6868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_LEVELDB_CODING_H_
7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
87dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include <string>
9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/basictypes.h"
11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/logging.h"
12868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/memory/ref_counted.h"
13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string16.h"
15868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string_piece.h"
16868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "content/common/indexed_db/indexed_db_key.h"
17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "content/common/indexed_db/indexed_db_key_path.h"
18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
19868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace content {
20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
21868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)CONTENT_EXPORT extern const unsigned char kMinimumIndexId;
22868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
237dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochCONTENT_EXPORT std::string MaxIDBKey();
247dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochCONTENT_EXPORT std::string MinIDBKey();
25868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
267dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochCONTENT_EXPORT void EncodeByte(unsigned char value, std::string* into);
277dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochCONTENT_EXPORT void EncodeBool(bool value, std::string* into);
287dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochCONTENT_EXPORT void EncodeInt(int64 value, std::string* into);
297dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochCONTENT_EXPORT void EncodeVarInt(int64 value, std::string* into);
307dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochCONTENT_EXPORT void EncodeString(const string16& value, std::string* into);
31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)CONTENT_EXPORT void EncodeStringWithLength(const string16& value,
327dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                           std::string* into);
337dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochCONTENT_EXPORT void EncodeDouble(double value, std::string* into);
347dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochCONTENT_EXPORT void EncodeIDBKey(const IndexedDBKey& value, std::string* into);
35868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)CONTENT_EXPORT void EncodeIDBKeyPath(const IndexedDBKeyPath& value,
367dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                     std::string* into);
37868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
38868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeByte(base::StringPiece* slice,
39868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                                  unsigned char* value);
40868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeBool(base::StringPiece* slice,
41868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                                  bool* value);
42868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeInt(base::StringPiece* slice,
43868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                                 int64* value);
44868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeVarInt(base::StringPiece* slice,
45868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                                    int64* value);
46868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeString(base::StringPiece* slice,
47868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                                    string16* value);
48868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeStringWithLength(
49868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    base::StringPiece* slice,
50868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    string16* value);
51868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeDouble(base::StringPiece* slice,
52868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                                    double* value);
53868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeIDBKey(
54868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    base::StringPiece* slice,
55868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    scoped_ptr<IndexedDBKey>* value);
56868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)CONTENT_EXPORT WARN_UNUSED_RESULT bool DecodeIDBKeyPath(
57868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    base::StringPiece* slice,
58868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    IndexedDBKeyPath* value);
59868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
60868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)CONTENT_EXPORT int CompareEncodedStringsWithLength(base::StringPiece* slice1,
61868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                                   base::StringPiece* slice2,
62868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                                   bool* ok);
63868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
64868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)CONTENT_EXPORT WARN_UNUSED_RESULT bool ExtractEncodedIDBKey(
65868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    base::StringPiece* slice,
667dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    std::string* result);
67868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
687dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochCONTENT_EXPORT int CompareEncodedIDBKeys(const std::string& a,
697dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                         const std::string& b,
70868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                         bool* ok);
71868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
727dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochCONTENT_EXPORT int Compare(const base::StringPiece& a,
737dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                           const base::StringPiece& b,
74eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                           bool index_keys);
75868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
76868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class KeyPrefix {
77868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public:
78868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  KeyPrefix();
79868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  explicit KeyPrefix(int64 database_id);
80868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  KeyPrefix(int64 database_id, int64 object_store_id);
81868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  KeyPrefix(int64 database_id, int64 object_store_id, int64 index_id);
82868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static KeyPrefix CreateWithSpecialIndex(int64 database_id,
83868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                          int64 object_store_id,
84868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                          int64 index_id);
85868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
86868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static const char* Decode(const char* start,
87868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                            const char* limit,
88868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                            KeyPrefix* result);
897dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  std::string Encode() const;
907dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  static std::string EncodeEmpty();
91868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int Compare(const KeyPrefix& other) const;
92868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
93868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  enum Type {
94868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    GLOBAL_METADATA,
95868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    DATABASE_METADATA,
96868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    OBJECT_STORE_DATA,
97868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXISTS_ENTRY,
98868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    INDEX_DATA,
99868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    INVALID_TYPE
100868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  };
101868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
102868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static const size_t kMaxDatabaseIdSizeBits = 3;
103868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static const size_t kMaxObjectStoreIdSizeBits = 3;
104868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static const size_t kMaxIndexIdSizeBits = 2;
105868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
106868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static const size_t kMaxDatabaseIdSizeBytes =
107868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      1ULL << kMaxDatabaseIdSizeBits;  // 8
108868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static const size_t kMaxObjectStoreIdSizeBytes =
109868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      1ULL << kMaxObjectStoreIdSizeBits;                                   // 8
110868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static const size_t kMaxIndexIdSizeBytes = 1ULL << kMaxIndexIdSizeBits;  // 4
111868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
112868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static const size_t kMaxDatabaseIdBits =
113868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      kMaxDatabaseIdSizeBytes * 8 - 1;  // 63
114868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static const size_t kMaxObjectStoreIdBits =
115868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      kMaxObjectStoreIdSizeBytes * 8 - 1;                              // 63
116868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static const size_t kMaxIndexIdBits = kMaxIndexIdSizeBytes * 8 - 1;  // 31
117868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
118868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static const int64 kMaxDatabaseId =
119868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      (1ULL << kMaxDatabaseIdBits) - 1;  // max signed int64
120868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static const int64 kMaxObjectStoreId =
121868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      (1ULL << kMaxObjectStoreIdBits) - 1;  // max signed int64
122868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static const int64 kMaxIndexId =
123868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      (1ULL << kMaxIndexIdBits) - 1;  // max signed int32
124868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
125868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static bool IsValidDatabaseId(int64 database_id);
126868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static bool IsValidObjectStoreId(int64 index_id);
127868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static bool IsValidIndexId(int64 index_id);
128868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static bool ValidIds(int64 database_id,
129868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                       int64 object_store_id,
130868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                       int64 index_id) {
131868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    return IsValidDatabaseId(database_id) &&
132868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)           IsValidObjectStoreId(object_store_id) && IsValidIndexId(index_id);
133868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  }
134868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static bool ValidIds(int64 database_id, int64 object_store_id) {
135868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    return IsValidDatabaseId(database_id) &&
136868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)           IsValidObjectStoreId(object_store_id);
137868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  }
138868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
139868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  Type type() const;
140868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
141868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int64 database_id_;
142868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int64 object_store_id_;
143868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int64 index_id_;
144868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
145868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static const int64 kInvalidId = -1;
146868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
147868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) private:
1487dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  static std::string EncodeInternal(int64 database_id,
1497dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                    int64 object_store_id,
1507dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                    int64 index_id);
151868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Special constructor for CreateWithSpecialIndex()
152868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  KeyPrefix(enum Type,
153868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)            int64 database_id,
154868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)            int64 object_store_id,
155868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)            int64 index_id);
156868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)};
157868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
158868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class SchemaVersionKey {
159868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public:
1607dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  CONTENT_EXPORT static std::string Encode();
161868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)};
162868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
163868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class MaxDatabaseIdKey {
164868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public:
1657dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  CONTENT_EXPORT static std::string Encode();
166868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)};
167868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
168868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class DataVersionKey {
169868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public:
1707dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  static std::string Encode();
171868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)};
172868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
173868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class DatabaseFreeListKey {
174868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public:
175868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  DatabaseFreeListKey();
176868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static const char* Decode(const char* start,
177868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                            const char* limit,
178868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                            DatabaseFreeListKey* result);
1797dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  CONTENT_EXPORT static std::string Encode(int64 database_id);
1807dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  static CONTENT_EXPORT std::string EncodeMaxKey();
181868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int64 DatabaseId() const;
182868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int Compare(const DatabaseFreeListKey& other) const;
183868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
184868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) private:
185868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int64 database_id_;
186868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)};
187868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
188868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class DatabaseNameKey {
189868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public:
190868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static const char* Decode(const char* start,
191868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                            const char* limit,
192868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                            DatabaseNameKey* result);
1937dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  CONTENT_EXPORT static std::string Encode(const std::string& origin_identifier,
1947dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                           const string16& database_name);
1957dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  static std::string EncodeMinKeyForOrigin(
196eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      const std::string& origin_identifier);
1977dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  static std::string EncodeStopKeyForOrigin(
198eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      const std::string& origin_identifier);
199868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  string16 origin() const { return origin_; }
200868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  string16 database_name() const { return database_name_; }
201868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int Compare(const DatabaseNameKey& other);
202868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
203868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) private:
204868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  string16 origin_;  // TODO(jsbell): Store encoded strings, or just pointers.
205868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  string16 database_name_;
206868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)};
207868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
208868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class DatabaseMetaDataKey {
209868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public:
210868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  enum MetaDataType {
211868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    ORIGIN_NAME = 0,
212868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    DATABASE_NAME = 1,
213868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    USER_VERSION = 2,
214868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    MAX_OBJECT_STORE_ID = 3,
215868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    USER_INT_VERSION = 4,
216868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    MAX_SIMPLE_METADATA_TYPE = 5
217868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  };
218868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2197dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  CONTENT_EXPORT static std::string Encode(int64 database_id,
2207dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                           MetaDataType type);
221868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)};
222868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
223868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class ObjectStoreMetaDataKey {
224868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public:
225868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  enum MetaDataType {
226868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    NAME = 0,
227868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    KEY_PATH = 1,
228868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    AUTO_INCREMENT = 2,
229868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EVICTABLE = 3,
230868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    LAST_VERSION = 4,
231868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    MAX_INDEX_ID = 5,
232868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    HAS_KEY_PATH = 6,
233868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    KEY_GENERATOR_CURRENT_NUMBER = 7
234868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  };
235868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
236868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ObjectStoreMetaDataKey();
237868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static const char* Decode(const char* start,
238868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                            const char* limit,
239868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                            ObjectStoreMetaDataKey* result);
2407dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  CONTENT_EXPORT static std::string Encode(int64 database_id,
2417dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                           int64 object_store_id,
2427dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                           unsigned char meta_data_type);
2437dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  CONTENT_EXPORT static std::string EncodeMaxKey(int64 database_id);
2447dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  CONTENT_EXPORT static std::string EncodeMaxKey(int64 database_id,
2457dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                                 int64 object_store_id);
246868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int64 ObjectStoreId() const;
247868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  unsigned char MetaDataType() const;
248868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int Compare(const ObjectStoreMetaDataKey& other);
249868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
250868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) private:
251868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int64 object_store_id_;
252868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  unsigned char meta_data_type_;
253868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)};
254868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
255868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class IndexMetaDataKey {
256868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public:
257868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  enum MetaDataType {
258868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    NAME = 0,
259868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    UNIQUE = 1,
260868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    KEY_PATH = 2,
261868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    MULTI_ENTRY = 3
262868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  };
263868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
264868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  IndexMetaDataKey();
265868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static const char* Decode(const char* start,
266868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                            const char* limit,
267868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                            IndexMetaDataKey* result);
2687dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  CONTENT_EXPORT static std::string Encode(int64 database_id,
2697dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                           int64 object_store_id,
2707dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                           int64 index_id,
2717dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                           unsigned char meta_data_type);
2727dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  CONTENT_EXPORT static std::string EncodeMaxKey(int64 database_id,
2737dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                                 int64 object_store_id);
2747dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  CONTENT_EXPORT static std::string EncodeMaxKey(int64 database_id,
275868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                                 int64 object_store_id,
2767dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                                 int64 index_id);
277868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int Compare(const IndexMetaDataKey& other);
278868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int64 IndexId() const;
279868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  unsigned char meta_data_type() const { return meta_data_type_; }
280868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
281868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) private:
282868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int64 object_store_id_;
283868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int64 index_id_;
284868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  unsigned char meta_data_type_;
285868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)};
286868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
287868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class ObjectStoreFreeListKey {
288868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public:
289868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ObjectStoreFreeListKey();
290868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static const char* Decode(const char* start,
291868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                            const char* limit,
292868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                            ObjectStoreFreeListKey* result);
2937dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  CONTENT_EXPORT static std::string Encode(int64 database_id,
2947dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                           int64 object_store_id);
2957dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  CONTENT_EXPORT static std::string EncodeMaxKey(int64 database_id);
296868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int64 ObjectStoreId() const;
297868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int Compare(const ObjectStoreFreeListKey& other);
298868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
299868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) private:
300868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int64 object_store_id_;
301868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)};
302868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
303868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class IndexFreeListKey {
304868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public:
305868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  IndexFreeListKey();
306868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static const char* Decode(const char* start,
307868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                            const char* limit,
308868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                            IndexFreeListKey* result);
3097dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  CONTENT_EXPORT static std::string Encode(int64 database_id,
3107dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                           int64 object_store_id,
3117dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                           int64 index_id);
3127dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  CONTENT_EXPORT static std::string EncodeMaxKey(int64 database_id,
3137dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                                 int64 object_store_id);
314868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int Compare(const IndexFreeListKey& other);
315868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int64 ObjectStoreId() const;
316868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int64 IndexId() const;
317868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
318868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) private:
319868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int64 object_store_id_;
320868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int64 index_id_;
321868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)};
322868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
323868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class ObjectStoreNamesKey {
324868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public:
325868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // TODO(jsbell): We never use this to look up object store ids,
326868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // because a mapping is kept in the IndexedDBDatabase. Can the
327868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // mapping become unreliable?  Can we remove this?
328868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static const char* Decode(const char* start,
329868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                            const char* limit,
330868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                            ObjectStoreNamesKey* result);
3317dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  CONTENT_EXPORT static std::string Encode(int64 database_id,
3327dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                           const string16& object_store_name);
333868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int Compare(const ObjectStoreNamesKey& other);
334868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  string16 object_store_name() const { return object_store_name_; }
335868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
336868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) private:
337eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // TODO(jsbell): Store the encoded string, or just pointers to it.
338eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  string16 object_store_name_;
339868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)};
340868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
341868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class IndexNamesKey {
342868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public:
343868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  IndexNamesKey();
344868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // TODO(jsbell): We never use this to look up index ids, because a mapping
345868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // is kept at a higher level.
346868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static const char* Decode(const char* start,
347868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                            const char* limit,
348868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                            IndexNamesKey* result);
3497dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  CONTENT_EXPORT static std::string Encode(int64 database_id,
3507dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                           int64 object_store_id,
3517dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                           const string16& index_name);
352868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int Compare(const IndexNamesKey& other);
353868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  string16 index_name() const { return index_name_; }
354868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
355868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) private:
356868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int64 object_store_id_;
357868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  string16 index_name_;
358868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)};
359868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
360868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class ObjectStoreDataKey {
361868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public:
362868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static const char* Decode(const char* start,
363868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                            const char* end,
364868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                            ObjectStoreDataKey* result);
3657dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  CONTENT_EXPORT static std::string Encode(int64 database_id,
3667dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                           int64 object_store_id,
3677dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                           const std::string encoded_user_key);
3687dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  static std::string Encode(int64 database_id,
3697dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                            int64 object_store_id,
3707dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                            const IndexedDBKey& user_key);
371868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int Compare(const ObjectStoreDataKey& other, bool* ok);
372868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  scoped_ptr<IndexedDBKey> user_key() const;
373868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static const int64 kSpecialIndexNumber;
374868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ObjectStoreDataKey();
375868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ~ObjectStoreDataKey();
376868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
377868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) private:
3787dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  std::string encoded_user_key_;
379868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)};
380868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
381868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class ExistsEntryKey {
382868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public:
383868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ExistsEntryKey();
384868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ~ExistsEntryKey();
385868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
386868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static const char* Decode(const char* start,
387868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                            const char* end,
388868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                            ExistsEntryKey* result);
3897dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  CONTENT_EXPORT static std::string Encode(int64 database_id,
3907dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                           int64 object_store_id,
3917dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                           const std::string& encoded_key);
3927dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  static std::string Encode(int64 database_id,
3937dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                            int64 object_store_id,
3947dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                            const IndexedDBKey& user_key);
395868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int Compare(const ExistsEntryKey& other, bool* ok);
396868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  scoped_ptr<IndexedDBKey> user_key() const;
397868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
398868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static const int64 kSpecialIndexNumber;
399868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
400868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) private:
4017dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  std::string encoded_user_key_;
402868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(ExistsEntryKey);
403868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)};
404868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
405868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class IndexDataKey {
406868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public:
407868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  IndexDataKey();
408868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ~IndexDataKey();
409868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static const char* Decode(const char* start,
410868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                            const char* limit,
411868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                            IndexDataKey* result);
4127dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  CONTENT_EXPORT static std::string Encode(
413868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      int64 database_id,
414868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      int64 object_store_id,
415868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      int64 index_id,
4167dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      const std::string& encoded_user_key,
4177dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      const std::string& encoded_primary_key,
418eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      int64 sequence_number);
4197dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  static std::string Encode(int64 database_id,
4207dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                            int64 object_store_id,
4217dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                            int64 index_id,
4227dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                            const IndexedDBKey& user_key);
4237dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  static std::string EncodeMinKey(int64 database_id,
424868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                  int64 object_store_id,
4257dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                  int64 index_id);
4267dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  CONTENT_EXPORT static std::string EncodeMaxKey(int64 database_id,
4277dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                                 int64 object_store_id,
4287dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                                 int64 index_id);
429868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int Compare(const IndexDataKey& other, bool ignore_duplicates, bool* ok);
430868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int64 DatabaseId() const;
431868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int64 ObjectStoreId() const;
432868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int64 IndexId() const;
433868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  scoped_ptr<IndexedDBKey> user_key() const;
434868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  scoped_ptr<IndexedDBKey> primary_key() const;
435868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
436868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) private:
437868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int64 database_id_;
438868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int64 object_store_id_;
439868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int64 index_id_;
4407dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  std::string encoded_user_key_;
4417dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  std::string encoded_primary_key_;
442868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int64 sequence_number_;
443868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
444868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(IndexDataKey);
445868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)};
446868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
447868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}  // namespace content
448868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
449868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#endif  // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_LEVELDB_CODING_H_
450