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

Side by Side Diff: sql/connection.h

Issue 1442753004: [sql] Validate database files before enabling memory-mapping. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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') | no next file with comments »
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 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 // database is razed or recovered, or if the diagnostic code adds new 699 // database is razed or recovered, or if the diagnostic code adds new
687 // capabilities. 700 // capabilities.
688 bool RegisterIntentToUpload() const; 701 bool RegisterIntentToUpload() const;
689 702
690 // Helper to collect diagnostic info for a corrupt database. 703 // Helper to collect diagnostic info for a corrupt database.
691 std::string CollectCorruptionInfo(); 704 std::string CollectCorruptionInfo();
692 705
693 // Helper to collect diagnostic info for errors. 706 // Helper to collect diagnostic info for errors.
694 std::string CollectErrorInfo(int error, Statement* stmt) const; 707 std::string CollectErrorInfo(int error, Statement* stmt) const;
695 708
709 // Calculates a value appropriate to pass to "PRAGMA mmap_size = ". So errors
710 // can make it unsafe to map a file, so the file is read using regular I/O,
711 // with any errors causing 0 (don't map anything) to be returned. If the
712 // entire file is read without error, a large value is returned which will
713 // allow the entire file to be mapped in most cases.
714 //
715 // Results are recorded in the database's meta table for future reference, so
716 // the file should only be read through once.
717 size_t GetAppropriateMmapSize();
718
696 // The actual sqlite database. Will be NULL before Init has been called or if 719 // The actual sqlite database. Will be NULL before Init has been called or if
697 // Init resulted in an error. 720 // Init resulted in an error.
698 sqlite3* db_; 721 sqlite3* db_;
699 722
700 // Parameters we'll configure in sqlite before doing anything else. Zero means 723 // Parameters we'll configure in sqlite before doing anything else. Zero means
701 // use the default value. 724 // use the default value.
702 int page_size_; 725 int page_size_;
703 int cache_size_; 726 int cache_size_;
704 bool exclusive_locking_; 727 bool exclusive_locking_;
705 bool restrict_to_user_; 728 bool restrict_to_user_;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 // Source for timing information, provided to allow tests to inject time 792 // Source for timing information, provided to allow tests to inject time
770 // changes. 793 // changes.
771 scoped_ptr<TimeSource> clock_; 794 scoped_ptr<TimeSource> clock_;
772 795
773 DISALLOW_COPY_AND_ASSIGN(Connection); 796 DISALLOW_COPY_AND_ASSIGN(Connection);
774 }; 797 };
775 798
776 } // namespace sql 799 } // namespace sql
777 800
778 #endif // SQL_CONNECTION_H_ 801 #endif // SQL_CONNECTION_H_
OLDNEW
« no previous file with comments | « no previous file | sql/connection.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698