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

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

Issue 10875027: Restart running apps when chrome restarts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: respond to comments Created 8 years, 4 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 | 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 <set>
9 #include <string> 10 #include <string>
10 11
11 #include "base/basictypes.h" 12 #include "base/basictypes.h"
12 #include "base/callback.h" 13 #include "base/callback.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/sessions/base_session_service.h" 16 #include "chrome/browser/sessions/base_session_service.h"
16 #include "chrome/browser/sessions/session_id.h" 17 #include "chrome/browser/sessions/session_id.h"
17 #include "chrome/browser/ui/browser.h" 18 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/browser_list.h" 19 #include "chrome/browser/ui/browser_list.h"
19 #include "content/public/browser/notification_observer.h" 20 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_registrar.h" 21 #include "content/public/browser/notification_registrar.h"
21 #include "ui/base/ui_base_types.h" 22 #include "ui/base/ui_base_types.h"
22 23
23 class Profile; 24 class Profile;
24 class SessionCommand; 25 class SessionCommand;
25 class TabContents; 26 class TabContents;
26 struct SessionTab; 27 struct SessionTab;
27 struct SessionWindow; 28 struct SessionWindow;
28 29
29 namespace content { 30 namespace content {
30 class NavigationEntry; 31 class NavigationEntry;
31 } 32 }
32 33
34 namespace extensions {
35 class ExtensionHost;
sky 2012/08/23 16:23:52 don't indent.
koz (OOO until 15th September) 2012/08/24 02:08:57 Done.
36 }
37
33 // SessionService ------------------------------------------------------------ 38 // SessionService ------------------------------------------------------------
34 39
35 // SessionService is responsible for maintaining the state of open windows 40 // SessionService is responsible for maintaining the state of open windows
36 // and tabs so that they can be restored at a later date. The state of the 41 // and tabs so that they can be restored at a later date. The state of the
37 // currently open browsers is referred to as the current session. 42 // currently open browsers is referred to as the current session.
38 // 43 //
39 // SessionService supports restoring from the last session. The last session 44 // SessionService supports restoring from the last session. The last session
40 // typically corresponds to the last run of the browser, but not always. For 45 // typically corresponds to the last run of the browser, but not always. For
41 // example, if the user has a tabbed browser and app window running, closes the 46 // example, if the user has a tabbed browser and app window running, closes the
42 // tabbed browser, then creates a new tabbed browser the current session is made 47 // tabbed browser, then creates a new tabbed browser the current session is made
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 void SetTabUserAgentOverride(const SessionID& window_id, 174 void SetTabUserAgentOverride(const SessionID& window_id,
170 const SessionID& tab_id, 175 const SessionID& tab_id,
171 const std::string& user_agent_override); 176 const std::string& user_agent_override);
172 177
173 // Callback from GetSavedSession of GetLastSession. 178 // Callback from GetSavedSession of GetLastSession.
174 // 179 //
175 // The contents of the supplied vector are deleted after the callback is 180 // The contents of the supplied vector are deleted after the callback is
176 // notified. To take ownership of the vector clear it before returning. 181 // notified. To take ownership of the vector clear it before returning.
177 // 182 //
178 // The time gives the time the session was closed. 183 // The time gives the time the session was closed.
179 typedef base::Callback<void(Handle, std::vector<SessionWindow*>*)> 184 typedef base::Callback<void(Handle, std::vector<SessionWindow*>*,
185 std::set<std::string>*)>
sky 2012/08/23 16:23:52 Can set the set be by reference?
koz (OOO until 15th September) 2012/08/24 02:08:57 Done.
180 SessionCallback; 186 SessionCallback;
181 187
182 // Fetches the contents of the last session, notifying the callback when 188 // Fetches the contents of the last session, notifying the callback when
183 // done. If the callback is supplied an empty vector of SessionWindows 189 // done. If the callback is supplied an empty vector of SessionWindows
184 // it means the session could not be restored. 190 // it means the session could not be restored.
185 // 191 //
186 // The created request does NOT directly invoke the callback, rather the 192 // The created request does NOT directly invoke the callback, rather the
187 // callback invokes OnGotSessionCommands from which we map the 193 // callback invokes OnGotSessionCommands from which we map the
188 // SessionCommands to browser state, then notify the callback. 194 // SessionCommands to browser state, then notify the callback.
189 Handle GetLastSession(CancelableRequestConsumerBase* consumer, 195 Handle GetLastSession(CancelableRequestConsumerBase* consumer,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 SessionCommand* CreateSetWindowTypeCommand(const SessionID& window_id, 256 SessionCommand* CreateSetWindowTypeCommand(const SessionID& window_id,
251 WindowType type); 257 WindowType type);
252 258
253 SessionCommand* CreatePinnedStateCommand(const SessionID& tab_id, 259 SessionCommand* CreatePinnedStateCommand(const SessionID& tab_id,
254 bool is_pinned); 260 bool is_pinned);
255 261
256 SessionCommand* CreateSessionStorageAssociatedCommand( 262 SessionCommand* CreateSessionStorageAssociatedCommand(
257 const SessionID& tab_id, 263 const SessionID& tab_id,
258 const std::string& session_storage_persistent_id); 264 const std::string& session_storage_persistent_id);
259 265
266 SessionCommand* CreateRunAppCommand(const std::string& extension_id);
267 SessionCommand* CreateStopAppCommand(const std::string& extension_id);
268
260 // Callback from the backend for getting the commands from the save file. 269 // Callback from the backend for getting the commands from the save file.
261 // Converts the commands in SessionWindows and notifies the real callback. 270 // Converts the commands in SessionWindows and notifies the real callback.
262 void OnGotSessionCommands( 271 void OnGotSessionCommands(
263 Handle handle, 272 Handle handle,
264 scoped_refptr<InternalGetCommandsRequest> request); 273 scoped_refptr<InternalGetCommandsRequest> request);
265 274
266 // Converts the commands into SessionWindows. On return any valid 275 // Converts the commands into SessionWindows. On return any valid
sky 2012/08/23 16:23:52 Update description.
koz (OOO until 15th September) 2012/08/24 02:08:57 Done.
267 // windows are added to valid_windows. It is up to the caller to delete 276 // windows are added to valid_windows. It is up to the caller to delete
268 // the windows added to valid_windows. 277 // the windows added to valid_windows.
269 // 278 //
270 // If ignore_recent_closes is true, any window/tab closes within in a certain 279 // If ignore_recent_closes is true, any window/tab closes within in a certain
271 // time frame are ignored. 280 // time frame are ignored.
272 void RestoreSessionFromCommands(const std::vector<SessionCommand*>& commands, 281 void RestoreSessionFromCommands(const std::vector<SessionCommand*>& commands,
273 std::vector<SessionWindow*>* valid_windows); 282 std::vector<SessionWindow*>* valid_windows,
283 std::set<std::string>* apps);
274 284
275 // Iterates through the vector updating the selected_tab_index of each 285 // Iterates through the vector updating the selected_tab_index of each
276 // SessionWindow based on the actual tabs that were restored. 286 // SessionWindow based on the actual tabs that were restored.
277 void UpdateSelectedTabIndex(std::vector<SessionWindow*>* windows); 287 void UpdateSelectedTabIndex(std::vector<SessionWindow*>* windows);
278 288
279 // Returns the window in windows with the specified id. If a window does 289 // Returns the window in windows with the specified id. If a window does
280 // not exist, one is created. 290 // not exist, one is created.
281 SessionWindow* GetWindow(SessionID::id_type window_id, 291 SessionWindow* GetWindow(SessionID::id_type window_id,
282 IdToSessionWindow* windows); 292 IdToSessionWindow* windows);
283 293
(...skipping 28 matching lines...) Expand all
312 std::map<int, SessionWindow*>* windows); 322 std::map<int, SessionWindow*>* windows);
313 323
314 // Creates tabs and windows from the specified commands. The created tabs 324 // Creates tabs and windows from the specified commands. The created tabs
315 // and windows are added to |tabs| and |windows| respectively. It is up to 325 // and windows are added to |tabs| and |windows| respectively. It is up to
316 // the caller to delete the tabs and windows added to |tabs| and |windows|. 326 // the caller to delete the tabs and windows added to |tabs| and |windows|.
317 // 327 //
318 // This does NOT add any created SessionTabs to SessionWindow.tabs, that is 328 // This does NOT add any created SessionTabs to SessionWindow.tabs, that is
319 // done by AddTabsToWindows. 329 // done by AddTabsToWindows.
320 bool CreateTabsAndWindows(const std::vector<SessionCommand*>& data, 330 bool CreateTabsAndWindows(const std::vector<SessionCommand*>& data,
321 std::map<int, SessionTab*>* tabs, 331 std::map<int, SessionTab*>* tabs,
322 std::map<int, SessionWindow*>* windows); 332 std::map<int, SessionWindow*>* windows,
333 std::set<std::string>* apps);
323 334
324 // Adds commands to commands that will recreate the state of the specified 335 // Adds commands to commands that will recreate the state of the specified
325 // tab. This adds at most kMaxNavigationCountToPersist navigations (in each 336 // tab. This adds at most kMaxNavigationCountToPersist navigations (in each
326 // direction from the current navigation index). 337 // direction from the current navigation index).
327 // A pair is added to tab_to_available_range indicating the range of 338 // A pair is added to tab_to_available_range indicating the range of
328 // indices that were written. 339 // indices that were written.
329 void BuildCommandsForTab( 340 void BuildCommandsForTab(
330 const SessionID& window_id, 341 const SessionID& window_id,
331 TabContents* tab, 342 TabContents* tab,
332 int index_in_window, 343 int index_in_window,
(...skipping 12 matching lines...) Expand all
345 356
346 // Iterates over all the known browsers invoking BuildCommandsForBrowser. 357 // Iterates over all the known browsers invoking BuildCommandsForBrowser.
347 // This only adds browsers that should be tracked 358 // This only adds browsers that should be tracked
348 // (should_track_changes_for_browser_type returns true). All browsers that 359 // (should_track_changes_for_browser_type returns true). All browsers that
349 // are tracked are added to windows_to_track (as long as it is non-null). 360 // are tracked are added to windows_to_track (as long as it is non-null).
350 void BuildCommandsFromBrowsers( 361 void BuildCommandsFromBrowsers(
351 std::vector<SessionCommand*>* commands, 362 std::vector<SessionCommand*>* commands,
352 IdToRange* tab_to_available_range, 363 IdToRange* tab_to_available_range,
353 std::set<SessionID::id_type>* windows_to_track); 364 std::set<SessionID::id_type>* windows_to_track);
354 365
366 // Iterates over all known running apps and adds a command to start them to
367 // |comands|.
368 void BuildCommandsFromRunningApps(std::vector<SessionCommand*>* commands);
369
355 // Schedules a reset. A reset means the contents of the file are recreated 370 // Schedules a reset. A reset means the contents of the file are recreated
356 // from the state of the browser. 371 // from the state of the browser.
357 void ScheduleReset(); 372 void ScheduleReset();
358 373
359 // Searches for a pending command that can be replaced with command. 374 // Searches for a pending command that can be replaced with command.
360 // If one is found, pending command is removed, command is added to 375 // If one is found, pending command is removed, command is added to
361 // the pending commands and true is returned. 376 // the pending commands and true is returned.
362 bool ReplacePendingCommand(SessionCommand* command); 377 bool ReplacePendingCommand(SessionCommand* command);
363 378
364 // Schedules the specified command. This method takes ownership of the 379 // Schedules the specified command. This method takes ownership of the
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 483
469 // Constants used in calculating histogram data. 484 // Constants used in calculating histogram data.
470 const base::TimeDelta save_delay_in_millis_; 485 const base::TimeDelta save_delay_in_millis_;
471 const base::TimeDelta save_delay_in_mins_; 486 const base::TimeDelta save_delay_in_mins_;
472 const base::TimeDelta save_delay_in_hrs_; 487 const base::TimeDelta save_delay_in_hrs_;
473 488
474 // For browser_tests, since we want to simulate the browser shutting down 489 // For browser_tests, since we want to simulate the browser shutting down
475 // without quitting. 490 // without quitting.
476 bool force_browser_not_alive_with_no_windows_; 491 bool force_browser_not_alive_with_no_windows_;
477 492
493 // Tracks the apps that are currently running so we can calculate the commands
494 // needed to re-open them in a reset.
495 std::set<extensions::ExtensionHost*> running_apps_;
sky 2012/08/23 16:23:52 I think this should be ordered. Otherwise when you
koz (OOO until 15th September) 2012/08/24 02:08:57 Due to the asynchronous nature in which apps run I
496
478 DISALLOW_COPY_AND_ASSIGN(SessionService); 497 DISALLOW_COPY_AND_ASSIGN(SessionService);
479 }; 498 };
480 499
481 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_ 500 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698