OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #import "ios/chrome/browser/ui/settings/utils/resized_avatar_cache.h" | 5 #import "ios/chrome/browser/ui/settings/utils/resized_avatar_cache.h" |
6 | 6 |
7 #import "base/mac/scoped_nsobject.h" | |
8 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 7 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
9 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 8 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
10 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h" | 9 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h" |
11 #import "ios/public/provider/chrome/browser/signin/chrome_identity_service.h" | 10 #import "ios/public/provider/chrome/browser/signin/chrome_identity_service.h" |
12 #import "ios/public/provider/chrome/browser/signin/signin_resources_provider.h" | 11 #import "ios/public/provider/chrome/browser/signin/signin_resources_provider.h" |
13 | 12 |
| 13 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 14 #error "This file requires ARC support." |
| 15 #endif |
| 16 |
14 namespace { | 17 namespace { |
15 const CGFloat kAccountProfilePhotoDimension = 40.0f; | 18 const CGFloat kAccountProfilePhotoDimension = 40.0f; |
16 } // namespace | 19 } // namespace |
17 | 20 |
18 @implementation ResizedAvatarCache { | 21 @implementation ResizedAvatarCache { |
19 // Retains resized images. Key is Chrome Identity. | 22 // Retains resized images. Key is Chrome Identity. |
20 base::scoped_nsobject<NSCache<ChromeIdentity*, UIImage*>> _resizedImages; | 23 NSCache<ChromeIdentity*, UIImage*>* _resizedImages; |
21 | 24 |
22 // Holds weak references to the cached avatar image from the | 25 // Holds weak references to the cached avatar image from the |
23 // ChromeIdentityService. Key is Chrome Identity. | 26 // ChromeIdentityService. Key is Chrome Identity. |
24 base::scoped_nsobject<NSMapTable<ChromeIdentity*, UIImage*>> _originalImages; | 27 NSMapTable<ChromeIdentity*, UIImage*>* _originalImages; |
25 } | 28 } |
26 | 29 |
27 - (instancetype)init { | 30 - (instancetype)init { |
28 self = [super init]; | 31 self = [super init]; |
29 if (self) { | 32 if (self) { |
30 _resizedImages.reset([[NSCache alloc] init]); | 33 _resizedImages = [[NSCache alloc] init]; |
31 _originalImages.reset([[NSMapTable strongToWeakObjectsMapTable] retain]); | 34 _originalImages = [NSMapTable strongToWeakObjectsMapTable]; |
32 } | 35 } |
33 return self; | 36 return self; |
34 } | 37 } |
35 | 38 |
36 - (UIImage*)resizedAvatarForIdentity:(ChromeIdentity*)identity { | 39 - (UIImage*)resizedAvatarForIdentity:(ChromeIdentity*)identity { |
37 UIImage* image = ios::GetChromeBrowserProvider() | 40 UIImage* image = ios::GetChromeBrowserProvider() |
38 ->GetChromeIdentityService() | 41 ->GetChromeIdentityService() |
39 ->GetCachedAvatarForIdentity(identity); | 42 ->GetCachedAvatarForIdentity(identity); |
40 if (!image) { | 43 if (!image) { |
41 image = ios::GetChromeBrowserProvider() | 44 image = ios::GetChromeBrowserProvider() |
(...skipping 17 matching lines...) Expand all Loading... |
59 CGFloat dimension = kAccountProfilePhotoDimension; | 62 CGFloat dimension = kAccountProfilePhotoDimension; |
60 if (image.size.width != dimension || image.size.height != dimension) { | 63 if (image.size.width != dimension || image.size.height != dimension) { |
61 image = ResizeImage(image, CGSizeMake(dimension, dimension), | 64 image = ResizeImage(image, CGSizeMake(dimension, dimension), |
62 ProjectionMode::kAspectFit); | 65 ProjectionMode::kAspectFit); |
63 } | 66 } |
64 [_resizedImages setObject:image forKey:identity]; | 67 [_resizedImages setObject:image forKey:identity]; |
65 return image; | 68 return image; |
66 } | 69 } |
67 | 70 |
68 @end | 71 @end |
OLD | NEW |