| 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_BASE_SESSION_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SESSIONS_BASE_SESSION_SERVICE_H_ |
| 6 #define CHROME_BROWSER_SESSIONS_BASE_SESSION_SERVICE_H_ | 6 #define CHROME_BROWSER_SESSIONS_BASE_SESSION_SERVICE_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "chrome/browser/common/cancelable_request.h" | 16 #include "chrome/browser/common/cancelable_request.h" |
| 17 #include "chrome/browser/sessions/session_id.h" | 17 #include "chrome/browser/sessions/session_id.h" |
| 18 #include "chrome/common/cancelable_task_tracker.h" | 18 #include "chrome/common/cancelable_task_tracker.h" |
| 19 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
| 20 | 20 |
| 21 class Profile; | 21 class Profile; |
| 22 class SessionBackend; | 22 class SessionBackend; |
| 23 class SessionCommand; | 23 class SessionCommand; |
| 24 class TabNavigation; | 24 |
| 25 namespace components { |
| 26 class SerializedNavigationEntry; |
| 27 } |
| 25 | 28 |
| 26 // BaseSessionService is the super class of both tab restore service and | 29 // BaseSessionService is the super class of both tab restore service and |
| 27 // session service. It contains commonality needed by both, in particular | 30 // session service. It contains commonality needed by both, in particular |
| 28 // it manages a set of SessionCommands that are periodically sent to a | 31 // it manages a set of SessionCommands that are periodically sent to a |
| 29 // SessionBackend. | 32 // SessionBackend. |
| 30 class BaseSessionService : public CancelableRequestProvider { | 33 class BaseSessionService : public CancelableRequestProvider { |
| 31 public: | 34 public: |
| 32 // Identifies the type of session service this is. This is used by the | 35 // Identifies the type of session service this is. This is used by the |
| 33 // backend to determine the name of the files. | 36 // backend to determine the name of the files. |
| 34 enum SessionType { | 37 enum SessionType { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 void StartSaveTimer(); | 85 void StartSaveTimer(); |
| 83 | 86 |
| 84 // Saves pending commands to the backend. This is invoked from the timer | 87 // Saves pending commands to the backend. This is invoked from the timer |
| 85 // scheduled by StartSaveTimer. | 88 // scheduled by StartSaveTimer. |
| 86 virtual void Save(); | 89 virtual void Save(); |
| 87 | 90 |
| 88 // Creates a SessionCommand that represents a navigation. | 91 // Creates a SessionCommand that represents a navigation. |
| 89 SessionCommand* CreateUpdateTabNavigationCommand( | 92 SessionCommand* CreateUpdateTabNavigationCommand( |
| 90 SessionID::id_type command_id, | 93 SessionID::id_type command_id, |
| 91 SessionID::id_type tab_id, | 94 SessionID::id_type tab_id, |
| 92 const TabNavigation& navigation); | 95 const components::SerializedNavigationEntry& navigation); |
| 93 | 96 |
| 94 // Creates a SessionCommand that represents marking a tab as an application. | 97 // Creates a SessionCommand that represents marking a tab as an application. |
| 95 SessionCommand* CreateSetTabExtensionAppIDCommand( | 98 SessionCommand* CreateSetTabExtensionAppIDCommand( |
| 96 SessionID::id_type command_id, | 99 SessionID::id_type command_id, |
| 97 SessionID::id_type tab_id, | 100 SessionID::id_type tab_id, |
| 98 const std::string& extension_id); | 101 const std::string& extension_id); |
| 99 | 102 |
| 100 // Creates a SessionCommand that containing user agent override used by a | 103 // Creates a SessionCommand that containing user agent override used by a |
| 101 // tab's navigations. | 104 // tab's navigations. |
| 102 SessionCommand* CreateSetTabUserAgentOverrideCommand( | 105 SessionCommand* CreateSetTabUserAgentOverrideCommand( |
| 103 SessionID::id_type command_id, | 106 SessionID::id_type command_id, |
| 104 SessionID::id_type tab_id, | 107 SessionID::id_type tab_id, |
| 105 const std::string& user_agent_override); | 108 const std::string& user_agent_override); |
| 106 | 109 |
| 107 // Creates a SessionCommand stores a browser window's app name. | 110 // Creates a SessionCommand stores a browser window's app name. |
| 108 SessionCommand* CreateSetWindowAppNameCommand( | 111 SessionCommand* CreateSetWindowAppNameCommand( |
| 109 SessionID::id_type command_id, | 112 SessionID::id_type command_id, |
| 110 SessionID::id_type window_id, | 113 SessionID::id_type window_id, |
| 111 const std::string& app_name); | 114 const std::string& app_name); |
| 112 | 115 |
| 113 // Converts a SessionCommand previously created by | 116 // Converts a SessionCommand previously created by |
| 114 // CreateUpdateTabNavigationCommand into a TabNavigation. Returns true | 117 // CreateUpdateTabNavigationCommand into a |
| 115 // on success. If successful |tab_id| is set to the id of the restored tab. | 118 // components::SerializedNavigationEntry. Returns true on success. If |
| 116 bool RestoreUpdateTabNavigationCommand(const SessionCommand& command, | 119 // successful |tab_id| is set to the id of the restored tab. |
| 117 TabNavigation* navigation, | 120 bool RestoreUpdateTabNavigationCommand( |
| 118 SessionID::id_type* tab_id); | 121 const SessionCommand& command, |
| 122 components::SerializedNavigationEntry* navigation, |
| 123 SessionID::id_type* tab_id); |
| 119 | 124 |
| 120 // Extracts a SessionCommand as previously created by | 125 // Extracts a SessionCommand as previously created by |
| 121 // CreateSetTabExtensionAppIDCommand into the tab id and application | 126 // CreateSetTabExtensionAppIDCommand into the tab id and application |
| 122 // extension id. | 127 // extension id. |
| 123 bool RestoreSetTabExtensionAppIDCommand( | 128 bool RestoreSetTabExtensionAppIDCommand( |
| 124 const SessionCommand& command, | 129 const SessionCommand& command, |
| 125 SessionID::id_type* tab_id, | 130 SessionID::id_type* tab_id, |
| 126 std::string* extension_app_id); | 131 std::string* extension_app_id); |
| 127 | 132 |
| 128 // Extracts a SessionCommand as previously created by | 133 // Extracts a SessionCommand as previously created by |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 // over the commands. | 186 // over the commands. |
| 182 bool pending_reset_; | 187 bool pending_reset_; |
| 183 | 188 |
| 184 // The number of commands sent to the backend before doing a reset. | 189 // The number of commands sent to the backend before doing a reset. |
| 185 int commands_since_reset_; | 190 int commands_since_reset_; |
| 186 | 191 |
| 187 DISALLOW_COPY_AND_ASSIGN(BaseSessionService); | 192 DISALLOW_COPY_AND_ASSIGN(BaseSessionService); |
| 188 }; | 193 }; |
| 189 | 194 |
| 190 #endif // CHROME_BROWSER_SESSIONS_BASE_SESSION_SERVICE_H_ | 195 #endif // CHROME_BROWSER_SESSIONS_BASE_SESSION_SERVICE_H_ |
| OLD | NEW |