| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "ios/chrome/browser/favicon/large_icon_cache.h" | 5 #include "ios/chrome/browser/favicon/large_icon_cache.h" |
| 6 | 6 |
| 7 #include "components/favicon_base/fallback_icon_style.h" | 7 #include "components/favicon_base/fallback_icon_style.h" |
| 8 #include "components/favicon_base/favicon_types.h" | 8 #include "components/favicon_base/favicon_types.h" |
| 9 #include "url/gurl.h" | 9 #include "url/gurl.h" |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 const int kMaxCacheSize = 12; | 13 const int kMaxCacheSize = 12; |
| 14 | 14 |
| 15 } // namespace | 15 } // namespace |
| 16 | 16 |
| 17 struct LargeIconCacheEntry { | 17 struct LargeIconCacheEntry { |
| 18 LargeIconCacheEntry() {} | 18 LargeIconCacheEntry() {} |
| 19 ~LargeIconCacheEntry() {} | 19 ~LargeIconCacheEntry() {} |
| 20 | 20 |
| 21 scoped_ptr<favicon_base::LargeIconResult> result; | 21 std::unique_ptr<favicon_base::LargeIconResult> result; |
| 22 }; | 22 }; |
| 23 | 23 |
| 24 LargeIconCache::LargeIconCache() : cache_(kMaxCacheSize) {} | 24 LargeIconCache::LargeIconCache() : cache_(kMaxCacheSize) {} |
| 25 | 25 |
| 26 LargeIconCache::~LargeIconCache() {} | 26 LargeIconCache::~LargeIconCache() {} |
| 27 | 27 |
| 28 void LargeIconCache::SetCachedResult( | 28 void LargeIconCache::SetCachedResult( |
| 29 const GURL& url, | 29 const GURL& url, |
| 30 const favicon_base::LargeIconResult& result) { | 30 const favicon_base::LargeIconResult& result) { |
| 31 scoped_ptr<LargeIconCacheEntry> entry(new LargeIconCacheEntry); | 31 std::unique_ptr<LargeIconCacheEntry> entry(new LargeIconCacheEntry); |
| 32 entry->result = CloneLargeIconResult(result); | 32 entry->result = CloneLargeIconResult(result); |
| 33 cache_.Put(url, std::move(entry)); | 33 cache_.Put(url, std::move(entry)); |
| 34 } | 34 } |
| 35 | 35 |
| 36 scoped_ptr<favicon_base::LargeIconResult> LargeIconCache::GetCachedResult( | 36 std::unique_ptr<favicon_base::LargeIconResult> LargeIconCache::GetCachedResult( |
| 37 const GURL& url) { | 37 const GURL& url) { |
| 38 auto iter = cache_.Get(url); | 38 auto iter = cache_.Get(url); |
| 39 if (iter != cache_.end()) { | 39 if (iter != cache_.end()) { |
| 40 DCHECK(iter->second->result); | 40 DCHECK(iter->second->result); |
| 41 return CloneLargeIconResult(*iter->second->result.get()); | 41 return CloneLargeIconResult(*iter->second->result.get()); |
| 42 } | 42 } |
| 43 | 43 |
| 44 return scoped_ptr<favicon_base::LargeIconResult>(); | 44 return std::unique_ptr<favicon_base::LargeIconResult>(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 scoped_ptr<favicon_base::LargeIconResult> LargeIconCache::CloneLargeIconResult( | 47 std::unique_ptr<favicon_base::LargeIconResult> |
| 48 LargeIconCache::CloneLargeIconResult( |
| 48 const favicon_base::LargeIconResult& large_icon_result) { | 49 const favicon_base::LargeIconResult& large_icon_result) { |
| 49 scoped_ptr<favicon_base::LargeIconResult> clone; | 50 std::unique_ptr<favicon_base::LargeIconResult> clone; |
| 50 if (large_icon_result.bitmap.is_valid()) { | 51 if (large_icon_result.bitmap.is_valid()) { |
| 51 clone.reset(new favicon_base::LargeIconResult(large_icon_result.bitmap)); | 52 clone.reset(new favicon_base::LargeIconResult(large_icon_result.bitmap)); |
| 52 } else { | 53 } else { |
| 53 clone.reset( | 54 clone.reset( |
| 54 new favicon_base::LargeIconResult(new favicon_base::FallbackIconStyle( | 55 new favicon_base::LargeIconResult(new favicon_base::FallbackIconStyle( |
| 55 *large_icon_result.fallback_icon_style.get()))); | 56 *large_icon_result.fallback_icon_style.get()))); |
| 56 } | 57 } |
| 57 return clone; | 58 return clone; |
| 58 } | 59 } |
| OLD | NEW |