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

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: Mojo can't get the size, sigh. 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, CollectDiagnosticInfo);
495 FRIEND_TEST_ALL_PREFIXES(SQLConnectionTest, RegisterIntentToUpload);
496
488 // Internal initialize function used by both Init and InitInMemory. The file 497 // 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 498 // 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. 499 // sqlite3_open. The string can also be sqlite's special ":memory:" string.
491 // 500 //
492 // |retry_flag| controls retrying the open if the error callback 501 // |retry_flag| controls retrying the open if the error callback
493 // addressed errors using RazeAndClose(). 502 // addressed errors using RazeAndClose().
494 enum Retry { 503 enum Retry {
495 NO_RETRY = 0, 504 NO_RETRY = 0,
496 RETRY_ON_POISON 505 RETRY_ON_POISON
497 }; 506 };
498 bool OpenInternal(const std::string& file_name, Retry retry_flag); 507 bool OpenInternal(const std::string& file_name, Retry retry_flag);
499 508
500 // Internal close function used by Close() and RazeAndClose(). 509 // Internal close function used by Close() and RazeAndClose().
501 // |forced| indicates that orderly-shutdown checks should not apply. 510 // |forced| indicates that orderly-shutdown checks should not apply.
502 void CloseInternal(bool forced); 511 void CloseInternal(bool forced);
503 512
504 // Check whether the current thread is allowed to make IO calls, but only 513 // 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 514 // if database wasn't open in memory. Function is inlined to be a no-op in
506 // official build. 515 // official build.
507 void AssertIOAllowed() { 516 void AssertIOAllowed() const {
508 if (!in_memory_) 517 if (!in_memory_)
509 base::ThreadRestrictions::AssertIOAllowed(); 518 base::ThreadRestrictions::AssertIOAllowed();
510 } 519 }
511 520
512 // Internal helper for DoesTableExist and DoesIndexExist. 521 // Internal helper for DoesTableExist and DoesIndexExist.
513 bool DoesTableOrIndexExist(const char* name, const char* type) const; 522 bool DoesTableOrIndexExist(const char* name, const char* type) const;
514 523
515 // Accessors for global error-ignorer, for injecting behavior during tests. 524 // Accessors for global error-ignorer, for injecting behavior during tests.
516 // See test/scoped_error_ignorer.h. 525 // See test/scoped_error_ignorer.h.
517 typedef base::Callback<bool(int)> ErrorIgnorerCallback; 526 typedef base::Callback<bool(int)> ErrorIgnorerCallback;
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 base::TimeTicks Now() { 655 base::TimeTicks Now() {
647 return clock_->Now(); 656 return clock_->Now();
648 } 657 }
649 658
650 // Release page-cache memory if memory-mapped I/O is enabled and the database 659 // Release page-cache memory if memory-mapped I/O is enabled and the database
651 // was changed. Passing true for |implicit_change_performed| allows 660 // was changed. Passing true for |implicit_change_performed| allows
652 // overriding the change detection for cases like DDL (CREATE, DROP, etc), 661 // overriding the change detection for cases like DDL (CREATE, DROP, etc),
653 // which do not participate in the total-rows-changed tracking. 662 // which do not participate in the total-rows-changed tracking.
654 void ReleaseCacheMemoryIfNeeded(bool implicit_change_performed); 663 void ReleaseCacheMemoryIfNeeded(bool implicit_change_performed);
655 664
665 // Returns the results of sqlite3_db_filename(), which should match the path
666 // passed to Open().
667 base::FilePath DbPath() const;
668
669 // Helper to prevent uploading too many diagnostic dumps for a given database,
670 // since every dump will likely show the same problem. Returns |true| if this
671 // function was not previously called for this database, and the persistent
672 // storage which tracks state was updated.
673 //
674 // |false| is returned if the function was previously called for this
675 // database, even across restarts. |false| is also returned if the persistent
676 // storage cannot be updated, possibly indicating problems requiring user or
677 // admin intervention, such as filesystem corruption or disk full. |false| is
678 // also returned if the persistent storage contains invalid data or is not
679 // readable.
680 //
681 // TODO(shess): It would make sense to reset the persistent state if the
682 // database is razed or recovered, or if the diagnostic code adds new
683 // capabilities.
684 bool RegisterIntentToUpload() const;
685
686 // Helper to collect diagnostic info for a corrupt database.
687 std::string CollectCorruptionInfo();
688
689 // Helper to collect diagnostic info for errors.
690 std::string CollectErrorInfo(int error, Statement* stmt) const;
691
656 // The actual sqlite database. Will be NULL before Init has been called or if 692 // The actual sqlite database. Will be NULL before Init has been called or if
657 // Init resulted in an error. 693 // Init resulted in an error.
658 sqlite3* db_; 694 sqlite3* db_;
659 695
660 // Parameters we'll configure in sqlite before doing anything else. Zero means 696 // Parameters we'll configure in sqlite before doing anything else. Zero means
661 // use the default value. 697 // use the default value.
662 int page_size_; 698 int page_size_;
663 int cache_size_; 699 int cache_size_;
664 bool exclusive_locking_; 700 bool exclusive_locking_;
665 bool restrict_to_user_; 701 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 765 // Source for timing information, provided to allow tests to inject time
730 // changes. 766 // changes.
731 scoped_ptr<TimeSource> clock_; 767 scoped_ptr<TimeSource> clock_;
732 768
733 DISALLOW_COPY_AND_ASSIGN(Connection); 769 DISALLOW_COPY_AND_ASSIGN(Connection);
734 }; 770 };
735 771
736 } // namespace sql 772 } // namespace sql
737 773
738 #endif // SQL_CONNECTION_H_ 774 #endif // SQL_CONNECTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698