| OLD | NEW |
| 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_property_releaser.h" | 16 #include "base/mac/objc_release_properties.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 Loading... |
| 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_; | |
| 162 } | 160 } |
| 163 | 161 |
| 164 @synthesize pinnedIDs = pinnedIDs_; | 162 @synthesize pinnedIDs = pinnedIDs_; |
| 165 | 163 |
| 166 + (SnapshotCache*)sharedInstance { | 164 + (SnapshotCache*)sharedInstance { |
| 167 static SnapshotCache* instance = [[SnapshotCache alloc] init]; | 165 static SnapshotCache* instance = [[SnapshotCache alloc] init]; |
| 168 return instance; | 166 return instance; |
| 169 } | 167 } |
| 170 | 168 |
| 171 - (id)init { | 169 - (id)init { |
| 172 if ((self = [super init])) { | 170 if ((self = [super init])) { |
| 173 DCHECK_CURRENTLY_ON(web::WebThread::UI); | 171 DCHECK_CURRENTLY_ON(web::WebThread::UI); |
| 174 propertyReleaser_SnapshotCache_.Init(self, [SnapshotCache class]); | |
| 175 | |
| 176 if ([self usesLRUCache]) { | 172 if ([self usesLRUCache]) { |
| 177 lruCache_.reset( | 173 lruCache_.reset( |
| 178 [[LRUCache alloc] initWithCacheSize:kLRUCacheMaxCapacity]); | 174 [[LRUCache alloc] initWithCacheSize:kLRUCacheMaxCapacity]); |
| 179 } else { | 175 } else { |
| 180 imageDictionary_.reset( | 176 imageDictionary_.reset( |
| 181 [[NSMutableDictionary alloc] initWithCapacity:kCacheInitialCapacity]); | 177 [[NSMutableDictionary alloc] initWithCapacity:kCacheInitialCapacity]); |
| 182 } | 178 } |
| 183 [[NSNotificationCenter defaultCenter] | 179 [[NSNotificationCenter defaultCenter] |
| 184 addObserver:self | 180 addObserver:self |
| 185 selector:@selector(handleLowMemory) | 181 selector:@selector(handleLowMemory) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 205 name:UIApplicationDidReceiveMemoryWarningNotification | 201 name:UIApplicationDidReceiveMemoryWarningNotification |
| 206 object:nil]; | 202 object:nil]; |
| 207 [[NSNotificationCenter defaultCenter] | 203 [[NSNotificationCenter defaultCenter] |
| 208 removeObserver:self | 204 removeObserver:self |
| 209 name:UIApplicationDidEnterBackgroundNotification | 205 name:UIApplicationDidEnterBackgroundNotification |
| 210 object:nil]; | 206 object:nil]; |
| 211 [[NSNotificationCenter defaultCenter] | 207 [[NSNotificationCenter defaultCenter] |
| 212 removeObserver:self | 208 removeObserver:self |
| 213 name:UIApplicationDidBecomeActiveNotification | 209 name:UIApplicationDidBecomeActiveNotification |
| 214 object:nil]; | 210 object:nil]; |
| 211 base::mac::ReleaseProperties(self); |
| 215 [super dealloc]; | 212 [super dealloc]; |
| 216 } | 213 } |
| 217 | 214 |
| 218 + (CGFloat)snapshotScaleForDevice { | 215 + (CGFloat)snapshotScaleForDevice { |
| 219 // On handset, the color snapshot is used for the stack view, so the scale of | 216 // On handset, the color snapshot is used for the stack view, so the scale of |
| 220 // the snapshot images should match the scale of the device. | 217 // the snapshot images should match the scale of the device. |
| 221 // On tablet, the color snapshot is only used to generate the grey snapshot, | 218 // On tablet, the color snapshot is only used to generate the grey snapshot, |
| 222 // which does not have to be high quality, so use scale of 1.0 on all tablets. | 219 // which does not have to be high quality, so use scale of 1.0 on all tablets. |
| 223 if (IsIPadIdiom()) { | 220 if (IsIPadIdiom()) { |
| 224 return 1.0; | 221 return 1.0; |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 | 589 |
| 593 - (BOOL)hasGreyImageInMemory:(NSString*)sessionID { | 590 - (BOOL)hasGreyImageInMemory:(NSString*)sessionID { |
| 594 return [greyImageDictionary_ objectForKey:sessionID] != nil; | 591 return [greyImageDictionary_ objectForKey:sessionID] != nil; |
| 595 } | 592 } |
| 596 | 593 |
| 597 - (NSUInteger)lruCacheMaxSize { | 594 - (NSUInteger)lruCacheMaxSize { |
| 598 return [lruCache_ maxCacheSize]; | 595 return [lruCache_ maxCacheSize]; |
| 599 } | 596 } |
| 600 | 597 |
| 601 @end | 598 @end |
| OLD | NEW |