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

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

Issue 18075008: IndexedDB: Switch key/value handling from vector<char> to std::string (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove C++11ism Created 7 years, 5 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_cursor.h" 5 #include "content/browser/indexed_db/indexed_db_cursor.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/browser/indexed_db/indexed_db_callbacks.h" 8 #include "content/browser/indexed_db/indexed_db_callbacks.h"
9 #include "content/browser/indexed_db/indexed_db_database_error.h" 9 #include "content/browser/indexed_db/indexed_db_database_error.h"
10 #include "content/browser/indexed_db/indexed_db_tracing.h" 10 #include "content/browser/indexed_db/indexed_db_tracing.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 91
92 transaction_->ScheduleTask( 92 transaction_->ScheduleTask(
93 new CursorAdvanceOperation(this, count, callbacks)); 93 new CursorAdvanceOperation(this, count, callbacks));
94 } 94 }
95 95
96 void IndexedDBCursor::CursorAdvanceOperation::Perform( 96 void IndexedDBCursor::CursorAdvanceOperation::Perform(
97 IndexedDBTransaction* /*transaction*/) { 97 IndexedDBTransaction* /*transaction*/) {
98 IDB_TRACE("CursorAdvanceOperation"); 98 IDB_TRACE("CursorAdvanceOperation");
99 if (!cursor_->cursor_ || !cursor_->cursor_->Advance(count_)) { 99 if (!cursor_->cursor_ || !cursor_->cursor_->Advance(count_)) {
100 cursor_->cursor_.reset(); 100 cursor_->cursor_.reset();
101 callbacks_->OnSuccess(static_cast<std::vector<char>*>(NULL)); 101 callbacks_->OnSuccess(static_cast<std::string*>(NULL));
102 return; 102 return;
103 } 103 }
104 104
105 callbacks_->OnSuccess( 105 callbacks_->OnSuccess(
106 cursor_->key(), cursor_->primary_key(), cursor_->Value()); 106 cursor_->key(), cursor_->primary_key(), cursor_->Value());
107 } 107 }
108 108
109 void IndexedDBCursor::CursorIterationOperation::Perform( 109 void IndexedDBCursor::CursorIterationOperation::Perform(
110 IndexedDBTransaction* /*transaction*/) { 110 IndexedDBTransaction* /*transaction*/) {
111 IDB_TRACE("CursorIterationOperation"); 111 IDB_TRACE("CursorIterationOperation");
112 if (!cursor_->cursor_ || 112 if (!cursor_->cursor_ ||
113 !cursor_->cursor_->ContinueFunction( 113 !cursor_->cursor_->ContinueFunction(
114 key_.get(), IndexedDBBackingStore::Cursor::SEEK)) { 114 key_.get(), IndexedDBBackingStore::Cursor::SEEK)) {
115 cursor_->cursor_.reset(); 115 cursor_->cursor_.reset();
116 callbacks_->OnSuccess(static_cast<std::vector<char>*>(NULL)); 116 callbacks_->OnSuccess(static_cast<std::string*>(NULL));
117 return; 117 return;
118 } 118 }
119 119
120 callbacks_->OnSuccess( 120 callbacks_->OnSuccess(
121 cursor_->key(), cursor_->primary_key(), cursor_->Value()); 121 cursor_->key(), cursor_->primary_key(), cursor_->Value());
122 } 122 }
123 123
124 void IndexedDBCursor::PrefetchContinue( 124 void IndexedDBCursor::PrefetchContinue(
125 int number_to_fetch, 125 int number_to_fetch,
126 scoped_refptr<IndexedDBCallbacks> callbacks) { 126 scoped_refptr<IndexedDBCallbacks> callbacks) {
127 IDB_TRACE("IndexedDBCursor::PrefetchContinue"); 127 IDB_TRACE("IndexedDBCursor::PrefetchContinue");
128 128
129 transaction_->ScheduleTask( 129 transaction_->ScheduleTask(
130 task_type_, 130 task_type_,
131 new CursorPrefetchIterationOperation(this, number_to_fetch, callbacks)); 131 new CursorPrefetchIterationOperation(this, number_to_fetch, callbacks));
132 } 132 }
133 133
134 void IndexedDBCursor::CursorPrefetchIterationOperation::Perform( 134 void IndexedDBCursor::CursorPrefetchIterationOperation::Perform(
135 IndexedDBTransaction* /*transaction*/) { 135 IndexedDBTransaction* /*transaction*/) {
136 IDB_TRACE("CursorPrefetchIterationOperation"); 136 IDB_TRACE("CursorPrefetchIterationOperation");
137 137
138 std::vector<IndexedDBKey> found_keys; 138 std::vector<IndexedDBKey> found_keys;
139 std::vector<IndexedDBKey> found_primary_keys; 139 std::vector<IndexedDBKey> found_primary_keys;
140 std::vector<std::vector<char> > found_values; 140 std::vector<std::string> found_values;
141 141
142 if (cursor_->cursor_) 142 if (cursor_->cursor_)
143 cursor_->saved_cursor_.reset(cursor_->cursor_->Clone()); 143 cursor_->saved_cursor_.reset(cursor_->cursor_->Clone());
144 const size_t max_size_estimate = 10 * 1024 * 1024; 144 const size_t max_size_estimate = 10 * 1024 * 1024;
145 size_t size_estimate = 0; 145 size_t size_estimate = 0;
146 146
147 for (int i = 0; i < number_to_fetch_; ++i) { 147 for (int i = 0; i < number_to_fetch_; ++i) {
148 if (!cursor_->cursor_ || !cursor_->cursor_->ContinueFunction()) { 148 if (!cursor_->cursor_ || !cursor_->cursor_->ContinueFunction()) {
149 cursor_->cursor_.reset(); 149 cursor_->cursor_.reset();
150 break; 150 break;
151 } 151 }
152 152
153 found_keys.push_back(cursor_->cursor_->key()); 153 found_keys.push_back(cursor_->cursor_->key());
154 found_primary_keys.push_back(cursor_->cursor_->primary_key()); 154 found_primary_keys.push_back(cursor_->cursor_->primary_key());
155 155
156 switch (cursor_->cursor_type_) { 156 switch (cursor_->cursor_type_) {
157 case indexed_db::CURSOR_KEY_ONLY: 157 case indexed_db::CURSOR_KEY_ONLY:
158 found_values.push_back(std::vector<char>()); 158 found_values.push_back(std::string());
159 break; 159 break;
160 case indexed_db::CURSOR_KEY_AND_VALUE: { 160 case indexed_db::CURSOR_KEY_AND_VALUE: {
161 std::vector<char> value; 161 std::string value;
162 value.swap(*cursor_->cursor_->Value()); 162 value.swap(*cursor_->cursor_->Value());
163 size_estimate += value.size(); 163 size_estimate += value.size();
164 found_values.push_back(value); 164 found_values.push_back(value);
165 break; 165 break;
166 } 166 }
167 default: 167 default:
168 NOTREACHED(); 168 NOTREACHED();
169 } 169 }
170 size_estimate += cursor_->cursor_->key().size_estimate(); 170 size_estimate += cursor_->cursor_->key().size_estimate();
171 size_estimate += cursor_->cursor_->primary_key().size_estimate(); 171 size_estimate += cursor_->cursor_->primary_key().size_estimate();
172 172
173 if (size_estimate > max_size_estimate) 173 if (size_estimate > max_size_estimate)
174 break; 174 break;
175 } 175 }
176 176
177 if (!found_keys.size()) { 177 if (!found_keys.size()) {
178 callbacks_->OnSuccess(static_cast<std::vector<char>*>(NULL)); 178 callbacks_->OnSuccess(static_cast<std::string*>(NULL));
179 return; 179 return;
180 } 180 }
181 181
182 callbacks_->OnSuccessWithPrefetch( 182 callbacks_->OnSuccessWithPrefetch(
183 found_keys, found_primary_keys, found_values); 183 found_keys, found_primary_keys, found_values);
184 } 184 }
185 185
186 void IndexedDBCursor::PrefetchReset(int used_prefetches, int) { 186 void IndexedDBCursor::PrefetchReset(int used_prefetches, int) {
187 IDB_TRACE("IndexedDBCursor::PrefetchReset"); 187 IDB_TRACE("IndexedDBCursor::PrefetchReset");
188 cursor_.swap(saved_cursor_); 188 cursor_.swap(saved_cursor_);
(...skipping 10 matching lines...) Expand all
199 } 199 }
200 200
201 void IndexedDBCursor::Close() { 201 void IndexedDBCursor::Close() {
202 IDB_TRACE("IndexedDBCursor::Close"); 202 IDB_TRACE("IndexedDBCursor::Close");
203 closed_ = true; 203 closed_ = true;
204 cursor_.reset(); 204 cursor_.reset();
205 saved_cursor_.reset(); 205 saved_cursor_.reset();
206 } 206 }
207 207
208 } // namespace content 208 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_cursor.h ('k') | content/browser/indexed_db/indexed_db_database.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698