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> |
| 9 |
8 #include <string> | 10 #include <string> |
9 #include <vector> | 11 #include <vector> |
10 | 12 |
11 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
12 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
13 #include "base/files/important_file_writer.h" | 15 #include "base/files/important_file_writer.h" |
| 16 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/scoped_vector.h" | 19 #include "base/memory/scoped_vector.h" |
17 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
18 #include "components/bookmarks/browser/bookmark_node.h" | 21 #include "components/bookmarks/browser/bookmark_node.h" |
19 | 22 |
20 namespace base { | 23 namespace base { |
21 class SequencedTaskRunner; | 24 class SequencedTaskRunner; |
22 } | 25 } |
23 | 26 |
24 namespace bookmarks { | 27 namespace bookmarks { |
25 | 28 |
26 class BookmarkIndex; | 29 class BookmarkIndex; |
27 class BookmarkModel; | 30 class BookmarkModel; |
28 | 31 |
29 // A list of BookmarkPermanentNodes that owns them. | 32 // A list of BookmarkPermanentNodes that owns them. |
30 typedef ScopedVector<BookmarkPermanentNode> BookmarkPermanentNodeList; | 33 typedef ScopedVector<BookmarkPermanentNode> BookmarkPermanentNodeList; |
31 | 34 |
32 // A callback that generates a BookmarkPermanentNodeList, given a max ID to | 35 // A callback that generates a BookmarkPermanentNodeList, given a max ID to |
33 // use. The max ID argument will be updated after any new nodes have been | 36 // use. The max ID argument will be updated after any new nodes have been |
34 // created and assigned IDs. | 37 // created and assigned IDs. |
35 typedef base::Callback<BookmarkPermanentNodeList(int64*)> LoadExtraCallback; | 38 typedef base::Callback<BookmarkPermanentNodeList(int64_t*)> LoadExtraCallback; |
36 | 39 |
37 // BookmarkLoadDetails is used by BookmarkStorage when loading bookmarks. | 40 // BookmarkLoadDetails is used by BookmarkStorage when loading bookmarks. |
38 // BookmarkModel creates a BookmarkLoadDetails and passes it (including | 41 // BookmarkModel creates a BookmarkLoadDetails and passes it (including |
39 // ownership) to BookmarkStorage. BookmarkStorage loads the bookmarks (and | 42 // ownership) to BookmarkStorage. BookmarkStorage loads the bookmarks (and |
40 // index) in the background thread, then calls back to the BookmarkModel (on | 43 // index) in the background thread, then calls back to the BookmarkModel (on |
41 // the main thread) when loading is done, passing ownership back to the | 44 // the main thread) when loading is done, passing ownership back to the |
42 // BookmarkModel. While loading BookmarkModel does not maintain references to | 45 // BookmarkModel. While loading BookmarkModel does not maintain references to |
43 // the contents of the BookmarkLoadDetails, this ensures we don't have any | 46 // the contents of the BookmarkLoadDetails, this ensures we don't have any |
44 // threading problems. | 47 // threading problems. |
45 class BookmarkLoadDetails { | 48 class BookmarkLoadDetails { |
46 public: | 49 public: |
47 BookmarkLoadDetails(BookmarkPermanentNode* bb_node, | 50 BookmarkLoadDetails(BookmarkPermanentNode* bb_node, |
48 BookmarkPermanentNode* other_folder_node, | 51 BookmarkPermanentNode* other_folder_node, |
49 BookmarkPermanentNode* mobile_folder_node, | 52 BookmarkPermanentNode* mobile_folder_node, |
50 const LoadExtraCallback& load_extra_callback, | 53 const LoadExtraCallback& load_extra_callback, |
51 BookmarkIndex* index, | 54 BookmarkIndex* index, |
52 int64 max_id); | 55 int64_t max_id); |
53 ~BookmarkLoadDetails(); | 56 ~BookmarkLoadDetails(); |
54 | 57 |
55 void LoadExtraNodes(); | 58 void LoadExtraNodes(); |
56 | 59 |
57 BookmarkPermanentNode* bb_node() { return bb_node_.get(); } | 60 BookmarkPermanentNode* bb_node() { return bb_node_.get(); } |
58 BookmarkPermanentNode* release_bb_node() { return bb_node_.release(); } | 61 BookmarkPermanentNode* release_bb_node() { return bb_node_.release(); } |
59 BookmarkPermanentNode* mobile_folder_node() { | 62 BookmarkPermanentNode* mobile_folder_node() { |
60 return mobile_folder_node_.get(); | 63 return mobile_folder_node_.get(); |
61 } | 64 } |
62 BookmarkPermanentNode* release_mobile_folder_node() { | 65 BookmarkPermanentNode* release_mobile_folder_node() { |
(...skipping 14 matching lines...) Expand all Loading... |
77 BookmarkIndex* index() { return index_.get(); } | 80 BookmarkIndex* index() { return index_.get(); } |
78 BookmarkIndex* release_index() { return index_.release(); } | 81 BookmarkIndex* release_index() { return index_.release(); } |
79 | 82 |
80 const BookmarkNode::MetaInfoMap& model_meta_info_map() const { | 83 const BookmarkNode::MetaInfoMap& model_meta_info_map() const { |
81 return model_meta_info_map_; | 84 return model_meta_info_map_; |
82 } | 85 } |
83 void set_model_meta_info_map(const BookmarkNode::MetaInfoMap& meta_info_map) { | 86 void set_model_meta_info_map(const BookmarkNode::MetaInfoMap& meta_info_map) { |
84 model_meta_info_map_ = meta_info_map; | 87 model_meta_info_map_ = meta_info_map; |
85 } | 88 } |
86 | 89 |
87 int64 model_sync_transaction_version() const { | 90 int64_t model_sync_transaction_version() const { |
88 return model_sync_transaction_version_; | 91 return model_sync_transaction_version_; |
89 } | 92 } |
90 void set_model_sync_transaction_version(int64 sync_transaction_version) { | 93 void set_model_sync_transaction_version(int64_t sync_transaction_version) { |
91 model_sync_transaction_version_ = sync_transaction_version; | 94 model_sync_transaction_version_ = sync_transaction_version; |
92 } | 95 } |
93 | 96 |
94 // Max id of the nodes. | 97 // Max id of the nodes. |
95 void set_max_id(int64 max_id) { max_id_ = max_id; } | 98 void set_max_id(int64_t max_id) { max_id_ = max_id; } |
96 int64 max_id() const { return max_id_; } | 99 int64_t max_id() const { return max_id_; } |
97 | 100 |
98 // Computed checksum. | 101 // Computed checksum. |
99 void set_computed_checksum(const std::string& value) { | 102 void set_computed_checksum(const std::string& value) { |
100 computed_checksum_ = value; | 103 computed_checksum_ = value; |
101 } | 104 } |
102 const std::string& computed_checksum() const { return computed_checksum_; } | 105 const std::string& computed_checksum() const { return computed_checksum_; } |
103 | 106 |
104 // Stored checksum. | 107 // Stored checksum. |
105 void set_stored_checksum(const std::string& value) { | 108 void set_stored_checksum(const std::string& value) { |
106 stored_checksum_ = value; | 109 stored_checksum_ = value; |
107 } | 110 } |
108 const std::string& stored_checksum() const { return stored_checksum_; } | 111 const std::string& stored_checksum() const { return stored_checksum_; } |
109 | 112 |
110 // Whether ids were reassigned. IDs are reassigned during decoding if the | 113 // Whether ids were reassigned. IDs are reassigned during decoding if the |
111 // 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 |
112 // unique. Basically, if the user modified the bookmarks directly we'll | 115 // unique. Basically, if the user modified the bookmarks directly we'll |
113 // reassign the ids to ensure they are unique. | 116 // reassign the ids to ensure they are unique. |
114 void set_ids_reassigned(bool value) { ids_reassigned_ = value; } | 117 void set_ids_reassigned(bool value) { ids_reassigned_ = value; } |
115 bool ids_reassigned() const { return ids_reassigned_; } | 118 bool ids_reassigned() const { return ids_reassigned_; } |
116 | 119 |
117 private: | 120 private: |
118 scoped_ptr<BookmarkPermanentNode> bb_node_; | 121 scoped_ptr<BookmarkPermanentNode> bb_node_; |
119 scoped_ptr<BookmarkPermanentNode> other_folder_node_; | 122 scoped_ptr<BookmarkPermanentNode> other_folder_node_; |
120 scoped_ptr<BookmarkPermanentNode> mobile_folder_node_; | 123 scoped_ptr<BookmarkPermanentNode> mobile_folder_node_; |
121 LoadExtraCallback load_extra_callback_; | 124 LoadExtraCallback load_extra_callback_; |
122 BookmarkPermanentNodeList extra_nodes_; | 125 BookmarkPermanentNodeList extra_nodes_; |
123 scoped_ptr<BookmarkIndex> index_; | 126 scoped_ptr<BookmarkIndex> index_; |
124 BookmarkNode::MetaInfoMap model_meta_info_map_; | 127 BookmarkNode::MetaInfoMap model_meta_info_map_; |
125 int64 model_sync_transaction_version_; | 128 int64_t model_sync_transaction_version_; |
126 int64 max_id_; | 129 int64_t max_id_; |
127 std::string computed_checksum_; | 130 std::string computed_checksum_; |
128 std::string stored_checksum_; | 131 std::string stored_checksum_; |
129 bool ids_reassigned_; | 132 bool ids_reassigned_; |
130 | 133 |
131 DISALLOW_COPY_AND_ASSIGN(BookmarkLoadDetails); | 134 DISALLOW_COPY_AND_ASSIGN(BookmarkLoadDetails); |
132 }; | 135 }; |
133 | 136 |
134 // BookmarkStorage handles reading/write the bookmark bar model. The | 137 // BookmarkStorage handles reading/write the bookmark bar model. The |
135 // BookmarkModel uses the BookmarkStorage to load bookmarks from disk, as well | 138 // BookmarkModel uses the BookmarkStorage to load bookmarks from disk, as well |
136 // as notifying the BookmarkStorage every time the model changes. | 139 // as notifying the BookmarkStorage every time the model changes. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; | 204 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; |
202 | 205 |
203 base::WeakPtrFactory<BookmarkStorage> weak_factory_; | 206 base::WeakPtrFactory<BookmarkStorage> weak_factory_; |
204 | 207 |
205 DISALLOW_COPY_AND_ASSIGN(BookmarkStorage); | 208 DISALLOW_COPY_AND_ASSIGN(BookmarkStorage); |
206 }; | 209 }; |
207 | 210 |
208 } // namespace bookmarks | 211 } // namespace bookmarks |
209 | 212 |
210 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_STORAGE_H_ | 213 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_STORAGE_H_ |
OLD | NEW |