OLD | NEW |
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/leveldb/leveldb_transaction.h" | 5 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" |
| 9 #include "base/time/time.h" |
8 #include "content/browser/indexed_db/leveldb/leveldb_database.h" | 10 #include "content/browser/indexed_db/leveldb/leveldb_database.h" |
9 #include "content/browser/indexed_db/leveldb/leveldb_write_batch.h" | 11 #include "content/browser/indexed_db/leveldb/leveldb_write_batch.h" |
10 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 12 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
11 | 13 |
12 using base::StringPiece; | 14 using base::StringPiece; |
13 | 15 |
14 namespace content { | 16 namespace content { |
15 | 17 |
16 LevelDBTransaction::LevelDBTransaction(LevelDBDatabase* db) | 18 LevelDBTransaction::LevelDBTransaction(LevelDBDatabase* db) |
17 : db_(db), | 19 : db_(db), |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 } | 88 } |
87 | 89 |
88 leveldb::Status LevelDBTransaction::Commit() { | 90 leveldb::Status LevelDBTransaction::Commit() { |
89 DCHECK(!finished_); | 91 DCHECK(!finished_); |
90 | 92 |
91 if (data_.empty()) { | 93 if (data_.empty()) { |
92 finished_ = true; | 94 finished_ = true; |
93 return leveldb::Status::OK(); | 95 return leveldb::Status::OK(); |
94 } | 96 } |
95 | 97 |
| 98 base::TimeTicks begin_time = base::TimeTicks::Now(); |
96 scoped_ptr<LevelDBWriteBatch> write_batch = LevelDBWriteBatch::Create(); | 99 scoped_ptr<LevelDBWriteBatch> write_batch = LevelDBWriteBatch::Create(); |
97 | 100 |
98 for (DataType::iterator iterator = data_.begin(); iterator != data_.end(); | 101 for (DataType::iterator iterator = data_.begin(); iterator != data_.end(); |
99 ++iterator) { | 102 ++iterator) { |
100 if (!iterator->second->deleted) | 103 if (!iterator->second->deleted) |
101 write_batch->Put(iterator->first, iterator->second->value); | 104 write_batch->Put(iterator->first, iterator->second->value); |
102 else | 105 else |
103 write_batch->Remove(iterator->first); | 106 write_batch->Remove(iterator->first); |
104 } | 107 } |
105 | 108 |
106 leveldb::Status s = db_->Write(*write_batch); | 109 leveldb::Status s = db_->Write(*write_batch); |
107 if (s.ok()) { | 110 if (s.ok()) { |
108 Clear(); | 111 Clear(); |
109 finished_ = true; | 112 finished_ = true; |
| 113 UMA_HISTOGRAM_TIMES("WebCore.IndexedDB.LevelDB.Transaction.CommitTime", |
| 114 base::TimeTicks::Now() - begin_time); |
110 } | 115 } |
111 return s; | 116 return s; |
112 } | 117 } |
113 | 118 |
114 void LevelDBTransaction::Rollback() { | 119 void LevelDBTransaction::Rollback() { |
115 DCHECK(!finished_); | 120 DCHECK(!finished_); |
116 finished_ = true; | 121 finished_ = true; |
117 Clear(); | 122 Clear(); |
118 } | 123 } |
119 | 124 |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 | 491 |
487 leveldb::Status s = db_->Write(*write_batch_); | 492 leveldb::Status s = db_->Write(*write_batch_); |
488 if (s.ok()) { | 493 if (s.ok()) { |
489 finished_ = true; | 494 finished_ = true; |
490 write_batch_->Clear(); | 495 write_batch_->Clear(); |
491 } | 496 } |
492 return s; | 497 return s; |
493 } | 498 } |
494 | 499 |
495 } // namespace content | 500 } // namespace content |
OLD | NEW |