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 <string> | 10 #include <string> |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 SessionServiceTestHelper; |
57 public: | 57 public: |
| 58 // Used to distinguish an application window from a normal one. |
| 59 enum AppType { |
| 60 TYPE_APP, |
| 61 TYPE_NORMAL |
| 62 }; |
| 63 |
58 // Creates a SessionService for the specified profile. | 64 // Creates a SessionService for the specified profile. |
59 explicit SessionService(Profile* profile); | 65 explicit SessionService(Profile* profile); |
60 // For testing. | 66 // For testing. |
61 explicit SessionService(const FilePath& save_path); | 67 explicit SessionService(const FilePath& save_path); |
62 | 68 |
63 virtual ~SessionService(); | 69 virtual ~SessionService(); |
64 | 70 |
65 // Returns true if a new window opening should really be treated like the | 71 // Returns true if a new window opening should really be treated like the |
66 // start of a session (with potential session restore, startup URLs, etc.). | 72 // start of a session (with potential session restore, startup URLs, etc.). |
67 // In particular, this is true if there are no tabbed browsers running | 73 // In particular, this is true if there are no tabbed browsers running |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 | 120 |
115 // Notification the window is about to close. | 121 // Notification the window is about to close. |
116 void WindowClosing(const SessionID& window_id); | 122 void WindowClosing(const SessionID& window_id); |
117 | 123 |
118 // Notification a window has finished closing. | 124 // Notification a window has finished closing. |
119 void WindowClosed(const SessionID& window_id); | 125 void WindowClosed(const SessionID& window_id); |
120 | 126 |
121 // Sets the type of window. In order for the contents of a window to be | 127 // Sets the type of window. In order for the contents of a window to be |
122 // tracked SetWindowType must be invoked with a type we track | 128 // tracked SetWindowType must be invoked with a type we track |
123 // (should_track_changes_for_browser_type returns true). | 129 // (should_track_changes_for_browser_type returns true). |
124 void SetWindowType(const SessionID& window_id, Browser::Type type); | 130 void SetWindowType(const SessionID& window_id, |
| 131 Browser::Type type, |
| 132 AppType app_type); |
| 133 |
| 134 // Sets the application name of the specified window. |
| 135 void SetWindowAppName(const SessionID& window_id, |
| 136 const std::string& app_name); |
125 | 137 |
126 // Invoked when the NavigationController has removed entries from the back of | 138 // Invoked when the NavigationController has removed entries from the back of |
127 // the list. |count| gives the number of entries in the navigation controller. | 139 // the list. |count| gives the number of entries in the navigation controller. |
128 void TabNavigationPathPrunedFromBack(const SessionID& window_id, | 140 void TabNavigationPathPrunedFromBack(const SessionID& window_id, |
129 const SessionID& tab_id, | 141 const SessionID& tab_id, |
130 int count); | 142 int count); |
131 | 143 |
132 // Invoked when the NavigationController has removed entries from the front of | 144 // Invoked when the NavigationController has removed entries from the front of |
133 // the list. |count| gives the number of entries that were removed. | 145 // the list. |count| gives the number of entries that were removed. |
134 void TabNavigationPathPrunedFromFront(const SessionID& window_id, | 146 void TabNavigationPathPrunedFromFront(const SessionID& window_id, |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 // Returns true if there are open trackable browser windows whose ids do | 367 // Returns true if there are open trackable browser windows whose ids do |
356 // match |window_id| with our profile. A trackable window is a window from | 368 // match |window_id| with our profile. A trackable window is a window from |
357 // which |should_track_changes_for_browser_type| returns true. See | 369 // which |should_track_changes_for_browser_type| returns true. See |
358 // |should_track_changes_for_browser_type| for details. | 370 // |should_track_changes_for_browser_type| for details. |
359 bool HasOpenTrackableBrowsers(const SessionID& window_id); | 371 bool HasOpenTrackableBrowsers(const SessionID& window_id); |
360 | 372 |
361 // Returns true if changes to tabs in the specified window should be tracked. | 373 // Returns true if changes to tabs in the specified window should be tracked. |
362 bool ShouldTrackChangesToWindow(const SessionID& window_id); | 374 bool ShouldTrackChangesToWindow(const SessionID& window_id); |
363 | 375 |
364 // Returns true if we track changes to the specified browser type. | 376 // Returns true if we track changes to the specified browser type. |
365 static bool should_track_changes_for_browser_type(Browser::Type type); | 377 static bool should_track_changes_for_browser_type( |
| 378 Browser::Type type, |
| 379 AppType app_type); |
366 | 380 |
367 // Returns true if we should record a window close as pending. | 381 // Returns true if we should record a window close as pending. |
368 // |has_open_trackable_browsers_| must be up-to-date before calling this. | 382 // |has_open_trackable_browsers_| must be up-to-date before calling this. |
369 bool should_record_close_as_pending() const { | 383 bool should_record_close_as_pending() const { |
370 // When this is called, the browser window being closed is still open, hence | 384 // When this is called, the browser window being closed is still open, hence |
371 // still in the browser list. If there is a browser window other than the | 385 // still in the browser list. If there is a browser window other than the |
372 // one being closed but no trackable windows, then the others must be App | 386 // one being closed but no trackable windows, then the others must be App |
373 // windows or similar. In this case, we record the close as pending. | 387 // windows or similar. In this case, we record the close as pending. |
374 return !has_open_trackable_browsers_ && | 388 return !has_open_trackable_browsers_ && |
375 (!browser_defaults::kBrowserAliveWithNoWindows || | 389 (!browser_defaults::kBrowserAliveWithNoWindows || |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 | 459 |
446 // Constants used in calculating histogram data. | 460 // Constants used in calculating histogram data. |
447 const base::TimeDelta save_delay_in_millis_; | 461 const base::TimeDelta save_delay_in_millis_; |
448 const base::TimeDelta save_delay_in_mins_; | 462 const base::TimeDelta save_delay_in_mins_; |
449 const base::TimeDelta save_delay_in_hrs_; | 463 const base::TimeDelta save_delay_in_hrs_; |
450 | 464 |
451 DISALLOW_COPY_AND_ASSIGN(SessionService); | 465 DISALLOW_COPY_AND_ASSIGN(SessionService); |
452 }; | 466 }; |
453 | 467 |
454 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_ | 468 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_ |
OLD | NEW |