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 receiver. | |
27 - (instancetype)initForReadingWithData:(NSData*)data | |
28 browserState:(ios::ChromeBrowserState*)browserState | |
29 NS_DESIGNATED_INITIALIZER; | |
30 | |
31 @end | |
32 | |
33 // A singleton service for saving the current session. Can either save on a | |
34 // delay or immediately. Saving is always performed on a separate thread. | |
35 @interface SessionServiceIOS : NSObject | |
36 | |
37 // Lazily creates a singleton instance. Use this instead of calling alloc/init. | |
38 + (SessionServiceIOS*)sharedService; | |
39 | |
40 // Saves the session represented by |window| to the given browserState directory | |
41 // on disk. If |immediately| is NO, the save is done after a delay. If another | |
42 // call is pending, this one is ignored. If YES, the save is done now, | |
43 // cancelling any pending calls. Either way, the save is done on a separate | |
44 // thread to avoid blocking the UI thread. As a result, |window| should contain | |
45 // copies of non-threadsafe objects. | |
46 - (void)saveWindow:(SessionWindowIOS*)window | |
47 forBrowserState:(ios::ChromeBrowserState*)browserState | |
48 immediately:(BOOL)immediately; | |
49 | |
50 // Loads the window from the given browserState directory on disk on the main | |
51 // thread. Returns nil if no session was previously saved. | |
52 - (SessionWindowIOS*)loadWindowForBrowserState: | |
53 (ios::ChromeBrowserState*)browserState; | |
54 | |
55 // Schedules deletion of the file containing the commands for the last session | |
56 // in the given browserState directory. | |
57 - (void)deleteLastSession:(NSString*)directory; | |
58 | |
59 // Loads the window from the given backup file on disk on the main thread. | |
60 // Returns nil if unable to read the sessions. | |
61 - (SessionWindowIOS*)loadWindowFromPath:(NSString*)path | |
62 forBrowserState:(ios::ChromeBrowserState*)browserState; | |
63 | |
64 // Returns the path of the session file. | |
65 - (NSString*)sessionFilePathForDirectory:(NSString*)directory; | |
66 | |
67 @end | |
68 | |
69 @interface SessionServiceIOS (Testing) | |
70 | |
71 // For some of the unit tests, we need to make sure the session is saved | |
72 // immediately so we can read it back in to verify various attributes. This | |
73 // is not a situation we normally expect to be in because we never | |
74 // want the session being saved on the main thread in the production app. | |
75 - (void)performSaveWindow:(SessionWindowIOS*)window | |
76 toDirectory:(NSString*)directory; | |
77 | |
78 @end | |
79 | |
80 #endif // IOS_CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_ | |
OLD | NEW |