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 <memory> | 18 #include <memory> |
19 | 19 |
20 #include "webrtc/base/arraysize.h" | 20 #include "webrtc/base/arraysize.h" |
| 21 #include "webrtc/base/checks.h" |
21 #include "webrtc/base/common.h" | 22 #include "webrtc/base/common.h" |
22 #include "webrtc/base/diskcache.h" | 23 #include "webrtc/base/diskcache.h" |
23 #include "webrtc/base/fileutils.h" | 24 #include "webrtc/base/fileutils.h" |
24 #include "webrtc/base/pathutils.h" | 25 #include "webrtc/base/pathutils.h" |
25 #include "webrtc/base/stream.h" | 26 #include "webrtc/base/stream.h" |
26 #include "webrtc/base/stringencode.h" | 27 #include "webrtc/base/stringencode.h" |
27 #include "webrtc/base/stringutils.h" | 28 #include "webrtc/base/stringutils.h" |
28 | 29 |
29 #if !defined(NDEBUG) | 30 #if !defined(NDEBUG) |
30 #define TRANSPARENT_CACHE_NAMES 1 | 31 #define TRANSPARENT_CACHE_NAMES 1 |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 // This escapes colons and other filesystem characters, so the user can't open | 256 // This escapes colons and other filesystem characters, so the user can't open |
256 // special devices (like "COM1:"), or access other directories. | 257 // special devices (like "COM1:"), or access other directories. |
257 size_t buffer_size = id.length()*3 + 1; | 258 size_t buffer_size = id.length()*3 + 1; |
258 char* buffer = new char[buffer_size]; | 259 char* buffer = new char[buffer_size]; |
259 encode(buffer, buffer_size, id.data(), id.length(), | 260 encode(buffer, buffer_size, id.data(), id.length(), |
260 unsafe_filename_characters(), '%'); | 261 unsafe_filename_characters(), '%'); |
261 // TODO: ASSERT(strlen(buffer) < FileSystem::MaxBasenameLength()); | 262 // TODO: ASSERT(strlen(buffer) < FileSystem::MaxBasenameLength()); |
262 #else // !TRANSPARENT_CACHE_NAMES | 263 #else // !TRANSPARENT_CACHE_NAMES |
263 // We might want to just use a hash of the filename at some point, both for | 264 // We might want to just use a hash of the filename at some point, both for |
264 // obfuscation, and to avoid both filename length and escaping issues. | 265 // obfuscation, and to avoid both filename length and escaping issues. |
265 ASSERT(false); | 266 RTC_NOTREACHED(); |
266 #endif // !TRANSPARENT_CACHE_NAMES | 267 #endif // !TRANSPARENT_CACHE_NAMES |
267 | 268 |
268 char extension[32]; | 269 char extension[32]; |
269 sprintfn(extension, arraysize(extension), ".%u", index); | 270 sprintfn(extension, arraysize(extension), ".%u", index); |
270 | 271 |
271 Pathname pathname; | 272 Pathname pathname; |
272 pathname.SetFolder(folder_); | 273 pathname.SetFolder(folder_); |
273 pathname.SetBasename(buffer); | 274 pathname.SetBasename(buffer); |
274 pathname.SetExtension(extension); | 275 pathname.SetExtension(extension); |
275 | 276 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 e.streams = 0; | 313 e.streams = 0; |
313 e.last_modified = time(0); | 314 e.last_modified = time(0); |
314 it = map_.insert(EntryMap::value_type(id, e)).first; | 315 it = map_.insert(EntryMap::value_type(id, e)).first; |
315 return &it->second; | 316 return &it->second; |
316 } | 317 } |
317 | 318 |
318 void DiskCache::ReleaseResource(const std::string& id, size_t index) const { | 319 void DiskCache::ReleaseResource(const std::string& id, size_t index) const { |
319 const Entry* entry = GetEntry(id); | 320 const Entry* entry = GetEntry(id); |
320 if (!entry) { | 321 if (!entry) { |
321 LOG_F(LS_WARNING) << "Missing cache entry"; | 322 LOG_F(LS_WARNING) << "Missing cache entry"; |
322 ASSERT(false); | 323 RTC_NOTREACHED(); |
323 return; | 324 return; |
324 } | 325 } |
325 | 326 |
326 entry->accessors -= 1; | 327 entry->accessors -= 1; |
327 total_accessors_ -= 1; | 328 total_accessors_ -= 1; |
328 | 329 |
329 if (LS_UNLOCKED != entry->lock_state) { | 330 if (LS_UNLOCKED != entry->lock_state) { |
330 // This is safe, because locked resources only issue WriteResource, which | 331 // This is safe, because locked resources only issue WriteResource, which |
331 // is non-const. Think about a better way to handle it. | 332 // is non-const. Think about a better way to handle it. |
332 DiskCache* this2 = const_cast<DiskCache*>(this); | 333 DiskCache* this2 = const_cast<DiskCache*>(this); |
333 Entry* entry2 = this2->GetOrCreateEntry(id, false); | 334 Entry* entry2 = this2->GetOrCreateEntry(id, false); |
334 | 335 |
335 size_t new_size = 0; | 336 size_t new_size = 0; |
336 std::string filename(IdToFilename(id, index)); | 337 std::string filename(IdToFilename(id, index)); |
337 FileStream::GetSize(filename, &new_size); | 338 FileStream::GetSize(filename, &new_size); |
338 entry2->size += new_size; | 339 entry2->size += new_size; |
339 this2->total_size_ += new_size; | 340 this2->total_size_ += new_size; |
340 | 341 |
341 if ((LS_UNLOCKING == entry->lock_state) && (0 == entry->accessors)) { | 342 if ((LS_UNLOCKING == entry->lock_state) && (0 == entry->accessors)) { |
342 entry2->last_modified = time(0); | 343 entry2->last_modified = time(0); |
343 entry2->lock_state = LS_UNLOCKED; | 344 entry2->lock_state = LS_UNLOCKED; |
344 this2->CheckLimit(); | 345 this2->CheckLimit(); |
345 } | 346 } |
346 } | 347 } |
347 } | 348 } |
348 | 349 |
349 /////////////////////////////////////////////////////////////////////////////// | 350 /////////////////////////////////////////////////////////////////////////////// |
350 | 351 |
351 } // namespace rtc | 352 } // namespace rtc |
OLD | NEW |