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

Side by Side Diff: sql/connection.h

Issue 1393393007: [sql] Track uploads of diagnostic data to prevent duplication. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Shift diagnostic generation and reporting to sql::Connection. Created 5 years, 2 months 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
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>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
16 #include "base/gtest_prod_util.h"
16 #include "base/macros.h" 17 #include "base/macros.h"
17 #include "base/memory/ref_counted.h" 18 #include "base/memory/ref_counted.h"
18 #include "base/memory/scoped_ptr.h" 19 #include "base/memory/scoped_ptr.h"
19 #include "base/threading/thread_restrictions.h" 20 #include "base/threading/thread_restrictions.h"
20 #include "base/time/time.h" 21 #include "base/time/time.h"
21 #include "base/trace_event/memory_dump_provider.h" 22 #include "base/trace_event/memory_dump_provider.h"
22 #include "sql/sql_export.h" 23 #include "sql/sql_export.h"
23 24
24 struct sqlite3; 25 struct sqlite3;
25 struct sqlite3_stmt; 26 struct sqlite3_stmt;
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 // error-handling at the end of OnSqliteError(). Expose to allow 464 // error-handling at the end of OnSqliteError(). Expose to allow
464 // those clients to work appropriately with ScopedErrorIgnorer in 465 // those clients to work appropriately with ScopedErrorIgnorer in
465 // tests. 466 // tests.
466 static bool ShouldIgnoreSqliteError(int error); 467 static bool ShouldIgnoreSqliteError(int error);
467 468
468 // base::trace_event::MemoryDumpProvider implementation. 469 // base::trace_event::MemoryDumpProvider implementation.
469 bool OnMemoryDump( 470 bool OnMemoryDump(
470 const base::trace_event::MemoryDumpArgs& args, 471 const base::trace_event::MemoryDumpArgs& args,
471 base::trace_event::ProcessMemoryDump* process_memory_dump) override; 472 base::trace_event::ProcessMemoryDump* process_memory_dump) override;
472 473
474 // Collect various diagnostic information and post a crash dump to aid
475 // debugging. Dump rate per database is limited to prevent overwhelming the
476 // crash server.
477 void ReportDiagnosticInfo(int extended_error, Statement* stmt);
478
473 private: 479 private:
474 // For recovery module. 480 // For recovery module.
475 friend class Recovery; 481 friend class Recovery;
476 482
477 // Allow test-support code to set/reset error ignorer. 483 // Allow test-support code to set/reset error ignorer.
478 friend class ScopedErrorIgnorer; 484 friend class ScopedErrorIgnorer;
479 485
480 // Statement accesses StatementRef which we don't want to expose to everybody 486 // Statement accesses StatementRef which we don't want to expose to everybody
481 // (they should go through Statement). 487 // (they should go through Statement).
482 friend class Statement; 488 friend class Statement;
483 489
484 friend class test::ScopedCommitHook; 490 friend class test::ScopedCommitHook;
485 friend class test::ScopedScalarFunction; 491 friend class test::ScopedScalarFunction;
486 friend class test::ScopedMockTimeSource; 492 friend class test::ScopedMockTimeSource;
487 493
494 FRIEND_TEST_ALL_PREFIXES(SQLConnectionTest, RegisterIntentToUpload);
495
488 // Internal initialize function used by both Init and InitInMemory. The file 496 // Internal initialize function used by both Init and InitInMemory. The file
489 // name is always 8 bits since we want to use the 8-bit version of 497 // name is always 8 bits since we want to use the 8-bit version of
490 // sqlite3_open. The string can also be sqlite's special ":memory:" string. 498 // sqlite3_open. The string can also be sqlite's special ":memory:" string.
491 // 499 //
492 // |retry_flag| controls retrying the open if the error callback 500 // |retry_flag| controls retrying the open if the error callback
493 // addressed errors using RazeAndClose(). 501 // addressed errors using RazeAndClose().
494 enum Retry { 502 enum Retry {
495 NO_RETRY = 0, 503 NO_RETRY = 0,
496 RETRY_ON_POISON 504 RETRY_ON_POISON
497 }; 505 };
498 bool OpenInternal(const std::string& file_name, Retry retry_flag); 506 bool OpenInternal(const std::string& file_name, Retry retry_flag);
499 507
500 // Internal close function used by Close() and RazeAndClose(). 508 // Internal close function used by Close() and RazeAndClose().
501 // |forced| indicates that orderly-shutdown checks should not apply. 509 // |forced| indicates that orderly-shutdown checks should not apply.
502 void CloseInternal(bool forced); 510 void CloseInternal(bool forced);
503 511
504 // Check whether the current thread is allowed to make IO calls, but only 512 // 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 513 // if database wasn't open in memory. Function is inlined to be a no-op in
506 // official build. 514 // official build.
507 void AssertIOAllowed() { 515 void AssertIOAllowed() const {
Scott Hess - ex-Googler 2015/10/19 22:23:41 So it can be used from const methods.
508 if (!in_memory_) 516 if (!in_memory_)
509 base::ThreadRestrictions::AssertIOAllowed(); 517 base::ThreadRestrictions::AssertIOAllowed();
510 } 518 }
511 519
512 // Internal helper for DoesTableExist and DoesIndexExist. 520 // Internal helper for DoesTableExist and DoesIndexExist.
513 bool DoesTableOrIndexExist(const char* name, const char* type) const; 521 bool DoesTableOrIndexExist(const char* name, const char* type) const;
514 522
515 // Accessors for global error-ignorer, for injecting behavior during tests. 523 // Accessors for global error-ignorer, for injecting behavior during tests.
516 // See test/scoped_error_ignorer.h. 524 // See test/scoped_error_ignorer.h.
517 typedef base::Callback<bool(int)> ErrorIgnorerCallback; 525 typedef base::Callback<bool(int)> ErrorIgnorerCallback;
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 base::TimeTicks Now() { 654 base::TimeTicks Now() {
647 return clock_->Now(); 655 return clock_->Now();
648 } 656 }
649 657
650 // Release page-cache memory if memory-mapped I/O is enabled and the database 658 // Release page-cache memory if memory-mapped I/O is enabled and the database
651 // was changed. Passing true for |implicit_change_performed| allows 659 // was changed. Passing true for |implicit_change_performed| allows
652 // overriding the change detection for cases like DDL (CREATE, DROP, etc), 660 // overriding the change detection for cases like DDL (CREATE, DROP, etc),
653 // which do not participate in the total-rows-changed tracking. 661 // which do not participate in the total-rows-changed tracking.
654 void ReleaseCacheMemoryIfNeeded(bool implicit_change_performed); 662 void ReleaseCacheMemoryIfNeeded(bool implicit_change_performed);
655 663
664 // Returns the results of sqlite3_db_filename(), which should match the path
665 // passed to Open().
666 base::FilePath DbPath() const;
667
668 // Helper to prevent uploading too many diagnostic dumps for a given database,
669 // since every dump will likely show the same problem. Returns |true| if this
670 // function was not previously called for this database, and the persistent
671 // storage which tracks state was updated.
672 //
673 // |false| is returned if the function was previously called for this
674 // database, even across restarts. |false| is also returned if the persistent
675 // storage cannot be updated, possibly indicating problems requiring user or
676 // admin intervention, such as filesystem corruption or disk full. |false| is
677 // also returned if the persistent storage contains invalid data or is not
678 // readable.
679 //
680 // TODO(shess): It would make sense to reset the persistent state if the
681 // database is razed or recovered, or if the diagnostic code adds new
682 // capabilities.
683 bool RegisterIntentToUpload() const;
684
685 // Helper to collect diagnostic info for a corrupt database.
686 std::string CollectCorruptionInfo();
687
688 // Helper to collect diagnostic info for errors.
689 std::string CollectErrorInfo(int error, Statement* stmt) const;
690
656 // The actual sqlite database. Will be NULL before Init has been called or if 691 // The actual sqlite database. Will be NULL before Init has been called or if
657 // Init resulted in an error. 692 // Init resulted in an error.
658 sqlite3* db_; 693 sqlite3* db_;
659 694
660 // Parameters we'll configure in sqlite before doing anything else. Zero means 695 // Parameters we'll configure in sqlite before doing anything else. Zero means
661 // use the default value. 696 // use the default value.
662 int page_size_; 697 int page_size_;
663 int cache_size_; 698 int cache_size_;
664 bool exclusive_locking_; 699 bool exclusive_locking_;
665 bool restrict_to_user_; 700 bool restrict_to_user_;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 // Source for timing information, provided to allow tests to inject time 764 // Source for timing information, provided to allow tests to inject time
730 // changes. 765 // changes.
731 scoped_ptr<TimeSource> clock_; 766 scoped_ptr<TimeSource> clock_;
732 767
733 DISALLOW_COPY_AND_ASSIGN(Connection); 768 DISALLOW_COPY_AND_ASSIGN(Connection);
734 }; 769 };
735 770
736 } // namespace sql 771 } // namespace sql
737 772
738 #endif // SQL_CONNECTION_H_ 773 #endif // SQL_CONNECTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698