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 <set> | 8 #include <set> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/scoped_vector.h" |
13 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "content/browser/indexed_db/indexed_db_blob_info.h" |
16 #include "content/browser/indexed_db/indexed_db_connection.h" | 18 #include "content/browser/indexed_db/indexed_db_connection.h" |
17 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 19 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
18 #include "content/browser/indexed_db/indexed_db_cursor.h" | 20 #include "content/browser/indexed_db/indexed_db_cursor.h" |
19 #include "content/browser/indexed_db/indexed_db_factory.h" | 21 #include "content/browser/indexed_db/indexed_db_factory.h" |
20 #include "content/browser/indexed_db/indexed_db_index_writer.h" | 22 #include "content/browser/indexed_db/indexed_db_index_writer.h" |
21 #include "content/browser/indexed_db/indexed_db_pending_connection.h" | 23 #include "content/browser/indexed_db/indexed_db_pending_connection.h" |
22 #include "content/browser/indexed_db/indexed_db_tracing.h" | 24 #include "content/browser/indexed_db/indexed_db_tracing.h" |
23 #include "content/browser/indexed_db/indexed_db_transaction.h" | 25 #include "content/browser/indexed_db/indexed_db_transaction.h" |
24 #include "content/browser/indexed_db/indexed_db_value.h" | 26 #include "content/browser/indexed_db/indexed_db_value.h" |
25 #include "content/common/indexed_db/indexed_db_key_path.h" | 27 #include "content/common/indexed_db/indexed_db_key_path.h" |
26 #include "content/common/indexed_db/indexed_db_key_range.h" | 28 #include "content/common/indexed_db/indexed_db_key_range.h" |
27 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" | 29 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" |
| 30 #include "webkit/browser/blob/blob_data_handle.h" |
28 | 31 |
29 using base::ASCIIToUTF16; | 32 using base::ASCIIToUTF16; |
30 using base::Int64ToString16; | 33 using base::Int64ToString16; |
31 using blink::WebIDBKeyTypeNumber; | 34 using blink::WebIDBKeyTypeNumber; |
32 | 35 |
33 namespace content { | 36 namespace content { |
34 | 37 |
35 // PendingUpgradeCall has a scoped_ptr<IndexedDBConnection> because it owns the | 38 // PendingUpgradeCall has a scoped_ptr<IndexedDBConnection> because it owns the |
36 // in-progress connection. | 39 // in-progress connection. |
37 class IndexedDBDatabase::PendingUpgradeCall { | 40 class IndexedDBDatabase::PendingUpgradeCall { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 DCHECK(pending_open_calls_.empty()); | 191 DCHECK(pending_open_calls_.empty()); |
189 DCHECK(pending_delete_calls_.empty()); | 192 DCHECK(pending_delete_calls_.empty()); |
190 } | 193 } |
191 | 194 |
192 scoped_ptr<IndexedDBConnection> IndexedDBDatabase::CreateConnection( | 195 scoped_ptr<IndexedDBConnection> IndexedDBDatabase::CreateConnection( |
193 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, | 196 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, |
194 int child_process_id) { | 197 int child_process_id) { |
195 scoped_ptr<IndexedDBConnection> connection( | 198 scoped_ptr<IndexedDBConnection> connection( |
196 new IndexedDBConnection(this, database_callbacks)); | 199 new IndexedDBConnection(this, database_callbacks)); |
197 connections_.insert(connection.get()); | 200 connections_.insert(connection.get()); |
198 /* TODO(ericu): Grant child process permissions here so that the connection | 201 backing_store_->GrantChildProcessPermissions(child_process_id); |
199 * can create Blobs. | |
200 */ | |
201 return connection.Pass(); | 202 return connection.Pass(); |
202 } | 203 } |
203 | 204 |
204 IndexedDBTransaction* IndexedDBDatabase::GetTransaction( | 205 IndexedDBTransaction* IndexedDBDatabase::GetTransaction( |
205 int64 transaction_id) const { | 206 int64 transaction_id) const { |
206 TransactionMap::const_iterator trans_iterator = | 207 TransactionMap::const_iterator trans_iterator = |
207 transactions_.find(transaction_id); | 208 transactions_.find(transaction_id); |
208 if (trans_iterator == transactions_.end()) | 209 if (trans_iterator == transactions_.end()) |
209 return NULL; | 210 return NULL; |
210 return trans_iterator->second; | 211 return trans_iterator->second; |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 database_id, | 712 database_id, |
712 object_store_id, | 713 object_store_id, |
713 static_cast<int64>(floor(key.number())) + 1, | 714 static_cast<int64>(floor(key.number())) + 1, |
714 check_current); | 715 check_current); |
715 } | 716 } |
716 | 717 |
717 struct IndexedDBDatabase::PutOperationParams { | 718 struct IndexedDBDatabase::PutOperationParams { |
718 PutOperationParams() {} | 719 PutOperationParams() {} |
719 int64 object_store_id; | 720 int64 object_store_id; |
720 IndexedDBValue value; | 721 IndexedDBValue value; |
| 722 ScopedVector<webkit_blob::BlobDataHandle> handles; |
721 scoped_ptr<IndexedDBKey> key; | 723 scoped_ptr<IndexedDBKey> key; |
722 IndexedDBDatabase::PutMode put_mode; | 724 IndexedDBDatabase::PutMode put_mode; |
723 scoped_refptr<IndexedDBCallbacks> callbacks; | 725 scoped_refptr<IndexedDBCallbacks> callbacks; |
724 std::vector<IndexKeys> index_keys; | 726 std::vector<IndexKeys> index_keys; |
725 | 727 |
726 private: | 728 private: |
727 DISALLOW_COPY_AND_ASSIGN(PutOperationParams); | 729 DISALLOW_COPY_AND_ASSIGN(PutOperationParams); |
728 }; | 730 }; |
729 | 731 |
730 void IndexedDBDatabase::Put(int64 transaction_id, | 732 void IndexedDBDatabase::Put(int64 transaction_id, |
731 int64 object_store_id, | 733 int64 object_store_id, |
732 IndexedDBValue* value, | 734 IndexedDBValue* value, |
| 735 ScopedVector<webkit_blob::BlobDataHandle>* handles, |
733 scoped_ptr<IndexedDBKey> key, | 736 scoped_ptr<IndexedDBKey> key, |
734 PutMode put_mode, | 737 PutMode put_mode, |
735 scoped_refptr<IndexedDBCallbacks> callbacks, | 738 scoped_refptr<IndexedDBCallbacks> callbacks, |
736 const std::vector<IndexKeys>& index_keys) { | 739 const std::vector<IndexKeys>& index_keys) { |
737 IDB_TRACE("IndexedDBDatabase::Put"); | 740 IDB_TRACE("IndexedDBDatabase::Put"); |
738 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 741 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
739 if (!transaction) | 742 if (!transaction) |
740 return; | 743 return; |
741 DCHECK_NE(transaction->mode(), indexed_db::TRANSACTION_READ_ONLY); | 744 DCHECK_NE(transaction->mode(), indexed_db::TRANSACTION_READ_ONLY); |
742 | 745 |
743 if (!ValidateObjectStoreId(object_store_id)) | 746 if (!ValidateObjectStoreId(object_store_id)) |
744 return; | 747 return; |
745 | 748 |
746 DCHECK(key); | 749 DCHECK(key); |
| 750 DCHECK(value); |
747 scoped_ptr<PutOperationParams> params(new PutOperationParams()); | 751 scoped_ptr<PutOperationParams> params(new PutOperationParams()); |
748 params->object_store_id = object_store_id; | 752 params->object_store_id = object_store_id; |
749 params->value.swap(*value); | 753 params->value.swap(*value); |
| 754 params->handles.swap(*handles); |
750 params->key = key.Pass(); | 755 params->key = key.Pass(); |
751 params->put_mode = put_mode; | 756 params->put_mode = put_mode; |
752 params->callbacks = callbacks; | 757 params->callbacks = callbacks; |
753 params->index_keys = index_keys; | 758 params->index_keys = index_keys; |
754 transaction->ScheduleTask(base::Bind( | 759 transaction->ScheduleTask(base::Bind( |
755 &IndexedDBDatabase::PutOperation, this, base::Passed(¶ms))); | 760 &IndexedDBDatabase::PutOperation, this, base::Passed(¶ms))); |
756 } | 761 } |
757 | 762 |
758 void IndexedDBDatabase::PutOperation(scoped_ptr<PutOperationParams> params, | 763 void IndexedDBDatabase::PutOperation(scoped_ptr<PutOperationParams> params, |
759 IndexedDBTransaction* transaction) { | 764 IndexedDBTransaction* transaction) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 } | 844 } |
840 | 845 |
841 // Before this point, don't do any mutation. After this point, rollback the | 846 // Before this point, don't do any mutation. After this point, rollback the |
842 // transaction in case of error. | 847 // transaction in case of error. |
843 leveldb::Status s = | 848 leveldb::Status s = |
844 backing_store_->PutRecord(transaction->BackingStoreTransaction(), | 849 backing_store_->PutRecord(transaction->BackingStoreTransaction(), |
845 id(), | 850 id(), |
846 params->object_store_id, | 851 params->object_store_id, |
847 *key, | 852 *key, |
848 params->value, | 853 params->value, |
| 854 ¶ms->handles, |
849 &record_identifier); | 855 &record_identifier); |
850 if (!s.ok()) { | 856 if (!s.ok()) { |
851 IndexedDBDatabaseError error( | 857 IndexedDBDatabaseError error( |
852 blink::WebIDBDatabaseExceptionUnknownError, | 858 blink::WebIDBDatabaseExceptionUnknownError, |
853 "Internal error: backing store error performing put/add."); | 859 "Internal error: backing store error performing put/add."); |
854 params->callbacks->OnError(error); | 860 params->callbacks->OnError(error); |
855 if (s.IsCorruption()) | 861 if (s.IsCorruption()) |
856 factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), | 862 factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), |
857 error); | 863 error); |
858 return; | 864 return; |
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1752 const base::string16& previous_version, | 1758 const base::string16& previous_version, |
1753 int64 previous_int_version, | 1759 int64 previous_int_version, |
1754 IndexedDBTransaction* transaction) { | 1760 IndexedDBTransaction* transaction) { |
1755 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); | 1761 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); |
1756 DCHECK(!transaction); | 1762 DCHECK(!transaction); |
1757 metadata_.version = previous_version; | 1763 metadata_.version = previous_version; |
1758 metadata_.int_version = previous_int_version; | 1764 metadata_.int_version = previous_int_version; |
1759 } | 1765 } |
1760 | 1766 |
1761 } // namespace content | 1767 } // namespace content |
OLD | NEW |