| 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
" | 5 #include "content/browser/indexed_db/mock_browsertest_indexed_db_class_factory.h
" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 160 |
| 161 FunctionTracer commit_tracer_; | 161 FunctionTracer commit_tracer_; |
| 162 FunctionTracer get_tracer_; | 162 FunctionTracer get_tracer_; |
| 163 }; | 163 }; |
| 164 | 164 |
| 165 const std::string LevelDBTraceTransaction::s_class_name = "LevelDBTransaction"; | 165 const std::string LevelDBTraceTransaction::s_class_name = "LevelDBTransaction"; |
| 166 | 166 |
| 167 class LevelDBTraceIteratorImpl : public LevelDBIteratorImpl { | 167 class LevelDBTraceIteratorImpl : public LevelDBIteratorImpl { |
| 168 public: | 168 public: |
| 169 LevelDBTraceIteratorImpl(std::unique_ptr<leveldb::Iterator> iterator, | 169 LevelDBTraceIteratorImpl(std::unique_ptr<leveldb::Iterator> iterator, |
| 170 LevelDBDatabase* db, |
| 171 const leveldb::Snapshot* snapshot, |
| 170 int inst_num) | 172 int inst_num) |
| 171 : LevelDBIteratorImpl(std::move(iterator)), | 173 : LevelDBIteratorImpl(std::move(iterator), db, snapshot), |
| 172 is_valid_tracer_(s_class_name, "IsValid", inst_num), | 174 is_valid_tracer_(s_class_name, "IsValid", inst_num), |
| 173 seek_to_last_tracer_(s_class_name, "SeekToLast", inst_num), | 175 seek_to_last_tracer_(s_class_name, "SeekToLast", inst_num), |
| 174 seek_tracer_(s_class_name, "Seek", inst_num), | 176 seek_tracer_(s_class_name, "Seek", inst_num), |
| 175 next_tracer_(s_class_name, "Next", inst_num), | 177 next_tracer_(s_class_name, "Next", inst_num), |
| 176 prev_tracer_(s_class_name, "Prev", inst_num), | 178 prev_tracer_(s_class_name, "Prev", inst_num), |
| 177 key_tracer_(s_class_name, "Key", inst_num), | 179 key_tracer_(s_class_name, "Key", inst_num), |
| 178 value_tracer_(s_class_name, "Value", inst_num) {} | 180 value_tracer_(s_class_name, "Value", inst_num) {} |
| 179 ~LevelDBTraceIteratorImpl() override {} | 181 ~LevelDBTraceIteratorImpl() override {} |
| 180 | 182 |
| 181 private: | 183 private: |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 mutable FunctionTracer prev_tracer_; | 219 mutable FunctionTracer prev_tracer_; |
| 218 mutable FunctionTracer key_tracer_; | 220 mutable FunctionTracer key_tracer_; |
| 219 mutable FunctionTracer value_tracer_; | 221 mutable FunctionTracer value_tracer_; |
| 220 }; | 222 }; |
| 221 | 223 |
| 222 const std::string LevelDBTraceIteratorImpl::s_class_name = "LevelDBIterator"; | 224 const std::string LevelDBTraceIteratorImpl::s_class_name = "LevelDBIterator"; |
| 223 | 225 |
| 224 class LevelDBTestIteratorImpl : public content::LevelDBIteratorImpl { | 226 class LevelDBTestIteratorImpl : public content::LevelDBIteratorImpl { |
| 225 public: | 227 public: |
| 226 LevelDBTestIteratorImpl(std::unique_ptr<leveldb::Iterator> iterator, | 228 LevelDBTestIteratorImpl(std::unique_ptr<leveldb::Iterator> iterator, |
| 229 LevelDBDatabase* db, |
| 230 const leveldb::Snapshot* snapshot, |
| 227 FailMethod fail_method, | 231 FailMethod fail_method, |
| 228 int fail_on_call_num) | 232 int fail_on_call_num) |
| 229 : LevelDBIteratorImpl(std::move(iterator)), | 233 : LevelDBIteratorImpl(std::move(iterator), db, snapshot), |
| 230 fail_method_(fail_method), | 234 fail_method_(fail_method), |
| 231 fail_on_call_num_(fail_on_call_num), | 235 fail_on_call_num_(fail_on_call_num), |
| 232 current_call_num_(0) {} | 236 current_call_num_(0) {} |
| 233 ~LevelDBTestIteratorImpl() override {} | 237 ~LevelDBTestIteratorImpl() override {} |
| 234 | 238 |
| 235 private: | 239 private: |
| 236 leveldb::Status Seek(const base::StringPiece& target) override { | 240 leveldb::Status Seek(const base::StringPiece& target) override { |
| 237 if (fail_method_ != FAIL_METHOD_SEEK || | 241 if (fail_method_ != FAIL_METHOD_SEEK || |
| 238 ++current_call_num_ != fail_on_call_num_) | 242 ++current_call_num_ != fail_on_call_num_) |
| 239 return LevelDBIteratorImpl::Seek(target); | 243 return LevelDBIteratorImpl::Seek(target); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 failure_method_, | 296 failure_method_, |
| 293 fail_on_call_num_[FAIL_CLASS_LEVELDB_TRANSACTION]); | 297 fail_on_call_num_[FAIL_CLASS_LEVELDB_TRANSACTION]); |
| 294 } else { | 298 } else { |
| 295 return IndexedDBClassFactory::CreateLevelDBTransaction(db); | 299 return IndexedDBClassFactory::CreateLevelDBTransaction(db); |
| 296 } | 300 } |
| 297 } | 301 } |
| 298 } | 302 } |
| 299 | 303 |
| 300 std::unique_ptr<LevelDBIteratorImpl> | 304 std::unique_ptr<LevelDBIteratorImpl> |
| 301 MockBrowserTestIndexedDBClassFactory::CreateIteratorImpl( | 305 MockBrowserTestIndexedDBClassFactory::CreateIteratorImpl( |
| 302 std::unique_ptr<leveldb::Iterator> iterator) { | 306 std::unique_ptr<leveldb::Iterator> iterator, |
| 307 LevelDBDatabase* db, |
| 308 const leveldb::Snapshot* snapshot) { |
| 303 instance_count_[FAIL_CLASS_LEVELDB_ITERATOR] = | 309 instance_count_[FAIL_CLASS_LEVELDB_ITERATOR] = |
| 304 instance_count_[FAIL_CLASS_LEVELDB_ITERATOR] + 1; | 310 instance_count_[FAIL_CLASS_LEVELDB_ITERATOR] + 1; |
| 305 if (only_trace_calls_) { | 311 if (only_trace_calls_) { |
| 306 return base::MakeUnique<LevelDBTraceIteratorImpl>( | 312 return base::MakeUnique<LevelDBTraceIteratorImpl>( |
| 307 std::move(iterator), instance_count_[FAIL_CLASS_LEVELDB_ITERATOR]); | 313 std::move(iterator), db, snapshot, |
| 314 instance_count_[FAIL_CLASS_LEVELDB_ITERATOR]); |
| 308 } else { | 315 } else { |
| 309 if (failure_class_ == FAIL_CLASS_LEVELDB_ITERATOR && | 316 if (failure_class_ == FAIL_CLASS_LEVELDB_ITERATOR && |
| 310 instance_count_[FAIL_CLASS_LEVELDB_ITERATOR] == | 317 instance_count_[FAIL_CLASS_LEVELDB_ITERATOR] == |
| 311 fail_on_instance_num_[FAIL_CLASS_LEVELDB_ITERATOR]) { | 318 fail_on_instance_num_[FAIL_CLASS_LEVELDB_ITERATOR]) { |
| 312 return base::MakeUnique<LevelDBTestIteratorImpl>( | 319 return base::MakeUnique<LevelDBTestIteratorImpl>( |
| 313 std::move(iterator), failure_method_, | 320 std::move(iterator), db, snapshot, failure_method_, |
| 314 fail_on_call_num_[FAIL_CLASS_LEVELDB_ITERATOR]); | 321 fail_on_call_num_[FAIL_CLASS_LEVELDB_ITERATOR]); |
| 315 } else { | 322 } else { |
| 316 return base::WrapUnique(new LevelDBIteratorImpl(std::move(iterator))); | 323 return base::WrapUnique( |
| 324 new LevelDBIteratorImpl(std::move(iterator), db, snapshot)); |
| 317 } | 325 } |
| 318 } | 326 } |
| 319 } | 327 } |
| 320 | 328 |
| 321 void MockBrowserTestIndexedDBClassFactory::FailOperation( | 329 void MockBrowserTestIndexedDBClassFactory::FailOperation( |
| 322 FailClass failure_class, | 330 FailClass failure_class, |
| 323 FailMethod failure_method, | 331 FailMethod failure_method, |
| 324 int fail_on_instance_num, | 332 int fail_on_instance_num, |
| 325 int fail_on_call_num) { | 333 int fail_on_call_num) { |
| 326 VLOG(0) << "FailOperation: class=" << failure_class | 334 VLOG(0) << "FailOperation: class=" << failure_class |
| (...skipping 11 matching lines...) Expand all Loading... |
| 338 | 346 |
| 339 void MockBrowserTestIndexedDBClassFactory::Reset() { | 347 void MockBrowserTestIndexedDBClassFactory::Reset() { |
| 340 failure_class_ = FAIL_CLASS_NOTHING; | 348 failure_class_ = FAIL_CLASS_NOTHING; |
| 341 failure_method_ = FAIL_METHOD_NOTHING; | 349 failure_method_ = FAIL_METHOD_NOTHING; |
| 342 instance_count_.clear(); | 350 instance_count_.clear(); |
| 343 fail_on_instance_num_.clear(); | 351 fail_on_instance_num_.clear(); |
| 344 fail_on_call_num_.clear(); | 352 fail_on_call_num_.clear(); |
| 345 } | 353 } |
| 346 | 354 |
| 347 } // namespace content | 355 } // namespace content |
| OLD | NEW |