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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
14 #include "base/json/json_file_value_serializer.h" | 14 #include "base/json/json_file_value_serializer.h" |
| 15 #include "base/json/json_reader.h" |
15 #include "base/json/json_string_value_serializer.h" | 16 #include "base/json/json_string_value_serializer.h" |
16 #include "base/metrics/histogram_macros.h" | 17 #include "base/metrics/histogram_macros.h" |
17 #include "base/sequenced_task_runner.h" | 18 #include "base/sequenced_task_runner.h" |
18 #include "base/time/time.h" | 19 #include "base/time/time.h" |
19 #include "components/bookmarks/browser/bookmark_codec.h" | 20 #include "components/bookmarks/browser/bookmark_codec.h" |
20 #include "components/bookmarks/browser/bookmark_index.h" | 21 #include "components/bookmarks/browser/bookmark_index.h" |
21 #include "components/bookmarks/browser/bookmark_model.h" | 22 #include "components/bookmarks/browser/bookmark_model.h" |
22 #include "components/bookmarks/common/bookmark_constants.h" | 23 #include "components/bookmarks/common/bookmark_constants.h" |
23 | 24 |
24 using base::TimeTicks; | 25 using base::TimeTicks; |
(...skipping 25 matching lines...) Expand all Loading... |
50 } | 51 } |
51 } | 52 } |
52 | 53 |
53 void LoadCallback(const base::FilePath& path, | 54 void LoadCallback(const base::FilePath& path, |
54 const base::WeakPtr<BookmarkStorage>& storage, | 55 const base::WeakPtr<BookmarkStorage>& storage, |
55 std::unique_ptr<BookmarkLoadDetails> details, | 56 std::unique_ptr<BookmarkLoadDetails> details, |
56 base::SequencedTaskRunner* task_runner) { | 57 base::SequencedTaskRunner* task_runner) { |
57 bool load_index = false; | 58 bool load_index = false; |
58 bool bookmark_file_exists = base::PathExists(path); | 59 bool bookmark_file_exists = base::PathExists(path); |
59 if (bookmark_file_exists) { | 60 if (bookmark_file_exists) { |
60 JSONFileValueDeserializer deserializer(path); | 61 // Titles may end up containing invalid utf and we shouldn't throw away |
| 62 // all bookmarks if some titles have invalid utf. |
| 63 JSONFileValueDeserializer deserializer( |
| 64 path, base::JSON_REPLACE_INVALID_CHARACTERS); |
61 std::unique_ptr<base::Value> root = deserializer.Deserialize(NULL, NULL); | 65 std::unique_ptr<base::Value> root = deserializer.Deserialize(NULL, NULL); |
62 | 66 |
63 if (root.get()) { | 67 if (root.get()) { |
64 // Building the index can take a while, so we do it on the background | 68 // Building the index can take a while, so we do it on the background |
65 // thread. | 69 // thread. |
66 int64_t max_node_id = 0; | 70 int64_t max_node_id = 0; |
67 BookmarkCodec codec; | 71 BookmarkCodec codec; |
68 TimeTicks start_time = TimeTicks::Now(); | 72 TimeTicks start_time = TimeTicks::Now(); |
69 codec.Decode(details->bb_node(), details->other_folder_node(), | 73 codec.Decode(details->bb_node(), details->other_folder_node(), |
70 details->mobile_folder_node(), &max_node_id, *root.get()); | 74 details->mobile_folder_node(), &max_node_id, *root.get()); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 } | 229 } |
226 | 230 |
227 std::unique_ptr<std::string> data(new std::string); | 231 std::unique_ptr<std::string> data(new std::string); |
228 if (!SerializeData(data.get())) | 232 if (!SerializeData(data.get())) |
229 return false; | 233 return false; |
230 writer_.WriteNow(std::move(data)); | 234 writer_.WriteNow(std::move(data)); |
231 return true; | 235 return true; |
232 } | 236 } |
233 | 237 |
234 } // namespace bookmarks | 238 } // namespace bookmarks |
OLD | NEW |