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 | 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/time.h" | 13 #include "base/time.h" |
14 #include "chrome/browser/defaults.h" | 14 #include "chrome/browser/defaults.h" |
15 #include "chrome/browser/sessions/base_session_service.h" | 15 #include "chrome/browser/sessions/base_session_service.h" |
16 #include "chrome/browser/sessions/session_id.h" | 16 #include "chrome/browser/sessions/session_id.h" |
17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/browser_list.h" | 18 #include "chrome/browser/ui/browser_list.h" |
| 19 #include "chrome/browser/ui/browser_list_observer.h" |
| 20 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
19 #include "content/public/browser/notification_observer.h" | 21 #include "content/public/browser/notification_observer.h" |
20 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
21 #include "ui/base/ui_base_types.h" | 23 #include "ui/base/ui_base_types.h" |
22 | 24 |
23 class Profile; | 25 class Profile; |
24 class SessionCommand; | 26 class SessionCommand; |
25 class TabContents; | 27 class TabContents; |
26 struct SessionTab; | 28 struct SessionTab; |
27 struct SessionWindow; | 29 struct SessionWindow; |
28 | 30 |
(...skipping 15 matching lines...) Expand all Loading... |
44 // illusion that app windows run in separate processes. Similar behavior occurs | 46 // illusion that app windows run in separate processes. Similar behavior occurs |
45 // with incognito windows. | 47 // with incognito windows. |
46 // | 48 // |
47 // SessionService itself maintains a set of SessionCommands that allow | 49 // SessionService itself maintains a set of SessionCommands that allow |
48 // SessionService to rebuild the open state of the browser (as | 50 // SessionService to rebuild the open state of the browser (as |
49 // SessionWindow, SessionTab and TabNavigation). The commands are periodically | 51 // SessionWindow, SessionTab and TabNavigation). The commands are periodically |
50 // flushed to SessionBackend and written to a file. Every so often | 52 // flushed to SessionBackend and written to a file. Every so often |
51 // SessionService rebuilds the contents of the file from the open state | 53 // SessionService rebuilds the contents of the file from the open state |
52 // of the browser. | 54 // of the browser. |
53 class SessionService : public BaseSessionService, | 55 class SessionService : public BaseSessionService, |
54 public content::NotificationObserver { | 56 public content::NotificationObserver, |
| 57 public chrome::BrowserListObserver, |
| 58 public TabStripModelObserver { |
55 friend class SessionServiceTestHelper; | 59 friend class SessionServiceTestHelper; |
56 public: | 60 public: |
57 // Used to distinguish an application window from a normal one. | 61 // Used to distinguish an application window from a normal one. |
58 enum AppType { | 62 enum AppType { |
59 TYPE_APP, | 63 TYPE_APP, |
60 TYPE_NORMAL | 64 TYPE_NORMAL |
61 }; | 65 }; |
62 | 66 |
63 // Creates a SessionService for the specified profile. | 67 // Creates a SessionService for the specified profile. |
64 explicit SessionService(Profile* profile); | 68 explicit SessionService(Profile* profile); |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 base::TimeTicks* last_updated_time); | 411 base::TimeTicks* last_updated_time); |
408 | 412 |
409 // Helper methods to record the histogram data | 413 // Helper methods to record the histogram data |
410 void RecordUpdatedTabClosed(base::TimeDelta delta, bool use_long_period); | 414 void RecordUpdatedTabClosed(base::TimeDelta delta, bool use_long_period); |
411 void RecordUpdatedNavListPruned(base::TimeDelta delta, bool use_long_period); | 415 void RecordUpdatedNavListPruned(base::TimeDelta delta, bool use_long_period); |
412 void RecordUpdatedNavEntryCommit(base::TimeDelta delta, bool use_long_period); | 416 void RecordUpdatedNavEntryCommit(base::TimeDelta delta, bool use_long_period); |
413 void RecordUpdatedSaveTime(base::TimeDelta delta, bool use_long_period); | 417 void RecordUpdatedSaveTime(base::TimeDelta delta, bool use_long_period); |
414 void RecordUpdatedSessionNavigationOrTab(base::TimeDelta delta, | 418 void RecordUpdatedSessionNavigationOrTab(base::TimeDelta delta, |
415 bool use_long_period); | 419 bool use_long_period); |
416 | 420 |
| 421 // chrome::BrowserListObserver implementation. |
| 422 virtual void OnBrowserAdded(Browser* browser) OVERRIDE; |
| 423 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; |
| 424 |
| 425 // TabStripModelObserver implementation. |
| 426 virtual void TabInsertedAt(TabContents* contents, |
| 427 int index, |
| 428 bool foreground) OVERRIDE; |
| 429 virtual void TabClosingAt(TabStripModel* tab_strip_model, |
| 430 TabContents* contents, |
| 431 int index) OVERRIDE; |
| 432 virtual void TabReplacedAt(TabStripModel* tab_strip_model, |
| 433 TabContents* old_contents, |
| 434 TabContents* new_contents, |
| 435 int index) OVERRIDE; |
| 436 |
417 // Convert back/forward between the Browser and SessionService DB window | 437 // Convert back/forward between the Browser and SessionService DB window |
418 // types. | 438 // types. |
419 static WindowType WindowTypeForBrowserType(Browser::Type type); | 439 static WindowType WindowTypeForBrowserType(Browser::Type type); |
420 static Browser::Type BrowserTypeForWindowType(WindowType type); | 440 static Browser::Type BrowserTypeForWindowType(WindowType type); |
421 | 441 |
422 content::NotificationRegistrar registrar_; | 442 content::NotificationRegistrar registrar_; |
423 | 443 |
424 // Maps from session tab id to the range of navigation entries that has | 444 // Maps from session tab id to the range of navigation entries that has |
425 // been written to disk. | 445 // been written to disk. |
426 // | 446 // |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 const base::TimeDelta save_delay_in_hrs_; | 491 const base::TimeDelta save_delay_in_hrs_; |
472 | 492 |
473 // For browser_tests, since we want to simulate the browser shutting down | 493 // For browser_tests, since we want to simulate the browser shutting down |
474 // without quitting. | 494 // without quitting. |
475 bool force_browser_not_alive_with_no_windows_; | 495 bool force_browser_not_alive_with_no_windows_; |
476 | 496 |
477 DISALLOW_COPY_AND_ASSIGN(SessionService); | 497 DISALLOW_COPY_AND_ASSIGN(SessionService); |
478 }; | 498 }; |
479 | 499 |
480 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_ | 500 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_ |
OLD | NEW |