| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "sql/recovery.h" | 5 #include "sql/recovery.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 95 |
| 96 } // namespace | 96 } // namespace |
| 97 | 97 |
| 98 // static | 98 // static |
| 99 bool Recovery::FullRecoverySupported() { | 99 bool Recovery::FullRecoverySupported() { |
| 100 // TODO(shess): See comment in Init(). | 100 // TODO(shess): See comment in Init(). |
| 101 return true; | 101 return true; |
| 102 } | 102 } |
| 103 | 103 |
| 104 // static | 104 // static |
| 105 scoped_ptr<Recovery> Recovery::Begin( | 105 std::unique_ptr<Recovery> Recovery::Begin(Connection* connection, |
| 106 Connection* connection, | 106 const base::FilePath& db_path) { |
| 107 const base::FilePath& db_path) { | |
| 108 // Recovery is likely to be used in error handling. Since recovery changes | 107 // Recovery is likely to be used in error handling. Since recovery changes |
| 109 // the state of the handle, protect against multiple layers attempting the | 108 // the state of the handle, protect against multiple layers attempting the |
| 110 // same recovery. | 109 // same recovery. |
| 111 if (!connection->is_open()) { | 110 if (!connection->is_open()) { |
| 112 // Warn about API mis-use. | 111 // Warn about API mis-use. |
| 113 DLOG_IF(FATAL, !connection->poisoned_) | 112 DLOG_IF(FATAL, !connection->poisoned_) |
| 114 << "Illegal to recover with closed database"; | 113 << "Illegal to recover with closed database"; |
| 115 return scoped_ptr<Recovery>(); | 114 return std::unique_ptr<Recovery>(); |
| 116 } | 115 } |
| 117 | 116 |
| 118 scoped_ptr<Recovery> r(new Recovery(connection)); | 117 std::unique_ptr<Recovery> r(new Recovery(connection)); |
| 119 if (!r->Init(db_path)) { | 118 if (!r->Init(db_path)) { |
| 120 // TODO(shess): Should Init() failure result in Raze()? | 119 // TODO(shess): Should Init() failure result in Raze()? |
| 121 r->Shutdown(POISON); | 120 r->Shutdown(POISON); |
| 122 return scoped_ptr<Recovery>(); | 121 return std::unique_ptr<Recovery>(); |
| 123 } | 122 } |
| 124 | 123 |
| 125 return r; | 124 return r; |
| 126 } | 125 } |
| 127 | 126 |
| 128 // static | 127 // static |
| 129 bool Recovery::Recovered(scoped_ptr<Recovery> r) { | 128 bool Recovery::Recovered(std::unique_ptr<Recovery> r) { |
| 130 return r->Backup(); | 129 return r->Backup(); |
| 131 } | 130 } |
| 132 | 131 |
| 133 // static | 132 // static |
| 134 void Recovery::Unrecoverable(scoped_ptr<Recovery> r) { | 133 void Recovery::Unrecoverable(std::unique_ptr<Recovery> r) { |
| 135 CHECK(r->db_); | 134 CHECK(r->db_); |
| 136 // ~Recovery() will RAZE_AND_POISON. | 135 // ~Recovery() will RAZE_AND_POISON. |
| 137 } | 136 } |
| 138 | 137 |
| 139 // static | 138 // static |
| 140 void Recovery::Rollback(scoped_ptr<Recovery> r) { | 139 void Recovery::Rollback(std::unique_ptr<Recovery> r) { |
| 141 // TODO(shess): HISTOGRAM to track? Or just have people crash out? | 140 // TODO(shess): HISTOGRAM to track? Or just have people crash out? |
| 142 // Crash and dump? | 141 // Crash and dump? |
| 143 r->Shutdown(POISON); | 142 r->Shutdown(POISON); |
| 144 } | 143 } |
| 145 | 144 |
| 146 Recovery::Recovery(Connection* connection) | 145 Recovery::Recovery(Connection* connection) |
| 147 : db_(connection), | 146 : db_(connection), |
| 148 recover_db_() { | 147 recover_db_() { |
| 149 // Result should keep the page size specified earlier. | 148 // Result should keep the page size specified earlier. |
| 150 if (db_->page_size_) | 149 if (db_->page_size_) |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 } | 502 } |
| 504 return false; | 503 return false; |
| 505 } | 504 } |
| 506 | 505 |
| 507 RecordRecoveryEvent(RECOVERY_SUCCESS_META_VERSION); | 506 RecordRecoveryEvent(RECOVERY_SUCCESS_META_VERSION); |
| 508 *version = recovery_version.ColumnInt(0); | 507 *version = recovery_version.ColumnInt(0); |
| 509 return true; | 508 return true; |
| 510 } | 509 } |
| 511 | 510 |
| 512 } // namespace sql | 511 } // namespace sql |
| OLD | NEW |