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

Side by Side Diff: storage/browser/quota/quota_database.cc

Issue 1236583002: Try to reset quota database which is suspected to be corrupted (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reworked in more logical way. Added unittest Created 5 years, 5 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium 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. 3 // found in the LICENSE file.
4 4
5 #include "storage/browser/quota/quota_database.h" 5 #include "storage/browser/quota/quota_database.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 opened = db_->OpenInMemory(); 452 opened = db_->OpenInMemory();
453 } else if (!base::CreateDirectory(db_file_path_.DirName())) { 453 } else if (!base::CreateDirectory(db_file_path_.DirName())) {
454 LOG(ERROR) << "Failed to create quota database directory."; 454 LOG(ERROR) << "Failed to create quota database directory.";
455 } else { 455 } else {
456 opened = db_->Open(db_file_path_); 456 opened = db_->Open(db_file_path_);
457 if (opened) 457 if (opened)
458 db_->Preload(); 458 db_->Preload();
459 } 459 }
460 460
461 if (!opened || !EnsureDatabaseVersion()) { 461 if (!opened || !EnsureDatabaseVersion()) {
462 LOG(ERROR) << "Failed to open the quota database."; 462 LOG(ERROR) << "Could not open the quota database: "
463 is_disabled_ = true; 463 << "probably database is currupted. "
464 db_.reset(); 464 << "Trying to reset...";
465 meta_table_.reset(); 465 if (!ResetSchema()) {
466 return false; 466 LOG(ERROR) << "Failed to reset the quota database.";
467 is_disabled_ = true;
468 db_.reset();
469 meta_table_.reset();
470 return false;
471 }
467 } 472 }
468 473
469 // Start a long-running transaction. 474 // Start a long-running transaction.
470 db_->BeginTransaction(); 475 db_->BeginTransaction();
471 476
472 return true; 477 return true;
473 } 478 }
474 479
475 bool QuotaDatabase::EnsureDatabaseVersion() { 480 bool QuotaDatabase::EnsureDatabaseVersion() {
476 static const size_t kTableCount = arraysize(kTables); 481 static const size_t kTableCount = arraysize(kTables);
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 if (lhs.origin < rhs.origin) return true; 650 if (lhs.origin < rhs.origin) return true;
646 if (rhs.origin < lhs.origin) return false; 651 if (rhs.origin < lhs.origin) return false;
647 if (lhs.type < rhs.type) return true; 652 if (lhs.type < rhs.type) return true;
648 if (rhs.type < lhs.type) return false; 653 if (rhs.type < lhs.type) return false;
649 if (lhs.used_count < rhs.used_count) return true; 654 if (lhs.used_count < rhs.used_count) return true;
650 if (rhs.used_count < lhs.used_count) return false; 655 if (rhs.used_count < lhs.used_count) return false;
651 return lhs.last_access_time < rhs.last_access_time; 656 return lhs.last_access_time < rhs.last_access_time;
652 } 657 }
653 658
654 } // namespace storage 659 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698