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

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

Issue 11446033: Convert SessionService to use new CancelableTaskTracker (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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 | Annotate | Revision Log
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_SESSION_SERVICE_H_ 5 #ifndef CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_
6 #define CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_ 6 #define CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/memory/scoped_vector.h"
13 #include "base/time.h" 14 #include "base/time.h"
14 #include "chrome/browser/defaults.h" 15 #include "chrome/browser/defaults.h"
15 #include "chrome/browser/profiles/profile_keyed_service.h" 16 #include "chrome/browser/profiles/profile_keyed_service.h"
16 #include "chrome/browser/sessions/base_session_service.h" 17 #include "chrome/browser/sessions/base_session_service.h"
17 #include "chrome/browser/sessions/session_id.h" 18 #include "chrome/browser/sessions/session_id.h"
18 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_list.h" 20 #include "chrome/browser/ui/browser_list.h"
20 #include "chrome/browser/ui/browser_list_observer.h" 21 #include "chrome/browser/ui/browser_list_observer.h"
22 #include "chrome/common/cancelable_task_tracker.h"
21 #include "content/public/browser/notification_observer.h" 23 #include "content/public/browser/notification_observer.h"
22 #include "content/public/browser/notification_registrar.h" 24 #include "content/public/browser/notification_registrar.h"
23 #include "ui/base/ui_base_types.h" 25 #include "ui/base/ui_base_types.h"
24 26
25 class Profile; 27 class Profile;
26 class SessionCommand; 28 class SessionCommand;
27 class TabContents; 29 class TabContents;
28 struct SessionTab; 30 struct SessionTab;
29 struct SessionWindow; 31 struct SessionWindow;
30 32
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 int index); 175 int index);
174 176
175 // Sets the index of the selected tab in the specified window. 177 // Sets the index of the selected tab in the specified window.
176 void SetSelectedTabInWindow(const SessionID& window_id, int index); 178 void SetSelectedTabInWindow(const SessionID& window_id, int index);
177 179
178 // Sets the user agent override of the specified tab. 180 // Sets the user agent override of the specified tab.
179 void SetTabUserAgentOverride(const SessionID& window_id, 181 void SetTabUserAgentOverride(const SessionID& window_id,
180 const SessionID& tab_id, 182 const SessionID& tab_id,
181 const std::string& user_agent_override); 183 const std::string& user_agent_override);
182 184
183 // Callback from GetSavedSession of GetLastSession. 185 // Callback from GetLastSession.
184 // 186 // The second parameter is the id of the window that was last active.
185 // The contents of the supplied vector are deleted after the callback is 187 typedef base::Callback<void(ScopedVector<SessionWindow>, SessionID::id_type)>
186 // notified. To take ownership of the vector clear it before returning. 188 SessionCallback;
187 //
188 // The session ID is the id of the window that was last active.
189 typedef base::Callback<void(Handle,
190 std::vector<SessionWindow*>*,
191 SessionID::id_type)> SessionCallback;
192 189
193 // Fetches the contents of the last session, notifying the callback when 190 // Fetches the contents of the last session, notifying the callback when
194 // done. If the callback is supplied an empty vector of SessionWindows 191 // done. If the callback is supplied an empty vector of SessionWindows
195 // it means the session could not be restored. 192 // it means the session could not be restored.
196 // 193 CancelableTaskTracker::TaskId GetLastSession(const SessionCallback& callback,
197 // The created request does NOT directly invoke the callback, rather the 194 CancelableTaskTracker* tracker);
198 // callback invokes OnGotSessionCommands from which we map the
199 // SessionCommands to browser state, then notify the callback.
200 Handle GetLastSession(CancelableRequestConsumerBase* consumer,
201 const SessionCallback& callback);
202 195
203 // Overridden from BaseSessionService because we want some UMA reporting on 196 // Overridden from BaseSessionService because we want some UMA reporting on
204 // session update activities. 197 // session update activities.
205 virtual void Save() OVERRIDE; 198 virtual void Save() OVERRIDE;
206 199
207 private: 200 private:
208 // Allow tests to access our innards for testing purposes. 201 // Allow tests to access our innards for testing purposes.
209 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RestoreActivation1); 202 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RestoreActivation1);
210 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RestoreActivation2); 203 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RestoreActivation2);
211 204
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 265
273 SessionCommand* CreatePinnedStateCommand(const SessionID& tab_id, 266 SessionCommand* CreatePinnedStateCommand(const SessionID& tab_id,
274 bool is_pinned); 267 bool is_pinned);
275 268
276 SessionCommand* CreateSessionStorageAssociatedCommand( 269 SessionCommand* CreateSessionStorageAssociatedCommand(
277 const SessionID& tab_id, 270 const SessionID& tab_id,
278 const std::string& session_storage_persistent_id); 271 const std::string& session_storage_persistent_id);
279 272
280 SessionCommand* CreateSetActiveWindowCommand(const SessionID& window_id); 273 SessionCommand* CreateSetActiveWindowCommand(const SessionID& window_id);
281 274
282 // Callback from the backend for getting the commands from the save file. 275 // Converts |commands| to SessionWindows and notifies the callback.
283 // Converts the commands in SessionWindows and notifies the real callback. 276 void OnGotSessionCommands(const SessionCallback& callback,
284 void OnGotSessionCommands( 277 ScopedVector<SessionCommand> commands);
marja 2012/12/06 08:21:58 (Here too)
285 Handle handle,
286 scoped_refptr<InternalGetCommandsRequest> request);
287 278
288 // Converts the commands into SessionWindows. On return any valid 279 // Converts the commands into SessionWindows. On return any valid
289 // windows are added to valid_windows. It is up to the caller to delete 280 // windows are added to valid_windows. It is up to the caller to delete
290 // the windows added to valid_windows. |active_window_id| will be set with the 281 // the windows added to valid_windows. |active_window_id| will be set with the
291 // id of the last active window, but it's only valid when this id corresponds 282 // id of the last active window, but it's only valid when this id corresponds
292 // to the id of one of the windows in valid_windows. 283 // to the id of one of the windows in valid_windows.
293 void RestoreSessionFromCommands(const std::vector<SessionCommand*>& commands, 284 void RestoreSessionFromCommands(const std::vector<SessionCommand*>& commands,
294 std::vector<SessionWindow*>* valid_windows, 285 std::vector<SessionWindow*>* valid_windows,
295 SessionID::id_type* active_window_id); 286 SessionID::id_type* active_window_id);
296 287
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 const base::TimeDelta save_delay_in_hrs_; 490 const base::TimeDelta save_delay_in_hrs_;
500 491
501 // For browser_tests, since we want to simulate the browser shutting down 492 // For browser_tests, since we want to simulate the browser shutting down
502 // without quitting. 493 // without quitting.
503 bool force_browser_not_alive_with_no_windows_; 494 bool force_browser_not_alive_with_no_windows_;
504 495
505 DISALLOW_COPY_AND_ASSIGN(SessionService); 496 DISALLOW_COPY_AND_ASSIGN(SessionService);
506 }; 497 };
507 498
508 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_ 499 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698