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_SESSIONS_SESSION_SERVICE_IOS_H_ | 5 #ifndef IOS_CHROME_BROWSER_SESSIONS_SESSION_SERVICE_IOS_H_ |
6 #define IOS_CHROME_BROWSER_SESSIONS_SESSION_SERVICE_IOS_H_ | 6 #define IOS_CHROME_BROWSER_SESSIONS_SESSION_SERVICE_IOS_H_ |
7 | 7 |
8 #import <Foundation/Foundation.h> | 8 #import <Foundation/Foundation.h> |
9 | 9 |
10 namespace ios { | 10 #include "base/sequenced_task_runner.h" |
11 class ChromeBrowserState; | |
12 } | |
13 | 11 |
14 @class SessionWindowIOS; | 12 @class SessionWindowIOS; |
15 | 13 |
16 // A singleton service for saving the current session. Can either save on a | 14 // A singleton service for saving the current session. Can either save on a |
17 // delay or immediately. Saving is always performed on a separate thread. | 15 // delay or immediately. Saving is always performed on a separate thread. |
18 @interface SessionServiceIOS : NSObject | 16 @interface SessionServiceIOS : NSObject |
19 | 17 |
20 // Lazily creates a singleton instance. Use this instead of calling alloc/init. | 18 // Lazily creates a singleton instance with a default task runner. |
21 + (SessionServiceIOS*)sharedService; | 19 + (SessionServiceIOS*)sharedService; |
22 | 20 |
23 // Saves the session represented by |window| to the given browserState directory | 21 // Initializes a SessionServiceIOS with a given task runner. Prefer to use the |
24 // on disk. If |immediately| is NO, the save is done after a delay. If another | 22 // |sharedService| method. |
25 // call is pending, this one is ignored. If YES, the save is done now, | 23 - (instancetype)initWithTaskRunner: |
26 // cancelling any pending calls. Either way, the save is done on a separate | 24 (const scoped_refptr<base::SequencedTaskRunner>&)taskRunner |
27 // thread to avoid blocking the UI thread. As a result, |window| should contain | 25 NS_DESIGNATED_INITIALIZER; |
28 // copies of non-threadsafe objects. | |
29 - (void)saveWindow:(SessionWindowIOS*)window | |
30 forBrowserState:(ios::ChromeBrowserState*)browserState | |
31 immediately:(BOOL)immediately; | |
32 | 26 |
33 // Loads the window from the given browserState directory on disk on the main | 27 // Saves the session represented by |sessionWindow| to |directory| on disk. If |
34 // thread. Returns nil if no session was previously saved. | 28 // |immediately| is NO, the save is done after a delay. If another call is |
35 - (SessionWindowIOS*)loadWindowForBrowserState: | 29 // pending, this one is ignored. If YES, the save is done now, cancelling any |
36 (ios::ChromeBrowserState*)browserState; | 30 // pending calls. Either way, the save is done on a separate thread to avoid |
| 31 // blocking the UI thread. |
| 32 - (void)saveSessionWindow:(SessionWindowIOS*)sessionWindow |
| 33 directory:(NSString*)directory |
| 34 immediately:(BOOL)immediately; |
37 | 35 |
38 // Schedules deletion of the file containing the commands for the last session | 36 // Loads the session window from default session file in |directory| on the |
39 // in the given browserState directory. | 37 // main thread. Returns nil in case of errors. |
40 - (void)deleteLastSession:(NSString*)directory; | 38 - (SessionWindowIOS*)loadSessionWindowFromDirectory:(NSString*)directory; |
41 | 39 |
42 // Loads the window from the given backup file on disk on the main thread. | 40 // Loads the session window from |sessionPath| on the main thread. Returns nil |
43 // Returns nil if unable to read the sessions. | 41 // in case of errors. |
44 - (SessionWindowIOS*)loadWindowFromPath:(NSString*)sessionPath; | 42 - (SessionWindowIOS*)loadSessionWindowFromPath:(NSString*)sessionPath; |
45 | 43 |
46 // Returns the path of the session file. | 44 // Schedules deletion of the file containing the last session in |directory|. |
47 - (NSString*)sessionFilePathForDirectory:(NSString*)directory; | 45 - (void)deleteLastSessionFileInDirectory:(NSString*)directory; |
| 46 |
| 47 // Returns the path of the session file for |directory|. |
| 48 + (NSString*)sessionPathForDirectory:(NSString*)directory; |
48 | 49 |
49 @end | 50 @end |
50 | 51 |
51 @interface SessionServiceIOS (Testing) | 52 @interface SessionServiceIOS (SubClassing) |
52 | 53 |
53 // For some of the unit tests, we need to make sure the session is saved | 54 // For some of the unit tests, we need to make sure the session is saved |
54 // immediately so we can read it back in to verify various attributes. This | 55 // immediately so we can read it back in to verify various attributes. This |
55 // is not a situation we normally expect to be in because we never | 56 // is not a situation we normally expect to be in because we never |
56 // want the session being saved on the main thread in the production app. | 57 // want the session being saved on the main thread in the production app. |
57 - (void)performSaveWindow:(SessionWindowIOS*)window | 58 - (void)performSaveSessionData:(NSData*)sessionData |
58 toDirectory:(NSString*)directory; | 59 sessionPath:(NSString*)sessionPath; |
59 | 60 |
60 @end | 61 @end |
61 | 62 |
62 #endif // IOS_CHROME_BROWSER_SESSIONS_SESSION_SERVICE_IOS_H_ | 63 #endif // IOS_CHROME_BROWSER_SESSIONS_SESSION_SERVICE_IOS_H_ |
OLD | NEW |