| 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 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 | 861 |
| 862 if (CanOmitEmptyFile(file_index) && file_required == FILE_NOT_REQUIRED) { | 862 if (CanOmitEmptyFile(file_index) && file_required == FILE_NOT_REQUIRED) { |
| 863 empty_file_omitted_[file_index] = true; | 863 empty_file_omitted_[file_index] = true; |
| 864 return true; | 864 return true; |
| 865 } | 865 } |
| 866 | 866 |
| 867 FilePath filename = GetFilenameFromFileIndex(file_index); | 867 FilePath filename = GetFilenameFromFileIndex(file_index); |
| 868 int flags = File::FLAG_CREATE | File::FLAG_READ | File::FLAG_WRITE | | 868 int flags = File::FLAG_CREATE | File::FLAG_READ | File::FLAG_WRITE | |
| 869 File::FLAG_SHARE_DELETE; | 869 File::FLAG_SHARE_DELETE; |
| 870 files_[file_index].Initialize(filename, flags); | 870 files_[file_index].Initialize(filename, flags); |
| 871 |
| 872 // It's possible that the creation failed because someone deleted the |
| 873 // directory (e.g. because someone pressed "clear cache" on Android). |
| 874 // If so, we would keep failing for a while until periodic index snapshot |
| 875 // re-creates the cache dir, so try to recover from it quickly here. |
| 876 if (!files_[file_index].IsValid() && |
| 877 files_[file_index].error_details() == File::FILE_ERROR_NOT_FOUND && |
| 878 !base::DirectoryExists(path_)) { |
| 879 if (base::CreateDirectory(path_)) |
| 880 files_[file_index].Initialize(filename, flags); |
| 881 } |
| 882 |
| 871 *out_error = files_[file_index].error_details(); | 883 *out_error = files_[file_index].error_details(); |
| 872 | |
| 873 empty_file_omitted_[file_index] = false; | 884 empty_file_omitted_[file_index] = false; |
| 874 | 885 |
| 875 return files_[file_index].IsValid(); | 886 return files_[file_index].IsValid(); |
| 876 } | 887 } |
| 877 | 888 |
| 878 bool SimpleSynchronousEntry::OpenFiles(SimpleEntryStat* out_entry_stat) { | 889 bool SimpleSynchronousEntry::OpenFiles(SimpleEntryStat* out_entry_stat) { |
| 879 for (int i = 0; i < kSimpleEntryFileCount; ++i) { | 890 for (int i = 0; i < kSimpleEntryFileCount; ++i) { |
| 880 File::Error error; | 891 File::Error error; |
| 881 if (!MaybeOpenFile(i, &error)) { | 892 if (!MaybeOpenFile(i, &error)) { |
| 882 // TODO(juliatuttle,gavinp): Remove one each of these triplets of | 893 // TODO(juliatuttle,gavinp): Remove one each of these triplets of |
| (...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1634 range.offset = offset; | 1645 range.offset = offset; |
| 1635 range.length = len; | 1646 range.length = len; |
| 1636 range.data_crc32 = data_crc32; | 1647 range.data_crc32 = data_crc32; |
| 1637 range.file_offset = data_file_offset; | 1648 range.file_offset = data_file_offset; |
| 1638 sparse_ranges_.insert(std::make_pair(offset, range)); | 1649 sparse_ranges_.insert(std::make_pair(offset, range)); |
| 1639 | 1650 |
| 1640 return true; | 1651 return true; |
| 1641 } | 1652 } |
| 1642 | 1653 |
| 1643 } // namespace disk_cache | 1654 } // namespace disk_cache |
| OLD | NEW |