| 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" | 10 #include "base/mac/objc_property_releaser.h" |
| 11 #include "base/mac/scoped_nsobject.h" | 11 #include "base/mac/scoped_nsobject.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #import "ios/chrome/browser/snapshots/lru_cache.h" |
| 13 | 14 |
| 14 typedef void (^GreyBlock)(UIImage*); | 15 typedef void (^GreyBlock)(UIImage*); |
| 15 | 16 |
| 16 // A singleton providing an in-memory and on-disk cache of tab snapshots. | 17 // A singleton providing an in-memory and on-disk cache of tab snapshots. |
| 17 // A snapshot is a full-screen image of the contents of the page at the current | 18 // A snapshot is a full-screen image of the contents of the page at the current |
| 18 // scroll offset and zoom level, used to stand in for the UIWebView if it has | 19 // scroll offset and zoom level, used to stand in for the UIWebView if it has |
| 19 // been purged from memory or when quickly switching tabs. | 20 // been purged from memory or when quickly switching tabs. |
| 20 // Persists to disk on a background thread each time a snapshot changes. | 21 // Persists to disk on a background thread each time a snapshot changes. |
| 21 @interface SnapshotCache : NSObject { | 22 @interface SnapshotCache : NSObject { |
| 22 @private | 23 @private |
| 23 // Dictionary to hold color snapshots in memory. n.b. Color snapshots are not | 24 // Dictionary to hold color snapshots in memory. n.b. Color snapshots are not |
| 24 // kept in memory on tablets. | 25 // kept in memory on tablets. |
| 25 base::scoped_nsobject<NSMutableDictionary> imageDictionary_; | 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 |
| 26 // Temporary dictionary to hold grey snapshots for tablet side swipe. This | 33 // Temporary dictionary to hold grey snapshots for tablet side swipe. This |
| 27 // will be nil before -createGreyCache is called and after -removeGreyCache | 34 // will be nil before -createGreyCache is called and after -removeGreyCache |
| 28 // is called. | 35 // is called. |
| 29 base::scoped_nsobject<NSMutableDictionary> greyImageDictionary_; | 36 base::scoped_nsobject<NSMutableDictionary> greyImageDictionary_; |
| 30 NSSet* pinnedIDs_; | 37 NSSet* pinnedIDs_; |
| 31 | 38 |
| 32 // Session ID of most recent pending grey snapshot request. | 39 // Session ID of most recent pending grey snapshot request. |
| 33 base::scoped_nsobject<NSString> mostRecentGreySessionId_; | 40 base::scoped_nsobject<NSString> mostRecentGreySessionId_; |
| 34 // Block used by pending request for a grey snapshot. | 41 // Block used by pending request for a grey snapshot. |
| 35 base::scoped_nsprotocol<GreyBlock> mostRecentGreyBlock_; | 42 base::scoped_nsprotocol<GreyBlock> mostRecentGreyBlock_; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 // immediately call back on |callback|. Otherwise, only use |callback| for the | 90 // immediately call back on |callback|. Otherwise, only use |callback| for the |
| 84 // most recent caller. The callback is not guaranteed to be called. | 91 // most recent caller. The callback is not guaranteed to be called. |
| 85 - (void)greyImageForSessionID:(NSString*)sessionID | 92 - (void)greyImageForSessionID:(NSString*)sessionID |
| 86 callback:(void (^)(UIImage*))callback; | 93 callback:(void (^)(UIImage*))callback; |
| 87 | 94 |
| 88 // Write a grey copy of the snapshot for |sessionID| to disk, but if and only if | 95 // Write a grey copy of the snapshot for |sessionID| to disk, but if and only if |
| 89 // a color version of the snapshot already exists in memory or on disk. | 96 // a color version of the snapshot already exists in memory or on disk. |
| 90 - (void)saveGreyInBackgroundForSessionID:(NSString*)sessionID; | 97 - (void)saveGreyInBackgroundForSessionID:(NSString*)sessionID; |
| 91 @end | 98 @end |
| 92 | 99 |
| 100 // Additionnal methods that should only be used for tests. |
| 101 @interface SnapshotCache (TestingAdditions) |
| 102 - (BOOL)hasImageInMemory:(NSString*)sessionID; |
| 103 - (BOOL)hasGreyImageInMemory:(NSString*)sessionID; |
| 104 - (NSUInteger)lruCacheMaxSize; |
| 105 @end |
| 106 |
| 93 #endif // IOS_CHROME_BROWSER_SNAPSHOTS_SNAPSHOT_CACHE_H_ | 107 #endif // IOS_CHROME_BROWSER_SNAPSHOTS_SNAPSHOT_CACHE_H_ |
| OLD | NEW |