Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(521)

Side by Side Diff: content/browser/indexed_db/indexed_db_database.cc

Issue 232343004: Pass blob info through from the IPC to the backing store on put. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix some nits Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 DCHECK(pending_open_calls_.empty()); 188 DCHECK(pending_open_calls_.empty());
186 DCHECK(pending_delete_calls_.empty()); 189 DCHECK(pending_delete_calls_.empty());
187 } 190 }
188 191
189 scoped_ptr<IndexedDBConnection> IndexedDBDatabase::CreateConnection( 192 scoped_ptr<IndexedDBConnection> IndexedDBDatabase::CreateConnection(
190 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, 193 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks,
191 int child_process_id) { 194 int child_process_id) {
192 scoped_ptr<IndexedDBConnection> connection( 195 scoped_ptr<IndexedDBConnection> connection(
193 new IndexedDBConnection(this, database_callbacks)); 196 new IndexedDBConnection(this, database_callbacks));
194 connections_.insert(connection.get()); 197 connections_.insert(connection.get());
195 /* TODO(ericu): Grant child process permissions here so that the connection 198 backing_store_->GrantChildProcessPermissions(child_process_id);
196 * can create Blobs.
197 */
198 return connection.Pass(); 199 return connection.Pass();
199 } 200 }
200 201
201 IndexedDBTransaction* IndexedDBDatabase::GetTransaction( 202 IndexedDBTransaction* IndexedDBDatabase::GetTransaction(
202 int64 transaction_id) const { 203 int64 transaction_id) const {
203 TransactionMap::const_iterator trans_iterator = 204 TransactionMap::const_iterator trans_iterator =
204 transactions_.find(transaction_id); 205 transactions_.find(transaction_id);
205 if (trans_iterator == transactions_.end()) 206 if (trans_iterator == transactions_.end())
206 return NULL; 207 return NULL;
207 return trans_iterator->second; 208 return trans_iterator->second;
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 database_id, 696 database_id,
696 object_store_id, 697 object_store_id,
697 static_cast<int64>(floor(key.number())) + 1, 698 static_cast<int64>(floor(key.number())) + 1,
698 check_current); 699 check_current);
699 } 700 }
700 701
701 struct IndexedDBDatabase::PutOperationParams { 702 struct IndexedDBDatabase::PutOperationParams {
702 PutOperationParams() {} 703 PutOperationParams() {}
703 int64 object_store_id; 704 int64 object_store_id;
704 IndexedDBValue value; 705 IndexedDBValue value;
706 ScopedVector<webkit_blob::BlobDataHandle> handles;
705 scoped_ptr<IndexedDBKey> key; 707 scoped_ptr<IndexedDBKey> key;
706 IndexedDBDatabase::PutMode put_mode; 708 IndexedDBDatabase::PutMode put_mode;
707 scoped_refptr<IndexedDBCallbacks> callbacks; 709 scoped_refptr<IndexedDBCallbacks> callbacks;
708 std::vector<IndexKeys> index_keys; 710 std::vector<IndexKeys> index_keys;
709 711
710 private: 712 private:
711 DISALLOW_COPY_AND_ASSIGN(PutOperationParams); 713 DISALLOW_COPY_AND_ASSIGN(PutOperationParams);
712 }; 714 };
713 715
714 void IndexedDBDatabase::Put(int64 transaction_id, 716 void IndexedDBDatabase::Put(int64 transaction_id,
715 int64 object_store_id, 717 int64 object_store_id,
716 IndexedDBValue* value, 718 IndexedDBValue* value,
719 ScopedVector<webkit_blob::BlobDataHandle>* handles,
717 scoped_ptr<IndexedDBKey> key, 720 scoped_ptr<IndexedDBKey> key,
718 PutMode put_mode, 721 PutMode put_mode,
719 scoped_refptr<IndexedDBCallbacks> callbacks, 722 scoped_refptr<IndexedDBCallbacks> callbacks,
720 const std::vector<IndexKeys>& index_keys) { 723 const std::vector<IndexKeys>& index_keys) {
721 IDB_TRACE("IndexedDBDatabase::Put"); 724 IDB_TRACE("IndexedDBDatabase::Put");
722 IndexedDBTransaction* transaction = GetTransaction(transaction_id); 725 IndexedDBTransaction* transaction = GetTransaction(transaction_id);
723 if (!transaction) 726 if (!transaction)
724 return; 727 return;
725 DCHECK_NE(transaction->mode(), indexed_db::TRANSACTION_READ_ONLY); 728 DCHECK_NE(transaction->mode(), indexed_db::TRANSACTION_READ_ONLY);
726 729
727 if (!ValidateObjectStoreId(object_store_id)) 730 if (!ValidateObjectStoreId(object_store_id))
728 return; 731 return;
729 732
730 DCHECK(key); 733 DCHECK(key);
734 DCHECK(value);
731 scoped_ptr<PutOperationParams> params(new PutOperationParams()); 735 scoped_ptr<PutOperationParams> params(new PutOperationParams());
732 params->object_store_id = object_store_id; 736 params->object_store_id = object_store_id;
733 params->value.swap(*value); 737 params->value.swap(*value);
738 params->handles.swap(*handles);
734 params->key = key.Pass(); 739 params->key = key.Pass();
735 params->put_mode = put_mode; 740 params->put_mode = put_mode;
736 params->callbacks = callbacks; 741 params->callbacks = callbacks;
737 params->index_keys = index_keys; 742 params->index_keys = index_keys;
738 transaction->ScheduleTask(base::Bind( 743 transaction->ScheduleTask(base::Bind(
739 &IndexedDBDatabase::PutOperation, this, base::Passed(&params))); 744 &IndexedDBDatabase::PutOperation, this, base::Passed(&params)));
740 } 745 }
741 746
742 void IndexedDBDatabase::PutOperation(scoped_ptr<PutOperationParams> params, 747 void IndexedDBDatabase::PutOperation(scoped_ptr<PutOperationParams> params,
743 IndexedDBTransaction* transaction) { 748 IndexedDBTransaction* transaction) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 } 828 }
824 829
825 // Before this point, don't do any mutation. After this point, rollback the 830 // Before this point, don't do any mutation. After this point, rollback the
826 // transaction in case of error. 831 // transaction in case of error.
827 leveldb::Status s = 832 leveldb::Status s =
828 backing_store_->PutRecord(transaction->BackingStoreTransaction(), 833 backing_store_->PutRecord(transaction->BackingStoreTransaction(),
829 id(), 834 id(),
830 params->object_store_id, 835 params->object_store_id,
831 *key, 836 *key,
832 params->value, 837 params->value,
838 &params->handles,
833 &record_identifier); 839 &record_identifier);
834 if (!s.ok()) { 840 if (!s.ok()) {
835 IndexedDBDatabaseError error( 841 IndexedDBDatabaseError error(
836 blink::WebIDBDatabaseExceptionUnknownError, 842 blink::WebIDBDatabaseExceptionUnknownError,
837 "Internal error: backing store error performing put/add."); 843 "Internal error: backing store error performing put/add.");
838 params->callbacks->OnError(error); 844 params->callbacks->OnError(error);
839 if (s.IsCorruption()) 845 if (s.IsCorruption())
840 factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), 846 factory_->HandleBackingStoreCorruption(backing_store_->origin_url(),
841 error); 847 error);
842 return; 848 return;
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after
1692 const base::string16& previous_version, 1698 const base::string16& previous_version,
1693 int64 previous_int_version, 1699 int64 previous_int_version,
1694 IndexedDBTransaction* transaction) { 1700 IndexedDBTransaction* transaction) {
1695 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); 1701 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation");
1696 DCHECK(!transaction); 1702 DCHECK(!transaction);
1697 metadata_.version = previous_version; 1703 metadata_.version = previous_version;
1698 metadata_.int_version = previous_int_version; 1704 metadata_.int_version = previous_int_version;
1699 } 1705 }
1700 1706
1701 } // namespace content 1707 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698