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

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

Issue 18023022: Blob support for IDB [Chromium] (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use ScopedVector and stl_utils for BlobDataHandles. Created 7 years 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_cursor.h" 5 #include "content/browser/indexed_db/indexed_db_cursor.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "content/browser/indexed_db/indexed_db_callbacks.h" 9 #include "content/browser/indexed_db/indexed_db_callbacks.h"
10 #include "content/browser/indexed_db/indexed_db_database_error.h" 10 #include "content/browser/indexed_db/indexed_db_database_error.h"
11 #include "content/browser/indexed_db/indexed_db_tracing.h" 11 #include "content/browser/indexed_db/indexed_db_tracing.h"
12 #include "content/browser/indexed_db/indexed_db_transaction.h" 12 #include "content/browser/indexed_db/indexed_db_transaction.h"
13 #include "content/browser/indexed_db/indexed_db_value.h"
13 14
14 namespace content { 15 namespace content {
15 16
16 IndexedDBCursor::IndexedDBCursor( 17 IndexedDBCursor::IndexedDBCursor(
17 scoped_ptr<IndexedDBBackingStore::Cursor> cursor, 18 scoped_ptr<IndexedDBBackingStore::Cursor> cursor,
18 indexed_db::CursorType cursor_type, 19 indexed_db::CursorType cursor_type,
19 IndexedDBDatabase::TaskType task_type, 20 IndexedDBDatabase::TaskType task_type,
20 IndexedDBTransaction* transaction) 21 IndexedDBTransaction* transaction)
21 : task_type_(task_type), 22 : task_type_(task_type),
22 cursor_type_(cursor_type), 23 cursor_type_(cursor_type),
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 &IndexedDBCursor::CursorAdvanceOperation, this, count, callbacks)); 55 &IndexedDBCursor::CursorAdvanceOperation, this, count, callbacks));
55 } 56 }
56 57
57 void IndexedDBCursor::CursorAdvanceOperation( 58 void IndexedDBCursor::CursorAdvanceOperation(
58 uint32 count, 59 uint32 count,
59 scoped_refptr<IndexedDBCallbacks> callbacks, 60 scoped_refptr<IndexedDBCallbacks> callbacks,
60 IndexedDBTransaction* /*transaction*/) { 61 IndexedDBTransaction* /*transaction*/) {
61 IDB_TRACE("IndexedDBCursor::CursorAdvanceOperation"); 62 IDB_TRACE("IndexedDBCursor::CursorAdvanceOperation");
62 if (!cursor_ || !cursor_->Advance(count)) { 63 if (!cursor_ || !cursor_->Advance(count)) {
63 cursor_.reset(); 64 cursor_.reset();
64 callbacks->OnSuccess(static_cast<std::string*>(NULL)); 65 callbacks->OnSuccess(static_cast<IndexedDBValue*>(NULL));
65 return; 66 return;
66 } 67 }
67 68
68 callbacks->OnSuccess(key(), primary_key(), Value()); 69 callbacks->OnSuccess(key(), primary_key(), Value());
69 } 70 }
70 71
71 void IndexedDBCursor::CursorIterationOperation( 72 void IndexedDBCursor::CursorIterationOperation(
72 scoped_ptr<IndexedDBKey> key, 73 scoped_ptr<IndexedDBKey> key,
73 scoped_ptr<IndexedDBKey> primary_key, 74 scoped_ptr<IndexedDBKey> primary_key,
74 scoped_refptr<IndexedDBCallbacks> callbacks, 75 scoped_refptr<IndexedDBCallbacks> callbacks,
75 IndexedDBTransaction* /*transaction*/) { 76 IndexedDBTransaction* /*transaction*/) {
76 IDB_TRACE("IndexedDBCursor::CursorIterationOperation"); 77 IDB_TRACE("IndexedDBCursor::CursorIterationOperation");
77 if (!cursor_ || 78 if (!cursor_ ||
78 !cursor_->Continue( 79 !cursor_->Continue(
79 key.get(), primary_key.get(), IndexedDBBackingStore::Cursor::SEEK)) { 80 key.get(), primary_key.get(), IndexedDBBackingStore::Cursor::SEEK)) {
80 cursor_.reset(); 81 cursor_.reset();
81 callbacks->OnSuccess(static_cast<std::string*>(NULL)); 82 callbacks->OnSuccess(static_cast<IndexedDBValue*>(NULL));
82 return; 83 return;
83 } 84 }
84 85
85 callbacks->OnSuccess(this->key(), this->primary_key(), Value()); 86 callbacks->OnSuccess(this->key(), this->primary_key(), Value());
86 } 87 }
87 88
88 void IndexedDBCursor::PrefetchContinue( 89 void IndexedDBCursor::PrefetchContinue(
89 int number_to_fetch, 90 int number_to_fetch,
90 scoped_refptr<IndexedDBCallbacks> callbacks) { 91 scoped_refptr<IndexedDBCallbacks> callbacks) {
91 IDB_TRACE("IndexedDBCursor::PrefetchContinue"); 92 IDB_TRACE("IndexedDBCursor::PrefetchContinue");
92 93
93 transaction_->ScheduleTask( 94 transaction_->ScheduleTask(
94 task_type_, 95 task_type_,
95 base::Bind(&IndexedDBCursor::CursorPrefetchIterationOperation, 96 base::Bind(&IndexedDBCursor::CursorPrefetchIterationOperation,
96 this, 97 this,
97 number_to_fetch, 98 number_to_fetch,
98 callbacks)); 99 callbacks));
99 } 100 }
100 101
101 void IndexedDBCursor::CursorPrefetchIterationOperation( 102 void IndexedDBCursor::CursorPrefetchIterationOperation(
102 int number_to_fetch, 103 int number_to_fetch,
103 scoped_refptr<IndexedDBCallbacks> callbacks, 104 scoped_refptr<IndexedDBCallbacks> callbacks,
104 IndexedDBTransaction* /*transaction*/) { 105 IndexedDBTransaction* /*transaction*/) {
105 IDB_TRACE("IndexedDBCursor::CursorPrefetchIterationOperation"); 106 IDB_TRACE("IndexedDBCursor::CursorPrefetchIterationOperation");
106 107
107 std::vector<IndexedDBKey> found_keys; 108 std::vector<IndexedDBKey> found_keys;
108 std::vector<IndexedDBKey> found_primary_keys; 109 std::vector<IndexedDBKey> found_primary_keys;
109 std::vector<std::string> found_values; 110 std::vector<IndexedDBValue> found_values;
110 111
111 if (cursor_) 112 if (cursor_)
112 saved_cursor_.reset(cursor_->Clone()); 113 saved_cursor_.reset(cursor_->Clone());
113 const size_t max_size_estimate = 10 * 1024 * 1024; 114 const size_t max_size_estimate = 10 * 1024 * 1024;
114 size_t size_estimate = 0; 115 size_t size_estimate = 0;
115 116
116 for (int i = 0; i < number_to_fetch; ++i) { 117 for (int i = 0; i < number_to_fetch; ++i) {
117 if (!cursor_ || !cursor_->Continue()) { 118 if (!cursor_ || !cursor_->Continue()) {
118 cursor_.reset(); 119 cursor_.reset();
119 break; 120 break;
120 } 121 }
121 122
122 found_keys.push_back(cursor_->key()); 123 found_keys.push_back(cursor_->key());
123 found_primary_keys.push_back(cursor_->primary_key()); 124 found_primary_keys.push_back(cursor_->primary_key());
124 125
125 switch (cursor_type_) { 126 switch (cursor_type_) {
126 case indexed_db::CURSOR_KEY_ONLY: 127 case indexed_db::CURSOR_KEY_ONLY:
127 found_values.push_back(std::string()); 128 found_values.push_back(IndexedDBValue());
128 break; 129 break;
129 case indexed_db::CURSOR_KEY_AND_VALUE: { 130 case indexed_db::CURSOR_KEY_AND_VALUE: {
130 std::string value; 131 IndexedDBValue value;
131 value.swap(*cursor_->Value()); 132 value.swap(*cursor_->Value());
132 size_estimate += value.size(); 133 size_estimate += value.bits.size();
jsbell 2013/12/18 23:04:40 We should include an estimate for the blob metadat
ericu 2013/12/19 05:19:11 Something like this? IndexedDBValue::SizeEstimate
133 found_values.push_back(value); 134 found_values.push_back(value);
134 break; 135 break;
135 } 136 }
136 default: 137 default:
137 NOTREACHED(); 138 NOTREACHED();
138 } 139 }
139 size_estimate += cursor_->key().size_estimate(); 140 size_estimate += cursor_->key().size_estimate();
140 size_estimate += cursor_->primary_key().size_estimate(); 141 size_estimate += cursor_->primary_key().size_estimate();
141 142
142 if (size_estimate > max_size_estimate) 143 if (size_estimate > max_size_estimate)
143 break; 144 break;
144 } 145 }
145 146
146 if (!found_keys.size()) { 147 if (!found_keys.size()) {
147 callbacks->OnSuccess(static_cast<std::string*>(NULL)); 148 callbacks->OnSuccess(static_cast<IndexedDBValue*>(NULL));
148 return; 149 return;
149 } 150 }
150 151
151 callbacks->OnSuccessWithPrefetch( 152 callbacks->OnSuccessWithPrefetch(
152 found_keys, found_primary_keys, found_values); 153 found_keys, found_primary_keys, found_values);
153 } 154 }
154 155
155 void IndexedDBCursor::PrefetchReset(int used_prefetches, int) { 156 void IndexedDBCursor::PrefetchReset(int used_prefetches, int) {
156 IDB_TRACE("IndexedDBCursor::PrefetchReset"); 157 IDB_TRACE("IndexedDBCursor::PrefetchReset");
157 cursor_.swap(saved_cursor_); 158 cursor_.swap(saved_cursor_);
(...skipping 10 matching lines...) Expand all
168 } 169 }
169 170
170 void IndexedDBCursor::Close() { 171 void IndexedDBCursor::Close() {
171 IDB_TRACE("IndexedDBCursor::Close"); 172 IDB_TRACE("IndexedDBCursor::Close");
172 closed_ = true; 173 closed_ = true;
173 cursor_.reset(); 174 cursor_.reset();
174 saved_cursor_.reset(); 175 saved_cursor_.reset();
175 } 176 }
176 177
177 } // namespace content 178 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698