OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef IOS_CHROME_BROWSER_UI_TAB_SWITCHER_TAB_SWITCHER_CACHE_H_ |
| 6 #define IOS_CHROME_BROWSER_UI_TAB_SWITCHER_TAB_SWITCHER_CACHE_H_ |
| 7 |
| 8 #import <UIKit/UIKit.h> |
| 9 |
| 10 #import "ios/chrome/browser/tabs/tab_model_observer.h" |
| 11 |
| 12 @class Tab; |
| 13 |
| 14 typedef void (^SnapshotCompletionBlock)(UIImage*); |
| 15 |
| 16 struct PendingSnapshotRequest { |
| 17 CFTimeInterval requestId; |
| 18 NSUInteger sessionId; |
| 19 |
| 20 PendingSnapshotRequest() : requestId(0), sessionId(0) {} |
| 21 |
| 22 void clear() { |
| 23 requestId = 0; |
| 24 sessionId = 0; |
| 25 } |
| 26 }; |
| 27 |
| 28 // A class that provides access to resized snapshots of tabs. The snapshots are |
| 29 // cached and freed under memory pressure. |
| 30 @interface TabSwitcherCache : NSObject<TabModelObserver> |
| 31 |
| 32 @property(nonatomic, readonly) TabModel* mainTabModel; |
| 33 |
| 34 // Request a snapshot for the given |tab| of the given |size|, |completionBlock| |
| 35 // will be called with the requested snapshot. Must be called from the main |
| 36 // thread with a non nil |tab|, a non nil |completionBlock|, and a non |
| 37 // CGSizeZero |size|. |
| 38 // If the resized snapshot is cached, |completionBlock| is called synchronously. |
| 39 // Otherwise it is called asynchronously on the main thread. The block's |
| 40 // execution can be cancelled with |cancelPendingSnapshotRequest:|. |
| 41 // Requesting a snapshot for a given tab will cancel any previous request for |
| 42 // that same tab. The completion handler for a cancelled request may never be |
| 43 // called. |
| 44 - (PendingSnapshotRequest)requestSnapshotForTab:(Tab*)tab |
| 45 withSize:(CGSize)size |
| 46 completionBlock: |
| 47 (SnapshotCompletionBlock)completionBlock; |
| 48 |
| 49 // Updates the snapshot for the given |tab| with |image| resized to |size|. |
| 50 - (void)updateSnapshotForTab:(Tab*)tab |
| 51 withImage:(UIImage*)image |
| 52 size:(CGSize)size; |
| 53 |
| 54 // Cancels the request identified by |pendingRequest|. Does nothing if no |
| 55 // request matches |pendingRequest|. |
| 56 - (void)cancelPendingSnapshotRequest:(PendingSnapshotRequest)pendingRequest; |
| 57 |
| 58 // Sets the main and incognito tab models. |
| 59 - (void)setMainTabModel:(TabModel*)mainTabModel |
| 60 otrTabModel:(TabModel*)otrTabModel; |
| 61 |
| 62 @end |
| 63 |
| 64 #endif // IOS_CHROME_BROWSER_UI_TAB_SWITCHER_TAB_SWITCHER_CACHE_H_ |
OLD | NEW |