| 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> |
| 19 |
| 18 #include "webrtc/base/arraysize.h" | 20 #include "webrtc/base/arraysize.h" |
| 19 #include "webrtc/base/common.h" | 21 #include "webrtc/base/common.h" |
| 20 #include "webrtc/base/diskcache.h" | 22 #include "webrtc/base/diskcache.h" |
| 21 #include "webrtc/base/fileutils.h" | 23 #include "webrtc/base/fileutils.h" |
| 22 #include "webrtc/base/pathutils.h" | 24 #include "webrtc/base/pathutils.h" |
| 23 #include "webrtc/base/stream.h" | 25 #include "webrtc/base/stream.h" |
| 24 #include "webrtc/base/stringencode.h" | 26 #include "webrtc/base/stringencode.h" |
| 25 #include "webrtc/base/stringutils.h" | 27 #include "webrtc/base/stringutils.h" |
| 26 | 28 |
| 27 #if !defined(NDEBUG) | 29 #if !defined(NDEBUG) |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 return NULL; | 118 return NULL; |
| 117 | 119 |
| 118 size_t previous_size = 0; | 120 size_t previous_size = 0; |
| 119 std::string filename(IdToFilename(id, index)); | 121 std::string filename(IdToFilename(id, index)); |
| 120 FileStream::GetSize(filename, &previous_size); | 122 FileStream::GetSize(filename, &previous_size); |
| 121 ASSERT(previous_size <= entry->size); | 123 ASSERT(previous_size <= entry->size); |
| 122 if (previous_size > entry->size) { | 124 if (previous_size > entry->size) { |
| 123 previous_size = entry->size; | 125 previous_size = entry->size; |
| 124 } | 126 } |
| 125 | 127 |
| 126 scoped_ptr<FileStream> file(new FileStream); | 128 std::unique_ptr<FileStream> file(new FileStream); |
| 127 if (!file->Open(filename, "wb", NULL)) { | 129 if (!file->Open(filename, "wb", NULL)) { |
| 128 LOG_F(LS_ERROR) << "Couldn't create cache file"; | 130 LOG_F(LS_ERROR) << "Couldn't create cache file"; |
| 129 return NULL; | 131 return NULL; |
| 130 } | 132 } |
| 131 | 133 |
| 132 entry->streams = std::max(entry->streams, index + 1); | 134 entry->streams = std::max(entry->streams, index + 1); |
| 133 entry->size -= previous_size; | 135 entry->size -= previous_size; |
| 134 total_size_ -= previous_size; | 136 total_size_ -= previous_size; |
| 135 | 137 |
| 136 entry->accessors += 1; | 138 entry->accessors += 1; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 154 } | 156 } |
| 155 | 157 |
| 156 StreamInterface* DiskCache::ReadResource(const std::string& id, | 158 StreamInterface* DiskCache::ReadResource(const std::string& id, |
| 157 size_t index) const { | 159 size_t index) const { |
| 158 const Entry* entry = GetEntry(id); | 160 const Entry* entry = GetEntry(id); |
| 159 if (LS_UNLOCKED != entry->lock_state) | 161 if (LS_UNLOCKED != entry->lock_state) |
| 160 return NULL; | 162 return NULL; |
| 161 if (index >= entry->streams) | 163 if (index >= entry->streams) |
| 162 return NULL; | 164 return NULL; |
| 163 | 165 |
| 164 scoped_ptr<FileStream> file(new FileStream); | 166 std::unique_ptr<FileStream> file(new FileStream); |
| 165 if (!file->Open(IdToFilename(id, index), "rb", NULL)) | 167 if (!file->Open(IdToFilename(id, index), "rb", NULL)) |
| 166 return NULL; | 168 return NULL; |
| 167 | 169 |
| 168 entry->accessors += 1; | 170 entry->accessors += 1; |
| 169 total_accessors_ += 1; | 171 total_accessors_ += 1; |
| 170 return new DiskCacheAdapter(this, id, index, file.release()); | 172 return new DiskCacheAdapter(this, id, index, file.release()); |
| 171 } | 173 } |
| 172 | 174 |
| 173 bool DiskCache::HasResource(const std::string& id) const { | 175 bool DiskCache::HasResource(const std::string& id) const { |
| 174 const Entry* entry = GetEntry(id); | 176 const Entry* entry = GetEntry(id); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 entry2->last_modified = time(0); | 342 entry2->last_modified = time(0); |
| 341 entry2->lock_state = LS_UNLOCKED; | 343 entry2->lock_state = LS_UNLOCKED; |
| 342 this2->CheckLimit(); | 344 this2->CheckLimit(); |
| 343 } | 345 } |
| 344 } | 346 } |
| 345 } | 347 } |
| 346 | 348 |
| 347 /////////////////////////////////////////////////////////////////////////////// | 349 /////////////////////////////////////////////////////////////////////////////// |
| 348 | 350 |
| 349 } // namespace rtc | 351 } // namespace rtc |
| OLD | NEW |