| OLD | NEW |
| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 // with incognito windows. | 46 // with incognito windows. |
| 47 // | 47 // |
| 48 // SessionService itself maintains a set of SessionCommands that allow | 48 // SessionService itself maintains a set of SessionCommands that allow |
| 49 // SessionService to rebuild the open state of the browser (as | 49 // SessionService to rebuild the open state of the browser (as |
| 50 // SessionWindow, SessionTab and TabNavigation). The commands are periodically | 50 // SessionWindow, SessionTab and TabNavigation). The commands are periodically |
| 51 // flushed to SessionBackend and written to a file. Every so often | 51 // flushed to SessionBackend and written to a file. Every so often |
| 52 // SessionService rebuilds the contents of the file from the open state | 52 // SessionService rebuilds the contents of the file from the open state |
| 53 // of the browser. | 53 // of the browser. |
| 54 class SessionService : public BaseSessionService, | 54 class SessionService : public BaseSessionService, |
| 55 public content::NotificationObserver { | 55 public content::NotificationObserver { |
| 56 friend class SessionServiceTestHelper; | 56 friend class SessionRestoreTest; |
| 57 friend class SessionServiceTestHelper; |
| 57 public: | 58 public: |
| 58 // Used to distinguish an application window from a normal one. | 59 // Used to distinguish an application window from a normal one. |
| 59 enum AppType { | 60 enum AppType { |
| 60 TYPE_APP, | 61 TYPE_APP, |
| 61 TYPE_NORMAL | 62 TYPE_NORMAL |
| 62 }; | 63 }; |
| 63 | 64 |
| 64 // Creates a SessionService for the specified profile. | 65 // Creates a SessionService for the specified profile. |
| 65 explicit SessionService(Profile* profile); | 66 explicit SessionService(Profile* profile); |
| 66 // For testing. | 67 // For testing. |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 | 381 |
| 381 // Returns true if we should record a window close as pending. | 382 // Returns true if we should record a window close as pending. |
| 382 // |has_open_trackable_browsers_| must be up-to-date before calling this. | 383 // |has_open_trackable_browsers_| must be up-to-date before calling this. |
| 383 bool should_record_close_as_pending() const { | 384 bool should_record_close_as_pending() const { |
| 384 // When this is called, the browser window being closed is still open, hence | 385 // When this is called, the browser window being closed is still open, hence |
| 385 // still in the browser list. If there is a browser window other than the | 386 // still in the browser list. If there is a browser window other than the |
| 386 // one being closed but no trackable windows, then the others must be App | 387 // one being closed but no trackable windows, then the others must be App |
| 387 // windows or similar. In this case, we record the close as pending. | 388 // windows or similar. In this case, we record the close as pending. |
| 388 return !has_open_trackable_browsers_ && | 389 return !has_open_trackable_browsers_ && |
| 389 (!browser_defaults::kBrowserAliveWithNoWindows || | 390 (!browser_defaults::kBrowserAliveWithNoWindows || |
| 391 force_browser_not_alive_with_no_windows_ || |
| 390 BrowserList::size() > 1); | 392 BrowserList::size() > 1); |
| 391 } | 393 } |
| 392 | 394 |
| 393 // Call when certain session relevant notifications | 395 // Call when certain session relevant notifications |
| 394 // (tab_closed, nav_list_pruned) occur. In addition, this is | 396 // (tab_closed, nav_list_pruned) occur. In addition, this is |
| 395 // currently called when Save() is called to compare how often the | 397 // currently called when Save() is called to compare how often the |
| 396 // session data is currently saved verses when we may want to save it. | 398 // session data is currently saved verses when we may want to save it. |
| 397 // It records the data in UMA stats. | 399 // It records the data in UMA stats. |
| 398 void RecordSessionUpdateHistogramData(int type, | 400 void RecordSessionUpdateHistogramData(int type, |
| 399 base::TimeTicks* last_updated_time); | 401 base::TimeTicks* last_updated_time); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 base::TimeTicks last_updated_tab_closed_time_; | 457 base::TimeTicks last_updated_tab_closed_time_; |
| 456 base::TimeTicks last_updated_nav_list_pruned_time_; | 458 base::TimeTicks last_updated_nav_list_pruned_time_; |
| 457 base::TimeTicks last_updated_nav_entry_commit_time_; | 459 base::TimeTicks last_updated_nav_entry_commit_time_; |
| 458 base::TimeTicks last_updated_save_time_; | 460 base::TimeTicks last_updated_save_time_; |
| 459 | 461 |
| 460 // Constants used in calculating histogram data. | 462 // Constants used in calculating histogram data. |
| 461 const base::TimeDelta save_delay_in_millis_; | 463 const base::TimeDelta save_delay_in_millis_; |
| 462 const base::TimeDelta save_delay_in_mins_; | 464 const base::TimeDelta save_delay_in_mins_; |
| 463 const base::TimeDelta save_delay_in_hrs_; | 465 const base::TimeDelta save_delay_in_hrs_; |
| 464 | 466 |
| 467 // For browser_tests, since we want to simulate the browser shutting down |
| 468 // without quitting. |
| 469 bool force_browser_not_alive_with_no_windows_; |
| 470 |
| 465 DISALLOW_COPY_AND_ASSIGN(SessionService); | 471 DISALLOW_COPY_AND_ASSIGN(SessionService); |
| 466 }; | 472 }; |
| 467 | 473 |
| 468 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_ | 474 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_ |
| OLD | NEW |