OLD | NEW |
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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 // | 139 // |
140 // This must be called before Open() to have an effect. | 140 // This must be called before Open() to have an effect. |
141 void set_exclusive_locking() { exclusive_locking_ = true; } | 141 void set_exclusive_locking() { exclusive_locking_ = true; } |
142 | 142 |
143 // Call to cause Open() to restrict access permissions of the | 143 // Call to cause Open() to restrict access permissions of the |
144 // database file to only the owner. | 144 // database file to only the owner. |
145 // TODO(shess): Currently only supported on OS_POSIX, is a noop on | 145 // TODO(shess): Currently only supported on OS_POSIX, is a noop on |
146 // other platforms. | 146 // other platforms. |
147 void set_restrict_to_user() { restrict_to_user_ = true; } | 147 void set_restrict_to_user() { restrict_to_user_ = true; } |
148 | 148 |
| 149 // Call to opt out of memory-mapped file I/O. |
| 150 void set_mmap_disabled() { mmap_disabled_ = true; } |
| 151 |
149 // Set an error-handling callback. On errors, the error number (and | 152 // Set an error-handling callback. On errors, the error number (and |
150 // statement, if available) will be passed to the callback. | 153 // statement, if available) will be passed to the callback. |
151 // | 154 // |
152 // If no callback is set, the default action is to crash in debug | 155 // If no callback is set, the default action is to crash in debug |
153 // mode or return failure in release mode. | 156 // mode or return failure in release mode. |
154 typedef base::Callback<void(int, Statement*)> ErrorCallback; | 157 typedef base::Callback<void(int, Statement*)> ErrorCallback; |
155 void set_error_callback(const ErrorCallback& callback) { | 158 void set_error_callback(const ErrorCallback& callback) { |
156 error_callback_ = callback; | 159 error_callback_ = callback; |
157 } | 160 } |
158 bool has_error_callback() const { | 161 bool has_error_callback() const { |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 // true, autocommit time if the database is not in a transaction, or update | 634 // true, autocommit time if the database is not in a transaction, or update |
632 // time if the database is in a transaction. Also records change count to | 635 // time if the database is in a transaction. Also records change count to |
633 // EVENT_CHANGES_AUTOCOMMIT or EVENT_CHANGES_COMMIT. | 636 // EVENT_CHANGES_AUTOCOMMIT or EVENT_CHANGES_COMMIT. |
634 void RecordTimeAndChanges(const base::TimeDelta& delta, bool read_only); | 637 void RecordTimeAndChanges(const base::TimeDelta& delta, bool read_only); |
635 | 638 |
636 // Helper to return the current time from the time source. | 639 // Helper to return the current time from the time source. |
637 base::TimeTicks Now() { | 640 base::TimeTicks Now() { |
638 return clock_->Now(); | 641 return clock_->Now(); |
639 } | 642 } |
640 | 643 |
| 644 // Release page-cache memory if memory-mapped I/O is enabled and the database |
| 645 // was changed. Passing true for |implicit_change_performed| allows |
| 646 // overriding the change detection for cases like DDL (CREATE, DROP, etc), |
| 647 // which do not participate in the total-rows-changed tracking. |
| 648 void ReleaseCacheMemoryIfNeeded(bool implicit_change_performed); |
| 649 |
641 // The actual sqlite database. Will be NULL before Init has been called or if | 650 // The actual sqlite database. Will be NULL before Init has been called or if |
642 // Init resulted in an error. | 651 // Init resulted in an error. |
643 sqlite3* db_; | 652 sqlite3* db_; |
644 | 653 |
645 // Parameters we'll configure in sqlite before doing anything else. Zero means | 654 // Parameters we'll configure in sqlite before doing anything else. Zero means |
646 // use the default value. | 655 // use the default value. |
647 int page_size_; | 656 int page_size_; |
648 int cache_size_; | 657 int cache_size_; |
649 bool exclusive_locking_; | 658 bool exclusive_locking_; |
650 bool restrict_to_user_; | 659 bool restrict_to_user_; |
(...skipping 21 matching lines...) Expand all Loading... |
672 // True if database is open with OpenInMemory(), False if database is open | 681 // True if database is open with OpenInMemory(), False if database is open |
673 // with Open(). | 682 // with Open(). |
674 bool in_memory_; | 683 bool in_memory_; |
675 | 684 |
676 // |true| if the connection was closed using RazeAndClose(). Used | 685 // |true| if the connection was closed using RazeAndClose(). Used |
677 // to enable diagnostics to distinguish calls to never-opened | 686 // to enable diagnostics to distinguish calls to never-opened |
678 // databases (incorrect use of the API) from calls to once-valid | 687 // databases (incorrect use of the API) from calls to once-valid |
679 // databases. | 688 // databases. |
680 bool poisoned_; | 689 bool poisoned_; |
681 | 690 |
| 691 // |true| if SQLite memory-mapped I/O is not desired for this connection. |
| 692 bool mmap_disabled_; |
| 693 |
| 694 // |true| if SQLite memory-mapped I/O was enabled for this connection. |
| 695 // Used by ReleaseCacheMemoryIfNeeded(). |
| 696 bool mmap_enabled_; |
| 697 |
| 698 // Used by ReleaseCacheMemoryIfNeeded() to track if new changes have happened |
| 699 // since memory was last released. |
| 700 int total_changes_at_last_release_; |
| 701 |
682 ErrorCallback error_callback_; | 702 ErrorCallback error_callback_; |
683 | 703 |
684 // Tag for auxiliary histograms. | 704 // Tag for auxiliary histograms. |
685 std::string histogram_tag_; | 705 std::string histogram_tag_; |
686 | 706 |
687 // Linear histogram for RecordEvent(). | 707 // Linear histogram for RecordEvent(). |
688 base::HistogramBase* stats_histogram_; | 708 base::HistogramBase* stats_histogram_; |
689 | 709 |
690 // Histogram for tracking time taken in commit. | 710 // Histogram for tracking time taken in commit. |
691 base::HistogramBase* commit_time_histogram_; | 711 base::HistogramBase* commit_time_histogram_; |
(...skipping 11 matching lines...) Expand all Loading... |
703 // Source for timing information, provided to allow tests to inject time | 723 // Source for timing information, provided to allow tests to inject time |
704 // changes. | 724 // changes. |
705 scoped_ptr<TimeSource> clock_; | 725 scoped_ptr<TimeSource> clock_; |
706 | 726 |
707 DISALLOW_COPY_AND_ASSIGN(Connection); | 727 DISALLOW_COPY_AND_ASSIGN(Connection); |
708 }; | 728 }; |
709 | 729 |
710 } // namespace sql | 730 } // namespace sql |
711 | 731 |
712 #endif // SQL_CONNECTION_H_ | 732 #endif // SQL_CONNECTION_H_ |
OLD | NEW |