| 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 // This posts the task to the SequencedWorkerPool, or run immediately |
| 158 // tests, it immediately runs the specified task on the current | 159 // if the SequencedWorkerPool has been shutdown. |
| 159 // thread. | |
| 160 bool RunTaskOnBackendThread(const tracked_objects::Location& from_here, | 160 bool RunTaskOnBackendThread(const tracked_objects::Location& from_here, |
| 161 const base::Closure& task); | 161 const base::Closure& task); |
| 162 | 162 |
| 163 // 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 bool RunningInProduction() const; | |
| 166 | |
| 167 // Max number of navigation entries in each direction we'll persist. | 163 // Max number of navigation entries in each direction we'll persist. |
| 168 static const int max_persist_navigation_count; | 164 static const int max_persist_navigation_count; |
| 169 | 165 |
| 170 private: | 166 private: |
| 171 friend class BetterSessionRestoreCrashTest; | 167 friend class BetterSessionRestoreCrashTest; |
| 172 | 168 |
| 173 // The profile. This may be null during testing. | 169 // The profile. This may be null during testing. |
| 174 Profile* profile_; | 170 Profile* profile_; |
| 175 | 171 |
| 176 // The backend. | 172 // The backend. |
| 177 scoped_refptr<SessionBackend> backend_; | 173 scoped_refptr<SessionBackend> backend_; |
| 178 | 174 |
| 179 // Used to invoke Save. | 175 // Used to invoke Save. |
| 180 base::WeakPtrFactory<BaseSessionService> weak_factory_; | 176 base::WeakPtrFactory<BaseSessionService> weak_factory_; |
| 181 | 177 |
| 182 // Commands we need to send over to the backend. | 178 // Commands we need to send over to the backend. |
| 183 std::vector<SessionCommand*> pending_commands_; | 179 std::vector<SessionCommand*> pending_commands_; |
| 184 | 180 |
| 185 // Whether the backend file should be recreated the next time we send | 181 // Whether the backend file should be recreated the next time we send |
| 186 // over the commands. | 182 // over the commands. |
| 187 bool pending_reset_; | 183 bool pending_reset_; |
| 188 | 184 |
| 189 // The number of commands sent to the backend before doing a reset. | 185 // The number of commands sent to the backend before doing a reset. |
| 190 int commands_since_reset_; | 186 int commands_since_reset_; |
| 191 | 187 |
| 188 // A token to make sure that all tasks will be serialized. |
| 189 base::SequencedWorkerPool::SequenceToken sequence_token_; |
| 190 |
| 192 DISALLOW_COPY_AND_ASSIGN(BaseSessionService); | 191 DISALLOW_COPY_AND_ASSIGN(BaseSessionService); |
| 193 }; | 192 }; |
| 194 | 193 |
| 195 #endif // CHROME_BROWSER_SESSIONS_BASE_SESSION_SERVICE_H_ | 194 #endif // CHROME_BROWSER_SESSIONS_BASE_SESSION_SERVICE_H_ |
| OLD | NEW |