Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: ios/chrome/browser/sessions/session_service_ios.h

Issue 2802763002: [ios] Cleanup SessionServiceIOS implementation. (Closed)
Patch Set: Address comments. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_H_ 5 #ifndef IOS_CHROME_BROWSER_SESSIONS_SESSION_SERVICE_IOS_H_
6 #define IOS_CHROME_BROWSER_SESSIONS_SESSION_SERVICE_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 #include "base/mac/scoped_nsobject.h"
11
12 namespace ios { 10 namespace ios {
13 class ChromeBrowserState; 11 class ChromeBrowserState;
14 } 12 }
15 13
16 @class SessionWindowIOS; 14 @class SessionWindowIOS;
17 15
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 16 // 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. 17 // delay or immediately. Saving is always performed on a separate thread.
35 @interface SessionServiceIOS : NSObject 18 @interface SessionServiceIOS : NSObject
36 19
37 // Lazily creates a singleton instance. Use this instead of calling alloc/init. 20 // Lazily creates a singleton instance. Use this instead of calling alloc/init.
38 + (SessionServiceIOS*)sharedService; 21 + (SessionServiceIOS*)sharedService;
39 22
40 // Saves the session represented by |window| to the given browserState directory 23 // 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 24 // 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, 25 // 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 26 // 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 27 // thread to avoid blocking the UI thread. As a result, |window| should contain
45 // copies of non-threadsafe objects. 28 // copies of non-threadsafe objects.
46 - (void)saveWindow:(SessionWindowIOS*)window 29 - (void)saveWindow:(SessionWindowIOS*)window
47 forBrowserState:(ios::ChromeBrowserState*)browserState 30 forBrowserState:(ios::ChromeBrowserState*)browserState
48 immediately:(BOOL)immediately; 31 immediately:(BOOL)immediately;
49 32
50 // Loads the window from the given browserState directory on disk on the main 33 // Loads the window from the given browserState directory on disk on the main
51 // thread. Returns nil if no session was previously saved. 34 // thread. Returns nil if no session was previously saved.
52 - (SessionWindowIOS*)loadWindowForBrowserState: 35 - (SessionWindowIOS*)loadWindowForBrowserState:
53 (ios::ChromeBrowserState*)browserState; 36 (ios::ChromeBrowserState*)browserState;
54 37
55 // Schedules deletion of the file containing the commands for the last session 38 // Schedules deletion of the file containing the commands for the last session
56 // in the given browserState directory. 39 // in the given browserState directory.
57 - (void)deleteLastSession:(NSString*)directory; 40 - (void)deleteLastSession:(NSString*)directory;
58 41
59 // Loads the window from the given backup file on disk on the main thread. 42 // Loads the window from the given backup file on disk on the main thread.
60 // Returns nil if unable to read the sessions. 43 // Returns nil if unable to read the sessions.
61 - (SessionWindowIOS*)loadWindowFromPath:(NSString*)path 44 - (SessionWindowIOS*)loadWindowFromPath:(NSString*)sessionPath;
62 forBrowserState:(ios::ChromeBrowserState*)browserState;
63 45
64 // Returns the path of the session file. 46 // Returns the path of the session file.
65 - (NSString*)sessionFilePathForDirectory:(NSString*)directory; 47 - (NSString*)sessionFilePathForDirectory:(NSString*)directory;
66 48
67 @end 49 @end
68 50
69 @interface SessionServiceIOS (Testing) 51 @interface SessionServiceIOS (Testing)
70 52
71 // For some of the unit tests, we need to make sure the session is saved 53 // 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 54 // 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 55 // 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. 56 // want the session being saved on the main thread in the production app.
75 - (void)performSaveWindow:(SessionWindowIOS*)window 57 - (void)performSaveWindow:(SessionWindowIOS*)window
76 toDirectory:(NSString*)directory; 58 toDirectory:(NSString*)directory;
77 59
78 @end 60 @end
79 61
80 #endif // IOS_CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_ 62 #endif // IOS_CHROME_BROWSER_SESSIONS_SESSION_SERVICE_IOS_H_
OLDNEW
« no previous file with comments | « ios/chrome/browser/sessions/session_service.mm ('k') | ios/chrome/browser/sessions/session_service_ios.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698