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" | |
13 #include "base/memory/ref_counted.h" | |
14 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
15 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
16 #include "base/task/cancelable_task_tracker.h" | 14 #include "base/task/cancelable_task_tracker.h" |
17 #include "base/threading/sequenced_worker_pool.h" | |
18 #include "components/sessions/session_id.h" | |
19 #include "url/gurl.h" | 15 #include "url/gurl.h" |
20 | 16 |
21 class BaseSessionServiceDelegate; | 17 class BaseSessionServiceDelegate; |
22 class SessionBackend; | 18 class SessionBackend; |
23 class SessionCommand; | 19 class SessionCommand; |
24 | 20 |
25 namespace sessions { | 21 namespace sessions { |
26 class SerializedNavigationEntry; | 22 class SerializedNavigationEntry; |
27 } | 23 } |
28 | 24 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 // time. | 73 // time. |
78 virtual void ScheduleCommand(SessionCommand* command); | 74 virtual void ScheduleCommand(SessionCommand* command); |
79 | 75 |
80 // Starts the timer that invokes Save (if timer isn't already running). | 76 // Starts the timer that invokes Save (if timer isn't already running). |
81 void StartSaveTimer(); | 77 void StartSaveTimer(); |
82 | 78 |
83 // Saves pending commands to the backend. This is invoked from the timer | 79 // Saves pending commands to the backend. This is invoked from the timer |
84 // scheduled by StartSaveTimer. | 80 // scheduled by StartSaveTimer. |
85 virtual void Save(); | 81 virtual void Save(); |
86 | 82 |
87 // Creates a SessionCommand that represents a navigation. | |
88 SessionCommand* CreateUpdateTabNavigationCommand( | |
89 SessionID::id_type command_id, | |
90 SessionID::id_type tab_id, | |
91 const sessions::SerializedNavigationEntry& navigation); | |
92 | |
93 // Creates a SessionCommand that represents marking a tab as an application. | |
94 SessionCommand* CreateSetTabExtensionAppIDCommand( | |
95 SessionID::id_type command_id, | |
96 SessionID::id_type tab_id, | |
97 const std::string& extension_id); | |
98 | |
99 // Creates a SessionCommand that containing user agent override used by a | |
100 // tab's navigations. | |
101 SessionCommand* CreateSetTabUserAgentOverrideCommand( | |
102 SessionID::id_type command_id, | |
103 SessionID::id_type tab_id, | |
104 const std::string& user_agent_override); | |
105 | |
106 // Creates a SessionCommand stores a browser window's app name. | |
107 SessionCommand* CreateSetWindowAppNameCommand( | |
108 SessionID::id_type command_id, | |
109 SessionID::id_type window_id, | |
110 const std::string& app_name); | |
111 | |
112 // Converts a SessionCommand previously created by | |
113 // CreateUpdateTabNavigationCommand into a | |
114 // sessions::SerializedNavigationEntry. Returns true on success. If | |
115 // successful |tab_id| is set to the id of the restored tab. | |
116 bool RestoreUpdateTabNavigationCommand( | |
117 const SessionCommand& command, | |
118 sessions::SerializedNavigationEntry* navigation, | |
119 SessionID::id_type* tab_id); | |
120 | |
121 // Extracts a SessionCommand as previously created by | |
122 // CreateSetTabExtensionAppIDCommand into the tab id and application | |
123 // extension id. | |
124 bool RestoreSetTabExtensionAppIDCommand( | |
125 const SessionCommand& command, | |
126 SessionID::id_type* tab_id, | |
127 std::string* extension_app_id); | |
128 | |
129 // Extracts a SessionCommand as previously created by | |
130 // CreateSetTabUserAgentOverrideCommand into the tab id and user agent. | |
131 bool RestoreSetTabUserAgentOverrideCommand( | |
132 const SessionCommand& command, | |
133 SessionID::id_type* tab_id, | |
134 std::string* user_agent_override); | |
135 | |
136 // Extracts a SessionCommand as previously created by | |
137 // CreateSetWindowAppNameCommand into the window id and application name. | |
138 bool RestoreSetWindowAppNameCommand( | |
139 const SessionCommand& command, | |
140 SessionID::id_type* window_id, | |
141 std::string* app_name); | |
142 | |
143 // Returns true if the entry at specified |url| should be written to disk. | 83 // Returns true if the entry at specified |url| should be written to disk. |
144 bool ShouldTrackEntry(const GURL& url); | 84 bool ShouldTrackEntry(const GURL& url); |
145 | 85 |
146 // Invokes SessionBackend::ReadLastSessionCommands with callback on the | 86 // Invokes SessionBackend::ReadLastSessionCommands with callback on the |
147 // backend thread. | 87 // backend thread. |
148 // If testing, SessionBackend::ReadLastSessionCommands is invoked directly. | 88 // If testing, SessionBackend::ReadLastSessionCommands is invoked directly. |
149 base::CancelableTaskTracker::TaskId ScheduleGetLastSessionCommands( | 89 base::CancelableTaskTracker::TaskId ScheduleGetLastSessionCommands( |
150 const InternalGetCommandsCallback& callback, | 90 const InternalGetCommandsCallback& callback, |
151 base::CancelableTaskTracker* tracker); | 91 base::CancelableTaskTracker* tracker); |
152 | 92 |
(...skipping 26 matching lines...) Expand all Loading... |
179 // A token to make sure that all tasks will be serialized. | 119 // A token to make sure that all tasks will be serialized. |
180 base::SequencedWorkerPool::SequenceToken sequence_token_; | 120 base::SequencedWorkerPool::SequenceToken sequence_token_; |
181 | 121 |
182 // Used to invoke Save. | 122 // Used to invoke Save. |
183 base::WeakPtrFactory<BaseSessionService> weak_factory_; | 123 base::WeakPtrFactory<BaseSessionService> weak_factory_; |
184 | 124 |
185 DISALLOW_COPY_AND_ASSIGN(BaseSessionService); | 125 DISALLOW_COPY_AND_ASSIGN(BaseSessionService); |
186 }; | 126 }; |
187 | 127 |
188 #endif // CHROME_BROWSER_SESSIONS_BASE_SESSION_SERVICE_H_ | 128 #endif // CHROME_BROWSER_SESSIONS_BASE_SESSION_SERVICE_H_ |
OLD | NEW |