Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(760)

Side by Side Diff: net/disk_cache/simple/simple_synchronous_entry.cc

Issue 2862943002: SimpleCache: try to recover on CreateEntry on missing cache dir (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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_) && base::CreateDirectory(path_)) {
879 files_[file_index].Initialize(filename, flags);
jkarlin 2017/05/05 17:16:21 I worry a bit about the state of the cache being s
pasko 2017/05/05 17:24:15 Writing index here would probably fix the issue, b
jkarlin 2017/05/05 17:42:18 Okay, works with me.
880 }
881
871 *out_error = files_[file_index].error_details(); 882 *out_error = files_[file_index].error_details();
872
873 empty_file_omitted_[file_index] = false; 883 empty_file_omitted_[file_index] = false;
874 884
875 return files_[file_index].IsValid(); 885 return files_[file_index].IsValid();
876 } 886 }
877 887
878 bool SimpleSynchronousEntry::OpenFiles(SimpleEntryStat* out_entry_stat) { 888 bool SimpleSynchronousEntry::OpenFiles(SimpleEntryStat* out_entry_stat) {
879 for (int i = 0; i < kSimpleEntryFileCount; ++i) { 889 for (int i = 0; i < kSimpleEntryFileCount; ++i) {
880 File::Error error; 890 File::Error error;
881 if (!MaybeOpenFile(i, &error)) { 891 if (!MaybeOpenFile(i, &error)) {
882 // TODO(juliatuttle,gavinp): Remove one each of these triplets of 892 // TODO(juliatuttle,gavinp): Remove one each of these triplets of
(...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after
1634 range.offset = offset; 1644 range.offset = offset;
1635 range.length = len; 1645 range.length = len;
1636 range.data_crc32 = data_crc32; 1646 range.data_crc32 = data_crc32;
1637 range.file_offset = data_file_offset; 1647 range.file_offset = data_file_offset;
1638 sparse_ranges_.insert(std::make_pair(offset, range)); 1648 sparse_ranges_.insert(std::make_pair(offset, range));
1639 1649
1640 return true; 1650 return true;
1641 } 1651 }
1642 1652
1643 } // namespace disk_cache 1653 } // namespace disk_cache
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698