| 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/base_session_service_delegate_impl.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/core/tab_restore_service_client.h" |
| 24 #include "components/sessions/session_service_commands.h" | 25 #include "components/sessions/session_service_commands.h" |
| 25 #include "content/public/browser/notification_observer.h" | 26 #include "content/public/browser/notification_observer.h" |
| 26 #include "content/public/browser/notification_registrar.h" | 27 #include "content/public/browser/notification_registrar.h" |
| 27 #include "ui/base/ui_base_types.h" | 28 #include "ui/base/ui_base_types.h" |
| 28 | 29 |
| 29 class Profile; | 30 class Profile; |
| 30 | 31 |
| 31 namespace content { | 32 namespace content { |
| 32 class NavigationEntry; | 33 class NavigationEntry; |
| 33 class WebContents; | 34 class WebContents; |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 // Sets the application extension id of the specified tab. | 200 // Sets the application extension id of the specified tab. |
| 200 void SetTabExtensionAppID(const SessionID& window_id, | 201 void SetTabExtensionAppID(const SessionID& window_id, |
| 201 const SessionID& tab_id, | 202 const SessionID& tab_id, |
| 202 const std::string& extension_app_id); | 203 const std::string& extension_app_id); |
| 203 | 204 |
| 204 // Sets the last active time of the tab. | 205 // Sets the last active time of the tab. |
| 205 void SetLastActiveTime(const SessionID& window_id, | 206 void SetLastActiveTime(const SessionID& window_id, |
| 206 const SessionID& tab_id, | 207 const SessionID& tab_id, |
| 207 base::TimeTicks last_active_time); | 208 base::TimeTicks last_active_time); |
| 208 | 209 |
| 209 // Callback from GetLastSession. | |
| 210 // The second parameter is the id of the window that was last active. | |
| 211 typedef base::Callback<void(ScopedVector<sessions::SessionWindow>, | |
| 212 SessionID::id_type)> SessionCallback; | |
| 213 | |
| 214 // Fetches the contents of the last session, notifying the callback when | 210 // Fetches the contents of the last session, notifying the callback when |
| 215 // done. If the callback is supplied an empty vector of SessionWindows | 211 // done. If the callback is supplied an empty vector of SessionWindows |
| 216 // it means the session could not be restored. | 212 // it means the session could not be restored. |
| 217 base::CancelableTaskTracker::TaskId GetLastSession( | 213 base::CancelableTaskTracker::TaskId GetLastSession( |
| 218 const SessionCallback& callback, | 214 const sessions::GetLastSessionCallback& callback, |
| 219 base::CancelableTaskTracker* tracker); | 215 base::CancelableTaskTracker* tracker); |
| 220 | 216 |
| 221 // BaseSessionServiceDelegateImpl: | 217 // BaseSessionServiceDelegateImpl: |
| 222 void OnSavedCommands() override; | 218 void OnSavedCommands() override; |
| 223 | 219 |
| 224 private: | 220 private: |
| 225 // Allow tests to access our innards for testing purposes. | 221 // Allow tests to access our innards for testing purposes. |
| 226 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, SavedSessionNotification); | 222 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, SavedSessionNotification); |
| 227 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RestoreActivation1); | 223 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RestoreActivation1); |
| 228 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RestoreActivation2); | 224 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RestoreActivation2); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 250 void Observe(int type, | 246 void Observe(int type, |
| 251 const content::NotificationSource& source, | 247 const content::NotificationSource& source, |
| 252 const content::NotificationDetails& details) override; | 248 const content::NotificationDetails& details) override; |
| 253 | 249 |
| 254 // chrome::BrowserListObserver | 250 // chrome::BrowserListObserver |
| 255 void OnBrowserAdded(Browser* browser) override {} | 251 void OnBrowserAdded(Browser* browser) override {} |
| 256 void OnBrowserRemoved(Browser* browser) override {} | 252 void OnBrowserRemoved(Browser* browser) override {} |
| 257 void OnBrowserSetLastActive(Browser* browser) override; | 253 void OnBrowserSetLastActive(Browser* browser) override; |
| 258 | 254 |
| 259 // Converts |commands| to SessionWindows and notifies the callback. | 255 // Converts |commands| to SessionWindows and notifies the callback. |
| 260 void OnGotSessionCommands(const SessionCallback& callback, | 256 void OnGotSessionCommands(const sessions::GetLastSessionCallback& callback, |
| 261 ScopedVector<sessions::SessionCommand> commands); | 257 ScopedVector<sessions::SessionCommand> commands); |
| 262 | 258 |
| 263 // Adds commands to commands that will recreate the state of the specified | 259 // Adds commands to commands that will recreate the state of the specified |
| 264 // tab. This adds at most kMaxNavigationCountToPersist navigations (in each | 260 // tab. This adds at most kMaxNavigationCountToPersist navigations (in each |
| 265 // direction from the current navigation index). | 261 // direction from the current navigation index). |
| 266 // A pair is added to tab_to_available_range indicating the range of | 262 // A pair is added to tab_to_available_range indicating the range of |
| 267 // indices that were written. | 263 // indices that were written. |
| 268 void BuildCommandsForTab( | 264 void BuildCommandsForTab( |
| 269 const SessionID& window_id, | 265 const SessionID& window_id, |
| 270 content::WebContents* tab, | 266 content::WebContents* tab, |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 // For browser_tests, since we want to simulate the browser shutting down | 392 // For browser_tests, since we want to simulate the browser shutting down |
| 397 // without quitting. | 393 // without quitting. |
| 398 bool force_browser_not_alive_with_no_windows_; | 394 bool force_browser_not_alive_with_no_windows_; |
| 399 | 395 |
| 400 base::WeakPtrFactory<SessionService> weak_factory_; | 396 base::WeakPtrFactory<SessionService> weak_factory_; |
| 401 | 397 |
| 402 DISALLOW_COPY_AND_ASSIGN(SessionService); | 398 DISALLOW_COPY_AND_ASSIGN(SessionService); |
| 403 }; | 399 }; |
| 404 | 400 |
| 405 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_ | 401 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_ |
| OLD | NEW |