summaryrefslogtreecommitdiffstats
path: root/third_party
diff options
context:
space:
mode:
authordgrogan@chromium.org <dgrogan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-31 00:37:45 +0000
committerdgrogan@chromium.org <dgrogan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-31 00:37:45 +0000
commit16880766bbb9a56837340d331db7727a401565fd (patch)
tree91b1c89dc01466b72129e2371ba9e60ad416451c /third_party
parent305ecfc7fa649d5cde58a33db615461fe161382d (diff)
downloadchromium_src-16880766bbb9a56837340d331db7727a401565fd.zip
chromium_src-16880766bbb9a56837340d331db7727a401565fd.tar.gz
chromium_src-16880766bbb9a56837340d331db7727a401565fd.tar.bz2
IndexedDB: refactor corruption-message parsing into its own function.
BUG=311874 R=jsbell@chromium.org Review URL: https://codereview.chromium.org/46573002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@231958 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party')
-rw-r--r--third_party/leveldatabase/env_chromium.cc60
-rw-r--r--third_party/leveldatabase/env_chromium.h2
2 files changed, 62 insertions, 0 deletions
diff --git a/third_party/leveldatabase/env_chromium.cc b/third_party/leveldatabase/env_chromium.cc
index ca8464b..961ad63 100644
--- a/third_party/leveldatabase/env_chromium.cc
+++ b/third_party/leveldatabase/env_chromium.cc
@@ -390,6 +390,66 @@ ErrorParsingResult ParseMethodAndError(const char* string,
return NONE;
}
+// Keep in sync with LevelDBCorruptionTypes in histograms.xml. Also, don't
+// change the order because indices into this array have been recorded in uma
+// histograms.
+const char* patterns[] = {
+ "missing files",
+ "log record too small",
+ "corrupted internal key",
+ "partial record",
+ "missing start of fragmented record",
+ "error in middle of record",
+ "unknown record type",
+ "truncated record at end",
+ "bad record length",
+ "VersionEdit",
+ "FileReader invoked with unexpected value",
+ "corrupted key",
+ "CURRENT file does not end with newline",
+ "no meta-nextfile entry",
+ "no meta-lognumber entry",
+ "no last-sequence-number entry",
+ "malformed WriteBatch",
+ "bad WriteBatch Put",
+ "bad WriteBatch Delete",
+ "unknown WriteBatch tag",
+ "WriteBatch has wrong count",
+ "bad entry in block",
+ "bad block contents",
+ "bad block handle",
+ "truncated block read",
+ "block checksum mismatch",
+ "checksum mismatch",
+ "corrupted compressed block contents",
+ "bad block type",
+ "bad magic number",
+ "file is too short",
+};
+
+// Returns 1-based index into the above array or 0 if nothing matches.
+int ParseCorruptionMessage(const leveldb::Status& status) {
+ DCHECK(!status.IsIOError());
+ DCHECK(!status.ok());
+ const int kOtherError = 0;
+ int error = kOtherError;
+ const std::string& str_error = status.ToString();
+ const size_t kNumPatterns = arraysize(patterns);
+ for (size_t i = 0; i < kNumPatterns; ++i) {
+ if (str_error.find(patterns[i]) != std::string::npos) {
+ error = i + 1;
+ break;
+ }
+ }
+ return error;
+}
+
+int GetNumCorruptionPatterns() {
+ // + 1 for the "other" error that is returned when a corruption message
+ // doesn't match any of the patterns.
+ return arraysize(patterns) + 1;
+}
+
bool IndicatesDiskFull(leveldb::Status status) {
if (status.ok())
return false;
diff --git a/third_party/leveldatabase/env_chromium.h b/third_party/leveldatabase/env_chromium.h
index 3afd462..e171cbda 100644
--- a/third_party/leveldatabase/env_chromium.h
+++ b/third_party/leveldatabase/env_chromium.h
@@ -69,6 +69,8 @@ enum ErrorParsingResult {
ErrorParsingResult ParseMethodAndError(const char* string,
MethodID* method,
int* error);
+int ParseCorruptionMessage(const leveldb::Status& status);
+int GetNumCorruptionPatterns();
bool IndicatesDiskFull(leveldb::Status status);
bool IsIOError(leveldb::Status status);
std::string FilePathToString(const base::FilePath& file_path);