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" |
(...skipping 17 matching lines...) Expand all Loading... |
28 // SessionBackend. | 28 // SessionBackend. |
29 class BaseSessionService { | 29 class BaseSessionService { |
30 public: | 30 public: |
31 // Identifies the type of session service this is. This is used by the | 31 // Identifies the type of session service this is. This is used by the |
32 // backend to determine the name of the files. | 32 // backend to determine the name of the files. |
33 enum SessionType { | 33 enum SessionType { |
34 SESSION_RESTORE, | 34 SESSION_RESTORE, |
35 TAB_RESTORE | 35 TAB_RESTORE |
36 }; | 36 }; |
37 | 37 |
| 38 typedef base::Callback<void(ScopedVector<SessionCommand>)> |
| 39 GetCommandsCallback; |
| 40 |
38 // Creates a new BaseSessionService. After creation you need to invoke | 41 // Creates a new BaseSessionService. After creation you need to invoke |
39 // Init. | 42 // Init. |
40 // |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. |
41 BaseSessionService(SessionType type, | 44 BaseSessionService(SessionType type, |
42 const base::FilePath& path, | 45 const base::FilePath& path, |
43 scoped_ptr<BaseSessionServiceDelegate> delegate); | 46 scoped_ptr<BaseSessionServiceDelegate> delegate); |
44 | 47 |
45 // Deletes the last session. | 48 // Deletes the last session. |
46 void DeleteLastSession(); | 49 void DeleteLastSession(); |
47 | 50 |
48 typedef base::Callback<void(ScopedVector<SessionCommand>)> | 51 typedef base::Callback<void(ScopedVector<SessionCommand>)> |
49 InternalGetCommandsCallback; | 52 InternalGetCommandsCallback; |
50 | 53 |
51 protected: | 54 protected: |
52 virtual ~BaseSessionService(); | 55 virtual ~BaseSessionService(); |
53 | 56 |
54 // Returns the backend. | 57 // Returns the backend. |
55 SessionBackend* backend() const { return backend_.get(); } | 58 SessionBackend* backend() const { return backend_.get(); } |
56 | 59 |
57 // Returns the set of commands that needed to be scheduled. The commands | 60 // Returns the set of commands which were scheduled to be written. Once |
58 // in the vector are owned by BaseSessionService, until they are scheduled | 61 // committed to the backend, the commands are removed from here. |
59 // on the backend at which point the backend owns the commands. | 62 ScopedVector<SessionCommand>& pending_commands() { |
60 std::vector<SessionCommand*>& pending_commands() { | |
61 return pending_commands_; | 63 return pending_commands_; |
62 } | 64 } |
63 | 65 |
64 // Whether the next save resets the file before writing to it. | 66 // Whether the next save resets the file before writing to it. |
65 void set_pending_reset(bool value) { pending_reset_ = value; } | 67 void set_pending_reset(bool value) { pending_reset_ = value; } |
66 bool pending_reset() const { return pending_reset_; } | 68 bool pending_reset() const { return pending_reset_; } |
67 | 69 |
68 // Returns the number of commands sent down since the last reset. | 70 // Returns the number of commands sent down since the last reset. |
69 int commands_since_reset() const { return commands_since_reset_; } | 71 int commands_since_reset() const { return commands_since_reset_; } |
70 | 72 |
71 // Schedules a command. This adds |command| to pending_commands_ and | 73 // Schedules a command. This adds |command| to pending_commands_ and |
72 // invokes StartSaveTimer to start a timer that invokes Save at a later | 74 // invokes StartSaveTimer to start a timer that invokes Save at a later |
73 // time. | 75 // time. |
74 virtual void ScheduleCommand(SessionCommand* command); | 76 virtual void ScheduleCommand(scoped_ptr<SessionCommand> command); |
75 | 77 |
76 // Starts the timer that invokes Save (if timer isn't already running). | 78 // Starts the timer that invokes Save (if timer isn't already running). |
77 void StartSaveTimer(); | 79 void StartSaveTimer(); |
78 | 80 |
79 // Saves pending commands to the backend. This is invoked from the timer | 81 // Saves pending commands to the backend. This is invoked from the timer |
80 // scheduled by StartSaveTimer. | 82 // scheduled by StartSaveTimer. |
81 virtual void Save(); | 83 virtual void Save(); |
82 | 84 |
83 // Returns true if the entry at specified |url| should be written to disk. | 85 // Returns true if the entry at specified |url| should be written to disk. |
84 bool ShouldTrackEntry(const GURL& url); | 86 bool ShouldTrackEntry(const GURL& url); |
(...skipping 13 matching lines...) Expand all Loading... |
98 // Max number of navigation entries in each direction we'll persist. | 100 // Max number of navigation entries in each direction we'll persist. |
99 static const int max_persist_navigation_count; | 101 static const int max_persist_navigation_count; |
100 | 102 |
101 private: | 103 private: |
102 friend class BetterSessionRestoreCrashTest; | 104 friend class BetterSessionRestoreCrashTest; |
103 | 105 |
104 // The backend. | 106 // The backend. |
105 scoped_refptr<SessionBackend> backend_; | 107 scoped_refptr<SessionBackend> backend_; |
106 | 108 |
107 // Commands we need to send over to the backend. | 109 // Commands we need to send over to the backend. |
108 std::vector<SessionCommand*> pending_commands_; | 110 ScopedVector<SessionCommand> pending_commands_; |
109 | 111 |
110 // Whether the backend file should be recreated the next time we send | 112 // Whether the backend file should be recreated the next time we send |
111 // over the commands. | 113 // over the commands. |
112 bool pending_reset_; | 114 bool pending_reset_; |
113 | 115 |
114 // The number of commands sent to the backend before doing a reset. | 116 // The number of commands sent to the backend before doing a reset. |
115 int commands_since_reset_; | 117 int commands_since_reset_; |
116 | 118 |
117 scoped_ptr<BaseSessionServiceDelegate> delegate_; | 119 scoped_ptr<BaseSessionServiceDelegate> delegate_; |
118 | 120 |
119 // A token to make sure that all tasks will be serialized. | 121 // A token to make sure that all tasks will be serialized. |
120 base::SequencedWorkerPool::SequenceToken sequence_token_; | 122 base::SequencedWorkerPool::SequenceToken sequence_token_; |
121 | 123 |
122 // Used to invoke Save. | 124 // Used to invoke Save. |
123 base::WeakPtrFactory<BaseSessionService> weak_factory_; | 125 base::WeakPtrFactory<BaseSessionService> weak_factory_; |
124 | 126 |
125 DISALLOW_COPY_AND_ASSIGN(BaseSessionService); | 127 DISALLOW_COPY_AND_ASSIGN(BaseSessionService); |
126 }; | 128 }; |
127 | 129 |
128 #endif // CHROME_BROWSER_SESSIONS_BASE_SESSION_SERVICE_H_ | 130 #endif // CHROME_BROWSER_SESSIONS_BASE_SESSION_SERVICE_H_ |
OLD | NEW |