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

Side by Side Diff: chrome/browser/sessions/base_session_service.h

Issue 694813003: Changing SessionService to have a BaseSessionService, not being one. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed browser tests Created 6 years, 1 month 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
« no previous file with comments | « no previous file | chrome/browser/sessions/base_session_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 CHROME_BROWSER_SESSIONS_BASE_SESSION_SERVICE_H_ 5 #ifndef CHROME_BROWSER_SESSIONS_BASE_SESSION_SERVICE_H_
6 #define CHROME_BROWSER_SESSIONS_BASE_SESSION_SERVICE_H_ 6 #define CHROME_BROWSER_SESSIONS_BASE_SESSION_SERVICE_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 21 matching lines...) Expand all
32 // backend to determine the name of the files. 32 // backend to determine the name of the files.
33 enum SessionType { 33 enum SessionType {
34 SESSION_RESTORE, 34 SESSION_RESTORE,
35 TAB_RESTORE 35 TAB_RESTORE
36 }; 36 };
37 37
38 typedef base::Callback<void(ScopedVector<SessionCommand>)> 38 typedef base::Callback<void(ScopedVector<SessionCommand>)>
39 GetCommandsCallback; 39 GetCommandsCallback;
40 40
41 // Creates a new BaseSessionService. After creation you need to invoke 41 // Creates a new BaseSessionService. After creation you need to invoke
42 // Init. 42 // Init. |delegate| will remain owned by the creator and it is guaranteed
43 // that its lifetime surpasses this class.
43 // |type| gives the type of session service, |path| the path to save files to. 44 // |type| gives the type of session service, |path| the path to save files to.
44 BaseSessionService(SessionType type, 45 BaseSessionService(SessionType type,
45 const base::FilePath& path, 46 const base::FilePath& path,
46 scoped_ptr<BaseSessionServiceDelegate> delegate); 47 BaseSessionServiceDelegate* delegate);
48 ~BaseSessionService();
49
50 // Moves the current session to the last session.
51 void MoveCurrentSessionToLastSession();
47 52
48 // Deletes the last session. 53 // Deletes the last session.
49 void DeleteLastSession(); 54 void DeleteLastSession();
50 55
51 typedef base::Callback<void(ScopedVector<SessionCommand>)>
52 InternalGetCommandsCallback;
53
54 protected:
55 virtual ~BaseSessionService();
56
57 // Returns the backend.
58 SessionBackend* backend() const { return backend_.get(); }
59
60 // Returns the set of commands which were scheduled to be written. Once 56 // Returns the set of commands which were scheduled to be written. Once
61 // committed to the backend, the commands are removed from here. 57 // committed to the backend, the commands are removed from here.
62 ScopedVector<SessionCommand>& pending_commands() { 58 const ScopedVector<SessionCommand>& pending_commands() {
63 return pending_commands_; 59 return pending_commands_;
64 } 60 }
65 61
66 // Whether the next save resets the file before writing to it. 62 // Whether the next save resets the file before writing to it.
67 void set_pending_reset(bool value) { pending_reset_ = value; } 63 void set_pending_reset(bool value) { pending_reset_ = value; }
68 bool pending_reset() const { return pending_reset_; } 64 bool pending_reset() const { return pending_reset_; }
69 65
70 // Returns the number of commands sent down since the last reset. 66 // Returns the number of commands sent down since the last reset.
71 int commands_since_reset() const { return commands_since_reset_; } 67 int commands_since_reset() const { return commands_since_reset_; }
72 68
73 // Schedules a command. This adds |command| to pending_commands_ and 69 // Schedules a command. This adds |command| to pending_commands_ and
74 // invokes StartSaveTimer to start a timer that invokes Save at a later 70 // invokes StartSaveTimer to start a timer that invokes Save at a later
75 // time. 71 // time.
76 virtual void ScheduleCommand(scoped_ptr<SessionCommand> command); 72 void ScheduleCommand(scoped_ptr<SessionCommand> command);
73
74 // Appends a command as part of a general rebuild. This will neither count
75 // against a rebuild, nor will it trigger a save of commands.
76 void AppendRebuildCommand(scoped_ptr<SessionCommand> command);
77
78 // Erase the |old_command| from the list of commands.
79 // The passed command will automatically be deleted.
80 void EraseCommand(SessionCommand* old_command);
81
82 // Swap a |new_command| into the list of queued commands at the location of
83 // the |old_command|. The |old_command| will be automatically deleted in the
84 // process.
85 void SwapCommand(SessionCommand* old_command,
86 scoped_ptr<SessionCommand> new_command);
87
88 // Clears all commands from the list.
89 void ClearPendingCommands();
77 90
78 // Starts the timer that invokes Save (if timer isn't already running). 91 // Starts the timer that invokes Save (if timer isn't already running).
79 void StartSaveTimer(); 92 void StartSaveTimer();
80 93
81 // Saves pending commands to the backend. This is invoked from the timer 94 // Passes all pending commands to the backend for saving.
82 // scheduled by StartSaveTimer. 95 void Save();
83 virtual void Save();
84 96
85 // Returns true if the entry at specified |url| should be written to disk. 97 // Uses the backend to load the last session commands from disc. |callback|
86 bool ShouldTrackEntry(const GURL& url); 98 // gets called once the data has arrived.
99 base::CancelableTaskTracker::TaskId ScheduleGetLastSessionCommands(
100 const GetCommandsCallback& callback,
101 base::CancelableTaskTracker* tracker);
87 102
88 // Invokes SessionBackend::ReadLastSessionCommands with callback on the 103 private:
89 // backend thread. 104 friend class BetterSessionRestoreCrashTest;
90 // If testing, SessionBackend::ReadLastSessionCommands is invoked directly. 105 friend class SessionServiceTestHelper;
91 base::CancelableTaskTracker::TaskId ScheduleGetLastSessionCommands( 106 friend class NoStartupWindowTest;
92 const InternalGetCommandsCallback& callback,
93 base::CancelableTaskTracker* tracker);
94 107
95 // This posts the task to the SequencedWorkerPool, or run immediately 108 // This posts the task to the SequencedWorkerPool, or run immediately
96 // if the SequencedWorkerPool has been shutdown. 109 // if the SequencedWorkerPool has been shutdown.
97 void RunTaskOnBackendThread(const tracked_objects::Location& from_here, 110 void RunTaskOnBackendThread(const tracked_objects::Location& from_here,
98 const base::Closure& task); 111 const base::Closure& task);
99 112
100 // Max number of navigation entries in each direction we'll persist. 113 // Returns true if any commands got processed yet - saved or queued (used by
101 static const int max_persist_navigation_count; 114 // unit tests).
115 bool ProcessedAnyCommandsForTest();
102 116
103 private: 117 // Read the last session commands directly from file.
104 friend class BetterSessionRestoreCrashTest; 118 bool ReadLastSessionCommandsForTest(ScopedVector<SessionCommand>* commands);
105 119
106 // The backend. 120 // The backend object which reads and saves commands.
107 scoped_refptr<SessionBackend> backend_; 121 scoped_refptr<SessionBackend> backend_;
108 122
109 // Commands we need to send over to the backend. 123 // Commands we need to send over to the backend.
110 ScopedVector<SessionCommand> pending_commands_; 124 ScopedVector<SessionCommand> pending_commands_;
111 125
112 // Whether the backend file should be recreated the next time we send 126 // Whether the backend file should be recreated the next time we send
113 // over the commands. 127 // over the commands.
114 bool pending_reset_; 128 bool pending_reset_;
115 129
116 // The number of commands sent to the backend before doing a reset. 130 // The number of commands sent to the backend before doing a reset.
117 int commands_since_reset_; 131 int commands_since_reset_;
118 132
119 scoped_ptr<BaseSessionServiceDelegate> delegate_; 133 BaseSessionServiceDelegate* delegate_;
120 134
121 // A token to make sure that all tasks will be serialized. 135 // A token to make sure that all tasks will be serialized.
122 base::SequencedWorkerPool::SequenceToken sequence_token_; 136 base::SequencedWorkerPool::SequenceToken sequence_token_;
123 137
124 // Used to invoke Save. 138 // Used to invoke Save.
125 base::WeakPtrFactory<BaseSessionService> weak_factory_; 139 base::WeakPtrFactory<BaseSessionService> weak_factory_;
126 140
127 DISALLOW_COPY_AND_ASSIGN(BaseSessionService); 141 DISALLOW_COPY_AND_ASSIGN(BaseSessionService);
128 }; 142 };
129 143
130 #endif // CHROME_BROWSER_SESSIONS_BASE_SESSION_SERVICE_H_ 144 #endif // CHROME_BROWSER_SESSIONS_BASE_SESSION_SERVICE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/sessions/base_session_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698