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 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 LOG_F(LS_WARNING) << "Cache overfull"; | 104 LOG_F(LS_WARNING) << "Cache overfull"; |
105 return false; | 105 return false; |
106 } | 106 } |
107 entry->lock_state = LS_LOCKED; | 107 entry->lock_state = LS_LOCKED; |
108 return true; | 108 return true; |
109 } | 109 } |
110 | 110 |
111 StreamInterface* DiskCache::WriteResource(const std::string& id, size_t index) { | 111 StreamInterface* DiskCache::WriteResource(const std::string& id, size_t index) { |
112 Entry* entry = GetOrCreateEntry(id, false); | 112 Entry* entry = GetOrCreateEntry(id, false); |
113 if (LS_LOCKED != entry->lock_state) | 113 if (LS_LOCKED != entry->lock_state) |
114 return NULL; | 114 return nullptr; |
115 | 115 |
116 size_t previous_size = 0; | 116 size_t previous_size = 0; |
117 std::string filename(IdToFilename(id, index)); | 117 std::string filename(IdToFilename(id, index)); |
118 FileStream::GetSize(filename, &previous_size); | 118 FileStream::GetSize(filename, &previous_size); |
119 RTC_DCHECK(previous_size <= entry->size); | 119 RTC_DCHECK(previous_size <= entry->size); |
120 if (previous_size > entry->size) { | 120 if (previous_size > entry->size) { |
121 previous_size = entry->size; | 121 previous_size = entry->size; |
122 } | 122 } |
123 | 123 |
124 std::unique_ptr<FileStream> file(new FileStream); | 124 std::unique_ptr<FileStream> file(new FileStream); |
125 if (!file->Open(filename, "wb", NULL)) { | 125 if (!file->Open(filename, "wb", nullptr)) { |
126 LOG_F(LS_ERROR) << "Couldn't create cache file"; | 126 LOG_F(LS_ERROR) << "Couldn't create cache file"; |
127 return NULL; | 127 return nullptr; |
128 } | 128 } |
129 | 129 |
130 entry->streams = std::max(entry->streams, index + 1); | 130 entry->streams = std::max(entry->streams, index + 1); |
131 entry->size -= previous_size; | 131 entry->size -= previous_size; |
132 total_size_ -= previous_size; | 132 total_size_ -= previous_size; |
133 | 133 |
134 entry->accessors += 1; | 134 entry->accessors += 1; |
135 total_accessors_ += 1; | 135 total_accessors_ += 1; |
136 return new DiskCacheAdapter(this, id, index, file.release()); | 136 return new DiskCacheAdapter(this, id, index, file.release()); |
137 } | 137 } |
(...skipping 10 matching lines...) Expand all Loading... |
148 entry->last_modified = time(0); | 148 entry->last_modified = time(0); |
149 CheckLimit(); | 149 CheckLimit(); |
150 } | 150 } |
151 return true; | 151 return true; |
152 } | 152 } |
153 | 153 |
154 StreamInterface* DiskCache::ReadResource(const std::string& id, | 154 StreamInterface* DiskCache::ReadResource(const std::string& id, |
155 size_t index) const { | 155 size_t index) const { |
156 const Entry* entry = GetEntry(id); | 156 const Entry* entry = GetEntry(id); |
157 if (LS_UNLOCKED != entry->lock_state) | 157 if (LS_UNLOCKED != entry->lock_state) |
158 return NULL; | 158 return nullptr; |
159 if (index >= entry->streams) | 159 if (index >= entry->streams) |
160 return NULL; | 160 return nullptr; |
161 | 161 |
162 std::unique_ptr<FileStream> file(new FileStream); | 162 std::unique_ptr<FileStream> file(new FileStream); |
163 if (!file->Open(IdToFilename(id, index), "rb", NULL)) | 163 if (!file->Open(IdToFilename(id, index), "rb", nullptr)) |
164 return NULL; | 164 return nullptr; |
165 | 165 |
166 entry->accessors += 1; | 166 entry->accessors += 1; |
167 total_accessors_ += 1; | 167 total_accessors_ += 1; |
168 return new DiskCacheAdapter(this, id, index, file.release()); | 168 return new DiskCacheAdapter(this, id, index, file.release()); |
169 } | 169 } |
170 | 170 |
171 bool DiskCache::HasResource(const std::string& id) const { | 171 bool DiskCache::HasResource(const std::string& id) const { |
172 const Entry* entry = GetEntry(id); | 172 const Entry* entry = GetEntry(id); |
173 return (NULL != entry) && (entry->streams > 0); | 173 return (nullptr != entry) && (entry->streams > 0); |
174 } | 174 } |
175 | 175 |
176 bool DiskCache::HasResourceStream(const std::string& id, size_t index) const { | 176 bool DiskCache::HasResourceStream(const std::string& id, size_t index) const { |
177 const Entry* entry = GetEntry(id); | 177 const Entry* entry = GetEntry(id); |
178 if ((NULL == entry) || (index >= entry->streams)) | 178 if ((nullptr == entry) || (index >= entry->streams)) |
179 return false; | 179 return false; |
180 | 180 |
181 std::string filename = IdToFilename(id, index); | 181 std::string filename = IdToFilename(id, index); |
182 | 182 |
183 return FileExists(filename); | 183 return FileExists(filename); |
184 } | 184 } |
185 | 185 |
186 bool DiskCache::DeleteResource(const std::string& id) { | 186 bool DiskCache::DeleteResource(const std::string& id) { |
187 Entry* entry = GetOrCreateEntry(id, false); | 187 Entry* entry = GetOrCreateEntry(id, false); |
188 if (!entry) | 188 if (!entry) |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 delete [] buffer; | 293 delete [] buffer; |
294 return true; | 294 return true; |
295 } | 295 } |
296 | 296 |
297 DiskCache::Entry* DiskCache::GetOrCreateEntry(const std::string& id, | 297 DiskCache::Entry* DiskCache::GetOrCreateEntry(const std::string& id, |
298 bool create) { | 298 bool create) { |
299 EntryMap::iterator it = map_.find(id); | 299 EntryMap::iterator it = map_.find(id); |
300 if (it != map_.end()) | 300 if (it != map_.end()) |
301 return &it->second; | 301 return &it->second; |
302 if (!create) | 302 if (!create) |
303 return NULL; | 303 return nullptr; |
304 Entry e; | 304 Entry e; |
305 e.lock_state = LS_UNLOCKED; | 305 e.lock_state = LS_UNLOCKED; |
306 e.accessors = 0; | 306 e.accessors = 0; |
307 e.size = 0; | 307 e.size = 0; |
308 e.streams = 0; | 308 e.streams = 0; |
309 e.last_modified = time(0); | 309 e.last_modified = time(0); |
310 it = map_.insert(EntryMap::value_type(id, e)).first; | 310 it = map_.insert(EntryMap::value_type(id, e)).first; |
311 return &it->second; | 311 return &it->second; |
312 } | 312 } |
313 | 313 |
(...skipping 24 matching lines...) Expand all Loading... |
338 entry2->last_modified = time(0); | 338 entry2->last_modified = time(0); |
339 entry2->lock_state = LS_UNLOCKED; | 339 entry2->lock_state = LS_UNLOCKED; |
340 this2->CheckLimit(); | 340 this2->CheckLimit(); |
341 } | 341 } |
342 } | 342 } |
343 } | 343 } |
344 | 344 |
345 /////////////////////////////////////////////////////////////////////////////// | 345 /////////////////////////////////////////////////////////////////////////////// |
346 | 346 |
347 } // namespace rtc | 347 } // namespace rtc |
OLD | NEW |