| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/ref_counted.h" | 10 #include "base/ref_counted.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 74 |
| 75 // Deletes the file containing the commands for the last session. | 75 // Deletes the file containing the commands for the last session. |
| 76 void DeleteLastSession(); | 76 void DeleteLastSession(); |
| 77 | 77 |
| 78 // Moves the current session to the last and resets the current. This is | 78 // Moves the current session to the last and resets the current. This is |
| 79 // called during startup and if the user launchs the app and no tabbed | 79 // called during startup and if the user launchs the app and no tabbed |
| 80 // browsers are running. | 80 // browsers are running. |
| 81 void MoveCurrentSessionToLastSession(); | 81 void MoveCurrentSessionToLastSession(); |
| 82 | 82 |
| 83 private: | 83 private: |
| 84 // Recreates the current file such that it only contains the header and | 84 // If current_session_file_ is open, it is truncated so that it is essentially |
| 85 // NO commands. | 85 // empty (only contains the header). If current_session_file_ isn't open, it |
| 86 // is is opened and the header is written to it. After this |
| 87 // current_session_file_ contains no commands. |
| 88 // NOTE: current_session_file_ may be NULL if the file couldn't be opened or |
| 89 // the header couldn't be written. |
| 86 void ResetFile(); | 90 void ResetFile(); |
| 87 | 91 |
| 88 // Opens the current file and writes the header. On success a handle to | 92 // Opens the current file and writes the header. On success a handle to |
| 89 // the file is returned. | 93 // the file is returned. |
| 90 net::FileStream* OpenAndWriteHeader(const FilePath& path); | 94 net::FileStream* OpenAndWriteHeader(const FilePath& path); |
| 91 | 95 |
| 92 // Appends the specified commands to the specified file. | 96 // Appends the specified commands to the specified file. |
| 93 bool AppendCommandsToFile(net::FileStream* file, | 97 bool AppendCommandsToFile(net::FileStream* file, |
| 94 const std::vector<SessionCommand*>& commands); | 98 const std::vector<SessionCommand*>& commands); |
| 95 | 99 |
| 100 // Returns the size of the header. The header is the first bytes written to |
| 101 // the file, and is used to identify the file as one written by us. |
| 102 int32 sizeof_header() const { |
| 103 int32 header[2]; |
| 104 return sizeof(header); |
| 105 } |
| 106 |
| 96 const BaseSessionService::SessionType type_; | 107 const BaseSessionService::SessionType type_; |
| 97 | 108 |
| 98 // Returns the path to the last file. | 109 // Returns the path to the last file. |
| 99 FilePath GetLastSessionPath(); | 110 FilePath GetLastSessionPath(); |
| 100 | 111 |
| 101 // Returns the path to the current file. | 112 // Returns the path to the current file. |
| 102 FilePath GetCurrentSessionPath(); | 113 FilePath GetCurrentSessionPath(); |
| 103 | 114 |
| 104 // Directory files are relative to. | 115 // Directory files are relative to. |
| 105 const FilePath path_to_dir_; | 116 const FilePath path_to_dir_; |
| 106 | 117 |
| 107 // Whether the previous target file is valid. | 118 // Whether the previous target file is valid. |
| 108 bool last_session_valid_; | 119 bool last_session_valid_; |
| 109 | 120 |
| 110 // Handle to the target file. | 121 // Handle to the target file. |
| 111 scoped_ptr<net::FileStream> current_session_file_; | 122 scoped_ptr<net::FileStream> current_session_file_; |
| 112 | 123 |
| 113 // Whether we've inited. Remember, the constructor is run on the | 124 // Whether we've inited. Remember, the constructor is run on the |
| 114 // Main thread, all others on the IO thread, hence lazy initialization. | 125 // Main thread, all others on the IO thread, hence lazy initialization. |
| 115 bool inited_; | 126 bool inited_; |
| 116 | 127 |
| 117 // If true, the file is empty (no commands have been added to it). | 128 // If true, the file is empty (no commands have been added to it). |
| 118 bool empty_file_; | 129 bool empty_file_; |
| 119 | 130 |
| 120 DISALLOW_COPY_AND_ASSIGN(SessionBackend); | 131 DISALLOW_COPY_AND_ASSIGN(SessionBackend); |
| 121 }; | 132 }; |
| 122 | 133 |
| 123 #endif // #define CHROME_BROWSER_SESSIONS_SESSION_BACKEND_H_ | 134 #endif // #define CHROME_BROWSER_SESSIONS_SESSION_BACKEND_H_ |
| OLD | NEW |