| 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 "base/threading/sequenced_worker_pool.h" |
| 16 #include "chrome/browser/common/cancelable_request.h" | 17 #include "chrome/browser/common/cancelable_request.h" |
| 17 #include "chrome/browser/sessions/session_id.h" | 18 #include "chrome/browser/sessions/session_id.h" |
| 18 #include "chrome/common/cancelable_task_tracker.h" | 19 #include "chrome/common/cancelable_task_tracker.h" |
| 19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 20 | 21 |
| 21 class Profile; | 22 class Profile; |
| 22 class SessionBackend; | 23 class SessionBackend; |
| 23 class SessionCommand; | 24 class SessionCommand; |
| 24 | 25 |
| 25 namespace sessions { | 26 namespace sessions { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 // Returns true if the entry at specified |url| should be written to disk. | 148 // Returns true if the entry at specified |url| should be written to disk. |
| 148 bool ShouldTrackEntry(const GURL& url); | 149 bool ShouldTrackEntry(const GURL& url); |
| 149 | 150 |
| 150 // Invokes SessionBackend::ReadLastSessionCommands with callback on the | 151 // Invokes SessionBackend::ReadLastSessionCommands with callback on the |
| 151 // backend thread. | 152 // backend thread. |
| 152 // If testing, SessionBackend::ReadLastSessionCommands is invoked directly. | 153 // If testing, SessionBackend::ReadLastSessionCommands is invoked directly. |
| 153 CancelableTaskTracker::TaskId ScheduleGetLastSessionCommands( | 154 CancelableTaskTracker::TaskId ScheduleGetLastSessionCommands( |
| 154 const InternalGetCommandsCallback& callback, | 155 const InternalGetCommandsCallback& callback, |
| 155 CancelableTaskTracker* tracker); | 156 CancelableTaskTracker* tracker); |
| 156 | 157 |
| 157 // In production, this posts the task to the FILE thread. For | 158 // In production, this posts the task to the SequencedWorkerPool. For |
| 158 // tests, it immediately runs the specified task on the current | 159 // tests, it immediately runs the specified task on the current |
| 159 // thread. | 160 // thread. |
| 160 bool RunTaskOnBackendThread(const tracked_objects::Location& from_here, | 161 bool RunTaskOnBackendThread(const tracked_objects::Location& from_here, |
| 161 const base::Closure& task); | 162 const base::Closure& task); |
| 162 | 163 |
| 163 // Returns true if we appear to be running in production, false if we appear | 164 // Returns true if we appear to be running in production, false if we appear |
| 164 // to be running as part of a unit test or if the FILE thread has gone away. | 165 // to be running as part of a unit test or if the SequencedWorkerPool has |
| 166 // been asked to shutdown. |
| 165 bool RunningInProduction() const; | 167 bool RunningInProduction() const; |
| 166 | 168 |
| 167 // Max number of navigation entries in each direction we'll persist. | 169 // Max number of navigation entries in each direction we'll persist. |
| 168 static const int max_persist_navigation_count; | 170 static const int max_persist_navigation_count; |
| 169 | 171 |
| 170 private: | 172 private: |
| 171 friend class BetterSessionRestoreCrashTest; | 173 friend class BetterSessionRestoreCrashTest; |
| 172 | 174 |
| 173 // The profile. This may be null during testing. | 175 // The profile. This may be null during testing. |
| 174 Profile* profile_; | 176 Profile* profile_; |
| 175 | 177 |
| 176 // The backend. | 178 // The backend. |
| 177 scoped_refptr<SessionBackend> backend_; | 179 scoped_refptr<SessionBackend> backend_; |
| 178 | 180 |
| 179 // Used to invoke Save. | 181 // Used to invoke Save. |
| 180 base::WeakPtrFactory<BaseSessionService> weak_factory_; | 182 base::WeakPtrFactory<BaseSessionService> weak_factory_; |
| 181 | 183 |
| 182 // Commands we need to send over to the backend. | 184 // Commands we need to send over to the backend. |
| 183 std::vector<SessionCommand*> pending_commands_; | 185 std::vector<SessionCommand*> pending_commands_; |
| 184 | 186 |
| 185 // Whether the backend file should be recreated the next time we send | 187 // Whether the backend file should be recreated the next time we send |
| 186 // over the commands. | 188 // over the commands. |
| 187 bool pending_reset_; | 189 bool pending_reset_; |
| 188 | 190 |
| 189 // The number of commands sent to the backend before doing a reset. | 191 // The number of commands sent to the backend before doing a reset. |
| 190 int commands_since_reset_; | 192 int commands_since_reset_; |
| 191 | 193 |
| 194 // A token to make sure that all tasks will be serialized. |
| 195 base::SequencedWorkerPool::SequenceToken sequence_token_; |
| 196 |
| 192 DISALLOW_COPY_AND_ASSIGN(BaseSessionService); | 197 DISALLOW_COPY_AND_ASSIGN(BaseSessionService); |
| 193 }; | 198 }; |
| 194 | 199 |
| 195 #endif // CHROME_BROWSER_SESSIONS_BASE_SESSION_SERVICE_H_ | 200 #endif // CHROME_BROWSER_SESSIONS_BASE_SESSION_SERVICE_H_ |
| OLD | NEW |