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/file_path.h" | 10 #include "base/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/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
15 #include "chrome/browser/common/cancelable_request.h" | 16 #include "chrome/browser/common/cancelable_request.h" |
16 #include "chrome/browser/sessions/session_id.h" | 17 #include "chrome/browser/sessions/session_id.h" |
| 18 #include "chrome/common/cancelable_task_tracker.h" |
17 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
18 | 20 |
19 class Profile; | 21 class Profile; |
20 class SessionBackend; | 22 class SessionBackend; |
21 class SessionCommand; | 23 class SessionCommand; |
22 class TabNavigation; | 24 class TabNavigation; |
23 | 25 |
24 // BaseSessionService is the super class of both tab restore service and | 26 // BaseSessionService is the super class of both tab restore service and |
25 // session service. It contains commonality needed by both, in particular | 27 // session service. It contains commonality needed by both, in particular |
26 // it manages a set of SessionCommands that are periodically sent to a | 28 // it manages a set of SessionCommands that are periodically sent to a |
(...skipping 14 matching lines...) Expand all Loading... |
41 // ignored and instead the path comes from the profile. | 43 // ignored and instead the path comes from the profile. |
42 BaseSessionService(SessionType type, | 44 BaseSessionService(SessionType type, |
43 Profile* profile, | 45 Profile* profile, |
44 const FilePath& path); | 46 const FilePath& path); |
45 | 47 |
46 Profile* profile() const { return profile_; } | 48 Profile* profile() const { return profile_; } |
47 | 49 |
48 // Deletes the last session. | 50 // Deletes the last session. |
49 void DeleteLastSession(); | 51 void DeleteLastSession(); |
50 | 52 |
51 class InternalGetCommandsRequest; | 53 typedef base::Callback<void(ScopedVector<SessionCommand>)> |
52 | |
53 typedef base::Callback<void(Handle, | |
54 scoped_refptr<InternalGetCommandsRequest>)> | |
55 InternalGetCommandsCallback; | 54 InternalGetCommandsCallback; |
56 | 55 |
57 // Callback used when fetching the last session. The last session consists | |
58 // of a vector of SessionCommands. | |
59 class InternalGetCommandsRequest : | |
60 public CancelableRequest<InternalGetCommandsCallback> { | |
61 public: | |
62 explicit InternalGetCommandsRequest(const CallbackType& callback); | |
63 | |
64 // The commands. The backend fills this in for us. | |
65 std::vector<SessionCommand*> commands; | |
66 | |
67 protected: | |
68 virtual ~InternalGetCommandsRequest(); | |
69 | |
70 private: | |
71 DISALLOW_COPY_AND_ASSIGN(InternalGetCommandsRequest); | |
72 }; | |
73 | |
74 protected: | 56 protected: |
75 virtual ~BaseSessionService(); | 57 virtual ~BaseSessionService(); |
76 | 58 |
77 // Returns the backend. | 59 // Returns the backend. |
78 SessionBackend* backend() const { return backend_; } | 60 SessionBackend* backend() const { return backend_; } |
79 | 61 |
80 // Returns the set of commands that needed to be scheduled. The commands | 62 // Returns the set of commands that needed to be scheduled. The commands |
81 // in the vector are owned by BaseSessionService, until they are scheduled | 63 // in the vector are owned by BaseSessionService, until they are scheduled |
82 // on the backend at which point the backend owns the commands. | 64 // on the backend at which point the backend owns the commands. |
83 std::vector<SessionCommand*>& pending_commands() { | 65 std::vector<SessionCommand*>& pending_commands() { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 // Extracts a SessionCommand as previously created by | 135 // Extracts a SessionCommand as previously created by |
154 // CreateSetWindowAppNameCommand into the window id and application name. | 136 // CreateSetWindowAppNameCommand into the window id and application name. |
155 bool RestoreSetWindowAppNameCommand( | 137 bool RestoreSetWindowAppNameCommand( |
156 const SessionCommand& command, | 138 const SessionCommand& command, |
157 SessionID::id_type* window_id, | 139 SessionID::id_type* window_id, |
158 std::string* app_name); | 140 std::string* app_name); |
159 | 141 |
160 // Returns true if the entry at specified |url| should be written to disk. | 142 // Returns true if the entry at specified |url| should be written to disk. |
161 bool ShouldTrackEntry(const GURL& url); | 143 bool ShouldTrackEntry(const GURL& url); |
162 | 144 |
163 // Invokes ReadLastSessionCommands with request on the backend thread. | 145 // Invokes SessionBackend::ReadLastSessionCommands with callback on the |
164 // If testing, ReadLastSessionCommands is invoked directly. | 146 // backend thread. |
165 Handle ScheduleGetLastSessionCommands( | 147 // If testing, SessionBackend::ReadLastSessionCommands is invoked directly. |
166 InternalGetCommandsRequest* request, | 148 CancelableTaskTracker::TaskId ScheduleGetLastSessionCommands( |
167 CancelableRequestConsumerBase* consumer); | 149 const InternalGetCommandsCallback& callback, |
| 150 CancelableTaskTracker* tracker); |
168 | 151 |
169 // In production, this posts the task to the FILE thread. For | 152 // In production, this posts the task to the FILE thread. For |
170 // tests, it immediately runs the specified task on the current | 153 // tests, it immediately runs the specified task on the current |
171 // thread. | 154 // thread. |
172 bool RunTaskOnBackendThread(const tracked_objects::Location& from_here, | 155 bool RunTaskOnBackendThread(const tracked_objects::Location& from_here, |
173 const base::Closure& task); | 156 const base::Closure& task); |
174 | 157 |
175 // Returns true if we appear to be running in production, false if we appear | 158 // Returns true if we appear to be running in production, false if we appear |
176 // to be running as part of a unit test or if the FILE thread has gone away. | 159 // to be running as part of a unit test or if the FILE thread has gone away. |
177 bool RunningInProduction() const; | 160 bool RunningInProduction() const; |
(...skipping 18 matching lines...) Expand all Loading... |
196 // over the commands. | 179 // over the commands. |
197 bool pending_reset_; | 180 bool pending_reset_; |
198 | 181 |
199 // The number of commands sent to the backend before doing a reset. | 182 // The number of commands sent to the backend before doing a reset. |
200 int commands_since_reset_; | 183 int commands_since_reset_; |
201 | 184 |
202 DISALLOW_COPY_AND_ASSIGN(BaseSessionService); | 185 DISALLOW_COPY_AND_ASSIGN(BaseSessionService); |
203 }; | 186 }; |
204 | 187 |
205 #endif // CHROME_BROWSER_SESSIONS_BASE_SESSION_SERVICE_H_ | 188 #endif // CHROME_BROWSER_SESSIONS_BASE_SESSION_SERVICE_H_ |
OLD | NEW |