OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/mock_browsertest_indexed_db_class_factory.h
" |
| 6 |
5 #include <stddef.h> | 7 #include <stddef.h> |
6 | |
7 #include <string> | 8 #include <string> |
| 9 #include <utility> |
8 | 10 |
9 #include "base/logging.h" | 11 #include "base/logging.h" |
10 #include "content/browser/indexed_db/indexed_db_transaction.h" | 12 #include "content/browser/indexed_db/indexed_db_transaction.h" |
11 #include "content/browser/indexed_db/leveldb/leveldb_iterator_impl.h" | 13 #include "content/browser/indexed_db/leveldb/leveldb_iterator_impl.h" |
12 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h" | 14 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h" |
13 #include "content/browser/indexed_db/mock_browsertest_indexed_db_class_factory.h
" | |
14 #include "third_party/leveldatabase/env_chromium.h" | 15 #include "third_party/leveldatabase/env_chromium.h" |
15 #include "third_party/leveldatabase/src/include/leveldb/status.h" | 16 #include "third_party/leveldatabase/src/include/leveldb/status.h" |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 class FunctionTracer { | 20 class FunctionTracer { |
20 public: | 21 public: |
21 FunctionTracer(const std::string& class_name, | 22 FunctionTracer(const std::string& class_name, |
22 const std::string& method_name, | 23 const std::string& method_name, |
23 int instance_num) | 24 int instance_num) |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 | 160 |
160 FunctionTracer commit_tracer_; | 161 FunctionTracer commit_tracer_; |
161 FunctionTracer get_tracer_; | 162 FunctionTracer get_tracer_; |
162 }; | 163 }; |
163 | 164 |
164 const std::string LevelDBTraceTransaction::s_class_name = "LevelDBTransaction"; | 165 const std::string LevelDBTraceTransaction::s_class_name = "LevelDBTransaction"; |
165 | 166 |
166 class LevelDBTraceIteratorImpl : public LevelDBIteratorImpl { | 167 class LevelDBTraceIteratorImpl : public LevelDBIteratorImpl { |
167 public: | 168 public: |
168 LevelDBTraceIteratorImpl(scoped_ptr<leveldb::Iterator> iterator, int inst_num) | 169 LevelDBTraceIteratorImpl(scoped_ptr<leveldb::Iterator> iterator, int inst_num) |
169 : LevelDBIteratorImpl(iterator.Pass()), | 170 : LevelDBIteratorImpl(std::move(iterator)), |
170 is_valid_tracer_(s_class_name, "IsValid", inst_num), | 171 is_valid_tracer_(s_class_name, "IsValid", inst_num), |
171 seek_to_last_tracer_(s_class_name, "SeekToLast", inst_num), | 172 seek_to_last_tracer_(s_class_name, "SeekToLast", inst_num), |
172 seek_tracer_(s_class_name, "Seek", inst_num), | 173 seek_tracer_(s_class_name, "Seek", inst_num), |
173 next_tracer_(s_class_name, "Next", inst_num), | 174 next_tracer_(s_class_name, "Next", inst_num), |
174 prev_tracer_(s_class_name, "Prev", inst_num), | 175 prev_tracer_(s_class_name, "Prev", inst_num), |
175 key_tracer_(s_class_name, "Key", inst_num), | 176 key_tracer_(s_class_name, "Key", inst_num), |
176 value_tracer_(s_class_name, "Value", inst_num) {} | 177 value_tracer_(s_class_name, "Value", inst_num) {} |
177 ~LevelDBTraceIteratorImpl() override {} | 178 ~LevelDBTraceIteratorImpl() override {} |
178 | 179 |
179 private: | 180 private: |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 mutable FunctionTracer value_tracer_; | 218 mutable FunctionTracer value_tracer_; |
218 }; | 219 }; |
219 | 220 |
220 const std::string LevelDBTraceIteratorImpl::s_class_name = "LevelDBIterator"; | 221 const std::string LevelDBTraceIteratorImpl::s_class_name = "LevelDBIterator"; |
221 | 222 |
222 class LevelDBTestIteratorImpl : public content::LevelDBIteratorImpl { | 223 class LevelDBTestIteratorImpl : public content::LevelDBIteratorImpl { |
223 public: | 224 public: |
224 LevelDBTestIteratorImpl(scoped_ptr<leveldb::Iterator> iterator, | 225 LevelDBTestIteratorImpl(scoped_ptr<leveldb::Iterator> iterator, |
225 FailMethod fail_method, | 226 FailMethod fail_method, |
226 int fail_on_call_num) | 227 int fail_on_call_num) |
227 : LevelDBIteratorImpl(iterator.Pass()), | 228 : LevelDBIteratorImpl(std::move(iterator)), |
228 fail_method_(fail_method), | 229 fail_method_(fail_method), |
229 fail_on_call_num_(fail_on_call_num), | 230 fail_on_call_num_(fail_on_call_num), |
230 current_call_num_(0) {} | 231 current_call_num_(0) {} |
231 ~LevelDBTestIteratorImpl() override {} | 232 ~LevelDBTestIteratorImpl() override {} |
232 | 233 |
233 private: | 234 private: |
234 leveldb::Status Seek(const base::StringPiece& target) override { | 235 leveldb::Status Seek(const base::StringPiece& target) override { |
235 if (fail_method_ != FAIL_METHOD_SEEK || | 236 if (fail_method_ != FAIL_METHOD_SEEK || |
236 ++current_call_num_ != fail_on_call_num_) | 237 ++current_call_num_ != fail_on_call_num_) |
237 return LevelDBIteratorImpl::Seek(target); | 238 return LevelDBIteratorImpl::Seek(target); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 } | 296 } |
296 } | 297 } |
297 } | 298 } |
298 | 299 |
299 LevelDBIteratorImpl* MockBrowserTestIndexedDBClassFactory::CreateIteratorImpl( | 300 LevelDBIteratorImpl* MockBrowserTestIndexedDBClassFactory::CreateIteratorImpl( |
300 scoped_ptr<leveldb::Iterator> iterator) { | 301 scoped_ptr<leveldb::Iterator> iterator) { |
301 instance_count_[FAIL_CLASS_LEVELDB_ITERATOR] = | 302 instance_count_[FAIL_CLASS_LEVELDB_ITERATOR] = |
302 instance_count_[FAIL_CLASS_LEVELDB_ITERATOR] + 1; | 303 instance_count_[FAIL_CLASS_LEVELDB_ITERATOR] + 1; |
303 if (only_trace_calls_) { | 304 if (only_trace_calls_) { |
304 return new LevelDBTraceIteratorImpl( | 305 return new LevelDBTraceIteratorImpl( |
305 iterator.Pass(), instance_count_[FAIL_CLASS_LEVELDB_ITERATOR]); | 306 std::move(iterator), instance_count_[FAIL_CLASS_LEVELDB_ITERATOR]); |
306 } else { | 307 } else { |
307 if (failure_class_ == FAIL_CLASS_LEVELDB_ITERATOR && | 308 if (failure_class_ == FAIL_CLASS_LEVELDB_ITERATOR && |
308 instance_count_[FAIL_CLASS_LEVELDB_ITERATOR] == | 309 instance_count_[FAIL_CLASS_LEVELDB_ITERATOR] == |
309 fail_on_instance_num_[FAIL_CLASS_LEVELDB_ITERATOR]) { | 310 fail_on_instance_num_[FAIL_CLASS_LEVELDB_ITERATOR]) { |
310 return new LevelDBTestIteratorImpl( | 311 return new LevelDBTestIteratorImpl( |
311 iterator.Pass(), | 312 std::move(iterator), failure_method_, |
312 failure_method_, | |
313 fail_on_call_num_[FAIL_CLASS_LEVELDB_ITERATOR]); | 313 fail_on_call_num_[FAIL_CLASS_LEVELDB_ITERATOR]); |
314 } else { | 314 } else { |
315 return new LevelDBIteratorImpl(iterator.Pass()); | 315 return new LevelDBIteratorImpl(std::move(iterator)); |
316 } | 316 } |
317 } | 317 } |
318 } | 318 } |
319 | 319 |
320 void MockBrowserTestIndexedDBClassFactory::FailOperation( | 320 void MockBrowserTestIndexedDBClassFactory::FailOperation( |
321 FailClass failure_class, | 321 FailClass failure_class, |
322 FailMethod failure_method, | 322 FailMethod failure_method, |
323 int fail_on_instance_num, | 323 int fail_on_instance_num, |
324 int fail_on_call_num) { | 324 int fail_on_call_num) { |
325 VLOG(0) << "FailOperation: class=" << failure_class | 325 VLOG(0) << "FailOperation: class=" << failure_class |
(...skipping 11 matching lines...) Expand all Loading... |
337 | 337 |
338 void MockBrowserTestIndexedDBClassFactory::Reset() { | 338 void MockBrowserTestIndexedDBClassFactory::Reset() { |
339 failure_class_ = FAIL_CLASS_NOTHING; | 339 failure_class_ = FAIL_CLASS_NOTHING; |
340 failure_method_ = FAIL_METHOD_NOTHING; | 340 failure_method_ = FAIL_METHOD_NOTHING; |
341 instance_count_.clear(); | 341 instance_count_.clear(); |
342 fail_on_instance_num_.clear(); | 342 fail_on_instance_num_.clear(); |
343 fail_on_call_num_.clear(); | 343 fail_on_call_num_.clear(); |
344 } | 344 } |
345 | 345 |
346 } // namespace content | 346 } // namespace content |
OLD | NEW |