| 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 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 scoped_ptr<favicon_base::LargeIconResult> result; | 21 scoped_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 LargeIconCacheEntry* entry = new LargeIconCacheEntry; | 31 scoped_ptr<LargeIconCacheEntry> entry(new LargeIconCacheEntry); |
| 32 entry->result = CloneLargeIconResult(result); | 32 entry->result = CloneLargeIconResult(result); |
| 33 cache_.Put(url, entry); | 33 cache_.Put(url, std::move(entry)); |
| 34 } | 34 } |
| 35 | 35 |
| 36 scoped_ptr<favicon_base::LargeIconResult> LargeIconCache::GetCachedResult( | 36 scoped_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 scoped_ptr<favicon_base::LargeIconResult>(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 scoped_ptr<favicon_base::LargeIconResult> LargeIconCache::CloneLargeIconResult( | 47 scoped_ptr<favicon_base::LargeIconResult> LargeIconCache::CloneLargeIconResult( |
| 48 const favicon_base::LargeIconResult& large_icon_result) { | 48 const favicon_base::LargeIconResult& large_icon_result) { |
| 49 scoped_ptr<favicon_base::LargeIconResult> clone; | 49 scoped_ptr<favicon_base::LargeIconResult> clone; |
| 50 if (large_icon_result.bitmap.is_valid()) { | 50 if (large_icon_result.bitmap.is_valid()) { |
| 51 clone.reset(new favicon_base::LargeIconResult(large_icon_result.bitmap)); | 51 clone.reset(new favicon_base::LargeIconResult(large_icon_result.bitmap)); |
| 52 } else { | 52 } else { |
| 53 clone.reset( | 53 clone.reset( |
| 54 new favicon_base::LargeIconResult(new favicon_base::FallbackIconStyle( | 54 new favicon_base::LargeIconResult(new favicon_base::FallbackIconStyle( |
| 55 *large_icon_result.fallback_icon_style.get()))); | 55 *large_icon_result.fallback_icon_style.get()))); |
| 56 } | 56 } |
| 57 return clone; | 57 return clone; |
| 58 } | 58 } |
| OLD | NEW |