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

Side by Side Diff: third_party/leveldatabase/env_chromium.cc

Issue 805043006: IndexedDB: ParseMethodAndError takes a leveldb::Status instance. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: str -> status_string Created 6 years 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) 2011 The LevelDB Authors. All rights reserved. 1 // Copyright (c) 2011 The LevelDB 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. See the AUTHORS file for names of contributors. 3 // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 4
5 #include "third_party/leveldatabase/env_chromium.h" 5 #include "third_party/leveldatabase/env_chromium.h"
6 6
7 #if defined(OS_POSIX) 7 #if defined(OS_POSIX)
8 #include <dirent.h> 8 #include <dirent.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 #endif 10 #endif
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 401
402 Status MakeIOError(Slice filename, 402 Status MakeIOError(Slice filename,
403 const std::string& message, 403 const std::string& message,
404 MethodID method) { 404 MethodID method) {
405 char buf[512]; 405 char buf[512];
406 snprintf(buf, sizeof(buf), "%s (ChromeMethodOnly: %d::%s)", message.c_str(), 406 snprintf(buf, sizeof(buf), "%s (ChromeMethodOnly: %d::%s)", message.c_str(),
407 method, MethodIDToString(method)); 407 method, MethodIDToString(method));
408 return Status::IOError(filename, buf); 408 return Status::IOError(filename, buf);
409 } 409 }
410 410
411 ErrorParsingResult ParseMethodAndError(const char* string, 411 ErrorParsingResult ParseMethodAndError(const leveldb::Status& status,
412 MethodID* method_param, 412 MethodID* method_param,
413 int* error) { 413 int* error) {
414 const std::string status_string = status.ToString();
414 int method; 415 int method;
415 if (RE2::PartialMatch(string, "ChromeMethodOnly: (\\d+)", &method)) { 416 if (RE2::PartialMatch(status_string.c_str(), "ChromeMethodOnly: (\\d+)",
417 &method)) {
416 *method_param = static_cast<MethodID>(method); 418 *method_param = static_cast<MethodID>(method);
417 return METHOD_ONLY; 419 return METHOD_ONLY;
418 } 420 }
419 if (RE2::PartialMatch( 421 if (RE2::PartialMatch(status_string.c_str(),
420 string, "ChromeMethodPFE: (\\d+)::.*::(\\d+)", &method, error)) { 422 "ChromeMethodPFE: (\\d+)::.*::(\\d+)", &method,
423 error)) {
421 *error = -*error; 424 *error = -*error;
422 *method_param = static_cast<MethodID>(method); 425 *method_param = static_cast<MethodID>(method);
423 return METHOD_AND_PFE; 426 return METHOD_AND_PFE;
424 } 427 }
425 if (RE2::PartialMatch( 428 if (RE2::PartialMatch(status_string.c_str(),
426 string, "ChromeMethodErrno: (\\d+)::.*::(\\d+)", &method, error)) { 429 "ChromeMethodErrno: (\\d+)::.*::(\\d+)", &method,
430 error)) {
427 *method_param = static_cast<MethodID>(method); 431 *method_param = static_cast<MethodID>(method);
428 return METHOD_AND_ERRNO; 432 return METHOD_AND_ERRNO;
429 } 433 }
430 return NONE; 434 return NONE;
431 } 435 }
432 436
433 // Keep in sync with LevelDBCorruptionTypes in histograms.xml. Also, don't 437 // Keep in sync with LevelDBCorruptionTypes in histograms.xml. Also, don't
434 // change the order because indices into this array have been recorded in uma 438 // change the order because indices into this array have been recorded in uma
435 // histograms. 439 // histograms.
436 const char* patterns[] = { 440 const char* patterns[] = {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 if (code == 0) 499 if (code == 0)
496 return "Unknown corruption"; 500 return "Unknown corruption";
497 return patterns[code - 1]; 501 return patterns[code - 1];
498 } 502 }
499 503
500 bool IndicatesDiskFull(const leveldb::Status& status) { 504 bool IndicatesDiskFull(const leveldb::Status& status) {
501 if (status.ok()) 505 if (status.ok())
502 return false; 506 return false;
503 leveldb_env::MethodID method; 507 leveldb_env::MethodID method;
504 int error = -1; 508 int error = -1;
505 leveldb_env::ErrorParsingResult result = leveldb_env::ParseMethodAndError( 509 leveldb_env::ErrorParsingResult result =
506 status.ToString().c_str(), &method, &error); 510 leveldb_env::ParseMethodAndError(status, &method, &error);
507 return (result == leveldb_env::METHOD_AND_PFE && 511 return (result == leveldb_env::METHOD_AND_PFE &&
508 static_cast<base::File::Error>(error) == 512 static_cast<base::File::Error>(error) ==
509 base::File::FILE_ERROR_NO_SPACE) || 513 base::File::FILE_ERROR_NO_SPACE) ||
510 (result == leveldb_env::METHOD_AND_ERRNO && error == ENOSPC); 514 (result == leveldb_env::METHOD_AND_ERRNO && error == ENOSPC);
511 } 515 }
512 516
513 bool IsIOError(const leveldb::Status& status) { 517 bool IsIOError(const leveldb::Status& status) {
514 leveldb_env::MethodID method; 518 leveldb_env::MethodID method;
515 int error = -1; 519 int error = -1;
516 leveldb_env::ErrorParsingResult result = leveldb_env::ParseMethodAndError( 520 leveldb_env::ErrorParsingResult result =
517 status.ToString().c_str(), &method, &error); 521 leveldb_env::ParseMethodAndError(status, &method, &error);
518 return result != leveldb_env::NONE; 522 return result != leveldb_env::NONE;
519 } 523 }
520 524
521 bool ChromiumEnv::MakeBackup(const std::string& fname) { 525 bool ChromiumEnv::MakeBackup(const std::string& fname) {
522 FilePath original_table_name = FilePath::FromUTF8Unsafe(fname); 526 FilePath original_table_name = FilePath::FromUTF8Unsafe(fname);
523 FilePath backup_table_name = 527 FilePath backup_table_name =
524 original_table_name.ReplaceExtension(backup_table_extension); 528 original_table_name.ReplaceExtension(backup_table_extension);
525 return base::CopyFile(original_table_name, backup_table_name); 529 return base::CopyFile(original_table_name, backup_table_name);
526 } 530 }
527 531
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 1090
1087 Env* IDBEnv() { 1091 Env* IDBEnv() {
1088 return leveldb_env::idb_env.Pointer(); 1092 return leveldb_env::idb_env.Pointer();
1089 } 1093 }
1090 1094
1091 Env* Env::Default() { 1095 Env* Env::Default() {
1092 return leveldb_env::default_env.Pointer(); 1096 return leveldb_env::default_env.Pointer();
1093 } 1097 }
1094 1098
1095 } // namespace leveldb 1099 } // namespace leveldb
OLDNEW
« no previous file with comments | « third_party/leveldatabase/env_chromium.h ('k') | third_party/leveldatabase/env_chromium_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698