| 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/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 9 #include "base/files/important_file_writer.h" | 10 #include "base/files/important_file_writer.h" |
| 10 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/scoped_vector.h" |
| 12 #include "components/bookmarks/browser/bookmark_node.h" | 14 #include "components/bookmarks/browser/bookmark_node.h" |
| 13 | 15 |
| 14 class BookmarkModel; | 16 class BookmarkModel; |
| 15 | 17 |
| 16 namespace base { | 18 namespace base { |
| 17 class SequencedTaskRunner; | 19 class SequencedTaskRunner; |
| 18 } | 20 } |
| 19 | 21 |
| 20 namespace bookmarks { | 22 namespace bookmarks { |
| 21 | 23 |
| 22 class BookmarkIndex; | 24 class BookmarkIndex; |
| 23 | 25 |
| 26 // A list of BookmarkPermanentNodes that owns them. |
| 27 typedef ScopedVector<BookmarkPermanentNode> BookmarkPermanentNodeList; |
| 28 |
| 29 // A callback that generates a BookmarkPermanentNodeList, given a max ID to |
| 30 // use. The max ID argument will be updated after any new nodes have been |
| 31 // created and assigned IDs. |
| 32 typedef base::Callback<BookmarkPermanentNodeList(int64*)> LoadExtraCallback; |
| 33 |
| 24 // BookmarkLoadDetails is used by BookmarkStorage when loading bookmarks. | 34 // BookmarkLoadDetails is used by BookmarkStorage when loading bookmarks. |
| 25 // BookmarkModel creates a BookmarkLoadDetails and passes it (including | 35 // BookmarkModel creates a BookmarkLoadDetails and passes it (including |
| 26 // ownership) to BookmarkStorage. BookmarkStorage loads the bookmarks (and | 36 // ownership) to BookmarkStorage. BookmarkStorage loads the bookmarks (and |
| 27 // index) in the background thread, then calls back to the BookmarkModel (on | 37 // index) in the background thread, then calls back to the BookmarkModel (on |
| 28 // the main thread) when loading is done, passing ownership back to the | 38 // the main thread) when loading is done, passing ownership back to the |
| 29 // BookmarkModel. While loading BookmarkModel does not maintain references to | 39 // BookmarkModel. While loading BookmarkModel does not maintain references to |
| 30 // the contents of the BookmarkLoadDetails, this ensures we don't have any | 40 // the contents of the BookmarkLoadDetails, this ensures we don't have any |
| 31 // threading problems. | 41 // threading problems. |
| 32 class BookmarkLoadDetails { | 42 class BookmarkLoadDetails { |
| 33 public: | 43 public: |
| 34 BookmarkLoadDetails(BookmarkPermanentNode* bb_node, | 44 BookmarkLoadDetails(BookmarkPermanentNode* bb_node, |
| 35 BookmarkPermanentNode* other_folder_node, | 45 BookmarkPermanentNode* other_folder_node, |
| 36 BookmarkPermanentNode* mobile_folder_node, | 46 BookmarkPermanentNode* mobile_folder_node, |
| 47 const LoadExtraCallback& load_extra_callback, |
| 37 BookmarkIndex* index, | 48 BookmarkIndex* index, |
| 38 int64 max_id); | 49 int64 max_id); |
| 39 ~BookmarkLoadDetails(); | 50 ~BookmarkLoadDetails(); |
| 40 | 51 |
| 52 void LoadExtraNodes(); |
| 53 |
| 41 BookmarkPermanentNode* bb_node() { return bb_node_.get(); } | 54 BookmarkPermanentNode* bb_node() { return bb_node_.get(); } |
| 42 BookmarkPermanentNode* release_bb_node() { return bb_node_.release(); } | 55 BookmarkPermanentNode* release_bb_node() { return bb_node_.release(); } |
| 43 BookmarkPermanentNode* mobile_folder_node() { | 56 BookmarkPermanentNode* mobile_folder_node() { |
| 44 return mobile_folder_node_.get(); | 57 return mobile_folder_node_.get(); |
| 45 } | 58 } |
| 46 BookmarkPermanentNode* release_mobile_folder_node() { | 59 BookmarkPermanentNode* release_mobile_folder_node() { |
| 47 return mobile_folder_node_.release(); | 60 return mobile_folder_node_.release(); |
| 48 } | 61 } |
| 49 BookmarkPermanentNode* other_folder_node() { | 62 BookmarkPermanentNode* other_folder_node() { |
| 50 return other_folder_node_.get(); | 63 return other_folder_node_.get(); |
| 51 } | 64 } |
| 52 BookmarkPermanentNode* release_other_folder_node() { | 65 BookmarkPermanentNode* release_other_folder_node() { |
| 53 return other_folder_node_.release(); | 66 return other_folder_node_.release(); |
| 54 } | 67 } |
| 68 const BookmarkPermanentNodeList& extra_nodes() { |
| 69 return extra_nodes_; |
| 70 } |
| 71 void release_extra_nodes(std::vector<BookmarkPermanentNode*>* extra_nodes) { |
| 72 extra_nodes_.release(extra_nodes); |
| 73 } |
| 55 BookmarkIndex* index() { return index_.get(); } | 74 BookmarkIndex* index() { return index_.get(); } |
| 56 BookmarkIndex* release_index() { return index_.release(); } | 75 BookmarkIndex* release_index() { return index_.release(); } |
| 57 | 76 |
| 58 const BookmarkNode::MetaInfoMap& model_meta_info_map() const { | 77 const BookmarkNode::MetaInfoMap& model_meta_info_map() const { |
| 59 return model_meta_info_map_; | 78 return model_meta_info_map_; |
| 60 } | 79 } |
| 61 void set_model_meta_info_map(const BookmarkNode::MetaInfoMap& meta_info_map) { | 80 void set_model_meta_info_map(const BookmarkNode::MetaInfoMap& meta_info_map) { |
| 62 model_meta_info_map_ = meta_info_map; | 81 model_meta_info_map_ = meta_info_map; |
| 63 } | 82 } |
| 64 | 83 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 89 // checksum of the file doesn't match, some IDs are missing or not | 108 // checksum of the file doesn't match, some IDs are missing or not |
| 90 // unique. Basically, if the user modified the bookmarks directly we'll | 109 // unique. Basically, if the user modified the bookmarks directly we'll |
| 91 // reassign the ids to ensure they are unique. | 110 // reassign the ids to ensure they are unique. |
| 92 void set_ids_reassigned(bool value) { ids_reassigned_ = value; } | 111 void set_ids_reassigned(bool value) { ids_reassigned_ = value; } |
| 93 bool ids_reassigned() const { return ids_reassigned_; } | 112 bool ids_reassigned() const { return ids_reassigned_; } |
| 94 | 113 |
| 95 private: | 114 private: |
| 96 scoped_ptr<BookmarkPermanentNode> bb_node_; | 115 scoped_ptr<BookmarkPermanentNode> bb_node_; |
| 97 scoped_ptr<BookmarkPermanentNode> other_folder_node_; | 116 scoped_ptr<BookmarkPermanentNode> other_folder_node_; |
| 98 scoped_ptr<BookmarkPermanentNode> mobile_folder_node_; | 117 scoped_ptr<BookmarkPermanentNode> mobile_folder_node_; |
| 118 LoadExtraCallback load_extra_callback_; |
| 119 BookmarkPermanentNodeList extra_nodes_; |
| 99 scoped_ptr<BookmarkIndex> index_; | 120 scoped_ptr<BookmarkIndex> index_; |
| 100 BookmarkNode::MetaInfoMap model_meta_info_map_; | 121 BookmarkNode::MetaInfoMap model_meta_info_map_; |
| 101 int64 model_sync_transaction_version_; | 122 int64 model_sync_transaction_version_; |
| 102 int64 max_id_; | 123 int64 max_id_; |
| 103 std::string computed_checksum_; | 124 std::string computed_checksum_; |
| 104 std::string stored_checksum_; | 125 std::string stored_checksum_; |
| 105 bool ids_reassigned_; | 126 bool ids_reassigned_; |
| 106 | 127 |
| 107 DISALLOW_COPY_AND_ASSIGN(BookmarkLoadDetails); | 128 DISALLOW_COPY_AND_ASSIGN(BookmarkLoadDetails); |
| 108 }; | 129 }; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 | 183 |
| 163 // Sequenced task runner where file I/O operations will be performed at. | 184 // Sequenced task runner where file I/O operations will be performed at. |
| 164 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; | 185 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; |
| 165 | 186 |
| 166 DISALLOW_COPY_AND_ASSIGN(BookmarkStorage); | 187 DISALLOW_COPY_AND_ASSIGN(BookmarkStorage); |
| 167 }; | 188 }; |
| 168 | 189 |
| 169 } // namespace bookmarks | 190 } // namespace bookmarks |
| 170 | 191 |
| 171 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_STORAGE_H_ | 192 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_STORAGE_H_ |
| OLD | NEW |