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 <limits> | 9 #include <limits> |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... | |
33 using base::PLATFORM_FILE_READ; | 33 using base::PLATFORM_FILE_READ; |
34 using base::PLATFORM_FILE_WRITE; | 34 using base::PLATFORM_FILE_WRITE; |
35 using base::ReadPlatformFile; | 35 using base::ReadPlatformFile; |
36 using base::TaskRunner; | 36 using base::TaskRunner; |
37 using base::Time; | 37 using base::Time; |
38 using base::TruncatePlatformFile; | 38 using base::TruncatePlatformFile; |
39 using base::WritePlatformFile; | 39 using base::WritePlatformFile; |
40 | 40 |
41 namespace disk_cache { | 41 namespace disk_cache { |
42 | 42 |
43 using simple_util::ConvertEntryHashKeyToHexString; | |
44 using simple_util::GetEntryHashKeyAsHexString; | |
45 using simple_util::GetFilenameFromHexStringAndIndex; | |
43 using simple_util::GetFilenameFromKeyAndIndex; | 46 using simple_util::GetFilenameFromKeyAndIndex; |
44 using simple_util::GetDataSizeFromKeyAndFileSize; | 47 using simple_util::GetDataSizeFromKeyAndFileSize; |
45 using simple_util::GetFileSizeFromKeyAndDataSize; | 48 using simple_util::GetFileSizeFromKeyAndDataSize; |
46 using simple_util::GetFileOffsetFromKeyAndDataOffset; | 49 using simple_util::GetFileOffsetFromKeyAndDataOffset; |
47 | 50 |
48 // static | 51 // static |
49 void SimpleSynchronousEntry::OpenEntry( | 52 void SimpleSynchronousEntry::OpenEntry( |
50 const FilePath& path, | 53 const FilePath& path, |
51 const std::string& key, | 54 const std::string& key, |
52 const scoped_refptr<TaskRunner>& callback_runner, | 55 const scoped_refptr<TaskRunner>& callback_runner, |
(...skipping 22 matching lines...) Expand all Loading... | |
75 if (rv != net::ERR_FILE_EXISTS) { | 78 if (rv != net::ERR_FILE_EXISTS) { |
76 sync_entry->Doom(); | 79 sync_entry->Doom(); |
77 } | 80 } |
78 delete sync_entry; | 81 delete sync_entry; |
79 sync_entry = NULL; | 82 sync_entry = NULL; |
80 } | 83 } |
81 callback_runner->PostTask(FROM_HERE, base::Bind(callback, sync_entry)); | 84 callback_runner->PostTask(FROM_HERE, base::Bind(callback, sync_entry)); |
82 } | 85 } |
83 | 86 |
84 // static | 87 // static |
88 bool SimpleSynchronousEntry::DeleteFilesForEntry(const FilePath& path, | |
89 const std::string& hash_key) { | |
90 bool result = true; | |
91 for (int i = 0; i < kSimpleEntryFileCount; ++i) { | |
92 FilePath to_delete = path.AppendASCII( | |
93 GetFilenameFromHexStringAndIndex(hash_key, i)); | |
94 if (!file_util::Delete(to_delete, false)) { | |
95 result = false; | |
96 DLOG(ERROR) << "Could not delete " << to_delete.MaybeAsASCII(); | |
97 } | |
98 } | |
99 return result; | |
100 } | |
101 | |
102 // static | |
85 void SimpleSynchronousEntry::DoomEntry( | 103 void SimpleSynchronousEntry::DoomEntry( |
86 const FilePath& path, | 104 const FilePath& path, |
87 const std::string& key, | 105 const std::string& key, |
88 scoped_refptr<TaskRunner> callback_runner, | 106 scoped_refptr<TaskRunner> callback_runner, |
89 const net::CompletionCallback& callback) { | 107 const net::CompletionCallback& callback) { |
90 for (int i = 0; i < kSimpleEntryFileCount; ++i) { | 108 bool deleted_well = DeleteFilesForEntry(path, |
91 FilePath to_delete = path.AppendASCII(GetFilenameFromKeyAndIndex(key, i)); | 109 GetEntryHashKeyAsHexString(key)); |
92 bool ALLOW_UNUSED result = file_util::Delete(to_delete, false); | 110 int result = deleted_well ? net::OK : net::ERR_FAILED; |
93 DLOG_IF(ERROR, !result) << "Could not delete " << to_delete.MaybeAsASCII(); | |
94 } | |
95 if (!callback.is_null()) | 111 if (!callback.is_null()) |
96 callback_runner->PostTask(FROM_HERE, base::Bind(callback, net::OK)); | 112 callback_runner->PostTask(FROM_HERE, base::Bind(callback, result)); |
113 } | |
114 | |
115 // static | |
116 void SimpleSynchronousEntry::DoomEntrySet( | |
117 scoped_ptr<std::set<uint64> > key_hashes, | |
118 const FilePath& path, | |
119 scoped_refptr<TaskRunner> callback_runner, | |
120 const net::CompletionCallback& callback) { | |
121 bool deleted_well = true; | |
122 for (std::set<uint64>::const_iterator it = key_hashes->begin(), | |
123 end = key_hashes->end(); it != end; ++it) | |
124 deleted_well &= DeleteFilesForEntry(path, | |
125 ConvertEntryHashKeyToHexString((*it))); | |
126 int result = deleted_well ? net::OK : net::ERR_FAILED; | |
127 if (!callback.is_null()) | |
128 callback_runner->PostTask(FROM_HERE, base::Bind(callback, result)); | |
97 } | 129 } |
98 | 130 |
99 void SimpleSynchronousEntry::Close() { | 131 void SimpleSynchronousEntry::Close() { |
100 for (int i = 0; i < kSimpleEntryFileCount; ++i) { | 132 for (int i = 0; i < kSimpleEntryFileCount; ++i) { |
101 bool ALLOW_UNUSED result = ClosePlatformFile(files_[i]); | 133 bool ALLOW_UNUSED result = ClosePlatformFile(files_[i]); |
102 DLOG_IF(INFO, !result) << "Could not Close() file."; | 134 DLOG_IF(INFO, !result) << "Could not Close() file."; |
103 } | 135 } |
104 delete this; | 136 delete this; |
105 } | 137 } |
106 | 138 |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 DLOG(WARNING) << "Could not write keys to new cache entry."; | 326 DLOG(WARNING) << "Could not write keys to new cache entry."; |
295 return net::ERR_FAILED; | 327 return net::ERR_FAILED; |
296 } | 328 } |
297 } | 329 } |
298 initialized_ = true; | 330 initialized_ = true; |
299 return net::OK; | 331 return net::OK; |
300 } | 332 } |
301 | 333 |
302 void SimpleSynchronousEntry::Doom() { | 334 void SimpleSynchronousEntry::Doom() { |
303 // TODO(gavinp): Consider if we should guard against redundant Doom() calls. | 335 // TODO(gavinp): Consider if we should guard against redundant Doom() calls. |
304 DoomEntry(path_, key_, | 336 DoomEntry(path_, key_, |
gavinp
2013/04/17 07:41:18
Should this call DeleteFilesForEntry now?
pasko-google - do not use
2013/04/17 19:47:52
Yes. Nice. Done.
| |
305 scoped_refptr<base::TaskRunner>(), net::CompletionCallback()); | 337 scoped_refptr<base::TaskRunner>(), net::CompletionCallback()); |
306 } | 338 } |
307 | 339 |
308 } // namespace disk_cache | 340 } // namespace disk_cache |
OLD | NEW |