| 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_backend_impl.h" | 5 #include "net/disk_cache/simple/simple_backend_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstdlib> | 8 #include <cstdlib> |
| 9 #include <functional> | 9 #include <functional> |
| 10 | 10 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 if (fd_limit_status == FD_LIMIT_STATUS_SUCCEEDED) { | 116 if (fd_limit_status == FD_LIMIT_STATUS_SUCCEEDED) { |
| 117 SIMPLE_CACHE_UMA(SPARSE_SLOWLY, | 117 SIMPLE_CACHE_UMA(SPARSE_SLOWLY, |
| 118 "FileDescriptorLimitSoft", cache_type, soft_fd_limit); | 118 "FileDescriptorLimitSoft", cache_type, soft_fd_limit); |
| 119 SIMPLE_CACHE_UMA(SPARSE_SLOWLY, | 119 SIMPLE_CACHE_UMA(SPARSE_SLOWLY, |
| 120 "FileDescriptorLimitHard", cache_type, hard_fd_limit); | 120 "FileDescriptorLimitHard", cache_type, hard_fd_limit); |
| 121 } | 121 } |
| 122 | 122 |
| 123 g_fd_limit_histogram_has_been_populated = true; | 123 g_fd_limit_histogram_has_been_populated = true; |
| 124 } | 124 } |
| 125 | 125 |
| 126 // Must run on IO Thread. | |
| 127 void DeleteBackendImpl(disk_cache::Backend** backend, | |
| 128 const net::CompletionCallback& callback, | |
| 129 int result) { | |
| 130 DCHECK(*backend); | |
| 131 delete *backend; | |
| 132 *backend = NULL; | |
| 133 callback.Run(result); | |
| 134 } | |
| 135 | |
| 136 // Detects if the files in the cache directory match the current disk cache | 126 // Detects if the files in the cache directory match the current disk cache |
| 137 // backend type and version. If the directory contains no cache, occupies it | 127 // backend type and version. If the directory contains no cache, occupies it |
| 138 // with the fresh structure. | 128 // with the fresh structure. |
| 139 bool FileStructureConsistent(const base::FilePath& path) { | 129 bool FileStructureConsistent(const base::FilePath& path) { |
| 140 if (!base::PathExists(path) && !file_util::CreateDirectory(path)) { | 130 if (!base::PathExists(path) && !file_util::CreateDirectory(path)) { |
| 141 LOG(ERROR) << "Failed to create directory: " << path.LossyDisplayName(); | 131 LOG(ERROR) << "Failed to create directory: " << path.LossyDisplayName(); |
| 142 return false; | 132 return false; |
| 143 } | 133 } |
| 144 return disk_cache::UpgradeSimpleCacheOnDisk(path); | 134 return disk_cache::UpgradeSimpleCacheOnDisk(path); |
| 145 } | 135 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 // A short bindable thunk that ensures a completion callback is always called | 178 // A short bindable thunk that ensures a completion callback is always called |
| 189 // after running an operation asynchronously. | 179 // after running an operation asynchronously. |
| 190 void RunOperationAndCallback( | 180 void RunOperationAndCallback( |
| 191 const Callback<int(const net::CompletionCallback&)>& operation, | 181 const Callback<int(const net::CompletionCallback&)>& operation, |
| 192 const net::CompletionCallback& operation_callback) { | 182 const net::CompletionCallback& operation_callback) { |
| 193 const int operation_result = operation.Run(operation_callback); | 183 const int operation_result = operation.Run(operation_callback); |
| 194 if (operation_result != net::ERR_IO_PENDING) | 184 if (operation_result != net::ERR_IO_PENDING) |
| 195 operation_callback.Run(operation_result); | 185 operation_callback.Run(operation_result); |
| 196 } | 186 } |
| 197 | 187 |
| 198 // A short bindable thunk that Dooms an entry if it successfully opens. | |
| 199 void DoomOpenedEntry(scoped_ptr<Entry*> in_entry, | |
| 200 const net::CompletionCallback& doom_callback, | |
| 201 int open_result) { | |
| 202 DCHECK_NE(open_result, net::ERR_IO_PENDING); | |
| 203 if (open_result == net::OK) { | |
| 204 DCHECK(in_entry); | |
| 205 SimpleEntryImpl* simple_entry = static_cast<SimpleEntryImpl*>(*in_entry); | |
| 206 const int doom_result = simple_entry->DoomEntry(doom_callback); | |
| 207 simple_entry->Close(); | |
| 208 if (doom_result != net::ERR_IO_PENDING) | |
| 209 doom_callback.Run(doom_result); | |
| 210 } else { | |
| 211 doom_callback.Run(open_result); | |
| 212 } | |
| 213 } | |
| 214 | |
| 215 void RecordIndexLoad(net::CacheType cache_type, | 188 void RecordIndexLoad(net::CacheType cache_type, |
| 216 base::TimeTicks constructed_since, | 189 base::TimeTicks constructed_since, |
| 217 int result) { | 190 int result) { |
| 218 const base::TimeDelta creation_to_index = base::TimeTicks::Now() - | 191 const base::TimeDelta creation_to_index = base::TimeTicks::Now() - |
| 219 constructed_since; | 192 constructed_since; |
| 220 if (result == net::OK) { | 193 if (result == net::OK) { |
| 221 SIMPLE_CACHE_UMA(TIMES, "CreationToIndex", cache_type, creation_to_index); | 194 SIMPLE_CACHE_UMA(TIMES, "CreationToIndex", cache_type, creation_to_index); |
| 222 } else { | 195 } else { |
| 223 SIMPLE_CACHE_UMA(TIMES, | 196 SIMPLE_CACHE_UMA(TIMES, |
| 224 "CreationToIndexFail", cache_type, creation_to_index); | 197 "CreationToIndexFail", cache_type, creation_to_index); |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 this)); | 706 this)); |
| 734 callback.Run(result); | 707 callback.Run(result); |
| 735 } | 708 } |
| 736 | 709 |
| 737 void SimpleBackendImpl::FlushWorkerPoolForTesting() { | 710 void SimpleBackendImpl::FlushWorkerPoolForTesting() { |
| 738 if (g_sequenced_worker_pool) | 711 if (g_sequenced_worker_pool) |
| 739 g_sequenced_worker_pool->FlushForTesting(); | 712 g_sequenced_worker_pool->FlushForTesting(); |
| 740 } | 713 } |
| 741 | 714 |
| 742 } // namespace disk_cache | 715 } // namespace disk_cache |
| OLD | NEW |