| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include <time.h> | 11 #include <time.h> |
| 12 | 12 |
| 13 #if defined(WEBRTC_WIN) | 13 #if defined(WEBRTC_WIN) |
| 14 #include "webrtc/base/win32.h" | 14 #include "webrtc/base/win32.h" |
| 15 #endif | 15 #endif |
| 16 | 16 |
| 17 #include <algorithm> | 17 #include <algorithm> |
| 18 #include "webrtc/base/common.h" | 18 #include "webrtc/base/common.h" |
| 19 #include "webrtc/base/diskcache.h" | 19 #include "webrtc/base/diskcache.h" |
| 20 #include "webrtc/base/fileutils.h" | 20 #include "webrtc/base/fileutils.h" |
| 21 #include "webrtc/base/pathutils.h" | 21 #include "webrtc/base/pathutils.h" |
| 22 #include "webrtc/base/stream.h" | 22 #include "webrtc/base/stream.h" |
| 23 #include "webrtc/base/stringencode.h" | 23 #include "webrtc/base/stringencode.h" |
| 24 #include "webrtc/base/stringutils.h" | 24 #include "webrtc/base/stringutils.h" |
| 25 | 25 |
| 26 #ifdef _DEBUG | 26 #if !defined(NDEBUG) |
| 27 #define TRANSPARENT_CACHE_NAMES 1 | 27 #define TRANSPARENT_CACHE_NAMES 1 |
| 28 #else // !_DEBUG | 28 #else |
| 29 #define TRANSPARENT_CACHE_NAMES 0 | 29 #define TRANSPARENT_CACHE_NAMES 0 |
| 30 #endif // !_DEBUG | 30 #endif |
| 31 | 31 |
| 32 namespace rtc { | 32 namespace rtc { |
| 33 | 33 |
| 34 class DiskCache; | 34 class DiskCache; |
| 35 | 35 |
| 36 /////////////////////////////////////////////////////////////////////////////// | 36 /////////////////////////////////////////////////////////////////////////////// |
| 37 // DiskCacheAdapter | 37 // DiskCacheAdapter |
| 38 /////////////////////////////////////////////////////////////////////////////// | 38 /////////////////////////////////////////////////////////////////////////////// |
| 39 | 39 |
| 40 class DiskCacheAdapter : public StreamAdapterInterface { | 40 class DiskCacheAdapter : public StreamAdapterInterface { |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 success = false; | 204 success = false; |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 | 207 |
| 208 total_size_ -= entry->size; | 208 total_size_ -= entry->size; |
| 209 map_.erase(id); | 209 map_.erase(id); |
| 210 return success; | 210 return success; |
| 211 } | 211 } |
| 212 | 212 |
| 213 bool DiskCache::CheckLimit() { | 213 bool DiskCache::CheckLimit() { |
| 214 #ifdef _DEBUG | 214 #if !defined(NDEBUG) |
| 215 // Temporary check to make sure everything is working correctly. | 215 // Temporary check to make sure everything is working correctly. |
| 216 size_t cache_size = 0; | 216 size_t cache_size = 0; |
| 217 for (EntryMap::iterator it = map_.begin(); it != map_.end(); ++it) { | 217 for (EntryMap::iterator it = map_.begin(); it != map_.end(); ++it) { |
| 218 cache_size += it->second.size; | 218 cache_size += it->second.size; |
| 219 } | 219 } |
| 220 ASSERT(cache_size == total_size_); | 220 ASSERT(cache_size == total_size_); |
| 221 #endif // _DEBUG | 221 #endif |
| 222 | 222 |
| 223 // TODO: Replace this with a non-brain-dead algorithm for clearing out the | 223 // TODO: Replace this with a non-brain-dead algorithm for clearing out the |
| 224 // oldest resources... something that isn't O(n^2) | 224 // oldest resources... something that isn't O(n^2) |
| 225 while (total_size_ > max_cache_) { | 225 while (total_size_ > max_cache_) { |
| 226 EntryMap::iterator oldest = map_.end(); | 226 EntryMap::iterator oldest = map_.end(); |
| 227 for (EntryMap::iterator it = map_.begin(); it != map_.end(); ++it) { | 227 for (EntryMap::iterator it = map_.begin(); it != map_.end(); ++it) { |
| 228 if ((LS_UNLOCKED != it->second.lock_state) || (it->second.accessors > 0)) | 228 if ((LS_UNLOCKED != it->second.lock_state) || (it->second.accessors > 0)) |
| 229 continue; | 229 continue; |
| 230 oldest = it; | 230 oldest = it; |
| 231 break; | 231 break; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 entry2->last_modified = time(0); | 339 entry2->last_modified = time(0); |
| 340 entry2->lock_state = LS_UNLOCKED; | 340 entry2->lock_state = LS_UNLOCKED; |
| 341 this2->CheckLimit(); | 341 this2->CheckLimit(); |
| 342 } | 342 } |
| 343 } | 343 } |
| 344 } | 344 } |
| 345 | 345 |
| 346 /////////////////////////////////////////////////////////////////////////////// | 346 /////////////////////////////////////////////////////////////////////////////// |
| 347 | 347 |
| 348 } // namespace rtc | 348 } // namespace rtc |
| OLD | NEW |