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

Side by Side Diff: sql/connection.h

Issue 1426743006: [sql] Validate database files before enabling memory-mapping. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename helper and address truncate case. Created 5 years, 1 month 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
« no previous file with comments | « no previous file | sql/connection.cc » ('j') | sql/connection.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef SQL_CONNECTION_H_ 5 #ifndef SQL_CONNECTION_H_
6 #define SQL_CONNECTION_H_ 6 #define SQL_CONNECTION_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 EVENT_CHANGES_AUTOCOMMIT, 197 EVENT_CHANGES_AUTOCOMMIT,
198 198
199 // Number of rows changed by statements in transactions. 199 // Number of rows changed by statements in transactions.
200 EVENT_CHANGES, 200 EVENT_CHANGES,
201 201
202 // Count actual SQLite transaction statements (not including nesting). 202 // Count actual SQLite transaction statements (not including nesting).
203 EVENT_BEGIN, 203 EVENT_BEGIN,
204 EVENT_COMMIT, 204 EVENT_COMMIT,
205 EVENT_ROLLBACK, 205 EVENT_ROLLBACK,
206 206
207 // Track success and failure in GetAppropriateMmapSize().
208 // GetAppropriateMmapSize() should record at most one of these per run. The
209 // case of mapping everything is not recorded.
210 EVENT_MMAP_META_MISSING, // No meta table present.
211 EVENT_MMAP_META_FAILURE_READ, // Failed reading meta table.
212 EVENT_MMAP_META_FAILURE_UPDATE, // Failed updating meta table.
213 EVENT_MMAP_VFS_FAILURE, // Failed to access VFS.
214 EVENT_MMAP_FAILED, // Failure from past run.
215 EVENT_MMAP_FAILED_NEW, // Read error in this run.
216 EVENT_MMAP_SUCCESS_NEW, // Read to EOF in this run.
217 EVENT_MMAP_SUCCESS_PARTIAL, // Read but did not reach EOF.
218 EVENT_MMAP_SUCCESS_NO_PROGRESS, // Read quota exhausted.
219
207 // Leave this at the end. 220 // Leave this at the end.
208 // TODO(shess): |EVENT_MAX| causes compile fail on Windows. 221 // TODO(shess): |EVENT_MAX| causes compile fail on Windows.
209 EVENT_MAX_VALUE 222 EVENT_MAX_VALUE
210 }; 223 };
211 void RecordEvent(Events event, size_t count); 224 void RecordEvent(Events event, size_t count);
212 void RecordOneEvent(Events event) { 225 void RecordOneEvent(Events event) {
213 RecordEvent(event, 1); 226 RecordEvent(event, 1);
214 } 227 }
215 228
216 // Run "PRAGMA integrity_check" and post each line of 229 // Run "PRAGMA integrity_check" and post each line of
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 // database is razed or recovered, or if the diagnostic code adds new 695 // database is razed or recovered, or if the diagnostic code adds new
683 // capabilities. 696 // capabilities.
684 bool RegisterIntentToUpload() const; 697 bool RegisterIntentToUpload() const;
685 698
686 // Helper to collect diagnostic info for a corrupt database. 699 // Helper to collect diagnostic info for a corrupt database.
687 std::string CollectCorruptionInfo(); 700 std::string CollectCorruptionInfo();
688 701
689 // Helper to collect diagnostic info for errors. 702 // Helper to collect diagnostic info for errors.
690 std::string CollectErrorInfo(int error, Statement* stmt) const; 703 std::string CollectErrorInfo(int error, Statement* stmt) const;
691 704
705 // Calculates a value appropriate to pass to "PRAGMA mmap_size = ". So errors
706 // can make it unsafe to map a file, so the file is read using regular I/O,
707 // with any errors causing 0 (don't map anything) to be returned. If the
708 // entire file is read without error, a large value is returned which will
709 // allow the entire file to be mapped in most cases.
710 //
711 // Results are recorded in the database's meta table for future reference, so
712 // the file should only be read through once.
713 size_t GetAppropriateMmapSize();
714
692 // The actual sqlite database. Will be NULL before Init has been called or if 715 // The actual sqlite database. Will be NULL before Init has been called or if
693 // Init resulted in an error. 716 // Init resulted in an error.
694 sqlite3* db_; 717 sqlite3* db_;
695 718
696 // Parameters we'll configure in sqlite before doing anything else. Zero means 719 // Parameters we'll configure in sqlite before doing anything else. Zero means
697 // use the default value. 720 // use the default value.
698 int page_size_; 721 int page_size_;
699 int cache_size_; 722 int cache_size_;
700 bool exclusive_locking_; 723 bool exclusive_locking_;
701 bool restrict_to_user_; 724 bool restrict_to_user_;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 // Source for timing information, provided to allow tests to inject time 788 // Source for timing information, provided to allow tests to inject time
766 // changes. 789 // changes.
767 scoped_ptr<TimeSource> clock_; 790 scoped_ptr<TimeSource> clock_;
768 791
769 DISALLOW_COPY_AND_ASSIGN(Connection); 792 DISALLOW_COPY_AND_ASSIGN(Connection);
770 }; 793 };
771 794
772 } // namespace sql 795 } // namespace sql
773 796
774 #endif // SQL_CONNECTION_H_ 797 #endif // SQL_CONNECTION_H_
OLDNEW
« no previous file with comments | « no previous file | sql/connection.cc » ('j') | sql/connection.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698