| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> |
| 10 #include <string> | 11 #include <string> |
| 11 #include <vector> | 12 #include <vector> |
| 12 | 13 |
| 13 #include "base/callback_forward.h" | 14 #include "base/callback_forward.h" |
| 14 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 15 #include "base/files/important_file_writer.h" | 16 #include "base/files/important_file_writer.h" |
| 16 #include "base/macros.h" | 17 #include "base/macros.h" |
| 17 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
| 18 #include "base/memory/scoped_ptr.h" | |
| 19 #include "base/memory/scoped_vector.h" | 19 #include "base/memory/scoped_vector.h" |
| 20 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
| 21 #include "components/bookmarks/browser/bookmark_node.h" | 21 #include "components/bookmarks/browser/bookmark_node.h" |
| 22 | 22 |
| 23 namespace base { | 23 namespace base { |
| 24 class SequencedTaskRunner; | 24 class SequencedTaskRunner; |
| 25 } | 25 } |
| 26 | 26 |
| 27 namespace bookmarks { | 27 namespace bookmarks { |
| 28 | 28 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 const std::string& stored_checksum() const { return stored_checksum_; } | 111 const std::string& stored_checksum() const { return stored_checksum_; } |
| 112 | 112 |
| 113 // Whether ids were reassigned. IDs are reassigned during decoding if the | 113 // Whether ids were reassigned. IDs are reassigned during decoding if the |
| 114 // checksum of the file doesn't match, some IDs are missing or not | 114 // checksum of the file doesn't match, some IDs are missing or not |
| 115 // unique. Basically, if the user modified the bookmarks directly we'll | 115 // unique. Basically, if the user modified the bookmarks directly we'll |
| 116 // reassign the ids to ensure they are unique. | 116 // reassign the ids to ensure they are unique. |
| 117 void set_ids_reassigned(bool value) { ids_reassigned_ = value; } | 117 void set_ids_reassigned(bool value) { ids_reassigned_ = value; } |
| 118 bool ids_reassigned() const { return ids_reassigned_; } | 118 bool ids_reassigned() const { return ids_reassigned_; } |
| 119 | 119 |
| 120 private: | 120 private: |
| 121 scoped_ptr<BookmarkPermanentNode> bb_node_; | 121 std::unique_ptr<BookmarkPermanentNode> bb_node_; |
| 122 scoped_ptr<BookmarkPermanentNode> other_folder_node_; | 122 std::unique_ptr<BookmarkPermanentNode> other_folder_node_; |
| 123 scoped_ptr<BookmarkPermanentNode> mobile_folder_node_; | 123 std::unique_ptr<BookmarkPermanentNode> mobile_folder_node_; |
| 124 LoadExtraCallback load_extra_callback_; | 124 LoadExtraCallback load_extra_callback_; |
| 125 BookmarkPermanentNodeList extra_nodes_; | 125 BookmarkPermanentNodeList extra_nodes_; |
| 126 scoped_ptr<BookmarkIndex> index_; | 126 std::unique_ptr<BookmarkIndex> index_; |
| 127 BookmarkNode::MetaInfoMap model_meta_info_map_; | 127 BookmarkNode::MetaInfoMap model_meta_info_map_; |
| 128 int64_t model_sync_transaction_version_; | 128 int64_t model_sync_transaction_version_; |
| 129 int64_t max_id_; | 129 int64_t max_id_; |
| 130 std::string computed_checksum_; | 130 std::string computed_checksum_; |
| 131 std::string stored_checksum_; | 131 std::string stored_checksum_; |
| 132 bool ids_reassigned_; | 132 bool ids_reassigned_; |
| 133 | 133 |
| 134 DISALLOW_COPY_AND_ASSIGN(BookmarkLoadDetails); | 134 DISALLOW_COPY_AND_ASSIGN(BookmarkLoadDetails); |
| 135 }; | 135 }; |
| 136 | 136 |
| 137 // BookmarkStorage handles reading/write the bookmark bar model. The | 137 // BookmarkStorage handles reading/write the bookmark bar model. The |
| 138 // BookmarkModel uses the BookmarkStorage to load bookmarks from disk, as well | 138 // BookmarkModel uses the BookmarkStorage to load bookmarks from disk, as well |
| 139 // as notifying the BookmarkStorage every time the model changes. | 139 // as notifying the BookmarkStorage every time the model changes. |
| 140 // | 140 // |
| 141 // Internally BookmarkStorage uses BookmarkCodec to do the actual read/write. | 141 // Internally BookmarkStorage uses BookmarkCodec to do the actual read/write. |
| 142 class BookmarkStorage : public base::ImportantFileWriter::DataSerializer { | 142 class BookmarkStorage : public base::ImportantFileWriter::DataSerializer { |
| 143 public: | 143 public: |
| 144 // Creates a BookmarkStorage for the specified model. The data will be loaded | 144 // Creates a BookmarkStorage for the specified model. The data will be loaded |
| 145 // from and saved to a location derived from |profile_path|. The IO code will | 145 // from and saved to a location derived from |profile_path|. The IO code will |
| 146 // be executed as a task in |sequenced_task_runner|. | 146 // be executed as a task in |sequenced_task_runner|. |
| 147 BookmarkStorage(BookmarkModel* model, | 147 BookmarkStorage(BookmarkModel* model, |
| 148 const base::FilePath& profile_path, | 148 const base::FilePath& profile_path, |
| 149 base::SequencedTaskRunner* sequenced_task_runner); | 149 base::SequencedTaskRunner* sequenced_task_runner); |
| 150 ~BookmarkStorage() override; | 150 ~BookmarkStorage() override; |
| 151 | 151 |
| 152 // Loads the bookmarks into the model, notifying the model when done. This | 152 // Loads the bookmarks into the model, notifying the model when done. This |
| 153 // takes ownership of |details| and send the |OnLoadFinished| callback from | 153 // takes ownership of |details| and send the |OnLoadFinished| callback from |
| 154 // a task in |task_runner|. See BookmarkLoadDetails for details. | 154 // a task in |task_runner|. See BookmarkLoadDetails for details. |
| 155 void LoadBookmarks( | 155 void LoadBookmarks( |
| 156 scoped_ptr<BookmarkLoadDetails> details, | 156 std::unique_ptr<BookmarkLoadDetails> details, |
| 157 const scoped_refptr<base::SequencedTaskRunner>& task_runner); | 157 const scoped_refptr<base::SequencedTaskRunner>& task_runner); |
| 158 | 158 |
| 159 // Schedules saving the bookmark bar model to disk. | 159 // Schedules saving the bookmark bar model to disk. |
| 160 void ScheduleSave(); | 160 void ScheduleSave(); |
| 161 | 161 |
| 162 // Notification the bookmark bar model is going to be deleted. If there is | 162 // Notification the bookmark bar model is going to be deleted. If there is |
| 163 // a pending save, it is saved immediately. | 163 // a pending save, it is saved immediately. |
| 164 void BookmarkModelDeleted(); | 164 void BookmarkModelDeleted(); |
| 165 | 165 |
| 166 // Callback from backend after loading the bookmark file. | 166 // Callback from backend after loading the bookmark file. |
| 167 void OnLoadFinished(scoped_ptr<BookmarkLoadDetails> details); | 167 void OnLoadFinished(std::unique_ptr<BookmarkLoadDetails> details); |
| 168 | 168 |
| 169 // ImportantFileWriter::DataSerializer implementation. | 169 // ImportantFileWriter::DataSerializer implementation. |
| 170 bool SerializeData(std::string* output) override; | 170 bool SerializeData(std::string* output) override; |
| 171 | 171 |
| 172 private: | 172 private: |
| 173 // The state of the bookmark file backup. We lazily backup this file in order | 173 // The state of the bookmark file backup. We lazily backup this file in order |
| 174 // to reduce disk writes until absolutely necessary. Will also leave the | 174 // to reduce disk writes until absolutely necessary. Will also leave the |
| 175 // backup unchanged if the browser starts & quits w/o changing bookmarks. | 175 // backup unchanged if the browser starts & quits w/o changing bookmarks. |
| 176 enum BackupState { | 176 enum BackupState { |
| 177 // No attempt has yet been made to backup the bookmarks file. | 177 // No attempt has yet been made to backup the bookmarks file. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 204 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; | 204 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; |
| 205 | 205 |
| 206 base::WeakPtrFactory<BookmarkStorage> weak_factory_; | 206 base::WeakPtrFactory<BookmarkStorage> weak_factory_; |
| 207 | 207 |
| 208 DISALLOW_COPY_AND_ASSIGN(BookmarkStorage); | 208 DISALLOW_COPY_AND_ASSIGN(BookmarkStorage); |
| 209 }; | 209 }; |
| 210 | 210 |
| 211 } // namespace bookmarks | 211 } // namespace bookmarks |
| 212 | 212 |
| 213 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_STORAGE_H_ | 213 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_STORAGE_H_ |
| OLD | NEW |