Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: sql/recovery.cc

Issue 1657593005: [sql] Prevent recovery against a closed database. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Detect API mis-use. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 return false; 101 return false;
102 #else 102 #else
103 return true; 103 return true;
104 #endif 104 #endif
105 } 105 }
106 106
107 // static 107 // static
108 scoped_ptr<Recovery> Recovery::Begin( 108 scoped_ptr<Recovery> Recovery::Begin(
109 Connection* connection, 109 Connection* connection,
110 const base::FilePath& db_path) { 110 const base::FilePath& db_path) {
111 // Recovery is likely to be used in error handling. Since recovery changes
112 // the state of the handle, protect against multiple layers attempting the
113 // same recovery.
114 if (!connection->is_open()) {
115 // Warn about API mis-use.
116 DLOG_IF(FATAL, !connection->poisoned_)
117 << "Illegal to recover with closed database";
118 return scoped_ptr<Recovery>();
119 }
120
111 scoped_ptr<Recovery> r(new Recovery(connection)); 121 scoped_ptr<Recovery> r(new Recovery(connection));
112 if (!r->Init(db_path)) { 122 if (!r->Init(db_path)) {
113 // TODO(shess): Should Init() failure result in Raze()? 123 // TODO(shess): Should Init() failure result in Raze()?
114 r->Shutdown(POISON); 124 r->Shutdown(POISON);
115 return scoped_ptr<Recovery>(); 125 return scoped_ptr<Recovery>();
116 } 126 }
117 127
118 return r; 128 return r;
119 } 129 }
120 130
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 } 537 }
528 return false; 538 return false;
529 } 539 }
530 540
531 RecordRecoveryEvent(RECOVERY_SUCCESS_META_VERSION); 541 RecordRecoveryEvent(RECOVERY_SUCCESS_META_VERSION);
532 *version = recovery_version.ColumnInt(0); 542 *version = recovery_version.ColumnInt(0);
533 return true; 543 return true;
534 } 544 }
535 545
536 } // namespace sql 546 } // namespace sql
OLDNEW
« no previous file with comments | « sql/connection.cc ('k') | sql/recovery_unittest.cc » ('j') | sql/recovery_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698