| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 // NOTE: this is invoked before every command, and does nothing if we've | 54 // NOTE: this is invoked before every command, and does nothing if we've |
| 55 // already Init'ed. | 55 // already Init'ed. |
| 56 void Init(); | 56 void Init(); |
| 57 bool inited() const { return inited_; } | 57 bool inited() const { return inited_; } |
| 58 | 58 |
| 59 // Appends the specified commands to the current file. If reset_first is | 59 // Appends the specified commands to the current file. If reset_first is |
| 60 // true the the current file is recreated. | 60 // true the the current file is recreated. |
| 61 // | 61 // |
| 62 // NOTE: this deletes SessionCommands in commands as well as the supplied | 62 // NOTE: this deletes SessionCommands in commands as well as the supplied |
| 63 // vector. | 63 // vector. |
| 64 void AppendCommands(std::vector<SessionCommand*>* commands, | 64 void AppendCommands(ScopedVector<SessionCommand>* commands, bool reset_first); |
| 65 bool reset_first); | |
| 66 | 65 |
| 67 // Invoked from the service to read the commands that make up the last | 66 // Invoked from the service to read the commands that make up the last |
| 68 // session, invokes ReadLastSessionCommandsImpl to do the work. | 67 // session, invokes ReadLastSessionCommandsImpl to do the work. |
| 69 void ReadLastSessionCommands( | 68 void ReadLastSessionCommands( |
| 70 const base::CancelableTaskTracker::IsCanceledCallback& is_canceled, | 69 const base::CancelableTaskTracker::IsCanceledCallback& is_canceled, |
| 71 const BaseSessionService::InternalGetCommandsCallback& callback); | 70 const BaseSessionService::GetCommandsCallback& callback); |
| 72 | 71 |
| 73 // Reads the commands from the last file. | 72 // Reads the commands from the last file. |
| 74 // | 73 // |
| 75 // On success, the read commands are added to commands. It is up to the | 74 // On success, the read commands are added to commands. |
| 76 // caller to delete the commands. | 75 bool ReadLastSessionCommandsImpl(ScopedVector<SessionCommand>* commands); |
| 77 bool ReadLastSessionCommandsImpl(std::vector<SessionCommand*>* commands); | |
| 78 | 76 |
| 79 // Deletes the file containing the commands for the last session. | 77 // Deletes the file containing the commands for the last session. |
| 80 void DeleteLastSession(); | 78 void DeleteLastSession(); |
| 81 | 79 |
| 82 // Moves the current session to the last and resets the current. This is | 80 // Moves the current session to the last and resets the current. This is |
| 83 // called during startup and if the user launchs the app and no tabbed | 81 // called during startup and if the user launchs the app and no tabbed |
| 84 // browsers are running. | 82 // browsers are running. |
| 85 void MoveCurrentSessionToLastSession(); | 83 void MoveCurrentSessionToLastSession(); |
| 86 | 84 |
| 87 // Reads the commands from the current file. | 85 // Reads the commands from the current file. |
| 88 // | 86 // |
| 89 // On success, the read commands are added to commands. It is up to the | 87 // On success, the read commands are added to commands. It is up to the |
| 90 // caller to delete the commands. | 88 // caller to delete the commands. |
| 91 bool ReadCurrentSessionCommandsImpl(std::vector<SessionCommand*>* commands); | 89 bool ReadCurrentSessionCommandsImpl(ScopedVector<SessionCommand>* commands); |
| 92 | 90 |
| 93 private: | 91 private: |
| 94 friend class base::RefCountedThreadSafe<SessionBackend>; | 92 friend class base::RefCountedThreadSafe<SessionBackend>; |
| 95 | 93 |
| 96 ~SessionBackend(); | 94 ~SessionBackend(); |
| 97 | 95 |
| 98 // If current_session_file_ is open, it is truncated so that it is essentially | 96 // If current_session_file_ is open, it is truncated so that it is essentially |
| 99 // empty (only contains the header). If current_session_file_ isn't open, it | 97 // empty (only contains the header). If current_session_file_ isn't open, it |
| 100 // is is opened and the header is written to it. After this | 98 // is is opened and the header is written to it. After this |
| 101 // current_session_file_ contains no commands. | 99 // current_session_file_ contains no commands. |
| 102 // NOTE: current_session_file_ may be NULL if the file couldn't be opened or | 100 // NOTE: current_session_file_ may be NULL if the file couldn't be opened or |
| 103 // the header couldn't be written. | 101 // the header couldn't be written. |
| 104 void ResetFile(); | 102 void ResetFile(); |
| 105 | 103 |
| 106 // Opens the current file and writes the header. On success a handle to | 104 // Opens the current file and writes the header. On success a handle to |
| 107 // the file is returned. | 105 // the file is returned. |
| 108 base::File* OpenAndWriteHeader(const base::FilePath& path); | 106 base::File* OpenAndWriteHeader(const base::FilePath& path); |
| 109 | 107 |
| 110 // Appends the specified commands to the specified file. | 108 // Appends the specified commands to the specified file. |
| 111 bool AppendCommandsToFile(base::File* file, | 109 bool AppendCommandsToFile(base::File* file, |
| 112 const std::vector<SessionCommand*>& commands); | 110 const ScopedVector<SessionCommand>& commands); |
| 113 | 111 |
| 114 const BaseSessionService::SessionType type_; | 112 const BaseSessionService::SessionType type_; |
| 115 | 113 |
| 116 // Returns the path to the last file. | 114 // Returns the path to the last file. |
| 117 base::FilePath GetLastSessionPath(); | 115 base::FilePath GetLastSessionPath(); |
| 118 | 116 |
| 119 // Returns the path to the current file. | 117 // Returns the path to the current file. |
| 120 base::FilePath GetCurrentSessionPath(); | 118 base::FilePath GetCurrentSessionPath(); |
| 121 | 119 |
| 122 // Directory files are relative to. | 120 // Directory files are relative to. |
| 123 const base::FilePath path_to_dir_; | 121 const base::FilePath path_to_dir_; |
| 124 | 122 |
| 125 // Whether the previous target file is valid. | 123 // Whether the previous target file is valid. |
| 126 bool last_session_valid_; | 124 bool last_session_valid_; |
| 127 | 125 |
| 128 // Handle to the target file. | 126 // Handle to the target file. |
| 129 scoped_ptr<base::File> current_session_file_; | 127 scoped_ptr<base::File> current_session_file_; |
| 130 | 128 |
| 131 // Whether we've inited. Remember, the constructor is run on the | 129 // Whether we've inited. Remember, the constructor is run on the |
| 132 // Main thread, all others on the IO thread, hence lazy initialization. | 130 // Main thread, all others on the IO thread, hence lazy initialization. |
| 133 bool inited_; | 131 bool inited_; |
| 134 | 132 |
| 135 // If true, the file is empty (no commands have been added to it). | 133 // If true, the file is empty (no commands have been added to it). |
| 136 bool empty_file_; | 134 bool empty_file_; |
| 137 | 135 |
| 138 DISALLOW_COPY_AND_ASSIGN(SessionBackend); | 136 DISALLOW_COPY_AND_ASSIGN(SessionBackend); |
| 139 }; | 137 }; |
| 140 | 138 |
| 141 #endif // CHROME_BROWSER_SESSIONS_SESSION_BACKEND_H_ | 139 #endif // CHROME_BROWSER_SESSIONS_SESSION_BACKEND_H_ |
| OLD | NEW |