| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 COMPONENTS_SESSIONS_CORE_BASE_SESSION_SERVICE_H_ | 5 #ifndef COMPONENTS_SESSIONS_CORE_BASE_SESSION_SERVICE_H_ |
| 6 #define COMPONENTS_SESSIONS_CORE_BASE_SESSION_SERVICE_H_ | 6 #define COMPONENTS_SESSIONS_CORE_BASE_SESSION_SERVICE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/scoped_vector.h" | |
| 14 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 15 #include "base/task/cancelable_task_tracker.h" | 14 #include "base/task/cancelable_task_tracker.h" |
| 16 #include "components/sessions/core/sessions_export.h" | 15 #include "components/sessions/core/sessions_export.h" |
| 17 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 18 | 17 |
| 19 | 18 |
| 20 namespace sessions { | 19 namespace sessions { |
| 21 class BaseSessionServiceDelegate; | 20 class BaseSessionServiceDelegate; |
| 22 class SessionCommand; | 21 class SessionCommand; |
| 23 class SessionBackend; | 22 class SessionBackend; |
| 24 | 23 |
| 25 // BaseSessionService is the super class of both tab restore service and | 24 // BaseSessionService is the super class of both tab restore service and |
| 26 // session service. It contains commonality needed by both, in particular | 25 // session service. It contains commonality needed by both, in particular |
| 27 // it manages a set of SessionCommands that are periodically sent to a | 26 // it manages a set of SessionCommands that are periodically sent to a |
| 28 // SessionBackend. | 27 // SessionBackend. |
| 29 class SESSIONS_EXPORT BaseSessionService { | 28 class SESSIONS_EXPORT BaseSessionService { |
| 30 public: | 29 public: |
| 31 // Identifies the type of session service this is. This is used by the | 30 // Identifies the type of session service this is. This is used by the |
| 32 // backend to determine the name of the files. | 31 // backend to determine the name of the files. |
| 33 enum SessionType { | 32 enum SessionType { |
| 34 SESSION_RESTORE, | 33 SESSION_RESTORE, |
| 35 TAB_RESTORE | 34 TAB_RESTORE |
| 36 }; | 35 }; |
| 37 | 36 |
| 38 typedef base::Callback<void(ScopedVector<SessionCommand>)> | 37 typedef base::Callback<void(std::vector<std::unique_ptr<SessionCommand>>)> |
| 39 GetCommandsCallback; | 38 GetCommandsCallback; |
| 40 | 39 |
| 41 // Creates a new BaseSessionService. After creation you need to invoke | 40 // Creates a new BaseSessionService. After creation you need to invoke |
| 42 // Init. |delegate| will remain owned by the creator and it is guaranteed | 41 // Init. |delegate| will remain owned by the creator and it is guaranteed |
| 43 // that its lifetime surpasses this class. | 42 // that its lifetime surpasses this class. |
| 44 // |type| gives the type of session service, |path| the path to save files to. | 43 // |type| gives the type of session service, |path| the path to save files to. |
| 45 BaseSessionService(SessionType type, | 44 BaseSessionService(SessionType type, |
| 46 const base::FilePath& path, | 45 const base::FilePath& path, |
| 47 BaseSessionServiceDelegate* delegate); | 46 BaseSessionServiceDelegate* delegate); |
| 48 ~BaseSessionService(); | 47 ~BaseSessionService(); |
| 49 | 48 |
| 50 // Moves the current session to the last session. | 49 // Moves the current session to the last session. |
| 51 void MoveCurrentSessionToLastSession(); | 50 void MoveCurrentSessionToLastSession(); |
| 52 | 51 |
| 53 // Deletes the last session. | 52 // Deletes the last session. |
| 54 void DeleteLastSession(); | 53 void DeleteLastSession(); |
| 55 | 54 |
| 56 // Returns the set of commands which were scheduled to be written. Once | 55 // Returns the set of commands which were scheduled to be written. Once |
| 57 // committed to the backend, the commands are removed from here. | 56 // committed to the backend, the commands are removed from here. |
| 58 const ScopedVector<SessionCommand>& pending_commands() { | 57 const std::vector<std::unique_ptr<SessionCommand>>& pending_commands() { |
| 59 return pending_commands_; | 58 return pending_commands_; |
| 60 } | 59 } |
| 61 | 60 |
| 62 // Whether the next save resets the file before writing to it. | 61 // Whether the next save resets the file before writing to it. |
| 63 void set_pending_reset(bool value) { pending_reset_ = value; } | 62 void set_pending_reset(bool value) { pending_reset_ = value; } |
| 64 bool pending_reset() const { return pending_reset_; } | 63 bool pending_reset() const { return pending_reset_; } |
| 65 | 64 |
| 66 // Returns the number of commands sent down since the last reset. | 65 // Returns the number of commands sent down since the last reset. |
| 67 int commands_since_reset() const { return commands_since_reset_; } | 66 int commands_since_reset() const { return commands_since_reset_; } |
| 68 | 67 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 | 104 |
| 106 // This posts the task to the SequencedWorkerPool, or run immediately | 105 // This posts the task to the SequencedWorkerPool, or run immediately |
| 107 // if the SequencedWorkerPool has been shutdown. | 106 // if the SequencedWorkerPool has been shutdown. |
| 108 void RunTaskOnBackendThread(const tracked_objects::Location& from_here, | 107 void RunTaskOnBackendThread(const tracked_objects::Location& from_here, |
| 109 const base::Closure& task); | 108 const base::Closure& task); |
| 110 | 109 |
| 111 // The backend object which reads and saves commands. | 110 // The backend object which reads and saves commands. |
| 112 scoped_refptr<SessionBackend> backend_; | 111 scoped_refptr<SessionBackend> backend_; |
| 113 | 112 |
| 114 // Commands we need to send over to the backend. | 113 // Commands we need to send over to the backend. |
| 115 ScopedVector<SessionCommand> pending_commands_; | 114 std::vector<std::unique_ptr<SessionCommand>> pending_commands_; |
| 116 | 115 |
| 117 // Whether the backend file should be recreated the next time we send | 116 // Whether the backend file should be recreated the next time we send |
| 118 // over the commands. | 117 // over the commands. |
| 119 bool pending_reset_; | 118 bool pending_reset_; |
| 120 | 119 |
| 121 // The number of commands sent to the backend before doing a reset. | 120 // The number of commands sent to the backend before doing a reset. |
| 122 int commands_since_reset_; | 121 int commands_since_reset_; |
| 123 | 122 |
| 124 BaseSessionServiceDelegate* delegate_; | 123 BaseSessionServiceDelegate* delegate_; |
| 125 | 124 |
| 126 // A token to make sure that all tasks will be serialized. | 125 // A token to make sure that all tasks will be serialized. |
| 127 base::SequencedWorkerPool::SequenceToken sequence_token_; | 126 base::SequencedWorkerPool::SequenceToken sequence_token_; |
| 128 | 127 |
| 129 // Used to invoke Save. | 128 // Used to invoke Save. |
| 130 base::WeakPtrFactory<BaseSessionService> weak_factory_; | 129 base::WeakPtrFactory<BaseSessionService> weak_factory_; |
| 131 | 130 |
| 132 DISALLOW_COPY_AND_ASSIGN(BaseSessionService); | 131 DISALLOW_COPY_AND_ASSIGN(BaseSessionService); |
| 133 }; | 132 }; |
| 134 | 133 |
| 135 } // namespace sessions | 134 } // namespace sessions |
| 136 | 135 |
| 137 #endif // COMPONENTS_SESSIONS_CORE_BASE_SESSION_SERVICE_H_ | 136 #endif // COMPONENTS_SESSIONS_CORE_BASE_SESSION_SERVICE_H_ |
| OLD | NEW |