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_database.h" | 5 #include "content/browser/indexed_db/indexed_db_database.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <vector> | |
9 | 8 |
10 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
11 #include "base/logging.h" | 10 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
13 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
15 #include "content/browser/indexed_db/indexed_db_backing_store.h" | 14 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
16 #include "content/browser/indexed_db/indexed_db_connection.h" | 15 #include "content/browser/indexed_db/indexed_db_connection.h" |
17 #include "content/browser/indexed_db/indexed_db_cursor.h" | 16 #include "content/browser/indexed_db/indexed_db_cursor.h" |
18 #include "content/browser/indexed_db/indexed_db_factory.h" | 17 #include "content/browser/indexed_db/indexed_db_factory.h" |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 const scoped_ptr<IndexedDBKeyRange> key_range_; | 220 const scoped_ptr<IndexedDBKeyRange> key_range_; |
222 const indexed_db::CursorType cursor_type_; | 221 const indexed_db::CursorType cursor_type_; |
223 const scoped_refptr<IndexedDBCallbacks> callbacks_; | 222 const scoped_refptr<IndexedDBCallbacks> callbacks_; |
224 }; | 223 }; |
225 | 224 |
226 class PutOperation : public IndexedDBTransaction::Operation { | 225 class PutOperation : public IndexedDBTransaction::Operation { |
227 public: | 226 public: |
228 PutOperation(scoped_refptr<IndexedDBBackingStore> backing_store, | 227 PutOperation(scoped_refptr<IndexedDBBackingStore> backing_store, |
229 int64 database_id, | 228 int64 database_id, |
230 const IndexedDBObjectStoreMetadata& object_store, | 229 const IndexedDBObjectStoreMetadata& object_store, |
231 std::vector<char>* value, | 230 std::string* value, |
232 scoped_ptr<IndexedDBKey> key, | 231 scoped_ptr<IndexedDBKey> key, |
233 IndexedDBDatabase::PutMode put_mode, | 232 IndexedDBDatabase::PutMode put_mode, |
234 scoped_refptr<IndexedDBCallbacks> callbacks, | 233 scoped_refptr<IndexedDBCallbacks> callbacks, |
235 const std::vector<int64>& index_ids, | 234 const std::vector<int64>& index_ids, |
236 const std::vector<IndexedDBDatabase::IndexKeys>& index_keys) | 235 const std::vector<IndexedDBDatabase::IndexKeys>& index_keys) |
237 : backing_store_(backing_store), | 236 : backing_store_(backing_store), |
238 database_id_(database_id), | 237 database_id_(database_id), |
239 object_store_(object_store), | 238 object_store_(object_store), |
240 key_(key.Pass()), | 239 key_(key.Pass()), |
241 put_mode_(put_mode), | 240 put_mode_(put_mode), |
242 callbacks_(callbacks), | 241 callbacks_(callbacks), |
243 index_ids_(index_ids), | 242 index_ids_(index_ids), |
244 index_keys_(index_keys) { | 243 index_keys_(index_keys) { |
245 value_.swap(*value); | 244 value_.swap(*value); |
246 } | 245 } |
247 virtual void Perform(IndexedDBTransaction* transaction) OVERRIDE; | 246 virtual void Perform(IndexedDBTransaction* transaction) OVERRIDE; |
248 | 247 |
249 private: | 248 private: |
250 const scoped_refptr<IndexedDBBackingStore> backing_store_; | 249 const scoped_refptr<IndexedDBBackingStore> backing_store_; |
251 const int64 database_id_; | 250 const int64 database_id_; |
252 const IndexedDBObjectStoreMetadata object_store_; | 251 const IndexedDBObjectStoreMetadata object_store_; |
253 std::vector<char> value_; | 252 std::string value_; |
254 scoped_ptr<IndexedDBKey> key_; | 253 scoped_ptr<IndexedDBKey> key_; |
255 const IndexedDBDatabase::PutMode put_mode_; | 254 const IndexedDBDatabase::PutMode put_mode_; |
256 const scoped_refptr<IndexedDBCallbacks> callbacks_; | 255 const scoped_refptr<IndexedDBCallbacks> callbacks_; |
257 const std::vector<int64> index_ids_; | 256 const std::vector<int64> index_ids_; |
258 const std::vector<IndexedDBDatabase::IndexKeys> index_keys_; | 257 const std::vector<IndexedDBDatabase::IndexKeys> index_keys_; |
259 }; | 258 }; |
260 | 259 |
261 class SetIndexesReadyOperation : public IndexedDBTransaction::Operation { | 260 class SetIndexesReadyOperation : public IndexedDBTransaction::Operation { |
262 public: | 261 public: |
263 explicit SetIndexesReadyOperation(size_t index_count) | 262 explicit SetIndexesReadyOperation(size_t index_count) |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 return; | 822 return; |
824 } | 823 } |
825 | 824 |
826 key = &backing_store_cursor->key(); | 825 key = &backing_store_cursor->key(); |
827 } | 826 } |
828 | 827 |
829 scoped_ptr<IndexedDBKey> primary_key; | 828 scoped_ptr<IndexedDBKey> primary_key; |
830 bool ok; | 829 bool ok; |
831 if (index_id_ == IndexedDBIndexMetadata::kInvalidId) { | 830 if (index_id_ == IndexedDBIndexMetadata::kInvalidId) { |
832 // Object Store Retrieval Operation | 831 // Object Store Retrieval Operation |
833 std::vector<char> value; | 832 std::string value; |
834 ok = backing_store_->GetRecord(transaction->BackingStoreTransaction(), | 833 ok = backing_store_->GetRecord(transaction->BackingStoreTransaction(), |
835 database_id_, | 834 database_id_, |
836 object_store_id_, | 835 object_store_id_, |
837 *key, | 836 *key, |
838 &value); | 837 &value); |
839 if (!ok) { | 838 if (!ok) { |
840 callbacks_->OnError( | 839 callbacks_->OnError( |
841 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError, | 840 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError, |
842 "Internal error in GetRecord.")); | 841 "Internal error in GetRecord.")); |
843 return; | 842 return; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 callbacks_->OnSuccess(); | 874 callbacks_->OnSuccess(); |
876 return; | 875 return; |
877 } | 876 } |
878 if (cursor_type_ == indexed_db::CURSOR_KEY_ONLY) { | 877 if (cursor_type_ == indexed_db::CURSOR_KEY_ONLY) { |
879 // Index Value Retrieval Operation | 878 // Index Value Retrieval Operation |
880 callbacks_->OnSuccess(*primary_key); | 879 callbacks_->OnSuccess(*primary_key); |
881 return; | 880 return; |
882 } | 881 } |
883 | 882 |
884 // Index Referenced Value Retrieval Operation | 883 // Index Referenced Value Retrieval Operation |
885 std::vector<char> value; | 884 std::string value; |
886 ok = backing_store_->GetRecord(transaction->BackingStoreTransaction(), | 885 ok = backing_store_->GetRecord(transaction->BackingStoreTransaction(), |
887 database_id_, | 886 database_id_, |
888 object_store_id_, | 887 object_store_id_, |
889 *primary_key, | 888 *primary_key, |
890 &value); | 889 &value); |
891 if (!ok) { | 890 if (!ok) { |
892 callbacks_->OnError( | 891 callbacks_->OnError( |
893 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError, | 892 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError, |
894 "Internal error in GetRecord.")); | 893 "Internal error in GetRecord.")); |
895 return; | 894 return; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
942 return backing_store->MaybeUpdateKeyGeneratorCurrentNumber( | 941 return backing_store->MaybeUpdateKeyGeneratorCurrentNumber( |
943 transaction->BackingStoreTransaction(), | 942 transaction->BackingStoreTransaction(), |
944 database_id, | 943 database_id, |
945 object_store_id, | 944 object_store_id, |
946 static_cast<int64>(floor(key->number())) + 1, | 945 static_cast<int64>(floor(key->number())) + 1, |
947 check_current); | 946 check_current); |
948 } | 947 } |
949 | 948 |
950 void IndexedDBDatabase::Put(int64 transaction_id, | 949 void IndexedDBDatabase::Put(int64 transaction_id, |
951 int64 object_store_id, | 950 int64 object_store_id, |
952 std::vector<char>* value, | 951 std::string* value, |
953 scoped_ptr<IndexedDBKey> key, | 952 scoped_ptr<IndexedDBKey> key, |
954 PutMode put_mode, | 953 PutMode put_mode, |
955 scoped_refptr<IndexedDBCallbacks> callbacks, | 954 scoped_refptr<IndexedDBCallbacks> callbacks, |
956 const std::vector<int64>& index_ids, | 955 const std::vector<int64>& index_ids, |
957 const std::vector<IndexKeys>& index_keys) { | 956 const std::vector<IndexKeys>& index_keys) { |
958 IDB_TRACE("IndexedDBDatabase::Put"); | 957 IDB_TRACE("IndexedDBDatabase::Put"); |
959 TransactionMap::const_iterator trans_iterator = | 958 TransactionMap::const_iterator trans_iterator = |
960 transactions_.find(transaction_id); | 959 transactions_.find(transaction_id); |
961 if (trans_iterator == transactions_.end()) | 960 if (trans_iterator == transactions_.end()) |
962 return; | 961 return; |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1260 transaction->BackingStoreTransaction(), | 1259 transaction->BackingStoreTransaction(), |
1261 database_id_, | 1260 database_id_, |
1262 object_store_id_, | 1261 object_store_id_, |
1263 index_id_, | 1262 index_id_, |
1264 *key_range_, | 1263 *key_range_, |
1265 direction_); | 1264 direction_); |
1266 } | 1265 } |
1267 } | 1266 } |
1268 | 1267 |
1269 if (!backing_store_cursor) { | 1268 if (!backing_store_cursor) { |
1270 callbacks_->OnSuccess(static_cast<std::vector<char>*>(NULL)); | 1269 callbacks_->OnSuccess(static_cast<std::string*>(NULL)); |
1271 return; | 1270 return; |
1272 } | 1271 } |
1273 | 1272 |
1274 IndexedDBDatabase::TaskType task_type( | 1273 IndexedDBDatabase::TaskType task_type( |
1275 static_cast<IndexedDBDatabase::TaskType>(task_type_)); | 1274 static_cast<IndexedDBDatabase::TaskType>(task_type_)); |
1276 scoped_refptr<IndexedDBCursor> cursor = IndexedDBCursor::Create( | 1275 scoped_refptr<IndexedDBCursor> cursor = IndexedDBCursor::Create( |
1277 backing_store_cursor.Pass(), cursor_type_, task_type, transaction); | 1276 backing_store_cursor.Pass(), cursor_type_, task_type, transaction); |
1278 callbacks_->OnSuccess( | 1277 callbacks_->OnSuccess( |
1279 cursor, cursor->key(), cursor->primary_key(), cursor->Value()); | 1278 cursor, cursor->key(), cursor->primary_key(), cursor->Value()); |
1280 } | 1279 } |
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1873 | 1872 |
1874 void IndexedDBDatabase::VersionChangeAbortOperation::Perform( | 1873 void IndexedDBDatabase::VersionChangeAbortOperation::Perform( |
1875 IndexedDBTransaction* transaction) { | 1874 IndexedDBTransaction* transaction) { |
1876 IDB_TRACE("VersionChangeAbortOperation"); | 1875 IDB_TRACE("VersionChangeAbortOperation"); |
1877 DCHECK(!transaction); | 1876 DCHECK(!transaction); |
1878 database_->metadata_.version = previous_version_; | 1877 database_->metadata_.version = previous_version_; |
1879 database_->metadata_.int_version = previous_int_version_; | 1878 database_->metadata_.int_version = previous_int_version_; |
1880 } | 1879 } |
1881 | 1880 |
1882 } // namespace content | 1881 } // namespace content |
OLD | NEW |