Add UMA stats for ExtensionCache
[chromium-blink-merge.git] / sql / transaction.cc
blob06bcbebebddde5c7fc504c1a2050f1fd2fce97c1
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "sql/transaction.h"
7 #include "base/logging.h"
8 #include "sql/connection.h"
10 namespace sql {
12 Transaction::Transaction(Connection* connection)
13 : connection_(connection),
14 is_open_(false) {
17 Transaction::~Transaction() {
18 if (is_open_)
19 connection_->RollbackTransaction();
22 bool Transaction::Begin() {
23 if (is_open_) {
24 NOTREACHED() << "Beginning a transaction twice!";
25 return false;
27 is_open_ = connection_->BeginTransaction();
28 return is_open_;
31 void Transaction::Rollback() {
32 if (!is_open_) {
33 NOTREACHED() << "Attempting to roll back a nonexistent transaction. "
34 << "Did you remember to call Begin() and check its return?";
35 return;
37 is_open_ = false;
38 connection_->RollbackTransaction();
41 bool Transaction::Commit() {
42 if (!is_open_) {
43 NOTREACHED() << "Attempting to commit a nonexistent transaction. "
44 << "Did you remember to call Begin() and check its return?";
45 return false;
47 is_open_ = false;
48 return connection_->CommitTransaction();
51 } // namespace sql