Offer user to send feedback from profile error dialog

This CL makes the following:
- Improves the wording of the profile error dialog so as not to confuse users
- Adds a checkbox to offer the user to send a feedback report.
- Prepopulates the feedback description to ask the user what happened, and to
  add more debugging info (currently the name of the corrupted file).
- File the profile-error feedback reports under a category with name
  "FEEDBACK_PROFILE_ERROR"

Screenshots:
- Profile error dialog: https://drive.google.com/a/google.com/file/d/0B6G_-uQnf1_La0tBU2RWTEdXQ28/view?usp=sharing
- Prepopulated feedback app - 1: https://drive.google.com/a/google.com/file/d/0B6G_-uQnf1_LZ19obE1Xa0hNSEE/view?usp=sharing
- Prepopulated feedback app - 2: https://drive.google.com/a/google.com/file/d/0B6G_-uQnf1_LZFc4WjdxcjFwN28/view?usp=sharing

BUG=455749

Review-Url: https://codereview.chromium.org/2107493002
Cr-Commit-Position: refs/heads/master@{#410094}
diff --git a/sql/connection.cc b/sql/connection.cc
index ab842666..9c7cb7d 100644
--- a/sql/connection.cc
+++ b/sql/connection.cc
@@ -243,23 +243,7 @@
 void Connection::ReportDiagnosticInfo(int extended_error, Statement* stmt) {
   AssertIOAllowed();
 
-  // Trim extended error codes.
-  const int error = (extended_error & 0xFF);
-  std::string debug_info;
-  if (error == SQLITE_CORRUPT) {
-    // CollectCorruptionInfo() is implemented in terms of sql::Connection,
-    // prevent reentrant calls to the error callback.
-    // TODO(shess): Rewrite IntegrityCheckHelper() in terms of raw SQLite.
-    ErrorCallback original_callback = std::move(error_callback_);
-    reset_error_callback();
-
-    debug_info = CollectCorruptionInfo();
-
-    error_callback_ = std::move(original_callback);
-  } else {
-    debug_info = CollectErrorInfo(extended_error, stmt);
-  }
-
+  std::string debug_info = GetDiagnosticInfo(extended_error, stmt);
   if (!debug_info.empty() && RegisterIntentToUpload()) {
     char debug_buf[2000];
     base::strlcpy(debug_buf, debug_info.c_str(), arraysize(debug_buf));
@@ -1922,6 +1906,40 @@
   return messages.size() == 1 && messages[0] == "ok";
 }
 
+std::string Connection::GetDiagnosticInfo(int extended_error,
+                                          Statement* statement) {
+  // Prevent reentrant calls to the error callback.
+  ErrorCallback original_callback = std::move(error_callback_);
+  reset_error_callback();
+
+  // Trim extended error codes.
+  const int error = (extended_error & 0xFF);
+  // CollectCorruptionInfo() is implemented in terms of sql::Connection,
+  // TODO(shess): Rewrite IntegrityCheckHelper() in terms of raw SQLite.
+  std::string result = (error == SQLITE_CORRUPT)
+                           ? CollectCorruptionInfo()
+                           : CollectErrorInfo(extended_error, statement);
+
+  // The following queries must be executed after CollectErrorInfo() above, so
+  // if they result in their own errors, they don't interfere with
+  // CollectErrorInfo().
+  const bool has_valid_header =
+      (ExecuteAndReturnErrorCode("PRAGMA auto_vacuum") == SQLITE_OK);
+  const bool select_sqlite_master_result =
+      (ExecuteAndReturnErrorCode("SELECT COUNT(*) FROM sqlite_master") ==
+       SQLITE_OK);
+
+  // Restore the original error callback.
+  error_callback_ = std::move(original_callback);
+
+  base::StringAppendF(&result, "Has valid header: %s\n",
+                      (has_valid_header ? "Yes" : "No"));
+  base::StringAppendF(&result, "Has valid schema: %s\n",
+                      (select_sqlite_master_result ? "Yes" : "No"));
+
+  return result;
+}
+
 // TODO(shess): Allow specifying maximum results (default 100 lines).
 bool Connection::IntegrityCheckHelper(
     const char* pragma_sql,