| 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 | |
| 152 // Set an error-handling callback. On errors, the error number (and | 149 // Set an error-handling callback. On errors, the error number (and |
| 153 // statement, if available) will be passed to the callback. | 150 // statement, if available) will be passed to the callback. |
| 154 // | 151 // |
| 155 // If no callback is set, the default action is to crash in debug | 152 // If no callback is set, the default action is to crash in debug |
| 156 // mode or return failure in release mode. | 153 // mode or return failure in release mode. |
| 157 typedef base::Callback<void(int, Statement*)> ErrorCallback; | 154 typedef base::Callback<void(int, Statement*)> ErrorCallback; |
| 158 void set_error_callback(const ErrorCallback& callback) { | 155 void set_error_callback(const ErrorCallback& callback) { |
| 159 error_callback_ = callback; | 156 error_callback_ = callback; |
| 160 } | 157 } |
| 161 bool has_error_callback() const { | 158 bool has_error_callback() const { |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 // true, autocommit time if the database is not in a transaction, or update | 631 // true, autocommit time if the database is not in a transaction, or update |
| 635 // time if the database is in a transaction. Also records change count to | 632 // time if the database is in a transaction. Also records change count to |
| 636 // EVENT_CHANGES_AUTOCOMMIT or EVENT_CHANGES_COMMIT. | 633 // EVENT_CHANGES_AUTOCOMMIT or EVENT_CHANGES_COMMIT. |
| 637 void RecordTimeAndChanges(const base::TimeDelta& delta, bool read_only); | 634 void RecordTimeAndChanges(const base::TimeDelta& delta, bool read_only); |
| 638 | 635 |
| 639 // Helper to return the current time from the time source. | 636 // Helper to return the current time from the time source. |
| 640 base::TimeTicks Now() { | 637 base::TimeTicks Now() { |
| 641 return clock_->Now(); | 638 return clock_->Now(); |
| 642 } | 639 } |
| 643 | 640 |
| 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 | |
| 650 // The actual sqlite database. Will be NULL before Init has been called or if | 641 // The actual sqlite database. Will be NULL before Init has been called or if |
| 651 // Init resulted in an error. | 642 // Init resulted in an error. |
| 652 sqlite3* db_; | 643 sqlite3* db_; |
| 653 | 644 |
| 654 // Parameters we'll configure in sqlite before doing anything else. Zero means | 645 // Parameters we'll configure in sqlite before doing anything else. Zero means |
| 655 // use the default value. | 646 // use the default value. |
| 656 int page_size_; | 647 int page_size_; |
| 657 int cache_size_; | 648 int cache_size_; |
| 658 bool exclusive_locking_; | 649 bool exclusive_locking_; |
| 659 bool restrict_to_user_; | 650 bool restrict_to_user_; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 681 // True if database is open with OpenInMemory(), False if database is open | 672 // True if database is open with OpenInMemory(), False if database is open |
| 682 // with Open(). | 673 // with Open(). |
| 683 bool in_memory_; | 674 bool in_memory_; |
| 684 | 675 |
| 685 // |true| if the connection was closed using RazeAndClose(). Used | 676 // |true| if the connection was closed using RazeAndClose(). Used |
| 686 // to enable diagnostics to distinguish calls to never-opened | 677 // to enable diagnostics to distinguish calls to never-opened |
| 687 // databases (incorrect use of the API) from calls to once-valid | 678 // databases (incorrect use of the API) from calls to once-valid |
| 688 // databases. | 679 // databases. |
| 689 bool poisoned_; | 680 bool poisoned_; |
| 690 | 681 |
| 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 | |
| 702 ErrorCallback error_callback_; | 682 ErrorCallback error_callback_; |
| 703 | 683 |
| 704 // Tag for auxiliary histograms. | 684 // Tag for auxiliary histograms. |
| 705 std::string histogram_tag_; | 685 std::string histogram_tag_; |
| 706 | 686 |
| 707 // Linear histogram for RecordEvent(). | 687 // Linear histogram for RecordEvent(). |
| 708 base::HistogramBase* stats_histogram_; | 688 base::HistogramBase* stats_histogram_; |
| 709 | 689 |
| 710 // Histogram for tracking time taken in commit. | 690 // Histogram for tracking time taken in commit. |
| 711 base::HistogramBase* commit_time_histogram_; | 691 base::HistogramBase* commit_time_histogram_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 723 // Source for timing information, provided to allow tests to inject time | 703 // Source for timing information, provided to allow tests to inject time |
| 724 // changes. | 704 // changes. |
| 725 scoped_ptr<TimeSource> clock_; | 705 scoped_ptr<TimeSource> clock_; |
| 726 | 706 |
| 727 DISALLOW_COPY_AND_ASSIGN(Connection); | 707 DISALLOW_COPY_AND_ASSIGN(Connection); |
| 728 }; | 708 }; |
| 729 | 709 |
| 730 } // namespace sql | 710 } // namespace sql |
| 731 | 711 |
| 732 #endif // SQL_CONNECTION_H_ | 712 #endif // SQL_CONNECTION_H_ |
| OLD | NEW |