OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/service_worker/service_worker_database.h" | 5 #include "content/browser/service_worker/service_worker_database.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 if (status != STATUS_OK) | 718 if (status != STATUS_OK) |
719 return status; | 719 return status; |
720 } | 720 } |
721 | 721 |
722 return WriteBatch(&batch); | 722 return WriteBatch(&batch); |
723 } | 723 } |
724 | 724 |
725 ServiceWorkerDatabase::Status ServiceWorkerDatabase::DestroyDatabase() { | 725 ServiceWorkerDatabase::Status ServiceWorkerDatabase::DestroyDatabase() { |
726 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 726 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
727 Disable(FROM_HERE, STATUS_OK); | 727 Disable(FROM_HERE, STATUS_OK); |
| 728 |
| 729 leveldb::Options options; |
| 730 if (path_.empty()) { |
| 731 if (env_) { |
| 732 options.env = env_.get(); |
| 733 } else { |
| 734 // In-memory database not initialized. |
| 735 return STATUS_OK; |
| 736 } |
| 737 } |
| 738 |
728 return LevelDBStatusToStatus( | 739 return LevelDBStatusToStatus( |
729 leveldb::DestroyDB(path_.AsUTF8Unsafe(), leveldb::Options())); | 740 leveldb::DestroyDB(path_.AsUTF8Unsafe(), options)); |
730 } | 741 } |
731 | 742 |
732 ServiceWorkerDatabase::Status ServiceWorkerDatabase::LazyOpen( | 743 ServiceWorkerDatabase::Status ServiceWorkerDatabase::LazyOpen( |
733 bool create_if_missing) { | 744 bool create_if_missing) { |
734 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 745 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
735 | 746 |
736 // Do not try to open a database if we tried and failed once. | 747 // Do not try to open a database if we tried and failed once. |
737 if (state_ == DISABLED) | 748 if (state_ == DISABLED) |
738 return STATUS_ERROR_FAILED; | 749 return STATUS_ERROR_FAILED; |
739 if (IsOpen()) | 750 if (IsOpen()) |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1113 | 1124 |
1114 void ServiceWorkerDatabase::HandleWriteResult( | 1125 void ServiceWorkerDatabase::HandleWriteResult( |
1115 const tracked_objects::Location& from_here, | 1126 const tracked_objects::Location& from_here, |
1116 Status status) { | 1127 Status status) { |
1117 if (status != STATUS_OK) | 1128 if (status != STATUS_OK) |
1118 Disable(from_here, status); | 1129 Disable(from_here, status); |
1119 ServiceWorkerMetrics::CountWriteDatabaseResult(status); | 1130 ServiceWorkerMetrics::CountWriteDatabaseResult(status); |
1120 } | 1131 } |
1121 | 1132 |
1122 } // namespace content | 1133 } // namespace content |
OLD | NEW |