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 #ifndef IOS_CHROME_BROWSER_SNAPSHOTS_SNAPSHOT_CACHE_H_ | 5 #ifndef IOS_CHROME_BROWSER_SNAPSHOTS_SNAPSHOT_CACHE_H_ |
6 #define IOS_CHROME_BROWSER_SNAPSHOTS_SNAPSHOT_CACHE_H_ | 6 #define IOS_CHROME_BROWSER_SNAPSHOTS_SNAPSHOT_CACHE_H_ |
7 | 7 |
8 #import <UIKit/UIKit.h> | 8 #import <UIKit/UIKit.h> |
9 | 9 |
10 #include "base/mac/objc_property_releaser.h" | |
11 #include "base/mac/scoped_nsobject.h" | |
12 #include "base/time/time.h" | 10 #include "base/time/time.h" |
13 #import "ios/chrome/browser/snapshots/lru_cache.h" | |
14 | 11 |
15 typedef void (^GreyBlock)(UIImage*); | 12 typedef void (^GreyBlock)(UIImage*); |
16 | 13 |
17 // A singleton providing an in-memory and on-disk cache of tab snapshots. | 14 // A singleton providing an in-memory and on-disk cache of tab snapshots. |
18 // A snapshot is a full-screen image of the contents of the page at the current | 15 // A snapshot is a full-screen image of the contents of the page at the current |
19 // scroll offset and zoom level, used to stand in for the UIWebView if it has | 16 // scroll offset and zoom level, used to stand in for the UIWebView if it has |
20 // been purged from memory or when quickly switching tabs. | 17 // been purged from memory or when quickly switching tabs. |
21 // Persists to disk on a background thread each time a snapshot changes. | 18 // Persists to disk on a background thread each time a snapshot changes. |
22 @interface SnapshotCache : NSObject { | 19 @interface SnapshotCache : NSObject |
23 @private | |
24 // Dictionary to hold color snapshots in memory. n.b. Color snapshots are not | |
25 // kept in memory on tablets. | |
26 base::scoped_nsobject<NSMutableDictionary> imageDictionary_; | |
27 | |
28 // Cache to hold color snapshots in memory. n.b. Color snapshots are not | |
29 // kept in memory on tablets. It is used in place of the imageDictionary_ when | |
30 // the LRU cache snapshot experiment is enabled. | |
31 base::scoped_nsobject<LRUCache> lruCache_; | |
32 | |
33 // Temporary dictionary to hold grey snapshots for tablet side swipe. This | |
34 // will be nil before -createGreyCache is called and after -removeGreyCache | |
35 // is called. | |
36 base::scoped_nsobject<NSMutableDictionary> greyImageDictionary_; | |
37 NSSet* pinnedIDs_; | |
38 | |
39 // Session ID of most recent pending grey snapshot request. | |
40 base::scoped_nsobject<NSString> mostRecentGreySessionId_; | |
41 // Block used by pending request for a grey snapshot. | |
42 base::scoped_nsprotocol<GreyBlock> mostRecentGreyBlock_; | |
43 | |
44 // Session ID and correspoinding UIImage for the snapshot that will likely | |
45 // be requested to be saved to disk when the application is backgrounded. | |
46 base::scoped_nsobject<NSString> backgroundingImageSessionId_; | |
47 base::scoped_nsobject<UIImage> backgroundingColorImage_; | |
48 | |
49 base::mac::ObjCPropertyReleaser propertyReleaser_SnapshotCache_; | |
50 } | |
51 | 20 |
52 // Track session IDs to not release on low memory and to reload on | 21 // Track session IDs to not release on low memory and to reload on |
53 // |UIApplicationDidBecomeActiveNotification|. | 22 // |UIApplicationDidBecomeActiveNotification|. |
54 @property(nonatomic, retain) NSSet* pinnedIDs; | 23 @property(nonatomic, retain) NSSet* pinnedIDs; |
55 | 24 |
56 + (SnapshotCache*)sharedInstance; | 25 + (SnapshotCache*)sharedInstance; |
57 | 26 |
58 // The scale that should be used for snapshots. | 27 // The scale that should be used for snapshots. |
59 + (CGFloat)snapshotScaleForDevice; | 28 + (CGFloat)snapshotScaleForDevice; |
60 | 29 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 @end | 67 @end |
99 | 68 |
100 // Additionnal methods that should only be used for tests. | 69 // Additionnal methods that should only be used for tests. |
101 @interface SnapshotCache (TestingAdditions) | 70 @interface SnapshotCache (TestingAdditions) |
102 - (BOOL)hasImageInMemory:(NSString*)sessionID; | 71 - (BOOL)hasImageInMemory:(NSString*)sessionID; |
103 - (BOOL)hasGreyImageInMemory:(NSString*)sessionID; | 72 - (BOOL)hasGreyImageInMemory:(NSString*)sessionID; |
104 - (NSUInteger)lruCacheMaxSize; | 73 - (NSUInteger)lruCacheMaxSize; |
105 @end | 74 @end |
106 | 75 |
107 #endif // IOS_CHROME_BROWSER_SNAPSHOTS_SNAPSHOT_CACHE_H_ | 76 #endif // IOS_CHROME_BROWSER_SNAPSHOTS_SNAPSHOT_CACHE_H_ |
OLD | NEW |