| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CHROME_BROWSER_ANDROID_THUMBNAIL_SCOPED_PTR_EXPIRING_CACHE_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_THUMBNAIL_SCOPED_PTR_EXPIRING_CACHE_H_ |
| 6 #define CHROME_BROWSER_ANDROID_THUMBNAIL_SCOPED_PTR_EXPIRING_CACHE_H_ | 6 #define CHROME_BROWSER_ANDROID_THUMBNAIL_SCOPED_PTR_EXPIRING_CACHE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 EvictIfFull(); | 31 EvictIfFull(); |
| 32 } | 32 } |
| 33 | 33 |
| 34 Value* Get(const Key& key) { | 34 Value* Get(const Key& key) { |
| 35 iterator iter = map_.find(key); | 35 iterator iter = map_.find(key); |
| 36 if (iter != map_.end()) | 36 if (iter != map_.end()) |
| 37 return iter->second; | 37 return iter->second; |
| 38 return NULL; | 38 return NULL; |
| 39 } | 39 } |
| 40 | 40 |
| 41 void Remove(const Key& key) { | 41 std::unique_ptr<Value> Remove(const Key& key) { |
| 42 iterator iter = map_.find(key); | 42 iterator iter = map_.find(key); |
| 43 std::unique_ptr<Value> value; |
| 43 if (iter != map_.end()) { | 44 if (iter != map_.end()) { |
| 44 delete iter->second; | 45 value.reset(iter->second); |
| 45 map_.erase(key); | 46 map_.erase(key); |
| 46 } | 47 } |
| 48 return std::move(value); |
| 47 } | 49 } |
| 48 | 50 |
| 49 void Clear() { | 51 void Clear() { |
| 50 for (iterator iter = map_.begin(); iter != map_.end(); iter++) { | 52 for (iterator iter = map_.begin(); iter != map_.end(); iter++) { |
| 51 delete iter->second; | 53 delete iter->second; |
| 52 } | 54 } |
| 53 map_.clear(); | 55 map_.clear(); |
| 54 } | 56 } |
| 55 | 57 |
| 56 iterator begin() { return map_.begin(); } | 58 iterator begin() { return map_.begin(); } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 67 } | 69 } |
| 68 } | 70 } |
| 69 | 71 |
| 70 size_t max_cache_size_; | 72 size_t max_cache_size_; |
| 71 LinkedHashMap map_; | 73 LinkedHashMap map_; |
| 72 | 74 |
| 73 DISALLOW_COPY_AND_ASSIGN(ScopedPtrExpiringCache); | 75 DISALLOW_COPY_AND_ASSIGN(ScopedPtrExpiringCache); |
| 74 }; | 76 }; |
| 75 | 77 |
| 76 #endif // CHROME_BROWSER_ANDROID_THUMBNAIL_SCOPED_PTR_EXPIRING_CACHE_H_ | 78 #endif // CHROME_BROWSER_ANDROID_THUMBNAIL_SCOPED_PTR_EXPIRING_CACHE_H_ |
| OLD | NEW |