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

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

Issue 168833003: Remove uses of PlatformFile from leveldb (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
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 "base/debug/trace_event.h" 5 #include "base/debug/trace_event.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "env_chromium_stdio.h" 10 #include "env_chromium_stdio.h"
(...skipping 14 matching lines...) Expand all
25 25
26 const base::FilePath::CharType backup_table_extension[] = 26 const base::FilePath::CharType backup_table_extension[] =
27 FILE_PATH_LITERAL(".bak"); 27 FILE_PATH_LITERAL(".bak");
28 const base::FilePath::CharType table_extension[] = FILE_PATH_LITERAL(".ldb"); 28 const base::FilePath::CharType table_extension[] = FILE_PATH_LITERAL(".ldb");
29 29
30 static const base::FilePath::CharType kLevelDBTestDirectoryPrefix[] 30 static const base::FilePath::CharType kLevelDBTestDirectoryPrefix[]
31 = FILE_PATH_LITERAL("leveldb-test-"); 31 = FILE_PATH_LITERAL("leveldb-test-");
32 32
33 class ChromiumFileLock : public FileLock { 33 class ChromiumFileLock : public FileLock {
34 public: 34 public:
35 ::base::PlatformFile file_; 35 ::base::File file_;
36 std::string name_; 36 std::string name_;
37 }; 37 };
38 38
39 class Retrier { 39 class Retrier {
40 public: 40 public:
41 Retrier(MethodID method, RetrierProvider* provider) 41 Retrier(MethodID method, RetrierProvider* provider)
42 : start_(base::TimeTicks::Now()), 42 : start_(base::TimeTicks::Now()),
43 limit_(start_ + base::TimeDelta::FromMilliseconds( 43 limit_(start_ + base::TimeDelta::FromMilliseconds(
44 provider->MaxRetryTimeMillis())), 44 provider->MaxRetryTimeMillis())),
45 last_(start_), 45 last_(start_),
46 time_to_sleep_(base::TimeDelta::FromMilliseconds(10)), 46 time_to_sleep_(base::TimeDelta::FromMilliseconds(10)),
47 success_(true), 47 success_(true),
48 method_(method), 48 method_(method),
49 last_error_(base::PLATFORM_FILE_OK), 49 last_error_(base::File::FILE_OK),
50 provider_(provider) {} 50 provider_(provider) {}
51 ~Retrier() { 51 ~Retrier() {
52 if (success_) { 52 if (success_) {
53 provider_->GetRetryTimeHistogram(method_)->AddTime(last_ - start_); 53 provider_->GetRetryTimeHistogram(method_)->AddTime(last_ - start_);
54 if (last_error_ != base::PLATFORM_FILE_OK) { 54 if (last_error_ != base::File::FILE_OK) {
55 DCHECK(last_error_ < 0); 55 DCHECK(last_error_ < 0);
56 provider_->GetRecoveredFromErrorHistogram(method_)->Add(-last_error_); 56 provider_->GetRecoveredFromErrorHistogram(method_)->Add(-last_error_);
57 } 57 }
58 } 58 }
59 } 59 }
60 bool ShouldKeepTrying(base::PlatformFileError last_error) { 60 bool ShouldKeepTrying(base::File::Error last_error) {
61 DCHECK_NE(last_error, base::PLATFORM_FILE_OK); 61 DCHECK_NE(last_error, base::File::FILE_OK);
62 last_error_ = last_error; 62 last_error_ = last_error;
63 if (last_ < limit_) { 63 if (last_ < limit_) {
64 base::PlatformThread::Sleep(time_to_sleep_); 64 base::PlatformThread::Sleep(time_to_sleep_);
65 last_ = base::TimeTicks::Now(); 65 last_ = base::TimeTicks::Now();
66 return true; 66 return true;
67 } 67 }
68 success_ = false; 68 success_ = false;
69 return false; 69 return false;
70 } 70 }
71 71
72 private: 72 private:
73 base::TimeTicks start_; 73 base::TimeTicks start_;
74 base::TimeTicks limit_; 74 base::TimeTicks limit_;
75 base::TimeTicks last_; 75 base::TimeTicks last_;
76 base::TimeDelta time_to_sleep_; 76 base::TimeDelta time_to_sleep_;
77 bool success_; 77 bool success_;
78 MethodID method_; 78 MethodID method_;
79 base::PlatformFileError last_error_; 79 base::File::Error last_error_;
80 RetrierProvider* provider_; 80 RetrierProvider* provider_;
81 }; 81 };
82 82
83 class IDBEnvStdio : public ChromiumEnvStdio { 83 class IDBEnvStdio : public ChromiumEnvStdio {
84 public: 84 public:
85 IDBEnvStdio() : ChromiumEnvStdio() { 85 IDBEnvStdio() : ChromiumEnvStdio() {
86 name_ = "LevelDBEnv.IDB"; 86 name_ = "LevelDBEnv.IDB";
87 make_backup_ = true; 87 make_backup_ = true;
88 } 88 }
89 }; 89 };
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 message, 174 message,
175 method, 175 method,
176 MethodIDToString(method), 176 MethodIDToString(method),
177 saved_errno); 177 saved_errno);
178 return Status::IOError(filename, buf); 178 return Status::IOError(filename, buf);
179 } 179 }
180 180
181 Status MakeIOError(Slice filename, 181 Status MakeIOError(Slice filename,
182 const char* message, 182 const char* message,
183 MethodID method, 183 MethodID method,
184 base::PlatformFileError error) { 184 base::File::Error error) {
185 DCHECK(error < 0); 185 DCHECK(error < 0);
186 char buf[512]; 186 char buf[512];
187 snprintf(buf, 187 snprintf(buf,
188 sizeof(buf), 188 sizeof(buf),
189 "%s (ChromeMethodPFE: %d::%s::%d)", 189 "%s (ChromeMethodPFE: %d::%s::%d)",
190 message, 190 message,
191 method, 191 method,
192 MethodIDToString(method), 192 MethodIDToString(method),
193 -error); 193 -error);
194 return Status::IOError(filename, buf); 194 return Status::IOError(filename, buf);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 } 295 }
296 296
297 bool IndicatesDiskFull(const leveldb::Status& status) { 297 bool IndicatesDiskFull(const leveldb::Status& status) {
298 if (status.ok()) 298 if (status.ok())
299 return false; 299 return false;
300 leveldb_env::MethodID method; 300 leveldb_env::MethodID method;
301 int error = -1; 301 int error = -1;
302 leveldb_env::ErrorParsingResult result = leveldb_env::ParseMethodAndError( 302 leveldb_env::ErrorParsingResult result = leveldb_env::ParseMethodAndError(
303 status.ToString().c_str(), &method, &error); 303 status.ToString().c_str(), &method, &error);
304 return (result == leveldb_env::METHOD_AND_PFE && 304 return (result == leveldb_env::METHOD_AND_PFE &&
305 static_cast<base::PlatformFileError>(error) == 305 static_cast<base::File::Error>(error) ==
306 base::PLATFORM_FILE_ERROR_NO_SPACE) || 306 base::File::FILE_ERROR_NO_SPACE) ||
307 (result == leveldb_env::METHOD_AND_ERRNO && error == ENOSPC); 307 (result == leveldb_env::METHOD_AND_ERRNO && error == ENOSPC);
308 } 308 }
309 309
310 bool IsIOError(const leveldb::Status& status) { 310 bool IsIOError(const leveldb::Status& status) {
311 leveldb_env::MethodID method; 311 leveldb_env::MethodID method;
312 int error = -1; 312 int error = -1;
313 leveldb_env::ErrorParsingResult result = leveldb_env::ParseMethodAndError( 313 leveldb_env::ErrorParsingResult result = leveldb_env::ParseMethodAndError(
314 status.ToString().c_str(), &method, &error); 314 status.ToString().c_str(), &method, &error);
315 return result != leveldb_env::NONE; 315 return result != leveldb_env::NONE;
316 } 316 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 ChromiumEnv::~ChromiumEnv() { 360 ChromiumEnv::~ChromiumEnv() {
361 // In chromium, ChromiumEnv is leaked. It'd be nice to add NOTREACHED here to 361 // In chromium, ChromiumEnv is leaked. It'd be nice to add NOTREACHED here to
362 // ensure that behavior isn't accidentally changed, but there's an instance in 362 // ensure that behavior isn't accidentally changed, but there's an instance in
363 // a unit test that is deleted. 363 // a unit test that is deleted.
364 } 364 }
365 365
366 bool ChromiumEnv::FileExists(const std::string& fname) { 366 bool ChromiumEnv::FileExists(const std::string& fname) {
367 return ::base::PathExists(CreateFilePath(fname)); 367 return ::base::PathExists(CreateFilePath(fname));
368 } 368 }
369 369
370 const char* ChromiumEnv::PlatformFileErrorString(const ::base::PlatformFileError & error) { 370 const char* ChromiumEnv::FileErrorString(::base::File::Error error) {
371 switch (error) { 371 switch (error) {
372 case ::base::PLATFORM_FILE_ERROR_FAILED: 372 case ::base::File::FILE_ERROR_FAILED:
373 return "No further details."; 373 return "No further details.";
374 case ::base::PLATFORM_FILE_ERROR_IN_USE: 374 case ::base::File::FILE_ERROR_IN_USE:
375 return "File currently in use."; 375 return "File currently in use.";
376 case ::base::PLATFORM_FILE_ERROR_EXISTS: 376 case ::base::File::FILE_ERROR_EXISTS:
377 return "File already exists."; 377 return "File already exists.";
378 case ::base::PLATFORM_FILE_ERROR_NOT_FOUND: 378 case ::base::File::FILE_ERROR_NOT_FOUND:
379 return "File not found."; 379 return "File not found.";
380 case ::base::PLATFORM_FILE_ERROR_ACCESS_DENIED: 380 case ::base::File::FILE_ERROR_ACCESS_DENIED:
381 return "Access denied."; 381 return "Access denied.";
382 case ::base::PLATFORM_FILE_ERROR_TOO_MANY_OPENED: 382 case ::base::File::FILE_ERROR_TOO_MANY_OPENED:
383 return "Too many files open."; 383 return "Too many files open.";
384 case ::base::PLATFORM_FILE_ERROR_NO_MEMORY: 384 case ::base::File::FILE_ERROR_NO_MEMORY:
385 return "Out of memory."; 385 return "Out of memory.";
386 case ::base::PLATFORM_FILE_ERROR_NO_SPACE: 386 case ::base::File::FILE_ERROR_NO_SPACE:
387 return "No space left on drive."; 387 return "No space left on drive.";
388 case ::base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY: 388 case ::base::File::FILE_ERROR_NOT_A_DIRECTORY:
389 return "Not a directory."; 389 return "Not a directory.";
390 case ::base::PLATFORM_FILE_ERROR_INVALID_OPERATION: 390 case ::base::File::FILE_ERROR_INVALID_OPERATION:
391 return "Invalid operation."; 391 return "Invalid operation.";
392 case ::base::PLATFORM_FILE_ERROR_SECURITY: 392 case ::base::File::FILE_ERROR_SECURITY:
393 return "Security error."; 393 return "Security error.";
394 case ::base::PLATFORM_FILE_ERROR_ABORT: 394 case ::base::File::FILE_ERROR_ABORT:
395 return "File operation aborted."; 395 return "File operation aborted.";
396 case ::base::PLATFORM_FILE_ERROR_NOT_A_FILE: 396 case ::base::File::FILE_ERROR_NOT_A_FILE:
397 return "The supplied path was not a file."; 397 return "The supplied path was not a file.";
398 case ::base::PLATFORM_FILE_ERROR_NOT_EMPTY: 398 case ::base::File::FILE_ERROR_NOT_EMPTY:
399 return "The file was not empty."; 399 return "The file was not empty.";
400 case ::base::PLATFORM_FILE_ERROR_INVALID_URL: 400 case ::base::File::FILE_ERROR_INVALID_URL:
401 return "Invalid URL."; 401 return "Invalid URL.";
402 case ::base::PLATFORM_FILE_ERROR_IO: 402 case ::base::File::FILE_ERROR_IO:
403 return "OS or hardware error."; 403 return "OS or hardware error.";
404 case ::base::PLATFORM_FILE_OK: 404 case ::base::File::FILE_OK:
405 return "OK."; 405 return "OK.";
406 case ::base::PLATFORM_FILE_ERROR_MAX: 406 case ::base::File::FILE_ERROR_MAX:
407 NOTREACHED(); 407 NOTREACHED();
408 } 408 }
409 NOTIMPLEMENTED(); 409 NOTIMPLEMENTED();
410 return "Unknown error."; 410 return "Unknown error.";
411 } 411 }
412 412
413 base::FilePath ChromiumEnv::RestoreFromBackup(const base::FilePath& base_name) { 413 base::FilePath ChromiumEnv::RestoreFromBackup(const base::FilePath& base_name) {
414 base::FilePath table_name = 414 base::FilePath table_name =
415 base_name.AddExtension(table_extension); 415 base_name.AddExtension(table_extension);
416 bool result = base::CopyFile(base_name.AddExtension(backup_table_extension), 416 bool result = base::CopyFile(base_name.AddExtension(backup_table_extension),
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 ++it) { 459 ++it) {
460 base::FilePath restored_table_name = 460 base::FilePath restored_table_name =
461 RestoreFromBackup(dir_filepath.Append(*it)); 461 RestoreFromBackup(dir_filepath.Append(*it));
462 result->push_back(FilePathToString(restored_table_name.BaseName())); 462 result->push_back(FilePathToString(restored_table_name.BaseName()));
463 } 463 }
464 } 464 }
465 465
466 Status ChromiumEnv::GetChildren(const std::string& dir_string, 466 Status ChromiumEnv::GetChildren(const std::string& dir_string,
467 std::vector<std::string>* result) { 467 std::vector<std::string>* result) {
468 std::vector<base::FilePath> entries; 468 std::vector<base::FilePath> entries;
469 base::PlatformFileError error = 469 base::File::Error error =
470 GetDirectoryEntries(CreateFilePath(dir_string), &entries); 470 GetDirectoryEntries(CreateFilePath(dir_string), &entries);
471 if (error != base::PLATFORM_FILE_OK) { 471 if (error != base::File::FILE_OK) {
472 RecordOSError(kGetChildren, error); 472 RecordOSError(kGetChildren, error);
473 return MakeIOError( 473 return MakeIOError(
474 dir_string, "Could not open/read directory", kGetChildren, error); 474 dir_string, "Could not open/read directory", kGetChildren, error);
475 } 475 }
476 result->clear(); 476 result->clear();
477 for (std::vector<base::FilePath>::iterator it = entries.begin(); 477 for (std::vector<base::FilePath>::iterator it = entries.begin();
478 it != entries.end(); 478 it != entries.end();
479 ++it) { 479 ++it) {
480 result->push_back(FilePathToString(*it)); 480 result->push_back(FilePathToString(*it));
481 } 481 }
(...skipping 13 matching lines...) Expand all
495 } 495 }
496 if (make_backup_ && fname_filepath.MatchesExtension(table_extension)) { 496 if (make_backup_ && fname_filepath.MatchesExtension(table_extension)) {
497 base::DeleteFile(fname_filepath.ReplaceExtension(backup_table_extension), 497 base::DeleteFile(fname_filepath.ReplaceExtension(backup_table_extension),
498 false); 498 false);
499 } 499 }
500 return result; 500 return result;
501 } 501 }
502 502
503 Status ChromiumEnv::CreateDir(const std::string& name) { 503 Status ChromiumEnv::CreateDir(const std::string& name) {
504 Status result; 504 Status result;
505 // TODO(rvargas): convert this code to base::File::Error. 505 base::File::Error error = base::File::FILE_OK;
506 base::PlatformFileError error = base::PLATFORM_FILE_OK;
507 Retrier retrier(kCreateDir, this); 506 Retrier retrier(kCreateDir, this);
508 do { 507 do {
509 if (base::CreateDirectoryAndGetError( 508 if (base::CreateDirectoryAndGetError(CreateFilePath(name), &error))
510 CreateFilePath(name),
511 reinterpret_cast<base::File::Error*>(&error))) {
512 return result; 509 return result;
513 }
514 } while (retrier.ShouldKeepTrying(error)); 510 } while (retrier.ShouldKeepTrying(error));
515 result = MakeIOError(name, "Could not create directory.", kCreateDir, error); 511 result = MakeIOError(name, "Could not create directory.", kCreateDir, error);
516 RecordOSError(kCreateDir, error); 512 RecordOSError(kCreateDir, error);
517 return result; 513 return result;
518 } 514 }
519 515
520 Status ChromiumEnv::DeleteDir(const std::string& name) { 516 Status ChromiumEnv::DeleteDir(const std::string& name) {
521 Status result; 517 Status result;
522 // TODO(jorlow): Should we assert this is a directory? 518 // TODO(jorlow): Should we assert this is a directory?
523 if (!::base::DeleteFile(CreateFilePath(name), false)) { 519 if (!::base::DeleteFile(CreateFilePath(name), false)) {
(...skipping 17 matching lines...) Expand all
541 } 537 }
542 538
543 Status ChromiumEnv::RenameFile(const std::string& src, const std::string& dst) { 539 Status ChromiumEnv::RenameFile(const std::string& src, const std::string& dst) {
544 Status result; 540 Status result;
545 base::FilePath src_file_path = CreateFilePath(src); 541 base::FilePath src_file_path = CreateFilePath(src);
546 if (!::base::PathExists(src_file_path)) 542 if (!::base::PathExists(src_file_path))
547 return result; 543 return result;
548 base::FilePath destination = CreateFilePath(dst); 544 base::FilePath destination = CreateFilePath(dst);
549 545
550 Retrier retrier(kRenameFile, this); 546 Retrier retrier(kRenameFile, this);
551 // TODO(rvargas): convert this code to base::File::Error. 547 base::File::Error error = base::File::FILE_OK;
552 base::PlatformFileError error = base::PLATFORM_FILE_OK;
553 do { 548 do {
554 if (base::ReplaceFile(src_file_path, destination, 549 if (base::ReplaceFile(src_file_path, destination, &error))
555 reinterpret_cast<base::File::Error*>(&error))) {
556 return result; 550 return result;
557 }
558 } while (retrier.ShouldKeepTrying(error)); 551 } while (retrier.ShouldKeepTrying(error));
559 552
560 DCHECK(error != base::PLATFORM_FILE_OK); 553 DCHECK(error != base::File::FILE_OK);
561 RecordOSError(kRenameFile, error); 554 RecordOSError(kRenameFile, error);
562 char buf[100]; 555 char buf[100];
563 snprintf(buf, 556 snprintf(buf,
564 sizeof(buf), 557 sizeof(buf),
565 "Could not rename file: %s", 558 "Could not rename file: %s",
566 PlatformFileErrorString(error)); 559 FileErrorString(error));
567 return MakeIOError(src, buf, kRenameFile, error); 560 return MakeIOError(src, buf, kRenameFile, error);
568 } 561 }
569 562
570 Status ChromiumEnv::LockFile(const std::string& fname, FileLock** lock) { 563 Status ChromiumEnv::LockFile(const std::string& fname, FileLock** lock) {
571 *lock = NULL; 564 *lock = NULL;
572 Status result; 565 Status result;
573 int flags = ::base::PLATFORM_FILE_OPEN_ALWAYS | 566 int flags = ::base::File::FLAG_OPEN_ALWAYS |
574 ::base::PLATFORM_FILE_READ | 567 ::base::File::FLAG_READ |
575 ::base::PLATFORM_FILE_WRITE; 568 ::base::File::FLAG_WRITE;
576 bool created; 569 ::base::File::Error error_code;
577 ::base::PlatformFileError error_code; 570 ::base::File file;
578 ::base::PlatformFile file;
579 Retrier retrier(kLockFile, this); 571 Retrier retrier(kLockFile, this);
580 do { 572 do {
581 file = ::base::CreatePlatformFile( 573 file.Initialize(CreateFilePath(fname), flags);
582 CreateFilePath(fname), flags, &created, &error_code); 574 if (!file.IsValid())
583 } while (error_code != ::base::PLATFORM_FILE_OK && 575 error_code = file.error_details();
584 retrier.ShouldKeepTrying(error_code)); 576 } while (!file.IsValid() && retrier.ShouldKeepTrying(error_code));
585 577
586 if (error_code == ::base::PLATFORM_FILE_ERROR_NOT_FOUND) { 578 if (!file.IsValid()) {
587 ::base::FilePath parent = CreateFilePath(fname).DirName(); 579 if (error_code == ::base::File::FILE_ERROR_NOT_FOUND) {
588 ::base::FilePath last_parent; 580 ::base::FilePath parent = CreateFilePath(fname).DirName();
589 int num_missing_ancestors = 0; 581 ::base::FilePath last_parent;
590 do { 582 int num_missing_ancestors = 0;
591 if (base::DirectoryExists(parent)) 583 do {
592 break; 584 if (base::DirectoryExists(parent))
593 ++num_missing_ancestors; 585 break;
594 last_parent = parent; 586 ++num_missing_ancestors;
595 parent = parent.DirName(); 587 last_parent = parent;
596 } while (parent != last_parent); 588 parent = parent.DirName();
597 RecordLockFileAncestors(num_missing_ancestors); 589 } while (parent != last_parent);
598 } 590 RecordLockFileAncestors(num_missing_ancestors);
591 }
599 592
600 if (error_code != ::base::PLATFORM_FILE_OK) { 593 result = MakeIOError(fname, FileErrorString(error_code), kLockFile,
601 result = MakeIOError( 594 error_code);
602 fname, PlatformFileErrorString(error_code), kLockFile, error_code);
603 RecordOSError(kLockFile, error_code); 595 RecordOSError(kLockFile, error_code);
604 return result; 596 return result;
605 } 597 }
606 598
607 if (!locks_.Insert(fname)) { 599 if (!locks_.Insert(fname)) {
608 result = MakeIOError(fname, "Lock file already locked.", kLockFile); 600 result = MakeIOError(fname, "Lock file already locked.", kLockFile);
609 ::base::ClosePlatformFile(file);
610 return result; 601 return result;
611 } 602 }
612 603
613 Retrier lock_retrier = Retrier(kLockFile, this); 604 Retrier lock_retrier = Retrier(kLockFile, this);
614 do { 605 do {
615 error_code = ::base::LockPlatformFile(file); 606 error_code = file.Lock();
616 } while (error_code != ::base::PLATFORM_FILE_OK && 607 } while (error_code != ::base::File::FILE_OK &&
617 retrier.ShouldKeepTrying(error_code)); 608 retrier.ShouldKeepTrying(error_code));
618 609
619 if (error_code != ::base::PLATFORM_FILE_OK) { 610 if (error_code != ::base::File::FILE_OK) {
620 ::base::ClosePlatformFile(file);
621 locks_.Remove(fname); 611 locks_.Remove(fname);
622 result = MakeIOError( 612 result = MakeIOError(fname, FileErrorString(error_code), kLockFile,
623 fname, PlatformFileErrorString(error_code), kLockFile, error_code); 613 error_code);
624 RecordOSError(kLockFile, error_code); 614 RecordOSError(kLockFile, error_code);
625 return result; 615 return result;
626 } 616 }
627 617
628 ChromiumFileLock* my_lock = new ChromiumFileLock; 618 ChromiumFileLock* my_lock = new ChromiumFileLock;
629 my_lock->file_ = file; 619 my_lock->file_ = file.Pass();
630 my_lock->name_ = fname; 620 my_lock->name_ = fname;
631 *lock = my_lock; 621 *lock = my_lock;
632 return result; 622 return result;
633 } 623 }
634 624
635 Status ChromiumEnv::UnlockFile(FileLock* lock) { 625 Status ChromiumEnv::UnlockFile(FileLock* lock) {
636 ChromiumFileLock* my_lock = reinterpret_cast<ChromiumFileLock*>(lock); 626 ChromiumFileLock* my_lock = reinterpret_cast<ChromiumFileLock*>(lock);
637 Status result; 627 Status result;
638 628
639 ::base::PlatformFileError error_code = 629 ::base::File::Error error_code = my_lock->file_.Unlock();
640 ::base::UnlockPlatformFile(my_lock->file_); 630 if (error_code != ::base::File::FILE_OK) {
641 if (error_code != ::base::PLATFORM_FILE_OK) {
642 result = 631 result =
643 MakeIOError(my_lock->name_, "Could not unlock lock file.", kUnlockFile); 632 MakeIOError(my_lock->name_, "Could not unlock lock file.", kUnlockFile);
644 RecordOSError(kUnlockFile, error_code); 633 RecordOSError(kUnlockFile, error_code);
645 ::base::ClosePlatformFile(my_lock->file_);
646 } else if (!::base::ClosePlatformFile(my_lock->file_)) {
647 result =
648 MakeIOError(my_lock->name_, "Could not close lock file.", kUnlockFile);
649 RecordErrorAt(kUnlockFile);
650 } 634 }
651 bool removed = locks_.Remove(my_lock->name_); 635 bool removed = locks_.Remove(my_lock->name_);
652 DCHECK(removed); 636 DCHECK(removed);
653 delete my_lock; 637 delete my_lock;
654 return result; 638 return result;
655 } 639 }
656 640
657 Status ChromiumEnv::GetTestDirectory(std::string* path) { 641 Status ChromiumEnv::GetTestDirectory(std::string* path) {
658 mu_.Acquire(); 642 mu_.Acquire();
659 if (test_directory_.empty()) { 643 if (test_directory_.empty()) {
(...skipping 21 matching lines...) Expand all
681 665
682 void ChromiumEnv::RecordErrorAt(MethodID method) const { 666 void ChromiumEnv::RecordErrorAt(MethodID method) const {
683 GetMethodIOErrorHistogram()->Add(method); 667 GetMethodIOErrorHistogram()->Add(method);
684 } 668 }
685 669
686 void ChromiumEnv::RecordLockFileAncestors(int num_missing_ancestors) const { 670 void ChromiumEnv::RecordLockFileAncestors(int num_missing_ancestors) const {
687 GetLockFileAncestorHistogram()->Add(num_missing_ancestors); 671 GetLockFileAncestorHistogram()->Add(num_missing_ancestors);
688 } 672 }
689 673
690 void ChromiumEnv::RecordOSError(MethodID method, 674 void ChromiumEnv::RecordOSError(MethodID method,
691 base::PlatformFileError error) const { 675 base::File::Error error) const {
692 DCHECK(error < 0); 676 DCHECK(error < 0);
693 RecordErrorAt(method); 677 RecordErrorAt(method);
694 GetOSErrorHistogram(method, -base::PLATFORM_FILE_ERROR_MAX)->Add(-error); 678 GetOSErrorHistogram(method, -base::File::FILE_ERROR_MAX)->Add(-error);
695 } 679 }
696 680
697 void ChromiumEnv::RecordOSError(MethodID method, int error) const { 681 void ChromiumEnv::RecordOSError(MethodID method, int error) const {
698 DCHECK(error > 0); 682 DCHECK(error > 0);
699 RecordErrorAt(method); 683 RecordErrorAt(method);
700 GetOSErrorHistogram(method, ERANGE + 1)->Add(error); 684 GetOSErrorHistogram(method, ERANGE + 1)->Add(error);
701 } 685 }
702 686
703 void ChromiumEnv::RecordBackupResult(bool result) const { 687 void ChromiumEnv::RecordBackupResult(bool result) const {
704 std::string uma_name(name_); 688 std::string uma_name(name_);
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 Env* IDBEnv() { 848 Env* IDBEnv() {
865 return leveldb_env::idb_env.Pointer(); 849 return leveldb_env::idb_env.Pointer();
866 } 850 }
867 851
868 Env* Env::Default() { 852 Env* Env::Default() {
869 return leveldb_env::default_env.Pointer(); 853 return leveldb_env::default_env.Pointer();
870 } 854 }
871 855
872 } // namespace leveldb 856 } // namespace leveldb
873 857
OLDNEW
« no previous file with comments | « third_party/leveldatabase/env_chromium.h ('k') | third_party/leveldatabase/env_chromium_stdio.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698