| 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 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 enum AppType { | 65 enum AppType { |
| 66 TYPE_APP, | 66 TYPE_APP, |
| 67 TYPE_NORMAL | 67 TYPE_NORMAL |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 // Creates a SessionService for the specified profile. | 70 // Creates a SessionService for the specified profile. |
| 71 explicit SessionService(Profile* profile); | 71 explicit SessionService(Profile* profile); |
| 72 // For testing. | 72 // For testing. |
| 73 explicit SessionService(const base::FilePath& save_path); | 73 explicit SessionService(const base::FilePath& save_path); |
| 74 | 74 |
| 75 virtual ~SessionService(); | 75 ~SessionService() override; |
| 76 | 76 |
| 77 // Returns true if a new window opening should really be treated like the | 77 // Returns true if a new window opening should really be treated like the |
| 78 // start of a session (with potential session restore, startup URLs, etc.). | 78 // start of a session (with potential session restore, startup URLs, etc.). |
| 79 // In particular, this is true if there are no tabbed browsers running | 79 // In particular, this is true if there are no tabbed browsers running |
| 80 // currently (eg. because only background or other app pages are running). | 80 // currently (eg. because only background or other app pages are running). |
| 81 bool ShouldNewWindowStartSession(); | 81 bool ShouldNewWindowStartSession(); |
| 82 | 82 |
| 83 // Invoke at a point when you think session restore might occur. For example, | 83 // Invoke at a point when you think session restore might occur. For example, |
| 84 // during startup and window creation this is invoked to see if a session | 84 // during startup and window creation this is invoked to see if a session |
| 85 // needs to be restored. If a session needs to be restored it is done so | 85 // needs to be restored. If a session needs to be restored it is done so |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 193 |
| 194 // Fetches the contents of the last session, notifying the callback when | 194 // Fetches the contents of the last session, notifying the callback when |
| 195 // done. If the callback is supplied an empty vector of SessionWindows | 195 // done. If the callback is supplied an empty vector of SessionWindows |
| 196 // it means the session could not be restored. | 196 // it means the session could not be restored. |
| 197 base::CancelableTaskTracker::TaskId GetLastSession( | 197 base::CancelableTaskTracker::TaskId GetLastSession( |
| 198 const SessionCallback& callback, | 198 const SessionCallback& callback, |
| 199 base::CancelableTaskTracker* tracker); | 199 base::CancelableTaskTracker* tracker); |
| 200 | 200 |
| 201 // Overridden from BaseSessionService because we want some UMA reporting on | 201 // Overridden from BaseSessionService because we want some UMA reporting on |
| 202 // session update activities. | 202 // session update activities. |
| 203 virtual void Save() override; | 203 void Save() override; |
| 204 | 204 |
| 205 private: | 205 private: |
| 206 // Allow tests to access our innards for testing purposes. | 206 // Allow tests to access our innards for testing purposes. |
| 207 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RestoreActivation1); | 207 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RestoreActivation1); |
| 208 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RestoreActivation2); | 208 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RestoreActivation2); |
| 209 FRIEND_TEST_ALL_PREFIXES(NoStartupWindowTest, DontInitSessionServiceForApps); | 209 FRIEND_TEST_ALL_PREFIXES(NoStartupWindowTest, DontInitSessionServiceForApps); |
| 210 | 210 |
| 211 typedef std::map<SessionID::id_type, std::pair<int, int> > IdToRange; | 211 typedef std::map<SessionID::id_type, std::pair<int, int> > IdToRange; |
| 212 typedef std::map<SessionID::id_type, SessionTab*> IdToSessionTab; | 212 typedef std::map<SessionID::id_type, SessionTab*> IdToSessionTab; |
| 213 typedef std::map<SessionID::id_type, SessionWindow*> IdToSessionWindow; | 213 typedef std::map<SessionID::id_type, SessionWindow*> IdToSessionWindow; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 226 | 226 |
| 227 // Returns true if we have scheduled any commands, or any scheduled commands | 227 // Returns true if we have scheduled any commands, or any scheduled commands |
| 228 // have been saved. | 228 // have been saved. |
| 229 bool processed_any_commands(); | 229 bool processed_any_commands(); |
| 230 | 230 |
| 231 // Implementation of RestoreIfNecessary. If |browser| is non-null and we need | 231 // Implementation of RestoreIfNecessary. If |browser| is non-null and we need |
| 232 // to restore, the tabs are added to it, otherwise a new browser is created. | 232 // to restore, the tabs are added to it, otherwise a new browser is created. |
| 233 bool RestoreIfNecessary(const std::vector<GURL>& urls_to_open, | 233 bool RestoreIfNecessary(const std::vector<GURL>& urls_to_open, |
| 234 Browser* browser); | 234 Browser* browser); |
| 235 | 235 |
| 236 virtual void Observe(int type, | 236 void Observe(int type, |
| 237 const content::NotificationSource& source, | 237 const content::NotificationSource& source, |
| 238 const content::NotificationDetails& details) override; | 238 const content::NotificationDetails& details) override; |
| 239 | 239 |
| 240 // chrome::BrowserListObserver | 240 // chrome::BrowserListObserver |
| 241 virtual void OnBrowserAdded(Browser* browser) override {} | 241 void OnBrowserAdded(Browser* browser) override {} |
| 242 virtual void OnBrowserRemoved(Browser* browser) override {} | 242 void OnBrowserRemoved(Browser* browser) override {} |
| 243 virtual void OnBrowserSetLastActive(Browser* browser) override; | 243 void OnBrowserSetLastActive(Browser* browser) override; |
| 244 | 244 |
| 245 // Sets the application extension id of the specified tab. | 245 // Sets the application extension id of the specified tab. |
| 246 void SetTabExtensionAppID(const SessionID& window_id, | 246 void SetTabExtensionAppID(const SessionID& window_id, |
| 247 const SessionID& tab_id, | 247 const SessionID& tab_id, |
| 248 const std::string& extension_app_id); | 248 const std::string& extension_app_id); |
| 249 | 249 |
| 250 // Methods to create the various commands. It is up to the caller to delete | 250 // Methods to create the various commands. It is up to the caller to delete |
| 251 // the returned the SessionCommand* object. | 251 // the returned the SessionCommand* object. |
| 252 SessionCommand* CreateSetSelectedTabInWindow(const SessionID& window_id, | 252 SessionCommand* CreateSetSelectedTabInWindow(const SessionID& window_id, |
| 253 int index); | 253 int index); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 // from the state of the browser. | 382 // from the state of the browser. |
| 383 void ScheduleReset(); | 383 void ScheduleReset(); |
| 384 | 384 |
| 385 // Searches for a pending command that can be replaced with command. | 385 // Searches for a pending command that can be replaced with command. |
| 386 // If one is found, pending command is removed, command is added to | 386 // If one is found, pending command is removed, command is added to |
| 387 // the pending commands and true is returned. | 387 // the pending commands and true is returned. |
| 388 bool ReplacePendingCommand(SessionCommand* command); | 388 bool ReplacePendingCommand(SessionCommand* command); |
| 389 | 389 |
| 390 // Schedules the specified command. This method takes ownership of the | 390 // Schedules the specified command. This method takes ownership of the |
| 391 // command. | 391 // command. |
| 392 virtual void ScheduleCommand(SessionCommand* command) override; | 392 void ScheduleCommand(SessionCommand* command) override; |
| 393 | 393 |
| 394 // Converts all pending tab/window closes to commands and schedules them. | 394 // Converts all pending tab/window closes to commands and schedules them. |
| 395 void CommitPendingCloses(); | 395 void CommitPendingCloses(); |
| 396 | 396 |
| 397 // Returns true if there is only one window open with a single tab that shares | 397 // Returns true if there is only one window open with a single tab that shares |
| 398 // our profile. | 398 // our profile. |
| 399 bool IsOnlyOneTabLeft() const; | 399 bool IsOnlyOneTabLeft() const; |
| 400 | 400 |
| 401 // Returns true if there are open trackable browser windows whose ids do | 401 // Returns true if there are open trackable browser windows whose ids do |
| 402 // match |window_id| with our profile. A trackable window is a window from | 402 // match |window_id| with our profile. A trackable window is a window from |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 // 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 |
| 494 // without quitting. | 494 // without quitting. |
| 495 bool force_browser_not_alive_with_no_windows_; | 495 bool force_browser_not_alive_with_no_windows_; |
| 496 | 496 |
| 497 base::WeakPtrFactory<SessionService> weak_factory_; | 497 base::WeakPtrFactory<SessionService> weak_factory_; |
| 498 | 498 |
| 499 DISALLOW_COPY_AND_ASSIGN(SessionService); | 499 DISALLOW_COPY_AND_ASSIGN(SessionService); |
| 500 }; | 500 }; |
| 501 | 501 |
| 502 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_ | 502 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_ |
| OLD | NEW |