OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
| 10 #include <set> |
10 #include <string> | 11 #include <string> |
11 | 12 |
12 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
13 #include "base/callback.h" | 14 #include "base/callback.h" |
14 #include "base/time.h" | 15 #include "base/time.h" |
15 #include "chrome/browser/defaults.h" | 16 #include "chrome/browser/defaults.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" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 // callback invokes OnGotSessionCommands from which we map the | 172 // callback invokes OnGotSessionCommands from which we map the |
172 // SessionCommands to browser state, then notify the callback. | 173 // SessionCommands to browser state, then notify the callback. |
173 Handle GetLastSession(CancelableRequestConsumerBase* consumer, | 174 Handle GetLastSession(CancelableRequestConsumerBase* consumer, |
174 const SessionCallback& callback); | 175 const SessionCallback& callback); |
175 | 176 |
176 // Overridden from BaseSessionService because we want some UMA reporting on | 177 // Overridden from BaseSessionService because we want some UMA reporting on |
177 // session update activities. | 178 // session update activities. |
178 virtual void Save() OVERRIDE; | 179 virtual void Save() OVERRIDE; |
179 | 180 |
180 private: | 181 private: |
| 182 class SessionStorageAssociationReader; |
| 183 |
181 typedef std::map<SessionID::id_type, std::pair<int, int> > IdToRange; | 184 typedef std::map<SessionID::id_type, std::pair<int, int> > IdToRange; |
182 typedef std::map<SessionID::id_type, SessionTab*> IdToSessionTab; | 185 typedef std::map<SessionID::id_type, SessionTab*> IdToSessionTab; |
183 typedef std::map<SessionID::id_type, SessionWindow*> IdToSessionWindow; | 186 typedef std::map<SessionID::id_type, SessionWindow*> IdToSessionWindow; |
184 | 187 |
185 | 188 |
186 // These types mirror Browser::Type, but are re-defined here because these | 189 // These types mirror Browser::Type, but are re-defined here because these |
187 // specific enumeration _values_ are written into the session database and | 190 // specific enumeration _values_ are written into the session database and |
188 // are needed to maintain forward compatibility. | 191 // are needed to maintain forward compatibility. |
189 // Note that we only store browsers of type TYPE_TABBED and TYPE_POPUP. | 192 // Note that we only store browsers of type TYPE_TABBED and TYPE_POPUP. |
190 enum WindowType { | 193 enum WindowType { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 SessionCommand* CreateSetSelectedNavigationIndexCommand( | 233 SessionCommand* CreateSetSelectedNavigationIndexCommand( |
231 const SessionID& tab_id, | 234 const SessionID& tab_id, |
232 int index); | 235 int index); |
233 | 236 |
234 SessionCommand* CreateSetWindowTypeCommand(const SessionID& window_id, | 237 SessionCommand* CreateSetWindowTypeCommand(const SessionID& window_id, |
235 WindowType type); | 238 WindowType type); |
236 | 239 |
237 SessionCommand* CreatePinnedStateCommand(const SessionID& tab_id, | 240 SessionCommand* CreatePinnedStateCommand(const SessionID& tab_id, |
238 bool is_pinned); | 241 bool is_pinned); |
239 | 242 |
| 243 void CreateAndScheduleSessionStorageCreatedCommand( |
| 244 int64 namespace_id, |
| 245 const FilePath& directory); |
| 246 |
240 // Callback from the backend for getting the commands from the save file. | 247 // Callback from the backend for getting the commands from the save file. |
241 // Converts the commands in SessionWindows and notifies the real callback. | 248 // Converts the commands in SessionWindows and notifies the real callback. |
242 void OnGotSessionCommands( | 249 void OnGotSessionCommands( |
243 Handle handle, | 250 Handle handle, |
244 scoped_refptr<InternalGetCommandsRequest> request); | 251 scoped_refptr<InternalGetCommandsRequest> request); |
245 | 252 |
246 // Converts the commands into SessionWindows. On return any valid | 253 // Converts the commands into SessionWindows. On return any valid |
247 // windows are added to valid_windows. It is up to the caller to delete | 254 // windows are added to valid_windows. It is up to the caller to delete |
248 // the windows added to valid_windows. | 255 // the windows added to valid_windows. |
249 // | 256 // |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 std::map<int, SessionWindow*>* windows); | 299 std::map<int, SessionWindow*>* windows); |
293 | 300 |
294 // Creates tabs and windows from the specified commands. The created tabs | 301 // Creates tabs and windows from the specified commands. The created tabs |
295 // and windows are added to |tabs| and |windows| respectively. It is up to | 302 // and windows are added to |tabs| and |windows| respectively. It is up to |
296 // the caller to delete the tabs and windows added to |tabs| and |windows|. | 303 // the caller to delete the tabs and windows added to |tabs| and |windows|. |
297 // | 304 // |
298 // This does NOT add any created SessionTabs to SessionWindow.tabs, that is | 305 // This does NOT add any created SessionTabs to SessionWindow.tabs, that is |
299 // done by AddTabsToWindows. | 306 // done by AddTabsToWindows. |
300 bool CreateTabsAndWindows(const std::vector<SessionCommand*>& data, | 307 bool CreateTabsAndWindows(const std::vector<SessionCommand*>& data, |
301 std::map<int, SessionTab*>* tabs, | 308 std::map<int, SessionTab*>* tabs, |
302 std::map<int, SessionWindow*>* windows); | 309 std::map<int, SessionWindow*>* windows, |
| 310 std::set<std::string>* needed_session_storages); |
303 | 311 |
304 // Adds commands to commands that will recreate the state of the specified | 312 // Adds commands to commands that will recreate the state of the specified |
305 // tab. This adds at most kMaxNavigationCountToPersist navigations (in each | 313 // tab. This adds at most kMaxNavigationCountToPersist navigations (in each |
306 // direction from the current navigation index). | 314 // direction from the current navigation index). |
307 // A pair is added to tab_to_available_range indicating the range of | 315 // A pair is added to tab_to_available_range indicating the range of |
308 // indices that were written. | 316 // indices that were written. |
309 void BuildCommandsForTab( | 317 void BuildCommandsForTab( |
310 const SessionID& window_id, | 318 const SessionID& window_id, |
311 TabContentsWrapper* tab, | 319 TabContentsWrapper* tab, |
312 int index_in_window, | 320 int index_in_window, |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 base::TimeTicks* last_updated_time); | 393 base::TimeTicks* last_updated_time); |
386 | 394 |
387 // Helper methods to record the histogram data | 395 // Helper methods to record the histogram data |
388 void RecordUpdatedTabClosed(base::TimeDelta delta, bool use_long_period); | 396 void RecordUpdatedTabClosed(base::TimeDelta delta, bool use_long_period); |
389 void RecordUpdatedNavListPruned(base::TimeDelta delta, bool use_long_period); | 397 void RecordUpdatedNavListPruned(base::TimeDelta delta, bool use_long_period); |
390 void RecordUpdatedNavEntryCommit(base::TimeDelta delta, bool use_long_period); | 398 void RecordUpdatedNavEntryCommit(base::TimeDelta delta, bool use_long_period); |
391 void RecordUpdatedSaveTime(base::TimeDelta delta, bool use_long_period); | 399 void RecordUpdatedSaveTime(base::TimeDelta delta, bool use_long_period); |
392 void RecordUpdatedSessionNavigationOrTab(base::TimeDelta delta, | 400 void RecordUpdatedSessionNavigationOrTab(base::TimeDelta delta, |
393 bool use_long_period); | 401 bool use_long_period); |
394 | 402 |
| 403 // Callback for SessionStorageAssociationReader. |
| 404 void AssociateSessionStorage(SessionStorageAssociationReader* reader, |
| 405 int64 namespace_id, |
| 406 const FilePath& directory); |
| 407 |
395 // Convert back/forward between the Browser and SessionService DB window | 408 // Convert back/forward between the Browser and SessionService DB window |
396 // types. | 409 // types. |
397 static WindowType WindowTypeForBrowserType(Browser::Type type); | 410 static WindowType WindowTypeForBrowserType(Browser::Type type); |
398 static Browser::Type BrowserTypeForWindowType(WindowType type); | 411 static Browser::Type BrowserTypeForWindowType(WindowType type); |
399 | 412 |
400 content::NotificationRegistrar registrar_; | 413 content::NotificationRegistrar registrar_; |
401 | 414 |
402 // Maps from session tab id to the range of navigation entries that has | 415 // Maps from session tab id to the range of navigation entries that has |
403 // been written to disk. | 416 // been written to disk. |
404 // | 417 // |
(...skipping 25 matching lines...) Expand all Loading... |
430 | 443 |
431 // Are there any open trackable browsers? | 444 // Are there any open trackable browsers? |
432 bool has_open_trackable_browsers_; | 445 bool has_open_trackable_browsers_; |
433 | 446 |
434 // If true and a new tabbed browser is created and there are no opened tabbed | 447 // If true and a new tabbed browser is created and there are no opened tabbed |
435 // browser (has_open_trackable_browsers_ is false), then the current session | 448 // browser (has_open_trackable_browsers_ is false), then the current session |
436 // is made the last session. See description above class for details on | 449 // is made the last session. See description above class for details on |
437 // current/last session. | 450 // current/last session. |
438 bool move_on_new_browser_; | 451 bool move_on_new_browser_; |
439 | 452 |
| 453 // Map from session storage namespace id (stored by |SessionStorageNamespace|) |
| 454 // to a pair (window_id, tab_id). |
| 455 typedef std::map<int64, |
| 456 std::pair<SessionID, SessionID> > SessionStorageNamespaceMap; |
| 457 |
| 458 SessionStorageNamespaceMap session_storage_namespace_map_; |
| 459 |
440 // Used for reporting frequency of session altering operations. | 460 // Used for reporting frequency of session altering operations. |
441 base::TimeTicks last_updated_tab_closed_time_; | 461 base::TimeTicks last_updated_tab_closed_time_; |
442 base::TimeTicks last_updated_nav_list_pruned_time_; | 462 base::TimeTicks last_updated_nav_list_pruned_time_; |
443 base::TimeTicks last_updated_nav_entry_commit_time_; | 463 base::TimeTicks last_updated_nav_entry_commit_time_; |
444 base::TimeTicks last_updated_save_time_; | 464 base::TimeTicks last_updated_save_time_; |
445 | 465 |
446 // Constants used in calculating histogram data. | 466 // Constants used in calculating histogram data. |
447 const base::TimeDelta save_delay_in_millis_; | 467 const base::TimeDelta save_delay_in_millis_; |
448 const base::TimeDelta save_delay_in_mins_; | 468 const base::TimeDelta save_delay_in_mins_; |
449 const base::TimeDelta save_delay_in_hrs_; | 469 const base::TimeDelta save_delay_in_hrs_; |
450 | 470 |
| 471 // For keeping track of |SessionStorageAssociationReader|s which are active at |
| 472 // the moment. When destructed, this map will drop the references to them. The |
| 473 // destructor of |SessionService| uses this map for nullifying the pointers in |
| 474 // the |SessionStorageAssociationReader|s so that they won't call |
| 475 // |SessionService| back after finishing their operations. |
| 476 typedef std::map<SessionStorageAssociationReader*, |
| 477 scoped_refptr<SessionStorageAssociationReader> > |
| 478 SessionStorageAssociationReaders; |
| 479 SessionStorageAssociationReaders session_storage_association_readers_; |
| 480 |
451 DISALLOW_COPY_AND_ASSIGN(SessionService); | 481 DISALLOW_COPY_AND_ASSIGN(SessionService); |
452 }; | 482 }; |
453 | 483 |
454 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_ | 484 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_ |
OLD | NEW |