diff --git a/browser/base/content/tabbrowser.xml b/browser/base/content/tabbrowser.xml index 4013a5a6954..6f4558d2187 100644 --- a/browser/base/content/tabbrowser.xml +++ b/browser/base/content/tabbrowser.xml @@ -4723,7 +4723,7 @@ mDatabasePerProfile; protected Context mContext = null; private final String mLogTag; @@ -43,6 +45,42 @@ public abstract class SQLiteBridgeContentProvider extends ContentProvider { mLogTag = logTag; } + /** + * Subclasses must override this to allow error reporting code to compose + * the correct histogram name. + * + * Ensure that you define the new histograms if you define a new class! + */ + protected abstract String getTelemetryPrefix(); + + /** + * Errors are recorded in telemetry using an enumerated histogram. + * + * + * + * These are the allowable enumeration values. Keep these in sync with the + * histogram definition! + * + */ + private static enum TelemetryErrorOp { + BULKINSERT (0), + DELETE (1), + INSERT (2), + QUERY (3), + UPDATE (4); + + private final int bucket; + + TelemetryErrorOp(final int bucket) { + this.bucket = bucket; + } + + public int getBucket() { + return bucket; + } + } + @Override public void shutdown() { if (mDatabasePerProfile == null) { @@ -255,7 +293,7 @@ public abstract class SQLiteBridgeContentProvider extends ContentProvider { try { deleted = db.delete(getTable(uri), selection, selectionArgs); } catch (SQLiteBridgeException ex) { - Log.e(mLogTag, "Error deleting record", ex); + reportError(ex, TelemetryErrorOp.DELETE); throw ex; } @@ -291,7 +329,7 @@ public abstract class SQLiteBridgeContentProvider extends ContentProvider { db.setTransactionSuccessful(); } } catch (SQLiteBridgeException ex) { - Log.e(mLogTag, "Error inserting in db", ex); + reportError(ex, TelemetryErrorOp.INSERT); throw ex; } finally { if (useTransaction) { @@ -312,7 +350,6 @@ public abstract class SQLiteBridgeContentProvider extends ContentProvider { return 0; } - long id = -1; int rowsAdded = 0; String table = getTable(uri); @@ -323,12 +360,12 @@ public abstract class SQLiteBridgeContentProvider extends ContentProvider { ContentValues values = new ContentValues(initialValues); setupDefaults(uri, values); onPreInsert(values, uri, db); - id = db.insert(table, null, values); + db.insert(table, null, values); rowsAdded++; } db.setTransactionSuccessful(); } catch (SQLiteBridgeException ex) { - Log.e(mLogTag, "Error inserting in db", ex); + reportError(ex, TelemetryErrorOp.BULKINSERT); throw ex; } finally { db.endTransaction(); @@ -360,7 +397,7 @@ public abstract class SQLiteBridgeContentProvider extends ContentProvider { try { updated = db.update(getTable(uri), values, selection, selectionArgs); } catch (SQLiteBridgeException ex) { - Log.e(mLogTag, "Error updating table", ex); + reportError(ex, TelemetryErrorOp.UPDATE); throw ex; } @@ -386,13 +423,32 @@ public abstract class SQLiteBridgeContentProvider extends ContentProvider { cursor = db.query(getTable(uri), projection, selection, selectionArgs, null, null, sortOrder, null); onPostQuery(cursor, uri, db); } catch (SQLiteBridgeException ex) { - Log.e(mLogTag, "Error querying database", ex); + reportError(ex, TelemetryErrorOp.QUERY); throw ex; } return cursor; } + private String getHistogram(SQLiteBridgeException e) { + // If you add values here, make sure to update + // toolkit/components/telemetry/Histograms.json. + if (ERROR_MESSAGE_DATABASE_IS_LOCKED.equals(e.getMessage())) { + return getTelemetryPrefix() + "_LOCKED"; + } + return null; + } + + protected void reportError(SQLiteBridgeException e, TelemetryErrorOp op) { + Log.e(mLogTag, "Error in database " + op.name(), e); + final String histogram = getHistogram(e); + if (histogram == null) { + return; + } + + Telemetry.HistogramAdd(histogram, op.getBucket()); + } + protected abstract String getDBName(); protected abstract int getDBVersion(); diff --git a/toolkit/components/telemetry/Histograms.json b/toolkit/components/telemetry/Histograms.json index 357c6b7312c..a3685f93a74 100644 --- a/toolkit/components/telemetry/Histograms.json +++ b/toolkit/components/telemetry/Histograms.json @@ -5908,6 +5908,24 @@ "extended_statistics_ok": true, "description": "Time spent to open an existing cache entry" }, + "SQLITEBRIDGE_PROVIDER_PASSWORDS_LOCKED": { + "expires_in_version": "never", + "kind": "enumerated", + "n_values": "10", + "description": "The number of errors using the PasswordsProvider due to a locked DB." + }, + "SQLITEBRIDGE_PROVIDER_FORMS_LOCKED": { + "expires_in_version": "never", + "kind": "enumerated", + "n_values": "10", + "description": "The number of errors using the FormHistoryProvider due to a locked DB." + }, + "SQLITEBRIDGE_PROVIDER_HOME_LOCKED": { + "expires_in_version": "never", + "kind": "enumerated", + "n_values": "10", + "description": "The number of errors using the HomeProvider due to a locked DB." + }, "SSL_TLS12_INTOLERANCE_REASON_PRE": { "expires_in_version": "never", "kind": "enumerated",