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

Side by Side Diff: sql/connection.cc

Issue 2107493002: Offer user to send feedback from profile error dialog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pkasting's & droger's Created 4 years, 4 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
« no previous file with comments | « sql/connection.h ('k') | sql/error_delegate_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "sql/connection.h" 5 #include "sql/connection.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 // static 236 // static
237 bool Connection::IsExpectedSqliteError(int error) { 237 bool Connection::IsExpectedSqliteError(int error) {
238 if (!current_expecter_cb_) 238 if (!current_expecter_cb_)
239 return false; 239 return false;
240 return current_expecter_cb_->Run(error); 240 return current_expecter_cb_->Run(error);
241 } 241 }
242 242
243 void Connection::ReportDiagnosticInfo(int extended_error, Statement* stmt) { 243 void Connection::ReportDiagnosticInfo(int extended_error, Statement* stmt) {
244 AssertIOAllowed(); 244 AssertIOAllowed();
245 245
246 // Trim extended error codes. 246 std::string debug_info = GetDiagnosticInfo(extended_error, stmt);
247 const int error = (extended_error & 0xFF);
248 std::string debug_info;
249 if (error == SQLITE_CORRUPT) {
250 // CollectCorruptionInfo() is implemented in terms of sql::Connection,
251 // prevent reentrant calls to the error callback.
252 // TODO(shess): Rewrite IntegrityCheckHelper() in terms of raw SQLite.
253 ErrorCallback original_callback = std::move(error_callback_);
254 reset_error_callback();
255
256 debug_info = CollectCorruptionInfo();
257
258 error_callback_ = std::move(original_callback);
259 } else {
260 debug_info = CollectErrorInfo(extended_error, stmt);
261 }
262
263 if (!debug_info.empty() && RegisterIntentToUpload()) { 247 if (!debug_info.empty() && RegisterIntentToUpload()) {
264 char debug_buf[2000]; 248 char debug_buf[2000];
265 base::strlcpy(debug_buf, debug_info.c_str(), arraysize(debug_buf)); 249 base::strlcpy(debug_buf, debug_info.c_str(), arraysize(debug_buf));
266 base::debug::Alias(&debug_buf); 250 base::debug::Alias(&debug_buf);
267 251
268 base::debug::DumpWithoutCrashing(); 252 base::debug::DumpWithoutCrashing();
269 } 253 }
270 } 254 }
271 255
272 // static 256 // static
(...skipping 1642 matching lines...) Expand 10 before | Expand all | Expand 10 after
1915 return IntegrityCheckHelper("PRAGMA integrity_check", messages); 1899 return IntegrityCheckHelper("PRAGMA integrity_check", messages);
1916 } 1900 }
1917 1901
1918 bool Connection::QuickIntegrityCheck() { 1902 bool Connection::QuickIntegrityCheck() {
1919 std::vector<std::string> messages; 1903 std::vector<std::string> messages;
1920 if (!IntegrityCheckHelper("PRAGMA quick_check", &messages)) 1904 if (!IntegrityCheckHelper("PRAGMA quick_check", &messages))
1921 return false; 1905 return false;
1922 return messages.size() == 1 && messages[0] == "ok"; 1906 return messages.size() == 1 && messages[0] == "ok";
1923 } 1907 }
1924 1908
1909 std::string Connection::GetDiagnosticInfo(int extended_error,
1910 Statement* statement) {
1911 // Prevent reentrant calls to the error callback.
1912 ErrorCallback original_callback = std::move(error_callback_);
1913 reset_error_callback();
1914
1915 // Trim extended error codes.
1916 const int error = (extended_error & 0xFF);
1917 // CollectCorruptionInfo() is implemented in terms of sql::Connection,
1918 // TODO(shess): Rewrite IntegrityCheckHelper() in terms of raw SQLite.
1919 std::string result = (error == SQLITE_CORRUPT)
1920 ? CollectCorruptionInfo()
1921 : CollectErrorInfo(extended_error, statement);
1922
1923 // The following queries must be executed after CollectErrorInfo() above, so
1924 // if they result in their own errors, they don't interfere with
1925 // CollectErrorInfo().
1926 const bool has_valid_header =
1927 (ExecuteAndReturnErrorCode("PRAGMA auto_vacuum") == SQLITE_OK);
1928 const bool select_sqlite_master_result =
1929 (ExecuteAndReturnErrorCode("SELECT COUNT(*) FROM sqlite_master") ==
1930 SQLITE_OK);
1931
1932 // Restore the original error callback.
1933 error_callback_ = std::move(original_callback);
1934
1935 base::StringAppendF(&result, "Has valid header: %s\n",
1936 (has_valid_header ? "Yes" : "No"));
1937 base::StringAppendF(&result, "Has valid schema: %s\n",
1938 (select_sqlite_master_result ? "Yes" : "No"));
1939
1940 return result;
1941 }
1942
1925 // TODO(shess): Allow specifying maximum results (default 100 lines). 1943 // TODO(shess): Allow specifying maximum results (default 100 lines).
1926 bool Connection::IntegrityCheckHelper( 1944 bool Connection::IntegrityCheckHelper(
1927 const char* pragma_sql, 1945 const char* pragma_sql,
1928 std::vector<std::string>* messages) { 1946 std::vector<std::string>* messages) {
1929 messages->clear(); 1947 messages->clear();
1930 1948
1931 // This has the side effect of setting SQLITE_RecoveryMode, which 1949 // This has the side effect of setting SQLITE_RecoveryMode, which
1932 // allows SQLite to process through certain cases of corruption. 1950 // allows SQLite to process through certain cases of corruption.
1933 // Failing to set this pragma probably means that the database is 1951 // Failing to set this pragma probably means that the database is
1934 // beyond recovery. 1952 // beyond recovery.
(...skipping 21 matching lines...) Expand all
1956 ignore_result(Execute(kNoWritableSchema)); 1974 ignore_result(Execute(kNoWritableSchema));
1957 1975
1958 return ret; 1976 return ret;
1959 } 1977 }
1960 1978
1961 base::TimeTicks TimeSource::Now() { 1979 base::TimeTicks TimeSource::Now() {
1962 return base::TimeTicks::Now(); 1980 return base::TimeTicks::Now();
1963 } 1981 }
1964 1982
1965 } // namespace sql 1983 } // namespace sql
OLDNEW
« no previous file with comments | « sql/connection.h ('k') | sql/error_delegate_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698