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 <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <map> | 10 #include <map> |
11 #include <set> | 11 #include <set> |
12 #include <string> | 12 #include <string> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/callback.h" | 15 #include "base/callback.h" |
16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
17 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
20 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
21 #include "base/threading/thread_restrictions.h" | 21 #include "base/threading/thread_restrictions.h" |
22 #include "base/time/time.h" | 22 #include "base/time/time.h" |
23 #include "base/trace_event/memory_dump_provider.h" | |
24 #include "sql/sql_export.h" | 23 #include "sql/sql_export.h" |
25 | 24 |
26 struct sqlite3; | 25 struct sqlite3; |
27 struct sqlite3_stmt; | 26 struct sqlite3_stmt; |
28 | 27 |
29 namespace base { | 28 namespace base { |
30 class FilePath; | 29 class FilePath; |
31 class HistogramBase; | 30 class HistogramBase; |
32 } | 31 } |
33 | 32 |
34 namespace sql { | 33 namespace sql { |
35 | 34 |
| 35 class ConnectionMemoryDumpProvider; |
36 class Recovery; | 36 class Recovery; |
37 class Statement; | 37 class Statement; |
38 | 38 |
39 // To allow some test classes to be friended. | 39 // To allow some test classes to be friended. |
40 namespace test { | 40 namespace test { |
41 class ScopedCommitHook; | 41 class ScopedCommitHook; |
42 class ScopedScalarFunction; | 42 class ScopedScalarFunction; |
43 class ScopedMockTimeSource; | 43 class ScopedMockTimeSource; |
44 } | 44 } |
45 | 45 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 TimeSource() {} | 98 TimeSource() {} |
99 virtual ~TimeSource() {} | 99 virtual ~TimeSource() {} |
100 | 100 |
101 // Return the current time (by default base::TimeTicks::Now()). | 101 // Return the current time (by default base::TimeTicks::Now()). |
102 virtual base::TimeTicks Now(); | 102 virtual base::TimeTicks Now(); |
103 | 103 |
104 private: | 104 private: |
105 DISALLOW_COPY_AND_ASSIGN(TimeSource); | 105 DISALLOW_COPY_AND_ASSIGN(TimeSource); |
106 }; | 106 }; |
107 | 107 |
108 class SQL_EXPORT Connection : public base::trace_event::MemoryDumpProvider { | 108 class SQL_EXPORT Connection { |
109 private: | 109 private: |
110 class StatementRef; // Forward declaration, see real one below. | 110 class StatementRef; // Forward declaration, see real one below. |
111 | 111 |
112 public: | 112 public: |
113 // The database is opened by calling Open[InMemory](). Any uncommitted | 113 // The database is opened by calling Open[InMemory](). Any uncommitted |
114 // transactions will be rolled back when this object is deleted. | 114 // transactions will be rolled back when this object is deleted. |
115 Connection(); | 115 Connection(); |
116 ~Connection() override; | 116 ~Connection(); |
117 | 117 |
118 // Pre-init configuration ---------------------------------------------------- | 118 // Pre-init configuration ---------------------------------------------------- |
119 | 119 |
120 // Sets the page size that will be used when creating a new database. This | 120 // Sets the page size that will be used when creating a new database. This |
121 // must be called before Init(), and will only have an effect on new | 121 // must be called before Init(), and will only have an effect on new |
122 // databases. | 122 // databases. |
123 // | 123 // |
124 // From sqlite.org: "The page size must be a power of two greater than or | 124 // From sqlite.org: "The page size must be a power of two greater than or |
125 // equal to 512 and less than or equal to SQLITE_MAX_PAGE_SIZE. The maximum | 125 // equal to 512 and less than or equal to SQLITE_MAX_PAGE_SIZE. The maximum |
126 // value for SQLITE_MAX_PAGE_SIZE is 32768." | 126 // value for SQLITE_MAX_PAGE_SIZE is 32768." |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 // Clients which provide an error_callback don't see the | 477 // Clients which provide an error_callback don't see the |
478 // error-handling at the end of OnSqliteError(). Expose to allow | 478 // error-handling at the end of OnSqliteError(). Expose to allow |
479 // those clients to work appropriately with ScopedErrorIgnorer in | 479 // those clients to work appropriately with ScopedErrorIgnorer in |
480 // tests. | 480 // tests. |
481 static bool ShouldIgnoreSqliteError(int error); | 481 static bool ShouldIgnoreSqliteError(int error); |
482 | 482 |
483 // Additionally ignores errors which are unlikely to be caused by problems | 483 // Additionally ignores errors which are unlikely to be caused by problems |
484 // with the syntax of a SQL statement, or problems with the database schema. | 484 // with the syntax of a SQL statement, or problems with the database schema. |
485 static bool ShouldIgnoreSqliteCompileError(int error); | 485 static bool ShouldIgnoreSqliteCompileError(int error); |
486 | 486 |
487 // base::trace_event::MemoryDumpProvider implementation. | |
488 bool OnMemoryDump( | |
489 const base::trace_event::MemoryDumpArgs& args, | |
490 base::trace_event::ProcessMemoryDump* process_memory_dump) override; | |
491 | |
492 // Collect various diagnostic information and post a crash dump to aid | 487 // Collect various diagnostic information and post a crash dump to aid |
493 // debugging. Dump rate per database is limited to prevent overwhelming the | 488 // debugging. Dump rate per database is limited to prevent overwhelming the |
494 // crash server. | 489 // crash server. |
495 void ReportDiagnosticInfo(int extended_error, Statement* stmt); | 490 void ReportDiagnosticInfo(int extended_error, Statement* stmt); |
496 | 491 |
497 private: | 492 private: |
498 // For recovery module. | 493 // For recovery module. |
499 friend class Recovery; | 494 friend class Recovery; |
500 | 495 |
501 // Allow test-support code to set/reset error ignorer. | 496 // Allow test-support code to set/reset error ignorer. |
502 friend class ScopedErrorIgnorer; | 497 friend class ScopedErrorIgnorer; |
503 | 498 |
504 // Statement accesses StatementRef which we don't want to expose to everybody | 499 // Statement accesses StatementRef which we don't want to expose to everybody |
505 // (they should go through Statement). | 500 // (they should go through Statement). |
506 friend class Statement; | 501 friend class Statement; |
507 | 502 |
508 friend class test::ScopedCommitHook; | 503 friend class test::ScopedCommitHook; |
509 friend class test::ScopedScalarFunction; | 504 friend class test::ScopedScalarFunction; |
510 friend class test::ScopedMockTimeSource; | 505 friend class test::ScopedMockTimeSource; |
511 | 506 |
512 FRIEND_TEST_ALL_PREFIXES(SQLConnectionTest, CollectDiagnosticInfo); | 507 FRIEND_TEST_ALL_PREFIXES(SQLConnectionTest, CollectDiagnosticInfo); |
513 FRIEND_TEST_ALL_PREFIXES(SQLConnectionTest, GetAppropriateMmapSize); | 508 FRIEND_TEST_ALL_PREFIXES(SQLConnectionTest, GetAppropriateMmapSize); |
| 509 FRIEND_TEST_ALL_PREFIXES(SQLConnectionTest, OnMemoryDump); |
514 FRIEND_TEST_ALL_PREFIXES(SQLConnectionTest, RegisterIntentToUpload); | 510 FRIEND_TEST_ALL_PREFIXES(SQLConnectionTest, RegisterIntentToUpload); |
515 | 511 |
516 // Internal initialize function used by both Init and InitInMemory. The file | 512 // Internal initialize function used by both Init and InitInMemory. The file |
517 // name is always 8 bits since we want to use the 8-bit version of | 513 // name is always 8 bits since we want to use the 8-bit version of |
518 // sqlite3_open. The string can also be sqlite's special ":memory:" string. | 514 // sqlite3_open. The string can also be sqlite's special ":memory:" string. |
519 // | 515 // |
520 // |retry_flag| controls retrying the open if the error callback | 516 // |retry_flag| controls retrying the open if the error callback |
521 // addressed errors using RazeAndClose(). | 517 // addressed errors using RazeAndClose(). |
522 enum Retry { | 518 enum Retry { |
523 NO_RETRY = 0, | 519 NO_RETRY = 0, |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 // autocommit). | 784 // autocommit). |
789 base::HistogramBase* update_time_histogram_; | 785 base::HistogramBase* update_time_histogram_; |
790 | 786 |
791 // Histogram for tracking time taken in all queries. | 787 // Histogram for tracking time taken in all queries. |
792 base::HistogramBase* query_time_histogram_; | 788 base::HistogramBase* query_time_histogram_; |
793 | 789 |
794 // Source for timing information, provided to allow tests to inject time | 790 // Source for timing information, provided to allow tests to inject time |
795 // changes. | 791 // changes. |
796 scoped_ptr<TimeSource> clock_; | 792 scoped_ptr<TimeSource> clock_; |
797 | 793 |
| 794 // Stores the dump provider object when db is open. |
| 795 scoped_ptr<ConnectionMemoryDumpProvider> memory_dump_provider_; |
| 796 |
798 DISALLOW_COPY_AND_ASSIGN(Connection); | 797 DISALLOW_COPY_AND_ASSIGN(Connection); |
799 }; | 798 }; |
800 | 799 |
801 } // namespace sql | 800 } // namespace sql |
802 | 801 |
803 #endif // SQL_CONNECTION_H_ | 802 #endif // SQL_CONNECTION_H_ |
OLD | NEW |