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 #include "components/bookmarks/browser/bookmark_storage.h" | 5 #include "components/bookmarks/browser/bookmark_storage.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 if (node->url().is_valid()) | 46 if (node->url().is_valid()) |
47 details->index()->Add(node); | 47 details->index()->Add(node); |
48 } else { | 48 } else { |
49 for (int i = 0; i < node->child_count(); ++i) | 49 for (int i = 0; i < node->child_count(); ++i) |
50 AddBookmarksToIndex(details, node->GetChild(i)); | 50 AddBookmarksToIndex(details, node->GetChild(i)); |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
54 void LoadCallback(const base::FilePath& path, | 54 void LoadCallback(const base::FilePath& path, |
55 const base::WeakPtr<BookmarkStorage>& storage, | 55 const base::WeakPtr<BookmarkStorage>& storage, |
| 56 const std::vector<std::string>& excluded_meta_keys, |
56 std::unique_ptr<BookmarkLoadDetails> details, | 57 std::unique_ptr<BookmarkLoadDetails> details, |
57 base::SequencedTaskRunner* task_runner) { | 58 base::SequencedTaskRunner* task_runner) { |
58 bool load_index = false; | 59 bool load_index = false; |
59 bool bookmark_file_exists = base::PathExists(path); | 60 bool bookmark_file_exists = base::PathExists(path); |
60 if (bookmark_file_exists) { | 61 if (bookmark_file_exists) { |
61 // Titles may end up containing invalid utf and we shouldn't throw away | 62 // Titles may end up containing invalid utf and we shouldn't throw away |
62 // all bookmarks if some titles have invalid utf. | 63 // all bookmarks if some titles have invalid utf. |
63 JSONFileValueDeserializer deserializer( | 64 JSONFileValueDeserializer deserializer( |
64 path, base::JSON_REPLACE_INVALID_CHARACTERS); | 65 path, base::JSON_REPLACE_INVALID_CHARACTERS); |
65 std::unique_ptr<base::Value> root = deserializer.Deserialize(NULL, NULL); | 66 std::unique_ptr<base::Value> root = deserializer.Deserialize(NULL, NULL); |
66 | 67 |
67 if (root.get()) { | 68 if (root.get()) { |
68 // Building the index can take a while, so we do it on the background | 69 // Building the index can take a while, so we do it on the background |
69 // thread. | 70 // thread. |
70 int64_t max_node_id = 0; | 71 int64_t max_node_id = 0; |
71 BookmarkCodec codec; | 72 BookmarkCodec codec; |
| 73 codec.set_excluded_meta_info_keys(excluded_meta_keys); |
| 74 |
72 TimeTicks start_time = TimeTicks::Now(); | 75 TimeTicks start_time = TimeTicks::Now(); |
73 codec.Decode(details->bb_node(), details->other_folder_node(), | 76 codec.Decode(details->bb_node(), details->other_folder_node(), |
74 details->mobile_folder_node(), &max_node_id, *root.get()); | 77 details->mobile_folder_node(), &max_node_id, *root.get()); |
75 details->set_max_id(std::max(max_node_id, details->max_id())); | 78 details->set_max_id(std::max(max_node_id, details->max_id())); |
76 details->set_computed_checksum(codec.computed_checksum()); | 79 details->set_computed_checksum(codec.computed_checksum()); |
77 details->set_stored_checksum(codec.stored_checksum()); | 80 details->set_stored_checksum(codec.stored_checksum()); |
78 details->set_ids_reassigned(codec.ids_reassigned()); | 81 details->set_ids_reassigned(codec.ids_reassigned()); |
79 details->set_model_meta_info_map(codec.model_meta_info_map()); | 82 details->set_model_meta_info_map(codec.model_meta_info_map()); |
80 details->set_model_sync_transaction_version( | 83 details->set_model_sync_transaction_version( |
81 codec.model_sync_transaction_version()); | 84 codec.model_sync_transaction_version()); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 if (writer_.HasPendingWrite()) | 165 if (writer_.HasPendingWrite()) |
163 writer_.DoScheduledWrite(); | 166 writer_.DoScheduledWrite(); |
164 } | 167 } |
165 | 168 |
166 void BookmarkStorage::LoadBookmarks( | 169 void BookmarkStorage::LoadBookmarks( |
167 std::unique_ptr<BookmarkLoadDetails> details, | 170 std::unique_ptr<BookmarkLoadDetails> details, |
168 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 171 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
169 sequenced_task_runner_->PostTask( | 172 sequenced_task_runner_->PostTask( |
170 FROM_HERE, | 173 FROM_HERE, |
171 base::Bind(&LoadCallback, writer_.path(), weak_factory_.GetWeakPtr(), | 174 base::Bind(&LoadCallback, writer_.path(), weak_factory_.GetWeakPtr(), |
172 base::Passed(&details), base::RetainedRef(task_runner))); | 175 model_->client()->ExecludedMetaKeys(), base::Passed(&details), |
| 176 base::RetainedRef(task_runner))); |
173 } | 177 } |
174 | 178 |
175 void BookmarkStorage::ScheduleSave() { | 179 void BookmarkStorage::ScheduleSave() { |
176 switch (backup_state_) { | 180 switch (backup_state_) { |
177 case BACKUP_NONE: | 181 case BACKUP_NONE: |
178 backup_state_ = BACKUP_DISPATCHED; | 182 backup_state_ = BACKUP_DISPATCHED; |
179 sequenced_task_runner_->PostTaskAndReply( | 183 sequenced_task_runner_->PostTaskAndReply( |
180 FROM_HERE, base::Bind(&BackupCallback, writer_.path()), | 184 FROM_HERE, base::Bind(&BackupCallback, writer_.path()), |
181 base::Bind(&BookmarkStorage::OnBackupFinished, | 185 base::Bind(&BookmarkStorage::OnBackupFinished, |
182 weak_factory_.GetWeakPtr())); | 186 weak_factory_.GetWeakPtr())); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 } | 233 } |
230 | 234 |
231 std::unique_ptr<std::string> data(new std::string); | 235 std::unique_ptr<std::string> data(new std::string); |
232 if (!SerializeData(data.get())) | 236 if (!SerializeData(data.get())) |
233 return false; | 237 return false; |
234 writer_.WriteNow(std::move(data)); | 238 writer_.WriteNow(std::move(data)); |
235 return true; | 239 return true; |
236 } | 240 } |
237 | 241 |
238 } // namespace bookmarks | 242 } // namespace bookmarks |
OLD | NEW |