OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef IOS_CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_ |
| 6 #define IOS_CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_ |
| 7 |
| 8 #import <Foundation/Foundation.h> |
| 9 |
| 10 #include "base/mac/scoped_nsobject.h" |
| 11 |
| 12 namespace ios { |
| 13 class ChromeBrowserState; |
| 14 } |
| 15 |
| 16 @class SessionWindowIOS; |
| 17 |
| 18 // Trivial NSKeyedUnarchiver subclass that can be configured with a |
| 19 // ChromeBrowserState instance that decoding classes can use. |
| 20 @interface SessionWindowUnarchiver : NSKeyedUnarchiver |
| 21 |
| 22 // The BrowserState set on the unarchiver at init; a weak pointer. |
| 23 @property(nonatomic, readonly) ios::ChromeBrowserState* browserState; |
| 24 |
| 25 // Inits exactly as initForReadingWithData: does, additionally setting |
| 26 // |browserState| on the reciever. |
| 27 - (instancetype)initForReadingWithData:(NSData*)data |
| 28 browserState:(ios::ChromeBrowserState*)browserState; |
| 29 |
| 30 @end |
| 31 |
| 32 // A singleton service for saving the current session. Can either save on a |
| 33 // delay or immediately. Saving is always performed on a separate thread. |
| 34 @interface SessionServiceIOS : NSObject |
| 35 |
| 36 // Lazily creates a singleton instance. Use this instead of calling alloc/init. |
| 37 + (SessionServiceIOS*)sharedService; |
| 38 |
| 39 // Saves the session represented by |window| to the given browserState directory |
| 40 // on disk. If |immediately| is NO, the save is done after a delay. If another |
| 41 // call is pending, this one is ignored. If YES, the save is done now, |
| 42 // cancelling any pending calls. Either way, the save is done on a separate |
| 43 // thread to avoid blocking the UI thread. As a result, |window| should contain |
| 44 // copies of non-threadsafe objects. |
| 45 - (void)saveWindow:(SessionWindowIOS*)window |
| 46 forBrowserState:(ios::ChromeBrowserState*)browserState |
| 47 immediately:(BOOL)immediately; |
| 48 |
| 49 // Loads the window from the given browserState directory on disk on the main |
| 50 // thread. Returns nil if no session was previously saved. |
| 51 - (SessionWindowIOS*)loadWindowForBrowserState: |
| 52 (ios::ChromeBrowserState*)browserState; |
| 53 |
| 54 // Schedules deletion of the file containing the commands for the last session |
| 55 // in the given browserState directory. |
| 56 - (void)deleteLastSession:(NSString*)directory; |
| 57 |
| 58 // Loads the window from the given backup file on disk on the main thread. |
| 59 // Returns nil if unable to read the sessions. |
| 60 - (SessionWindowIOS*)loadWindowFromPath:(NSString*)path |
| 61 forBrowserState:(ios::ChromeBrowserState*)browserState; |
| 62 |
| 63 // Returns the path of the session file. |
| 64 - (NSString*)sessionFilePathForDirectory:(NSString*)directory; |
| 65 |
| 66 @end |
| 67 |
| 68 #endif // IOS_CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_ |
OLD | NEW |