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/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/important_file_writer.h" | 9 #include "base/files/important_file_writer.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "components/bookmarks/browser/bookmark_node.h" | 12 #include "components/bookmarks/browser/bookmark_node.h" |
13 | 13 |
14 class BookmarkIndex; | 14 class BookmarkIndex; |
15 class BookmarkModel; | 15 class BookmarkModel; |
16 | 16 |
17 namespace base { | 17 namespace base { |
| 18 class ListValue; |
18 class SequencedTaskRunner; | 19 class SequencedTaskRunner; |
19 } | 20 } |
20 | 21 |
21 namespace bookmarks { | 22 namespace bookmarks { |
22 | 23 |
23 // BookmarkLoadDetails is used by BookmarkStorage when loading bookmarks. | 24 // BookmarkLoadDetails is used by BookmarkStorage when loading bookmarks. |
24 // BookmarkModel creates a BookmarkLoadDetails and passes it (including | 25 // BookmarkModel creates a BookmarkLoadDetails and passes it (including |
25 // ownership) to BookmarkStorage. BookmarkStorage loads the bookmarks (and | 26 // ownership) to BookmarkStorage. BookmarkStorage loads the bookmarks (and |
26 // index) in the background thread, then calls back to the BookmarkModel (on | 27 // index) in the background thread, then calls back to the BookmarkModel (on |
27 // the main thread) when loading is done, passing ownership back to the | 28 // the main thread) when loading is done, passing ownership back to the |
28 // BookmarkModel. While loading BookmarkModel does not maintain references to | 29 // BookmarkModel. While loading BookmarkModel does not maintain references to |
29 // the contents of the BookmarkLoadDetails, this ensures we don't have any | 30 // the contents of the BookmarkLoadDetails, this ensures we don't have any |
30 // threading problems. | 31 // threading problems. |
31 class BookmarkLoadDetails { | 32 class BookmarkLoadDetails { |
32 public: | 33 public: |
33 BookmarkLoadDetails(BookmarkPermanentNode* bb_node, | 34 BookmarkLoadDetails(BookmarkPermanentNode* bb_node, |
34 BookmarkPermanentNode* other_folder_node, | 35 BookmarkPermanentNode* other_folder_node, |
35 BookmarkPermanentNode* mobile_folder_node, | 36 BookmarkPermanentNode* mobile_folder_node, |
| 37 BookmarkPermanentNode* managed_node, |
36 BookmarkIndex* index, | 38 BookmarkIndex* index, |
37 int64 max_id); | 39 int64 max_id); |
38 ~BookmarkLoadDetails(); | 40 ~BookmarkLoadDetails(); |
39 | 41 |
40 BookmarkPermanentNode* bb_node() { return bb_node_.get(); } | 42 BookmarkPermanentNode* bb_node() { return bb_node_.get(); } |
41 BookmarkPermanentNode* release_bb_node() { return bb_node_.release(); } | 43 BookmarkPermanentNode* release_bb_node() { return bb_node_.release(); } |
42 BookmarkPermanentNode* mobile_folder_node() { | 44 BookmarkPermanentNode* mobile_folder_node() { |
43 return mobile_folder_node_.get(); | 45 return mobile_folder_node_.get(); |
44 } | 46 } |
45 BookmarkPermanentNode* release_mobile_folder_node() { | 47 BookmarkPermanentNode* release_mobile_folder_node() { |
46 return mobile_folder_node_.release(); | 48 return mobile_folder_node_.release(); |
47 } | 49 } |
48 BookmarkPermanentNode* other_folder_node() { | 50 BookmarkPermanentNode* other_folder_node() { |
49 return other_folder_node_.get(); | 51 return other_folder_node_.get(); |
50 } | 52 } |
51 BookmarkPermanentNode* release_other_folder_node() { | 53 BookmarkPermanentNode* release_other_folder_node() { |
52 return other_folder_node_.release(); | 54 return other_folder_node_.release(); |
53 } | 55 } |
| 56 BookmarkPermanentNode* managed_node() { return managed_node_.get(); } |
| 57 BookmarkPermanentNode* release_managed_node() { |
| 58 return managed_node_.release(); |
| 59 } |
54 BookmarkIndex* index() { return index_.get(); } | 60 BookmarkIndex* index() { return index_.get(); } |
55 BookmarkIndex* release_index() { return index_.release(); } | 61 BookmarkIndex* release_index() { return index_.release(); } |
56 | 62 |
57 const BookmarkNode::MetaInfoMap& model_meta_info_map() const { | 63 const BookmarkNode::MetaInfoMap& model_meta_info_map() const { |
58 return model_meta_info_map_; | 64 return model_meta_info_map_; |
59 } | 65 } |
60 void set_model_meta_info_map(const BookmarkNode::MetaInfoMap& meta_info_map) { | 66 void set_model_meta_info_map(const BookmarkNode::MetaInfoMap& meta_info_map) { |
61 model_meta_info_map_ = meta_info_map; | 67 model_meta_info_map_ = meta_info_map; |
62 } | 68 } |
63 | 69 |
(...skipping 24 matching lines...) Expand all Loading... |
88 // checksum of the file doesn't match, some IDs are missing or not | 94 // checksum of the file doesn't match, some IDs are missing or not |
89 // unique. Basically, if the user modified the bookmarks directly we'll | 95 // unique. Basically, if the user modified the bookmarks directly we'll |
90 // reassign the ids to ensure they are unique. | 96 // reassign the ids to ensure they are unique. |
91 void set_ids_reassigned(bool value) { ids_reassigned_ = value; } | 97 void set_ids_reassigned(bool value) { ids_reassigned_ = value; } |
92 bool ids_reassigned() const { return ids_reassigned_; } | 98 bool ids_reassigned() const { return ids_reassigned_; } |
93 | 99 |
94 private: | 100 private: |
95 scoped_ptr<BookmarkPermanentNode> bb_node_; | 101 scoped_ptr<BookmarkPermanentNode> bb_node_; |
96 scoped_ptr<BookmarkPermanentNode> other_folder_node_; | 102 scoped_ptr<BookmarkPermanentNode> other_folder_node_; |
97 scoped_ptr<BookmarkPermanentNode> mobile_folder_node_; | 103 scoped_ptr<BookmarkPermanentNode> mobile_folder_node_; |
| 104 scoped_ptr<BookmarkPermanentNode> managed_node_; |
98 scoped_ptr<BookmarkIndex> index_; | 105 scoped_ptr<BookmarkIndex> index_; |
99 BookmarkNode::MetaInfoMap model_meta_info_map_; | 106 BookmarkNode::MetaInfoMap model_meta_info_map_; |
100 int64 model_sync_transaction_version_; | 107 int64 model_sync_transaction_version_; |
101 int64 max_id_; | 108 int64 max_id_; |
102 std::string computed_checksum_; | 109 std::string computed_checksum_; |
103 std::string stored_checksum_; | 110 std::string stored_checksum_; |
104 bool ids_reassigned_; | 111 bool ids_reassigned_; |
105 | 112 |
106 DISALLOW_COPY_AND_ASSIGN(BookmarkLoadDetails); | 113 DISALLOW_COPY_AND_ASSIGN(BookmarkLoadDetails); |
107 }; | 114 }; |
(...skipping 11 matching lines...) Expand all Loading... |
119 // be executed as a task in |sequenced_task_runner|. | 126 // be executed as a task in |sequenced_task_runner|. |
120 BookmarkStorage(BookmarkModel* model, | 127 BookmarkStorage(BookmarkModel* model, |
121 const base::FilePath& profile_path, | 128 const base::FilePath& profile_path, |
122 base::SequencedTaskRunner* sequenced_task_runner); | 129 base::SequencedTaskRunner* sequenced_task_runner); |
123 | 130 |
124 // Loads the bookmarks into the model, notifying the model when done. This | 131 // Loads the bookmarks into the model, notifying the model when done. This |
125 // takes ownership of |details| and send the |OnLoadFinished| callback from | 132 // takes ownership of |details| and send the |OnLoadFinished| callback from |
126 // a task in |task_runner|. See BookmarkLoadDetails for details. | 133 // a task in |task_runner|. See BookmarkLoadDetails for details. |
127 void LoadBookmarks( | 134 void LoadBookmarks( |
128 scoped_ptr<BookmarkLoadDetails> details, | 135 scoped_ptr<BookmarkLoadDetails> details, |
| 136 scoped_ptr<base::ListValue> initial_managed_bookmarks, |
129 const scoped_refptr<base::SequencedTaskRunner>& task_runner); | 137 const scoped_refptr<base::SequencedTaskRunner>& task_runner); |
130 | 138 |
131 // Schedules saving the bookmark bar model to disk. | 139 // Schedules saving the bookmark bar model to disk. |
132 void ScheduleSave(); | 140 void ScheduleSave(); |
133 | 141 |
134 // Notification the bookmark bar model is going to be deleted. If there is | 142 // Notification the bookmark bar model is going to be deleted. If there is |
135 // a pending save, it is saved immediately. | 143 // a pending save, it is saved immediately. |
136 void BookmarkModelDeleted(); | 144 void BookmarkModelDeleted(); |
137 | 145 |
138 // Callback from backend after loading the bookmark file. | 146 // Callback from backend after loading the bookmark file. |
(...skipping 22 matching lines...) Expand all Loading... |
161 | 169 |
162 // Sequenced task runner where file I/O operations will be performed at. | 170 // Sequenced task runner where file I/O operations will be performed at. |
163 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; | 171 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; |
164 | 172 |
165 DISALLOW_COPY_AND_ASSIGN(BookmarkStorage); | 173 DISALLOW_COPY_AND_ASSIGN(BookmarkStorage); |
166 }; | 174 }; |
167 | 175 |
168 } // namespace bookmarks | 176 } // namespace bookmarks |
169 | 177 |
170 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_STORAGE_H_ | 178 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_STORAGE_H_ |
OLD | NEW |