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

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

Issue 2810743002: [ios] Refactor SessionServiceIOS to remove dependency on BrowserState. (Closed)
Patch Set: Rebase. 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_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 // Initialize 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 |sessionPath| 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. As a result, |sessionWindow| should contain copies
marq (ping after 24h) 2017/04/11 10:46:29 Should, or could? Or shouldn't?
sdefresne 2017/04/11 11:49:41 Removed as the object is now only accessed on the
32 // of non-threadsafe objects.
33 - (void)saveSessionWindow:(SessionWindowIOS*)sessionWindow
34 sessionPath:(NSString*)sessionPath
35 immediately:(BOOL)immediately;
36
37 // Loads the session window from the given file on disk on the main thread.
38 // Returns nil in case of errors.
39 - (SessionWindowIOS*)loadSessionWindowFromPath:(NSString*)sessionPath;
37 40
38 // Schedules deletion of the file containing the commands for the last session 41 // Schedules deletion of the file containing the commands for the last session
39 // in the given browserState directory. 42 // at the given path.
40 - (void)deleteLastSession:(NSString*)directory; 43 - (void)deleteLastSessionAtPath:(NSString*)sessionPath;
41
42 // Loads the window from the given backup file on disk on the main thread.
43 // Returns nil if unable to read the sessions.
44 - (SessionWindowIOS*)loadWindowFromPath:(NSString*)sessionPath;
45 44
46 // Returns the path of the session file. 45 // Returns the path of the session file.
47 - (NSString*)sessionFilePathForDirectory:(NSString*)directory; 46 - (NSString*)sessionPathForDirectory:(NSString*)directory;
48 47
49 @end 48 @end
50 49
51 @interface SessionServiceIOS (Testing) 50 @interface SessionServiceIOS (Testing)
52 51
53 // For some of the unit tests, we need to make sure the session is saved 52 // 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 53 // 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 54 // 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. 55 // want the session being saved on the main thread in the production app.
57 - (void)performSaveWindow:(SessionWindowIOS*)window 56 - (void)performSaveSessionData:(NSData*)sessionData
marq (ping after 24h) 2017/04/11 10:46:29 Can we remove the need for this by running tests o
sdefresne 2017/04/11 11:49:41 Updated the tests to not use this method. I still
58 toDirectory:(NSString*)directory; 57 sessionPath:(NSString*)sessionPath;
59 58
60 @end 59 @end
61 60
62 #endif // IOS_CHROME_BROWSER_SESSIONS_SESSION_SERVICE_IOS_H_ 61 #endif // IOS_CHROME_BROWSER_SESSIONS_SESSION_SERVICE_IOS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698