| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_BOOKMARKS_BROWSER_BOOKMARK_STORAGE_H_ | 5 #ifndef COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_STORAGE_H_ |
| 6 #define COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_STORAGE_H_ | 6 #define COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_STORAGE_H_ |
| 7 | 7 |
| 8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/important_file_writer.h" | 10 #include "base/files/important_file_writer.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 // | 135 // |
| 136 // Internally BookmarkStorage uses BookmarkCodec to do the actual read/write. | 136 // Internally BookmarkStorage uses BookmarkCodec to do the actual read/write. |
| 137 class BookmarkStorage : public base::ImportantFileWriter::DataSerializer { | 137 class BookmarkStorage : public base::ImportantFileWriter::DataSerializer { |
| 138 public: | 138 public: |
| 139 // Creates a BookmarkStorage for the specified model. The data will be loaded | 139 // Creates a BookmarkStorage for the specified model. The data will be loaded |
| 140 // from and saved to a location derived from |profile_path|. The IO code will | 140 // from and saved to a location derived from |profile_path|. The IO code will |
| 141 // be executed as a task in |sequenced_task_runner|. | 141 // be executed as a task in |sequenced_task_runner|. |
| 142 BookmarkStorage(BookmarkModel* model, | 142 BookmarkStorage(BookmarkModel* model, |
| 143 const base::FilePath& profile_path, | 143 const base::FilePath& profile_path, |
| 144 base::SequencedTaskRunner* sequenced_task_runner); | 144 base::SequencedTaskRunner* sequenced_task_runner); |
| 145 virtual ~BookmarkStorage(); | 145 ~BookmarkStorage() override; |
| 146 | 146 |
| 147 // Loads the bookmarks into the model, notifying the model when done. This | 147 // Loads the bookmarks into the model, notifying the model when done. This |
| 148 // takes ownership of |details| and send the |OnLoadFinished| callback from | 148 // takes ownership of |details| and send the |OnLoadFinished| callback from |
| 149 // a task in |task_runner|. See BookmarkLoadDetails for details. | 149 // a task in |task_runner|. See BookmarkLoadDetails for details. |
| 150 void LoadBookmarks( | 150 void LoadBookmarks( |
| 151 scoped_ptr<BookmarkLoadDetails> details, | 151 scoped_ptr<BookmarkLoadDetails> details, |
| 152 const scoped_refptr<base::SequencedTaskRunner>& task_runner); | 152 const scoped_refptr<base::SequencedTaskRunner>& task_runner); |
| 153 | 153 |
| 154 // Schedules saving the bookmark bar model to disk. | 154 // Schedules saving the bookmark bar model to disk. |
| 155 void ScheduleSave(); | 155 void ScheduleSave(); |
| 156 | 156 |
| 157 // Notification the bookmark bar model is going to be deleted. If there is | 157 // Notification the bookmark bar model is going to be deleted. If there is |
| 158 // a pending save, it is saved immediately. | 158 // a pending save, it is saved immediately. |
| 159 void BookmarkModelDeleted(); | 159 void BookmarkModelDeleted(); |
| 160 | 160 |
| 161 // Callback from backend after loading the bookmark file. | 161 // Callback from backend after loading the bookmark file. |
| 162 void OnLoadFinished(scoped_ptr<BookmarkLoadDetails> details); | 162 void OnLoadFinished(scoped_ptr<BookmarkLoadDetails> details); |
| 163 | 163 |
| 164 // ImportantFileWriter::DataSerializer implementation. | 164 // ImportantFileWriter::DataSerializer implementation. |
| 165 virtual bool SerializeData(std::string* output) override; | 165 bool SerializeData(std::string* output) override; |
| 166 | 166 |
| 167 private: | 167 private: |
| 168 // Serializes the data and schedules save using ImportantFileWriter. | 168 // Serializes the data and schedules save using ImportantFileWriter. |
| 169 // Returns true on successful serialization. | 169 // Returns true on successful serialization. |
| 170 bool SaveNow(); | 170 bool SaveNow(); |
| 171 | 171 |
| 172 // The model. The model is NULL once BookmarkModelDeleted has been invoked. | 172 // The model. The model is NULL once BookmarkModelDeleted has been invoked. |
| 173 BookmarkModel* model_; | 173 BookmarkModel* model_; |
| 174 | 174 |
| 175 // Helper to write bookmark data safely. | 175 // Helper to write bookmark data safely. |
| 176 base::ImportantFileWriter writer_; | 176 base::ImportantFileWriter writer_; |
| 177 | 177 |
| 178 // Sequenced task runner where file I/O operations will be performed at. | 178 // Sequenced task runner where file I/O operations will be performed at. |
| 179 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; | 179 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; |
| 180 | 180 |
| 181 base::WeakPtrFactory<BookmarkStorage> weak_factory_; | 181 base::WeakPtrFactory<BookmarkStorage> weak_factory_; |
| 182 | 182 |
| 183 DISALLOW_COPY_AND_ASSIGN(BookmarkStorage); | 183 DISALLOW_COPY_AND_ASSIGN(BookmarkStorage); |
| 184 }; | 184 }; |
| 185 | 185 |
| 186 } // namespace bookmarks | 186 } // namespace bookmarks |
| 187 | 187 |
| 188 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_STORAGE_H_ | 188 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_STORAGE_H_ |
| OLD | NEW |