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> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
15 #include "base/hash.h" | 15 #include "base/hash.h" |
16 #include "base/location.h" | 16 #include "base/location.h" |
| 17 #include "base/metrics/histogram.h" |
17 #include "base/numerics/safe_conversions.h" | 18 #include "base/numerics/safe_conversions.h" |
18 #include "base/sha1.h" | 19 #include "base/sha1.h" |
19 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 21 #include "base/timer/elapsed_timer.h" |
20 #include "net/base/io_buffer.h" | 22 #include "net/base/io_buffer.h" |
21 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
22 #include "net/disk_cache/simple/simple_backend_version.h" | 24 #include "net/disk_cache/simple/simple_backend_version.h" |
23 #include "net/disk_cache/simple/simple_histogram_macros.h" | 25 #include "net/disk_cache/simple/simple_histogram_macros.h" |
24 #include "net/disk_cache/simple/simple_util.h" | 26 #include "net/disk_cache/simple/simple_util.h" |
25 #include "third_party/zlib/zlib.h" | 27 #include "third_party/zlib/zlib.h" |
26 | 28 |
27 using base::File; | 29 using base::File; |
28 using base::FilePath; | 30 using base::FilePath; |
29 using base::Time; | 31 using base::Time; |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 : sparse_offset(sparse_offset_p), | 211 : sparse_offset(sparse_offset_p), |
210 buf_len(buf_len_p) {} | 212 buf_len(buf_len_p) {} |
211 | 213 |
212 // static | 214 // static |
213 void SimpleSynchronousEntry::OpenEntry( | 215 void SimpleSynchronousEntry::OpenEntry( |
214 net::CacheType cache_type, | 216 net::CacheType cache_type, |
215 const FilePath& path, | 217 const FilePath& path, |
216 const uint64 entry_hash, | 218 const uint64 entry_hash, |
217 bool had_index, | 219 bool had_index, |
218 SimpleEntryCreationResults *out_results) { | 220 SimpleEntryCreationResults *out_results) { |
| 221 base::ElapsedTimer open_time; |
219 SimpleSynchronousEntry* sync_entry = | 222 SimpleSynchronousEntry* sync_entry = |
220 new SimpleSynchronousEntry(cache_type, path, "", entry_hash); | 223 new SimpleSynchronousEntry(cache_type, path, "", entry_hash); |
221 out_results->result = | 224 out_results->result = |
222 sync_entry->InitializeForOpen(had_index, | 225 sync_entry->InitializeForOpen(had_index, |
223 &out_results->entry_stat, | 226 &out_results->entry_stat, |
224 &out_results->stream_0_data, | 227 &out_results->stream_0_data, |
225 &out_results->stream_0_crc32); | 228 &out_results->stream_0_crc32); |
226 if (out_results->result != net::OK) { | 229 if (out_results->result != net::OK) { |
227 sync_entry->Doom(); | 230 sync_entry->Doom(); |
228 delete sync_entry; | 231 delete sync_entry; |
229 out_results->sync_entry = NULL; | 232 out_results->sync_entry = NULL; |
230 out_results->stream_0_data = NULL; | 233 out_results->stream_0_data = NULL; |
231 return; | 234 return; |
232 } | 235 } |
| 236 UMA_HISTOGRAM_TIMES("SimpleCache.DiskOpenLatency", open_time.Elapsed()); |
233 out_results->sync_entry = sync_entry; | 237 out_results->sync_entry = sync_entry; |
234 } | 238 } |
235 | 239 |
236 // static | 240 // static |
237 void SimpleSynchronousEntry::CreateEntry( | 241 void SimpleSynchronousEntry::CreateEntry( |
238 net::CacheType cache_type, | 242 net::CacheType cache_type, |
239 const FilePath& path, | 243 const FilePath& path, |
240 const std::string& key, | 244 const std::string& key, |
241 const uint64 entry_hash, | 245 const uint64 entry_hash, |
242 bool had_index, | 246 bool had_index, |
(...skipping 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1427 range.offset = offset; | 1431 range.offset = offset; |
1428 range.length = len; | 1432 range.length = len; |
1429 range.data_crc32 = data_crc32; | 1433 range.data_crc32 = data_crc32; |
1430 range.file_offset = data_file_offset; | 1434 range.file_offset = data_file_offset; |
1431 sparse_ranges_.insert(std::make_pair(offset, range)); | 1435 sparse_ranges_.insert(std::make_pair(offset, range)); |
1432 | 1436 |
1433 return true; | 1437 return true; |
1434 } | 1438 } |
1435 | 1439 |
1436 } // namespace disk_cache | 1440 } // namespace disk_cache |
OLD | NEW |