OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_SESSION_BACKEND_H_ | 5 #ifndef CHROME_BROWSER_SESSIONS_SESSION_BACKEND_H_ |
6 #define CHROME_BROWSER_SESSIONS_SESSION_BACKEND_H_ | 6 #define CHROME_BROWSER_SESSIONS_SESSION_BACKEND_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
13 #include "chrome/browser/sessions/base_session_service.h" | 13 #include "chrome/browser/sessions/base_session_service.h" |
14 #include "chrome/browser/sessions/session_command.h" | 14 #include "chrome/browser/sessions/session_command.h" |
15 | 15 #include "net/base/file_stream.h" |
16 namespace net { | |
17 class FileStream; | |
18 } | |
19 | 16 |
20 // SessionBackend ------------------------------------------------------------- | 17 // SessionBackend ------------------------------------------------------------- |
21 | 18 |
22 // SessionBackend is the backend used by BaseSessionService. It is responsible | 19 // SessionBackend is the backend used by BaseSessionService. It is responsible |
23 // for maintaining two files: | 20 // for maintaining two files: |
24 // . The current file, which is the file commands passed to AppendCommands | 21 // . The current file, which is the file commands passed to AppendCommands |
25 // get written to. | 22 // get written to. |
26 // . The last file. When created the current file is moved to the last | 23 // . The last file. When created the current file is moved to the last |
27 // file. | 24 // file. |
28 // | 25 // |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 86 |
90 // Reads the commands from the current file. | 87 // Reads the commands from the current file. |
91 // | 88 // |
92 // On success, the read commands are added to commands. It is up to the | 89 // On success, the read commands are added to commands. It is up to the |
93 // caller to delete the commands. | 90 // caller to delete the commands. |
94 bool ReadCurrentSessionCommandsImpl(std::vector<SessionCommand*>* commands); | 91 bool ReadCurrentSessionCommandsImpl(std::vector<SessionCommand*>* commands); |
95 | 92 |
96 private: | 93 private: |
97 friend class base::RefCountedThreadSafe<SessionBackend>; | 94 friend class base::RefCountedThreadSafe<SessionBackend>; |
98 | 95 |
99 ~SessionBackend(); | 96 ~SessionBackend() {} |
100 | 97 |
101 // If current_session_file_ is open, it is truncated so that it is essentially | 98 // If current_session_file_ is open, it is truncated so that it is essentially |
102 // empty (only contains the header). If current_session_file_ isn't open, it | 99 // empty (only contains the header). If current_session_file_ isn't open, it |
103 // is is opened and the header is written to it. After this | 100 // is is opened and the header is written to it. After this |
104 // current_session_file_ contains no commands. | 101 // current_session_file_ contains no commands. |
105 // NOTE: current_session_file_ may be NULL if the file couldn't be opened or | 102 // NOTE: current_session_file_ may be NULL if the file couldn't be opened or |
106 // the header couldn't be written. | 103 // the header couldn't be written. |
107 void ResetFile(); | 104 void ResetFile(); |
108 | 105 |
109 // Opens the current file and writes the header. On success a handle to | 106 // Opens the current file and writes the header. On success a handle to |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 // Main thread, all others on the IO thread, hence lazy initialization. | 139 // Main thread, all others on the IO thread, hence lazy initialization. |
143 bool inited_; | 140 bool inited_; |
144 | 141 |
145 // If true, the file is empty (no commands have been added to it). | 142 // If true, the file is empty (no commands have been added to it). |
146 bool empty_file_; | 143 bool empty_file_; |
147 | 144 |
148 DISALLOW_COPY_AND_ASSIGN(SessionBackend); | 145 DISALLOW_COPY_AND_ASSIGN(SessionBackend); |
149 }; | 146 }; |
150 | 147 |
151 #endif // CHROME_BROWSER_SESSIONS_SESSION_BACKEND_H_ | 148 #endif // CHROME_BROWSER_SESSIONS_SESSION_BACKEND_H_ |
OLD | NEW |