Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: ios/chrome/browser/snapshots/snapshot_cache.mm

Issue 2881183002: Revert of Replace ObjCPropertyReleaser with ReleaseProperties() project-wide. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/snapshots/snapshot_cache.h" 5 #import "ios/chrome/browser/snapshots/snapshot_cache.h"
6 6
7 #import <UIKit/UIKit.h> 7 #import <UIKit/UIKit.h>
8 8
9 #include "base/critical_closure.h" 9 #include "base/critical_closure.h"
10 #include "base/files/file_enumerator.h" 10 #include "base/files/file_enumerator.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/mac/bind_objc_block.h" 15 #include "base/mac/bind_objc_block.h"
16 #include "base/mac/objc_release_properties.h" 16 #include "base/mac/objc_property_releaser.h"
17 #include "base/mac/scoped_cftyperef.h" 17 #include "base/mac/scoped_cftyperef.h"
18 #include "base/mac/scoped_nsobject.h" 18 #include "base/mac/scoped_nsobject.h"
19 #include "base/strings/sys_string_conversions.h" 19 #include "base/strings/sys_string_conversions.h"
20 #include "base/task_runner_util.h" 20 #include "base/task_runner_util.h"
21 #include "base/threading/thread_restrictions.h" 21 #include "base/threading/thread_restrictions.h"
22 #include "ios/chrome/browser/experimental_flags.h" 22 #include "ios/chrome/browser/experimental_flags.h"
23 #import "ios/chrome/browser/snapshots/lru_cache.h" 23 #import "ios/chrome/browser/snapshots/lru_cache.h"
24 #import "ios/chrome/browser/snapshots/snapshot_cache_internal.h" 24 #import "ios/chrome/browser/snapshots/snapshot_cache_internal.h"
25 #include "ios/chrome/browser/ui/ui_util.h" 25 #include "ios/chrome/browser/ui/ui_util.h"
26 #import "ios/chrome/browser/ui/uikit_ui_util.h" 26 #import "ios/chrome/browser/ui/uikit_ui_util.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 150
151 // Session ID of most recent pending grey snapshot request. 151 // Session ID of most recent pending grey snapshot request.
152 base::scoped_nsobject<NSString> mostRecentGreySessionId_; 152 base::scoped_nsobject<NSString> mostRecentGreySessionId_;
153 // Block used by pending request for a grey snapshot. 153 // Block used by pending request for a grey snapshot.
154 base::scoped_nsprotocol<GreyBlock> mostRecentGreyBlock_; 154 base::scoped_nsprotocol<GreyBlock> mostRecentGreyBlock_;
155 155
156 // Session ID and correspoinding UIImage for the snapshot that will likely 156 // Session ID and correspoinding UIImage for the snapshot that will likely
157 // be requested to be saved to disk when the application is backgrounded. 157 // be requested to be saved to disk when the application is backgrounded.
158 base::scoped_nsobject<NSString> backgroundingImageSessionId_; 158 base::scoped_nsobject<NSString> backgroundingImageSessionId_;
159 base::scoped_nsobject<UIImage> backgroundingColorImage_; 159 base::scoped_nsobject<UIImage> backgroundingColorImage_;
160
161 base::mac::ObjCPropertyReleaser propertyReleaser_SnapshotCache_;
160 } 162 }
161 163
162 @synthesize pinnedIDs = pinnedIDs_; 164 @synthesize pinnedIDs = pinnedIDs_;
163 165
164 + (SnapshotCache*)sharedInstance { 166 + (SnapshotCache*)sharedInstance {
165 static SnapshotCache* instance = [[SnapshotCache alloc] init]; 167 static SnapshotCache* instance = [[SnapshotCache alloc] init];
166 return instance; 168 return instance;
167 } 169 }
168 170
169 - (id)init { 171 - (id)init {
170 if ((self = [super init])) { 172 if ((self = [super init])) {
171 DCHECK_CURRENTLY_ON(web::WebThread::UI); 173 DCHECK_CURRENTLY_ON(web::WebThread::UI);
174 propertyReleaser_SnapshotCache_.Init(self, [SnapshotCache class]);
175
172 if ([self usesLRUCache]) { 176 if ([self usesLRUCache]) {
173 lruCache_.reset( 177 lruCache_.reset(
174 [[LRUCache alloc] initWithCacheSize:kLRUCacheMaxCapacity]); 178 [[LRUCache alloc] initWithCacheSize:kLRUCacheMaxCapacity]);
175 } else { 179 } else {
176 imageDictionary_.reset( 180 imageDictionary_.reset(
177 [[NSMutableDictionary alloc] initWithCapacity:kCacheInitialCapacity]); 181 [[NSMutableDictionary alloc] initWithCapacity:kCacheInitialCapacity]);
178 } 182 }
179 [[NSNotificationCenter defaultCenter] 183 [[NSNotificationCenter defaultCenter]
180 addObserver:self 184 addObserver:self
181 selector:@selector(handleLowMemory) 185 selector:@selector(handleLowMemory)
(...skipping 19 matching lines...) Expand all
201 name:UIApplicationDidReceiveMemoryWarningNotification 205 name:UIApplicationDidReceiveMemoryWarningNotification
202 object:nil]; 206 object:nil];
203 [[NSNotificationCenter defaultCenter] 207 [[NSNotificationCenter defaultCenter]
204 removeObserver:self 208 removeObserver:self
205 name:UIApplicationDidEnterBackgroundNotification 209 name:UIApplicationDidEnterBackgroundNotification
206 object:nil]; 210 object:nil];
207 [[NSNotificationCenter defaultCenter] 211 [[NSNotificationCenter defaultCenter]
208 removeObserver:self 212 removeObserver:self
209 name:UIApplicationDidBecomeActiveNotification 213 name:UIApplicationDidBecomeActiveNotification
210 object:nil]; 214 object:nil];
211 base::mac::ReleaseProperties(self);
212 [super dealloc]; 215 [super dealloc];
213 } 216 }
214 217
215 + (CGFloat)snapshotScaleForDevice { 218 + (CGFloat)snapshotScaleForDevice {
216 // On handset, the color snapshot is used for the stack view, so the scale of 219 // On handset, the color snapshot is used for the stack view, so the scale of
217 // the snapshot images should match the scale of the device. 220 // the snapshot images should match the scale of the device.
218 // On tablet, the color snapshot is only used to generate the grey snapshot, 221 // On tablet, the color snapshot is only used to generate the grey snapshot,
219 // which does not have to be high quality, so use scale of 1.0 on all tablets. 222 // which does not have to be high quality, so use scale of 1.0 on all tablets.
220 if (IsIPadIdiom()) { 223 if (IsIPadIdiom()) {
221 return 1.0; 224 return 1.0;
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 592
590 - (BOOL)hasGreyImageInMemory:(NSString*)sessionID { 593 - (BOOL)hasGreyImageInMemory:(NSString*)sessionID {
591 return [greyImageDictionary_ objectForKey:sessionID] != nil; 594 return [greyImageDictionary_ objectForKey:sessionID] != nil;
592 } 595 }
593 596
594 - (NSUInteger)lruCacheMaxSize { 597 - (NSUInteger)lruCacheMaxSize {
595 return [lruCache_ maxCacheSize]; 598 return [lruCache_ maxCacheSize];
596 } 599 }
597 600
598 @end 601 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698