| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h" | 5 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h" |
| 6 | 6 |
| 7 #include <iterator> | 7 #include <iterator> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 13 #include "base/strings/string_piece.h" |
| 14 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/sys_byteorder.h" | 15 #include "base/sys_byteorder.h" |
| 14 #include "content/browser/indexed_db/leveldb/leveldb_slice.h" | 16 #include "content/browser/indexed_db/leveldb/leveldb_slice.h" |
| 15 #include "content/common/indexed_db/indexed_db_key.h" | 17 #include "content/common/indexed_db/indexed_db_key.h" |
| 16 #include "content/common/indexed_db/indexed_db_key_path.h" | 18 #include "content/common/indexed_db/indexed_db_key_path.h" |
| 17 #include "third_party/WebKit/public/platform/WebIDBKeyPath.h" | 19 #include "third_party/WebKit/public/platform/WebIDBKeyPath.h" |
| 18 | 20 |
| 19 // LevelDB stores key/value pairs. Keys and values are strings of bytes, | 21 // LevelDB stores key/value pairs. Keys and values are strings of bytes, |
| 20 // normally of type std::vector<char>. | 22 // normally of type std::vector<char>. |
| 21 // | 23 // |
| 22 // The keys in the backing store are variable-length tuples with different types | 24 // The keys in the backing store are variable-length tuples with different types |
| (...skipping 1247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1270 if (!DecodeByte(&slice, &type_byte)) | 1272 if (!DecodeByte(&slice, &type_byte)) |
| 1271 return 0; | 1273 return 0; |
| 1272 DCHECK_EQ(type_byte, kDatabaseNameTypeByte); | 1274 DCHECK_EQ(type_byte, kDatabaseNameTypeByte); |
| 1273 if (!DecodeStringWithLength(&slice, &result->origin_)) | 1275 if (!DecodeStringWithLength(&slice, &result->origin_)) |
| 1274 return 0; | 1276 return 0; |
| 1275 if (!DecodeStringWithLength(&slice, &result->database_name_)) | 1277 if (!DecodeStringWithLength(&slice, &result->database_name_)) |
| 1276 return 0; | 1278 return 0; |
| 1277 return slice.begin(); | 1279 return slice.begin(); |
| 1278 } | 1280 } |
| 1279 | 1281 |
| 1280 std::vector<char> DatabaseNameKey::Encode(const string16& origin, | 1282 std::vector<char> DatabaseNameKey::Encode(const std::string& origin_identifier, |
| 1281 const string16& database_name) { | 1283 const string16& database_name) { |
| 1282 std::vector<char> ret = KeyPrefix::EncodeEmpty(); | 1284 std::vector<char> ret = KeyPrefix::EncodeEmpty(); |
| 1283 ret.push_back(kDatabaseNameTypeByte); | 1285 ret.push_back(kDatabaseNameTypeByte); |
| 1284 EncodeStringWithLength(origin, &ret); | 1286 EncodeStringWithLength(base::ASCIIToUTF16(origin_identifier), &ret); |
| 1285 EncodeStringWithLength(database_name, &ret); | 1287 EncodeStringWithLength(database_name, &ret); |
| 1286 return ret; | 1288 return ret; |
| 1287 } | 1289 } |
| 1288 | 1290 |
| 1289 std::vector<char> DatabaseNameKey::EncodeMinKeyForOrigin( | 1291 std::vector<char> DatabaseNameKey::EncodeMinKeyForOrigin( |
| 1290 const string16& origin) { | 1292 const std::string& origin_identifier) { |
| 1291 return Encode(origin, string16()); | 1293 return Encode(origin_identifier, string16()); |
| 1292 } | 1294 } |
| 1293 | 1295 |
| 1294 std::vector<char> DatabaseNameKey::EncodeStopKeyForOrigin( | 1296 std::vector<char> DatabaseNameKey::EncodeStopKeyForOrigin( |
| 1295 const string16& origin) { | 1297 const std::string& origin_identifier) { |
| 1296 // just after origin in collation order | 1298 // just after origin in collation order |
| 1297 return EncodeMinKeyForOrigin(origin + base::char16('\x01')); | 1299 return EncodeMinKeyForOrigin(origin_identifier + '\x01'); |
| 1298 } | 1300 } |
| 1299 | 1301 |
| 1300 int DatabaseNameKey::Compare(const DatabaseNameKey& other) { | 1302 int DatabaseNameKey::Compare(const DatabaseNameKey& other) { |
| 1301 if (int x = origin_.compare(other.origin_)) | 1303 if (int x = origin_.compare(other.origin_)) |
| 1302 return x; | 1304 return x; |
| 1303 return database_name_.compare(other.database_name_); | 1305 return database_name_.compare(other.database_name_); |
| 1304 } | 1306 } |
| 1305 | 1307 |
| 1306 std::vector<char> DatabaseMetaDataKey::Encode(int64 database_id, | 1308 std::vector<char> DatabaseMetaDataKey::Encode(int64 database_id, |
| 1307 MetaDataType meta_data_type) { | 1309 MetaDataType meta_data_type) { |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1890 scoped_ptr<IndexedDBKey> IndexDataKey::primary_key() const { | 1892 scoped_ptr<IndexedDBKey> IndexDataKey::primary_key() const { |
| 1891 scoped_ptr<IndexedDBKey> key; | 1893 scoped_ptr<IndexedDBKey> key; |
| 1892 StringPiece slice(&encoded_primary_key_[0], encoded_primary_key_.size()); | 1894 StringPiece slice(&encoded_primary_key_[0], encoded_primary_key_.size()); |
| 1893 if (!DecodeIDBKey(&slice, &key)) { | 1895 if (!DecodeIDBKey(&slice, &key)) { |
| 1894 // TODO(jsbell): Return error. | 1896 // TODO(jsbell): Return error. |
| 1895 } | 1897 } |
| 1896 return key.Pass(); | 1898 return key.Pass(); |
| 1897 } | 1899 } |
| 1898 | 1900 |
| 1899 } // namespace content | 1901 } // namespace content |
| OLD | NEW |