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/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/task/cancelable_task_tracker.h" | 15 #include "base/task/cancelable_task_tracker.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 #include "chrome/browser/defaults.h" | 17 #include "chrome/browser/defaults.h" |
18 #include "chrome/browser/sessions/base_session_service_delegate_impl.h" | 18 #include "chrome/browser/sessions/session_common_utils.h" |
19 #include "chrome/browser/sessions/session_service_utils.h" | 19 #include "chrome/browser/sessions/session_service_utils.h" |
20 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
21 #include "chrome/browser/ui/browser_finder.h" | 21 #include "chrome/browser/ui/browser_finder.h" |
22 #include "chrome/browser/ui/browser_list_observer.h" | 22 #include "chrome/browser/ui/browser_list_observer.h" |
23 #include "components/keyed_service/core/keyed_service.h" | 23 #include "components/keyed_service/core/keyed_service.h" |
| 24 #include "components/sessions/base_session_service_delegate.h" |
24 #include "components/sessions/core/tab_restore_service_client.h" | 25 #include "components/sessions/core/tab_restore_service_client.h" |
25 #include "components/sessions/session_service_commands.h" | 26 #include "components/sessions/session_service_commands.h" |
26 #include "content/public/browser/notification_observer.h" | 27 #include "content/public/browser/notification_observer.h" |
27 #include "content/public/browser/notification_registrar.h" | 28 #include "content/public/browser/notification_registrar.h" |
28 #include "ui/base/ui_base_types.h" | 29 #include "ui/base/ui_base_types.h" |
29 | 30 |
30 class Profile; | 31 class Profile; |
31 | 32 |
32 namespace content { | 33 namespace content { |
33 class NavigationEntry; | 34 class NavigationEntry; |
(...skipping 19 matching lines...) Expand all Loading... |
53 // the last session and the current session reset. This is done to provide the | 54 // the last session and the current session reset. This is done to provide the |
54 // illusion that app windows run in separate processes. Similar behavior occurs | 55 // illusion that app windows run in separate processes. Similar behavior occurs |
55 // with incognito windows. | 56 // with incognito windows. |
56 // | 57 // |
57 // SessionService itself uses functions from session_service_commands to store | 58 // SessionService itself uses functions from session_service_commands to store |
58 // commands which can rebuild the open state of the browser (as |SessionWindow|, | 59 // commands which can rebuild the open state of the browser (as |SessionWindow|, |
59 // |SessionTab| and |SerializedNavigationEntry|). The commands are periodically | 60 // |SessionTab| and |SerializedNavigationEntry|). The commands are periodically |
60 // flushed to |SessionBackend| and written to a file. Every so often | 61 // flushed to |SessionBackend| and written to a file. Every so often |
61 // |SessionService| rebuilds the contents of the file from the open state of the | 62 // |SessionService| rebuilds the contents of the file from the open state of the |
62 // browser. | 63 // browser. |
63 class SessionService : public BaseSessionServiceDelegateImpl, | 64 class SessionService : public sessions::BaseSessionServiceDelegate, |
64 public KeyedService, | 65 public KeyedService, |
65 public content::NotificationObserver, | 66 public content::NotificationObserver, |
66 public chrome::BrowserListObserver { | 67 public chrome::BrowserListObserver { |
67 friend class SessionServiceTestHelper; | 68 friend class SessionServiceTestHelper; |
68 public: | 69 public: |
69 // Used to distinguish an application from a ordinary content window. | 70 // Used to distinguish an application from a ordinary content window. |
70 enum AppType { | 71 enum AppType { |
71 TYPE_APP, | 72 TYPE_APP, |
72 TYPE_NORMAL | 73 TYPE_NORMAL |
73 }; | 74 }; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 const SessionID& tab_id, | 208 const SessionID& tab_id, |
208 base::TimeTicks last_active_time); | 209 base::TimeTicks last_active_time); |
209 | 210 |
210 // Fetches the contents of the last session, notifying the callback when | 211 // Fetches the contents of the last session, notifying the callback when |
211 // done. If the callback is supplied an empty vector of SessionWindows | 212 // done. If the callback is supplied an empty vector of SessionWindows |
212 // it means the session could not be restored. | 213 // it means the session could not be restored. |
213 base::CancelableTaskTracker::TaskId GetLastSession( | 214 base::CancelableTaskTracker::TaskId GetLastSession( |
214 const sessions::GetLastSessionCallback& callback, | 215 const sessions::GetLastSessionCallback& callback, |
215 base::CancelableTaskTracker* tracker); | 216 base::CancelableTaskTracker* tracker); |
216 | 217 |
217 // BaseSessionServiceDelegateImpl: | 218 // sessions::BaseSessionServiceDelegate: |
| 219 base::SequencedWorkerPool* GetBlockingPool() override; |
| 220 bool ShouldUseDelayedSave() override; |
218 void OnSavedCommands() override; | 221 void OnSavedCommands() override; |
219 | 222 |
220 private: | 223 private: |
221 // Allow tests to access our innards for testing purposes. | 224 // Allow tests to access our innards for testing purposes. |
222 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, SavedSessionNotification); | 225 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, SavedSessionNotification); |
223 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RestoreActivation1); | 226 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RestoreActivation1); |
224 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RestoreActivation2); | 227 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RestoreActivation2); |
225 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RemoveUnusedRestoreWindowsTest); | 228 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RemoveUnusedRestoreWindowsTest); |
226 FRIEND_TEST_ALL_PREFIXES(NoStartupWindowTest, DontInitSessionServiceForApps); | 229 FRIEND_TEST_ALL_PREFIXES(NoStartupWindowTest, DontInitSessionServiceForApps); |
227 | 230 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 | 331 |
329 // Deletes session data if no windows are open for the current profile. | 332 // Deletes session data if no windows are open for the current profile. |
330 void MaybeDeleteSessionOnlyData(); | 333 void MaybeDeleteSessionOnlyData(); |
331 | 334 |
332 // Unit test accessors. | 335 // Unit test accessors. |
333 sessions::BaseSessionService* GetBaseSessionServiceForTest(); | 336 sessions::BaseSessionService* GetBaseSessionServiceForTest(); |
334 | 337 |
335 // The profile. This may be null during testing. | 338 // The profile. This may be null during testing. |
336 Profile* profile_; | 339 Profile* profile_; |
337 | 340 |
| 341 // Whether to use delayed save. Set to false when constructed with a FilePath |
| 342 // (which should only be used for testing). |
| 343 bool should_use_delayed_save_; |
| 344 |
338 // The owned BaseSessionService. | 345 // The owned BaseSessionService. |
339 scoped_ptr<sessions::BaseSessionService> base_session_service_; | 346 scoped_ptr<sessions::BaseSessionService> base_session_service_; |
340 | 347 |
341 content::NotificationRegistrar registrar_; | 348 content::NotificationRegistrar registrar_; |
342 | 349 |
343 // Maps from session tab id to the range of navigation entries that has | 350 // Maps from session tab id to the range of navigation entries that has |
344 // been written to disk. | 351 // been written to disk. |
345 // | 352 // |
346 // This is only used if not all the navigation entries have been | 353 // This is only used if not all the navigation entries have been |
347 // written. | 354 // written. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 // For browser_tests, since we want to simulate the browser shutting down | 399 // For browser_tests, since we want to simulate the browser shutting down |
393 // without quitting. | 400 // without quitting. |
394 bool force_browser_not_alive_with_no_windows_; | 401 bool force_browser_not_alive_with_no_windows_; |
395 | 402 |
396 base::WeakPtrFactory<SessionService> weak_factory_; | 403 base::WeakPtrFactory<SessionService> weak_factory_; |
397 | 404 |
398 DISALLOW_COPY_AND_ASSIGN(SessionService); | 405 DISALLOW_COPY_AND_ASSIGN(SessionService); |
399 }; | 406 }; |
400 | 407 |
401 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_ | 408 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_ |
OLD | NEW |