[M108 Migration][HBBTV] Implement ewk_context_register_jsplugin_mime_types API
[platform/framework/web/chromium-efl.git] / sql / transaction.cc
1 // Copyright 2011 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "sql/transaction.h"
6
7 #include "base/check.h"
8 #include "base/sequence_checker.h"
9 #include "sql/database.h"
10
11 namespace sql {
12
13 Transaction::Transaction(Database* database) : database_(*database) {
14   DCHECK(database);
15 }
16
17 Transaction::~Transaction() {
18   DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
19 #if DCHECK_IS_ON()
20   DCHECK(begin_called_)
21       << "Begin() not called immediately after Transaction creation";
22 #endif  // DCHECK_IS_ON()
23
24   if (is_active_)
25     database_.RollbackTransaction();
26 }
27
28 bool Transaction::Begin() {
29   DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
30 #if DCHECK_IS_ON()
31   DCHECK(!begin_called_) << __func__ << " already called";
32   begin_called_ = true;
33 #endif  // DCHECK_IS_ON()
34
35   DCHECK(!is_active_);
36   is_active_ = database_.BeginTransaction();
37   return is_active_;
38 }
39
40 void Transaction::Rollback() {
41   DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
42 #if DCHECK_IS_ON()
43   DCHECK(begin_called_) << __func__ << " called before Begin()";
44   DCHECK(!commit_called_) << __func__ << " called after Commit()";
45   DCHECK(!rollback_called_) << __func__ << " called twice";
46   rollback_called_ = true;
47 #endif  // DCHECK_IS_ON()
48
49   DCHECK(is_active_) << __func__ << " called after Begin() failed";
50   is_active_ = false;
51
52   database_.RollbackTransaction();
53 }
54
55 bool Transaction::Commit() {
56   DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
57 #if DCHECK_IS_ON()
58   DCHECK(begin_called_) << __func__ << " called before Begin()";
59   DCHECK(!rollback_called_) << __func__ << " called after Rollback()";
60   DCHECK(!commit_called_) << __func__ << " called after Commit()";
61   commit_called_ = true;
62 #endif  // DCHECK_IS_ON()
63
64   DCHECK(is_active_) << __func__ << " called after Begin() failed";
65   is_active_ = false;
66   return database_.CommitTransaction();
67 }
68
69 }  // namespace sql