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 "net/disk_cache/simple/simple_synchronous_entry.h" | 5 #include "net/disk_cache/simple/simple_synchronous_entry.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstring> | 8 #include <cstring> |
9 #include <functional> | 9 #include <functional> |
10 #include <limits> | 10 #include <limits> |
(...skipping 25 matching lines...) Expand all Loading... |
36 enum OpenEntryResult { | 36 enum OpenEntryResult { |
37 OPEN_ENTRY_SUCCESS = 0, | 37 OPEN_ENTRY_SUCCESS = 0, |
38 OPEN_ENTRY_PLATFORM_FILE_ERROR = 1, | 38 OPEN_ENTRY_PLATFORM_FILE_ERROR = 1, |
39 OPEN_ENTRY_CANT_READ_HEADER = 2, | 39 OPEN_ENTRY_CANT_READ_HEADER = 2, |
40 OPEN_ENTRY_BAD_MAGIC_NUMBER = 3, | 40 OPEN_ENTRY_BAD_MAGIC_NUMBER = 3, |
41 OPEN_ENTRY_BAD_VERSION = 4, | 41 OPEN_ENTRY_BAD_VERSION = 4, |
42 OPEN_ENTRY_CANT_READ_KEY = 5, | 42 OPEN_ENTRY_CANT_READ_KEY = 5, |
43 OPEN_ENTRY_KEY_MISMATCH = 6, | 43 OPEN_ENTRY_KEY_MISMATCH = 6, |
44 OPEN_ENTRY_KEY_HASH_MISMATCH = 7, | 44 OPEN_ENTRY_KEY_HASH_MISMATCH = 7, |
45 OPEN_ENTRY_SPARSE_OPEN_FAILED = 8, | 45 OPEN_ENTRY_SPARSE_OPEN_FAILED = 8, |
46 OPEN_ENTRY_MAX = 9, | 46 OPEN_ENTRY_INVALID_FILE_LENGTH = 9, |
| 47 OPEN_ENTRY_MAX = 10, |
47 }; | 48 }; |
48 | 49 |
49 // Used in histograms, please only add entries at the end. | 50 // Used in histograms, please only add entries at the end. |
50 enum WriteResult { | 51 enum WriteResult { |
51 WRITE_RESULT_SUCCESS = 0, | 52 WRITE_RESULT_SUCCESS = 0, |
52 WRITE_RESULT_PRETRUNCATE_FAILURE, | 53 WRITE_RESULT_PRETRUNCATE_FAILURE, |
53 WRITE_RESULT_WRITE_FAILURE, | 54 WRITE_RESULT_WRITE_FAILURE, |
54 WRITE_RESULT_TRUNCATE_FAILURE, | 55 WRITE_RESULT_TRUNCATE_FAILURE, |
55 WRITE_RESULT_LAZY_STREAM_ENTRY_DOOMED, | 56 WRITE_RESULT_LAZY_STREAM_ENTRY_DOOMED, |
56 WRITE_RESULT_LAZY_CREATE_FAILURE, | 57 WRITE_RESULT_LAZY_CREATE_FAILURE, |
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
944 // each will only be known when reading the EOF record for stream 0. | 945 // each will only be known when reading the EOF record for stream 0. |
945 // | 946 // |
946 // The size for file 0 and 1 is temporarily kept in | 947 // The size for file 0 and 1 is temporarily kept in |
947 // |data_size(1)| and |data_size(2)| respectively. Reading the key in | 948 // |data_size(1)| and |data_size(2)| respectively. Reading the key in |
948 // InitializeForOpen yields the data size for each file. In the case of | 949 // InitializeForOpen yields the data size for each file. In the case of |
949 // file hash_1, this is the total size of stream 2, and is assigned to | 950 // file hash_1, this is the total size of stream 2, and is assigned to |
950 // data_size(2). In the case of file 0, it is the combined size of stream | 951 // data_size(2). In the case of file 0, it is the combined size of stream |
951 // 0, stream 1 and one EOF record. The exact distribution of sizes between | 952 // 0, stream 1 and one EOF record. The exact distribution of sizes between |
952 // stream 1 and stream 0 is only determined after reading the EOF record | 953 // stream 1 and stream 0 is only determined after reading the EOF record |
953 // for stream 0 in ReadAndValidateStream0. | 954 // for stream 0 in ReadAndValidateStream0. |
| 955 if (!base::IsValueInRangeForNumericType<int>(file_info.size)) { |
| 956 RecordSyncOpenResult(cache_type_, OPEN_ENTRY_INVALID_FILE_LENGTH, |
| 957 had_index_); |
| 958 return false; |
| 959 } |
954 out_entry_stat->set_data_size(i + 1, static_cast<int>(file_info.size)); | 960 out_entry_stat->set_data_size(i + 1, static_cast<int>(file_info.size)); |
955 } | 961 } |
956 SIMPLE_CACHE_UMA(CUSTOM_COUNTS, | 962 SIMPLE_CACHE_UMA(CUSTOM_COUNTS, |
957 "SyncOpenEntryAge", cache_type_, | 963 "SyncOpenEntryAge", cache_type_, |
958 entry_age.InHours(), 1, 1000, 50); | 964 entry_age.InHours(), 1, 1000, 50); |
959 | 965 |
960 files_created_ = false; | 966 files_created_ = false; |
961 | 967 |
962 return true; | 968 return true; |
963 } | 969 } |
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1645 range.offset = offset; | 1651 range.offset = offset; |
1646 range.length = len; | 1652 range.length = len; |
1647 range.data_crc32 = data_crc32; | 1653 range.data_crc32 = data_crc32; |
1648 range.file_offset = data_file_offset; | 1654 range.file_offset = data_file_offset; |
1649 sparse_ranges_.insert(std::make_pair(offset, range)); | 1655 sparse_ranges_.insert(std::make_pair(offset, range)); |
1650 | 1656 |
1651 return true; | 1657 return true; |
1652 } | 1658 } |
1653 | 1659 |
1654 } // namespace disk_cache | 1660 } // namespace disk_cache |
OLD | NEW |