| 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 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 // error-handling at the end of OnSqliteError(). Expose to allow | 463 // error-handling at the end of OnSqliteError(). Expose to allow |
| 464 // those clients to work appropriately with ScopedErrorIgnorer in | 464 // those clients to work appropriately with ScopedErrorIgnorer in |
| 465 // tests. | 465 // tests. |
| 466 static bool ShouldIgnoreSqliteError(int error); | 466 static bool ShouldIgnoreSqliteError(int error); |
| 467 | 467 |
| 468 // base::trace_event::MemoryDumpProvider implementation. | 468 // base::trace_event::MemoryDumpProvider implementation. |
| 469 bool OnMemoryDump( | 469 bool OnMemoryDump( |
| 470 const base::trace_event::MemoryDumpArgs& args, | 470 const base::trace_event::MemoryDumpArgs& args, |
| 471 base::trace_event::ProcessMemoryDump* process_memory_dump) override; | 471 base::trace_event::ProcessMemoryDump* process_memory_dump) override; |
| 472 | 472 |
| 473 // Helper to prevent uploading too many diagnostic dumps for a given database, |
| 474 // since every dump will likely show the same problem. Returns |true| if this |
| 475 // function was not previously called for this database, and the persistent |
| 476 // storage which tracks state was updated. |
| 477 // |
| 478 // |false| is returned if the function was previously called for this |
| 479 // database, even across restarts. |false| is also returned if the persistent |
| 480 // storage cannot be updated, possibly indicating problems requiring user or |
| 481 // admin intervention, such as filesystem corruption or disk full. |false| is |
| 482 // also returned if the persistent storage contains invalid data or is not |
| 483 // readable. |
| 484 // |
| 485 // TODO(shess): It would make sense to reset the persistent state if the |
| 486 // database is razed or recovered, or if the diagnostic code adds new |
| 487 // capabilities. |
| 488 bool RegisterIntentToUpload() const; |
| 489 |
| 473 private: | 490 private: |
| 474 // For recovery module. | 491 // For recovery module. |
| 475 friend class Recovery; | 492 friend class Recovery; |
| 476 | 493 |
| 477 // Allow test-support code to set/reset error ignorer. | 494 // Allow test-support code to set/reset error ignorer. |
| 478 friend class ScopedErrorIgnorer; | 495 friend class ScopedErrorIgnorer; |
| 479 | 496 |
| 480 // Statement accesses StatementRef which we don't want to expose to everybody | 497 // Statement accesses StatementRef which we don't want to expose to everybody |
| 481 // (they should go through Statement). | 498 // (they should go through Statement). |
| 482 friend class Statement; | 499 friend class Statement; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 497 }; | 514 }; |
| 498 bool OpenInternal(const std::string& file_name, Retry retry_flag); | 515 bool OpenInternal(const std::string& file_name, Retry retry_flag); |
| 499 | 516 |
| 500 // Internal close function used by Close() and RazeAndClose(). | 517 // Internal close function used by Close() and RazeAndClose(). |
| 501 // |forced| indicates that orderly-shutdown checks should not apply. | 518 // |forced| indicates that orderly-shutdown checks should not apply. |
| 502 void CloseInternal(bool forced); | 519 void CloseInternal(bool forced); |
| 503 | 520 |
| 504 // Check whether the current thread is allowed to make IO calls, but only | 521 // Check whether the current thread is allowed to make IO calls, but only |
| 505 // if database wasn't open in memory. Function is inlined to be a no-op in | 522 // if database wasn't open in memory. Function is inlined to be a no-op in |
| 506 // official build. | 523 // official build. |
| 507 void AssertIOAllowed() { | 524 void AssertIOAllowed() const { |
| 508 if (!in_memory_) | 525 if (!in_memory_) |
| 509 base::ThreadRestrictions::AssertIOAllowed(); | 526 base::ThreadRestrictions::AssertIOAllowed(); |
| 510 } | 527 } |
| 511 | 528 |
| 512 // Internal helper for DoesTableExist and DoesIndexExist. | 529 // Internal helper for DoesTableExist and DoesIndexExist. |
| 513 bool DoesTableOrIndexExist(const char* name, const char* type) const; | 530 bool DoesTableOrIndexExist(const char* name, const char* type) const; |
| 514 | 531 |
| 515 // Accessors for global error-ignorer, for injecting behavior during tests. | 532 // Accessors for global error-ignorer, for injecting behavior during tests. |
| 516 // See test/scoped_error_ignorer.h. | 533 // See test/scoped_error_ignorer.h. |
| 517 typedef base::Callback<bool(int)> ErrorIgnorerCallback; | 534 typedef base::Callback<bool(int)> ErrorIgnorerCallback; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 base::TimeTicks Now() { | 663 base::TimeTicks Now() { |
| 647 return clock_->Now(); | 664 return clock_->Now(); |
| 648 } | 665 } |
| 649 | 666 |
| 650 // Release page-cache memory if memory-mapped I/O is enabled and the database | 667 // Release page-cache memory if memory-mapped I/O is enabled and the database |
| 651 // was changed. Passing true for |implicit_change_performed| allows | 668 // was changed. Passing true for |implicit_change_performed| allows |
| 652 // overriding the change detection for cases like DDL (CREATE, DROP, etc), | 669 // overriding the change detection for cases like DDL (CREATE, DROP, etc), |
| 653 // which do not participate in the total-rows-changed tracking. | 670 // which do not participate in the total-rows-changed tracking. |
| 654 void ReleaseCacheMemoryIfNeeded(bool implicit_change_performed); | 671 void ReleaseCacheMemoryIfNeeded(bool implicit_change_performed); |
| 655 | 672 |
| 673 // Returns the results of sqlite3_db_filename(), which should match the path |
| 674 // passed to Open(). |
| 675 base::FilePath DbPath() const; |
| 676 |
| 656 // The actual sqlite database. Will be NULL before Init has been called or if | 677 // The actual sqlite database. Will be NULL before Init has been called or if |
| 657 // Init resulted in an error. | 678 // Init resulted in an error. |
| 658 sqlite3* db_; | 679 sqlite3* db_; |
| 659 | 680 |
| 660 // Parameters we'll configure in sqlite before doing anything else. Zero means | 681 // Parameters we'll configure in sqlite before doing anything else. Zero means |
| 661 // use the default value. | 682 // use the default value. |
| 662 int page_size_; | 683 int page_size_; |
| 663 int cache_size_; | 684 int cache_size_; |
| 664 bool exclusive_locking_; | 685 bool exclusive_locking_; |
| 665 bool restrict_to_user_; | 686 bool restrict_to_user_; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 // Source for timing information, provided to allow tests to inject time | 750 // Source for timing information, provided to allow tests to inject time |
| 730 // changes. | 751 // changes. |
| 731 scoped_ptr<TimeSource> clock_; | 752 scoped_ptr<TimeSource> clock_; |
| 732 | 753 |
| 733 DISALLOW_COPY_AND_ASSIGN(Connection); | 754 DISALLOW_COPY_AND_ASSIGN(Connection); |
| 734 }; | 755 }; |
| 735 | 756 |
| 736 } // namespace sql | 757 } // namespace sql |
| 737 | 758 |
| 738 #endif // SQL_CONNECTION_H_ | 759 #endif // SQL_CONNECTION_H_ |
| OLD | NEW |