OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "content/browser/indexed_db/indexed_db_backing_store.h" | 5 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 INDEXED_DB_BACKING_STORE_OPEN_FAILED_CLEANUP_JOURNAL_ERROR, | 812 INDEXED_DB_BACKING_STORE_OPEN_FAILED_CLEANUP_JOURNAL_ERROR, |
813 INDEXED_DB_BACKING_STORE_OPEN_MAX, | 813 INDEXED_DB_BACKING_STORE_OPEN_MAX, |
814 }; | 814 }; |
815 | 815 |
816 // static | 816 // static |
817 scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Open( | 817 scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Open( |
818 IndexedDBFactory* indexed_db_factory, | 818 IndexedDBFactory* indexed_db_factory, |
819 const Origin& origin, | 819 const Origin& origin, |
820 const base::FilePath& path_base, | 820 const base::FilePath& path_base, |
821 net::URLRequestContext* request_context, | 821 net::URLRequestContext* request_context, |
822 blink::WebIDBDataLoss* data_loss, | 822 IndexedDBDataLossInfo* data_loss_info, |
823 std::string* data_loss_message, | |
824 bool* disk_full, | 823 bool* disk_full, |
825 base::SequencedTaskRunner* task_runner, | 824 base::SequencedTaskRunner* task_runner, |
826 bool clean_journal, | 825 bool clean_journal, |
827 leveldb::Status* status) { | 826 leveldb::Status* status) { |
828 *data_loss = blink::WebIDBDataLossNone; | |
829 DefaultLevelDBFactory leveldb_factory; | 827 DefaultLevelDBFactory leveldb_factory; |
830 return IndexedDBBackingStore::Open( | 828 return IndexedDBBackingStore::Open( |
831 indexed_db_factory, origin, path_base, request_context, data_loss, | 829 indexed_db_factory, origin, path_base, request_context, data_loss_info, |
832 data_loss_message, disk_full, &leveldb_factory, task_runner, | 830 disk_full, &leveldb_factory, task_runner, clean_journal, status); |
833 clean_journal, status); | |
834 } | 831 } |
835 | 832 |
836 static std::string OriginToCustomHistogramSuffix(const Origin& origin) { | 833 static std::string OriginToCustomHistogramSuffix(const Origin& origin) { |
837 if (origin.host() == "docs.google.com") | 834 if (origin.host() == "docs.google.com") |
838 return ".Docs"; | 835 return ".Docs"; |
839 return std::string(); | 836 return std::string(); |
840 } | 837 } |
841 | 838 |
842 static void HistogramOpenStatus(IndexedDBBackingStoreOpenResult result, | 839 static void HistogramOpenStatus(IndexedDBBackingStoreOpenResult result, |
843 const Origin& origin) { | 840 const Origin& origin) { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
955 int written = file.Write(0, output_js.c_str(), output_js.length()); | 952 int written = file.Write(0, output_js.c_str(), output_js.length()); |
956 return size_t(written) == output_js.length(); | 953 return size_t(written) == output_js.length(); |
957 } | 954 } |
958 | 955 |
959 // static | 956 // static |
960 scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Open( | 957 scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Open( |
961 IndexedDBFactory* indexed_db_factory, | 958 IndexedDBFactory* indexed_db_factory, |
962 const Origin& origin, | 959 const Origin& origin, |
963 const base::FilePath& path_base, | 960 const base::FilePath& path_base, |
964 net::URLRequestContext* request_context, | 961 net::URLRequestContext* request_context, |
965 blink::WebIDBDataLoss* data_loss, | 962 IndexedDBDataLossInfo* data_loss_info, |
966 std::string* data_loss_message, | |
967 bool* is_disk_full, | 963 bool* is_disk_full, |
968 LevelDBFactory* leveldb_factory, | 964 LevelDBFactory* leveldb_factory, |
969 base::SequencedTaskRunner* task_runner, | 965 base::SequencedTaskRunner* task_runner, |
970 bool clean_journal, | 966 bool clean_journal, |
971 leveldb::Status* status) { | 967 leveldb::Status* status) { |
972 IDB_TRACE("IndexedDBBackingStore::Open"); | 968 IDB_TRACE("IndexedDBBackingStore::Open"); |
973 DCHECK(!path_base.empty()); | 969 DCHECK(!path_base.empty()); |
974 *data_loss = blink::WebIDBDataLossNone; | |
975 *data_loss_message = ""; | |
976 *is_disk_full = false; | 970 *is_disk_full = false; |
977 | 971 |
| 972 data_loss_info->status = blink::WebIDBDataLossNone; |
978 *status = leveldb::Status::OK(); | 973 *status = leveldb::Status::OK(); |
979 | 974 |
980 std::unique_ptr<LevelDBComparator> comparator(new Comparator()); | 975 std::unique_ptr<LevelDBComparator> comparator(new Comparator()); |
981 | 976 |
982 if (!base::IsStringASCII(path_base.AsUTF8Unsafe())) { | 977 if (!base::IsStringASCII(path_base.AsUTF8Unsafe())) { |
983 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_ATTEMPT_NON_ASCII, | 978 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_ATTEMPT_NON_ASCII, |
984 origin); | 979 origin); |
985 } | 980 } |
986 if (!base::CreateDirectory(path_base)) { | 981 if (!base::CreateDirectory(path_base)) { |
987 *status = | 982 *status = |
(...skipping 17 matching lines...) Expand all Loading... |
1005 | 1000 |
1006 std::unique_ptr<LevelDBDatabase> db; | 1001 std::unique_ptr<LevelDBDatabase> db; |
1007 *status = leveldb_factory->OpenLevelDB( | 1002 *status = leveldb_factory->OpenLevelDB( |
1008 file_path, comparator.get(), &db, is_disk_full); | 1003 file_path, comparator.get(), &db, is_disk_full); |
1009 | 1004 |
1010 DCHECK(!db == !status->ok()); | 1005 DCHECK(!db == !status->ok()); |
1011 if (!status->ok()) { | 1006 if (!status->ok()) { |
1012 if (leveldb_env::IndicatesDiskFull(*status)) { | 1007 if (leveldb_env::IndicatesDiskFull(*status)) { |
1013 *is_disk_full = true; | 1008 *is_disk_full = true; |
1014 } else if (status->IsCorruption()) { | 1009 } else if (status->IsCorruption()) { |
1015 *data_loss = blink::WebIDBDataLossTotal; | 1010 data_loss_info->status = blink::WebIDBDataLossTotal; |
1016 *data_loss_message = leveldb_env::GetCorruptionMessage(*status); | 1011 data_loss_info->message = leveldb_env::GetCorruptionMessage(*status); |
1017 } | 1012 } |
1018 } | 1013 } |
1019 | 1014 |
1020 bool is_schema_known = false; | 1015 bool is_schema_known = false; |
1021 if (db) { | 1016 if (db) { |
1022 std::string corruption_message; | 1017 std::string corruption_message; |
1023 if (ReadCorruptionInfo(path_base, origin, &corruption_message)) { | 1018 if (ReadCorruptionInfo(path_base, origin, &corruption_message)) { |
1024 LOG(ERROR) << "IndexedDB recovering from a corrupted (and deleted) " | 1019 LOG(ERROR) << "IndexedDB recovering from a corrupted (and deleted) " |
1025 "database."; | 1020 "database."; |
1026 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_FAILED_PRIOR_CORRUPTION, | 1021 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_FAILED_PRIOR_CORRUPTION, |
1027 origin); | 1022 origin); |
1028 db.reset(); | 1023 db.reset(); |
1029 *data_loss = blink::WebIDBDataLossTotal; | 1024 data_loss_info->status = blink::WebIDBDataLossTotal; |
1030 *data_loss_message = | 1025 data_loss_info->message = |
1031 "IndexedDB (database was corrupt): " + corruption_message; | 1026 "IndexedDB (database was corrupt): " + corruption_message; |
1032 } else if (!IsSchemaKnown(db.get(), &is_schema_known)) { | 1027 } else if (!IsSchemaKnown(db.get(), &is_schema_known)) { |
1033 LOG(ERROR) << "IndexedDB had IO error checking schema, treating it as " | 1028 LOG(ERROR) << "IndexedDB had IO error checking schema, treating it as " |
1034 "failure to open"; | 1029 "failure to open"; |
1035 HistogramOpenStatus( | 1030 HistogramOpenStatus( |
1036 INDEXED_DB_BACKING_STORE_OPEN_FAILED_IO_ERROR_CHECKING_SCHEMA, | 1031 INDEXED_DB_BACKING_STORE_OPEN_FAILED_IO_ERROR_CHECKING_SCHEMA, |
1037 origin); | 1032 origin); |
1038 db.reset(); | 1033 db.reset(); |
1039 *data_loss = blink::WebIDBDataLossTotal; | 1034 data_loss_info->status = blink::WebIDBDataLossTotal; |
1040 *data_loss_message = "I/O error checking schema"; | 1035 data_loss_info->message = "I/O error checking schema"; |
1041 } else if (!is_schema_known) { | 1036 } else if (!is_schema_known) { |
1042 LOG(ERROR) << "IndexedDB backing store had unknown schema, treating it " | 1037 LOG(ERROR) << "IndexedDB backing store had unknown schema, treating it " |
1043 "as failure to open"; | 1038 "as failure to open"; |
1044 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_FAILED_UNKNOWN_SCHEMA, | 1039 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_FAILED_UNKNOWN_SCHEMA, |
1045 origin); | 1040 origin); |
1046 db.reset(); | 1041 db.reset(); |
1047 *data_loss = blink::WebIDBDataLossTotal; | 1042 data_loss_info->status = blink::WebIDBDataLossTotal; |
1048 *data_loss_message = "Unknown schema"; | 1043 data_loss_info->message = "Unknown schema"; |
1049 } | 1044 } |
1050 } | 1045 } |
1051 | 1046 |
1052 DCHECK(status->ok() || !is_schema_known || status->IsIOError() || | 1047 DCHECK(status->ok() || !is_schema_known || status->IsIOError() || |
1053 status->IsCorruption()); | 1048 status->IsCorruption()); |
1054 | 1049 |
1055 if (db) { | 1050 if (db) { |
1056 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_SUCCESS, origin); | 1051 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_SUCCESS, origin); |
1057 } else if (status->IsIOError()) { | 1052 } else if (status->IsIOError()) { |
1058 LOG(ERROR) << "Unable to open backing store, not trying to recover - " | 1053 LOG(ERROR) << "Unable to open backing store, not trying to recover - " |
(...skipping 3413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4472 | 4467 |
4473 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( | 4468 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( |
4474 const WriteDescriptor& other) = default; | 4469 const WriteDescriptor& other) = default; |
4475 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() = | 4470 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() = |
4476 default; | 4471 default; |
4477 IndexedDBBackingStore::Transaction::WriteDescriptor& | 4472 IndexedDBBackingStore::Transaction::WriteDescriptor& |
4478 IndexedDBBackingStore::Transaction::WriteDescriptor:: | 4473 IndexedDBBackingStore::Transaction::WriteDescriptor:: |
4479 operator=(const WriteDescriptor& other) = default; | 4474 operator=(const WriteDescriptor& other) = default; |
4480 | 4475 |
4481 } // namespace content | 4476 } // namespace content |
OLD | NEW |