| 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/command_line.h" |
| 12 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 13 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 14 #include "base/hash.h" | 15 #include "base/hash.h" |
| 15 #include "base/location.h" | 16 #include "base/location.h" |
| 16 #include "base/metrics/histogram_macros.h" | 17 #include "base/metrics/histogram_macros.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" |
| 20 #include "base/timer/elapsed_timer.h" | 21 #include "base/timer/elapsed_timer.h" |
| 21 #include "net/base/io_buffer.h" | 22 #include "net/base/io_buffer.h" |
| 22 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
| 23 #include "net/disk_cache/simple/simple_backend_version.h" | 24 #include "net/disk_cache/simple/simple_backend_version.h" |
| 24 #include "net/disk_cache/simple/simple_histogram_macros.h" | 25 #include "net/disk_cache/simple/simple_histogram_macros.h" |
| 25 #include "net/disk_cache/simple/simple_util.h" | 26 #include "net/disk_cache/simple/simple_util.h" |
| 26 #include "third_party/zlib/zlib.h" | 27 #include "third_party/zlib/zlib.h" |
| 27 | 28 |
| 29 #include <unistd.h> |
| 30 |
| 28 using base::File; | 31 using base::File; |
| 29 using base::FilePath; | 32 using base::FilePath; |
| 30 using base::Time; | 33 using base::Time; |
| 31 | 34 |
| 32 namespace { | 35 namespace { |
| 33 | 36 |
| 34 // Used in histograms, please only add entries at the end. | 37 // Used in histograms, please only add entries at the end. |
| 35 enum OpenEntryResult { | 38 enum OpenEntryResult { |
| 36 OPEN_ENTRY_SUCCESS = 0, | 39 OPEN_ENTRY_SUCCESS = 0, |
| 37 OPEN_ENTRY_PLATFORM_FILE_ERROR = 1, | 40 OPEN_ENTRY_PLATFORM_FILE_ERROR = 1, |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 out_results->result = sync_entry->InitializeForCreate( | 262 out_results->result = sync_entry->InitializeForCreate( |
| 260 had_index, &out_results->entry_stat); | 263 had_index, &out_results->entry_stat); |
| 261 if (out_results->result != net::OK) { | 264 if (out_results->result != net::OK) { |
| 262 if (out_results->result != net::ERR_FILE_EXISTS) | 265 if (out_results->result != net::ERR_FILE_EXISTS) |
| 263 sync_entry->Doom(); | 266 sync_entry->Doom(); |
| 264 delete sync_entry; | 267 delete sync_entry; |
| 265 out_results->sync_entry = NULL; | 268 out_results->sync_entry = NULL; |
| 266 return; | 269 return; |
| 267 } | 270 } |
| 268 out_results->sync_entry = sync_entry; | 271 out_results->sync_entry = sync_entry; |
| 272 if (base::CommandLine::ForCurrentProcess()-> HasSwitch( |
| 273 "simple-cache-slower-creates")) { |
| 274 usleep(20 * 1000); |
| 275 } |
| 269 } | 276 } |
| 270 | 277 |
| 271 // static | 278 // static |
| 272 int SimpleSynchronousEntry::DoomEntry(const FilePath& path, | 279 int SimpleSynchronousEntry::DoomEntry(const FilePath& path, |
| 273 uint64_t entry_hash) { | 280 uint64_t entry_hash) { |
| 274 const bool deleted_well = DeleteFilesForEntryHash(path, entry_hash); | 281 const bool deleted_well = DeleteFilesForEntryHash(path, entry_hash); |
| 275 return deleted_well ? net::OK : net::ERR_FAILED; | 282 return deleted_well ? net::OK : net::ERR_FAILED; |
| 276 } | 283 } |
| 277 | 284 |
| 278 // static | 285 // static |
| (...skipping 1188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1467 range.offset = offset; | 1474 range.offset = offset; |
| 1468 range.length = len; | 1475 range.length = len; |
| 1469 range.data_crc32 = data_crc32; | 1476 range.data_crc32 = data_crc32; |
| 1470 range.file_offset = data_file_offset; | 1477 range.file_offset = data_file_offset; |
| 1471 sparse_ranges_.insert(std::make_pair(offset, range)); | 1478 sparse_ranges_.insert(std::make_pair(offset, range)); |
| 1472 | 1479 |
| 1473 return true; | 1480 return true; |
| 1474 } | 1481 } |
| 1475 | 1482 |
| 1476 } // namespace disk_cache | 1483 } // namespace disk_cache |
| OLD | NEW |