OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_LEVELDB_CODING_H_ | 5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_LEVELDB_CODING_H_ |
6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_LEVELDB_CODING_H_ | 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_LEVELDB_CODING_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 KeyPrefix(int64 database_id, int64 object_store_id, int64 index_id); | 85 KeyPrefix(int64 database_id, int64 object_store_id, int64 index_id); |
86 static KeyPrefix CreateWithSpecialIndex(int64 database_id, | 86 static KeyPrefix CreateWithSpecialIndex(int64 database_id, |
87 int64 object_store_id, | 87 int64 object_store_id, |
88 int64 index_id); | 88 int64 index_id); |
89 | 89 |
90 static bool Decode(base::StringPiece* slice, KeyPrefix* result); | 90 static bool Decode(base::StringPiece* slice, KeyPrefix* result); |
91 std::string Encode() const; | 91 std::string Encode() const; |
92 static std::string EncodeEmpty(); | 92 static std::string EncodeEmpty(); |
93 int Compare(const KeyPrefix& other) const; | 93 int Compare(const KeyPrefix& other) const; |
94 | 94 |
| 95 // These are serialized to disk; any new items must be appended, and none can |
| 96 // be deleted. |
95 enum Type { | 97 enum Type { |
96 GLOBAL_METADATA, | 98 GLOBAL_METADATA, |
97 DATABASE_METADATA, | 99 DATABASE_METADATA, |
98 OBJECT_STORE_DATA, | 100 OBJECT_STORE_DATA, |
99 EXISTS_ENTRY, | 101 EXISTS_ENTRY, |
100 INDEX_DATA, | 102 INDEX_DATA, |
101 INVALID_TYPE | 103 INVALID_TYPE, |
| 104 BLOB_ENTRY |
102 }; | 105 }; |
103 | 106 |
104 static const size_t kMaxDatabaseIdSizeBits = 3; | 107 static const size_t kMaxDatabaseIdSizeBits = 3; |
105 static const size_t kMaxObjectStoreIdSizeBits = 3; | 108 static const size_t kMaxObjectStoreIdSizeBits = 3; |
106 static const size_t kMaxIndexIdSizeBits = 2; | 109 static const size_t kMaxIndexIdSizeBits = 2; |
107 | 110 |
108 static const size_t kMaxDatabaseIdSizeBytes = | 111 static const size_t kMaxDatabaseIdSizeBytes = |
109 1ULL << kMaxDatabaseIdSizeBits; // 8 | 112 1ULL << kMaxDatabaseIdSizeBits; // 8 |
110 static const size_t kMaxObjectStoreIdSizeBytes = | 113 static const size_t kMaxObjectStoreIdSizeBytes = |
111 1ULL << kMaxObjectStoreIdSizeBits; // 8 | 114 1ULL << kMaxObjectStoreIdSizeBits; // 8 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 class MaxDatabaseIdKey { | 168 class MaxDatabaseIdKey { |
166 public: | 169 public: |
167 CONTENT_EXPORT static std::string Encode(); | 170 CONTENT_EXPORT static std::string Encode(); |
168 }; | 171 }; |
169 | 172 |
170 class DataVersionKey { | 173 class DataVersionKey { |
171 public: | 174 public: |
172 static std::string Encode(); | 175 static std::string Encode(); |
173 }; | 176 }; |
174 | 177 |
| 178 class BlobJournalKey { |
| 179 public: |
| 180 static std::string Encode(); |
| 181 }; |
| 182 |
| 183 class LiveBlobJournalKey { |
| 184 public: |
| 185 static std::string Encode(); |
| 186 }; |
| 187 |
175 class DatabaseFreeListKey { | 188 class DatabaseFreeListKey { |
176 public: | 189 public: |
177 DatabaseFreeListKey(); | 190 DatabaseFreeListKey(); |
178 static bool Decode(base::StringPiece* slice, DatabaseFreeListKey* result); | 191 static bool Decode(base::StringPiece* slice, DatabaseFreeListKey* result); |
179 CONTENT_EXPORT static std::string Encode(int64 database_id); | 192 CONTENT_EXPORT static std::string Encode(int64 database_id); |
180 static CONTENT_EXPORT std::string EncodeMaxKey(); | 193 static CONTENT_EXPORT std::string EncodeMaxKey(); |
181 int64 DatabaseId() const; | 194 int64 DatabaseId() const; |
182 int Compare(const DatabaseFreeListKey& other) const; | 195 int Compare(const DatabaseFreeListKey& other) const; |
183 | 196 |
184 private: | 197 private: |
(...skipping 20 matching lines...) Expand all Loading... |
205 }; | 218 }; |
206 | 219 |
207 class DatabaseMetaDataKey { | 220 class DatabaseMetaDataKey { |
208 public: | 221 public: |
209 enum MetaDataType { | 222 enum MetaDataType { |
210 ORIGIN_NAME = 0, | 223 ORIGIN_NAME = 0, |
211 DATABASE_NAME = 1, | 224 DATABASE_NAME = 1, |
212 USER_VERSION = 2, | 225 USER_VERSION = 2, |
213 MAX_OBJECT_STORE_ID = 3, | 226 MAX_OBJECT_STORE_ID = 3, |
214 USER_INT_VERSION = 4, | 227 USER_INT_VERSION = 4, |
215 MAX_SIMPLE_METADATA_TYPE = 5 | 228 BLOB_KEY_GENERATOR_CURRENT_NUMBER = 5, |
| 229 MAX_SIMPLE_METADATA_TYPE = 6 |
216 }; | 230 }; |
217 | 231 |
| 232 static const int64 kAllBlobsKey = 1; |
| 233 static const int64 kBlobKeyGeneratorInitialNumber = 2; |
| 234 static const int64 kInvalidBlobKey = -1; // All keys <= 0 are invalid. |
| 235 |
| 236 static bool IsValidBlobKey(int64 blobKey); |
218 CONTENT_EXPORT static std::string Encode(int64 database_id, | 237 CONTENT_EXPORT static std::string Encode(int64 database_id, |
219 MetaDataType type); | 238 MetaDataType type); |
220 }; | 239 }; |
221 | 240 |
222 class ObjectStoreMetaDataKey { | 241 class ObjectStoreMetaDataKey { |
223 public: | 242 public: |
224 enum MetaDataType { | 243 enum MetaDataType { |
225 NAME = 0, | 244 NAME = 0, |
226 KEY_PATH = 1, | 245 KEY_PATH = 1, |
227 AUTO_INCREMENT = 2, | 246 AUTO_INCREMENT = 2, |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 const IndexedDBKey& user_key); | 396 const IndexedDBKey& user_key); |
378 scoped_ptr<IndexedDBKey> user_key() const; | 397 scoped_ptr<IndexedDBKey> user_key() const; |
379 | 398 |
380 static const int64 kSpecialIndexNumber; | 399 static const int64 kSpecialIndexNumber; |
381 | 400 |
382 private: | 401 private: |
383 std::string encoded_user_key_; | 402 std::string encoded_user_key_; |
384 DISALLOW_COPY_AND_ASSIGN(ExistsEntryKey); | 403 DISALLOW_COPY_AND_ASSIGN(ExistsEntryKey); |
385 }; | 404 }; |
386 | 405 |
| 406 class BlobEntryKey { |
| 407 public: |
| 408 BlobEntryKey() : database_id_(0), object_store_id_(0) {} |
| 409 static bool Decode(base::StringPiece* slice, BlobEntryKey* result); |
| 410 static bool FromObjectStoreDataKey(base::StringPiece* slice, |
| 411 BlobEntryKey* result); |
| 412 static std::string ReencodeToObjectStoreDataKey(base::StringPiece* slice); |
| 413 static std::string EncodeMinKeyForObjectStore(int64 database_id, |
| 414 int64 object_store_id); |
| 415 static std::string EncodeStopKeyForObjectStore(int64 database_id, |
| 416 int64 object_store_id); |
| 417 static std::string Encode(int64 database_id, |
| 418 int64 object_store_id, |
| 419 const IndexedDBKey& user_key); |
| 420 std::string Encode() const; |
| 421 int64 database_id() const { return database_id_; } |
| 422 int64 object_store_id() const { return object_store_id_; } |
| 423 |
| 424 static const int64 kSpecialIndexNumber; |
| 425 |
| 426 private: |
| 427 static std::string Encode(int64 database_id, |
| 428 int64 object_store_id, |
| 429 const std::string& encoded_user_key); |
| 430 int64 database_id_; |
| 431 int64 object_store_id_; |
| 432 // This is the user's ObjectStoreDataKey, not the BlobEntryKey itself. |
| 433 std::string encoded_user_key_; |
| 434 DISALLOW_COPY_AND_ASSIGN(BlobEntryKey); |
| 435 }; |
| 436 |
387 class IndexDataKey { | 437 class IndexDataKey { |
388 public: | 438 public: |
389 IndexDataKey(); | 439 IndexDataKey(); |
390 ~IndexDataKey(); | 440 ~IndexDataKey(); |
391 static bool Decode(base::StringPiece* slice, IndexDataKey* result); | 441 static bool Decode(base::StringPiece* slice, IndexDataKey* result); |
392 CONTENT_EXPORT static std::string Encode( | 442 CONTENT_EXPORT static std::string Encode( |
393 int64 database_id, | 443 int64 database_id, |
394 int64 object_store_id, | 444 int64 object_store_id, |
395 int64 index_id, | 445 int64 index_id, |
396 const std::string& encoded_user_key, | 446 const std::string& encoded_user_key, |
(...skipping 27 matching lines...) Expand all Loading... |
424 std::string encoded_user_key_; | 474 std::string encoded_user_key_; |
425 std::string encoded_primary_key_; | 475 std::string encoded_primary_key_; |
426 int64 sequence_number_; | 476 int64 sequence_number_; |
427 | 477 |
428 DISALLOW_COPY_AND_ASSIGN(IndexDataKey); | 478 DISALLOW_COPY_AND_ASSIGN(IndexDataKey); |
429 }; | 479 }; |
430 | 480 |
431 } // namespace content | 481 } // namespace content |
432 | 482 |
433 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_LEVELDB_CODING_H_ | 483 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_LEVELDB_CODING_H_ |
OLD | NEW |