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_reader.h" |
16 #include "base/json/json_string_value_serializer.h" | 16 #include "base/json/json_string_value_serializer.h" |
17 #include "base/metrics/histogram_macros.h" | 17 #include "base/metrics/histogram_macros.h" |
18 #include "base/sequenced_task_runner.h" | 18 #include "base/sequenced_task_runner.h" |
19 #include "base/sys_info.h" | |
19 #include "base/time/time.h" | 20 #include "base/time/time.h" |
20 #include "components/bookmarks/browser/bookmark_codec.h" | 21 #include "components/bookmarks/browser/bookmark_codec.h" |
21 #include "components/bookmarks/browser/bookmark_model.h" | 22 #include "components/bookmarks/browser/bookmark_model.h" |
22 #include "components/bookmarks/browser/titled_url_index.h" | 23 #include "components/bookmarks/browser/titled_url_index.h" |
23 #include "components/bookmarks/common/bookmark_constants.h" | 24 #include "components/bookmarks/common/bookmark_constants.h" |
24 | 25 |
25 using base::TimeTicks; | 26 using base::TimeTicks; |
26 | 27 |
27 namespace bookmarks { | 28 namespace bookmarks { |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 // Extension used for backup files (copy of main file created during startup). | 32 // Extension used for backup files (copy of main file created during startup). |
32 const base::FilePath::CharType kBackupExtension[] = FILE_PATH_LITERAL("bak"); | 33 const base::FilePath::CharType kBackupExtension[] = FILE_PATH_LITERAL("bak"); |
33 | 34 |
34 // How often we save. | 35 // How often we save. |
35 const int kSaveDelayMS = 2500; | 36 const int kSaveDelayMS = 2500; |
36 | 37 |
38 // Optional keys present in MetaInfo maps in bookmark nodes to load in memory. | |
39 const char* const kOptionalMetakeys[] = {"imageData", "pageData"}; | |
40 | |
37 void BackupCallback(const base::FilePath& path) { | 41 void BackupCallback(const base::FilePath& path) { |
38 base::FilePath backup_path = path.ReplaceExtension(kBackupExtension); | 42 base::FilePath backup_path = path.ReplaceExtension(kBackupExtension); |
39 base::CopyFile(path, backup_path); | 43 base::CopyFile(path, backup_path); |
40 } | 44 } |
41 | 45 |
42 // Adds node to the model's index, recursing through all children as well. | 46 // Adds node to the model's index, recursing through all children as well. |
43 void AddBookmarksToIndex(BookmarkLoadDetails* details, | 47 void AddBookmarksToIndex(BookmarkLoadDetails* details, |
44 BookmarkNode* node) { | 48 BookmarkNode* node) { |
45 if (node->is_url()) { | 49 if (node->is_url()) { |
46 if (node->url().is_valid()) | 50 if (node->url().is_valid()) |
(...skipping 15 matching lines...) Expand all Loading... | |
62 // all bookmarks if some titles have invalid utf. | 66 // all bookmarks if some titles have invalid utf. |
63 JSONFileValueDeserializer deserializer( | 67 JSONFileValueDeserializer deserializer( |
64 path, base::JSON_REPLACE_INVALID_CHARACTERS); | 68 path, base::JSON_REPLACE_INVALID_CHARACTERS); |
65 std::unique_ptr<base::Value> root = deserializer.Deserialize(NULL, NULL); | 69 std::unique_ptr<base::Value> root = deserializer.Deserialize(NULL, NULL); |
66 | 70 |
67 if (root.get()) { | 71 if (root.get()) { |
68 // Building the index can take a while, so we do it on the background | 72 // Building the index can take a while, so we do it on the background |
69 // thread. | 73 // thread. |
70 int64_t max_node_id = 0; | 74 int64_t max_node_id = 0; |
71 BookmarkCodec codec; | 75 BookmarkCodec codec; |
76 // Do not load the image and page data into memory for low-end devices. | |
77 if (base::SysInfo::IsLowEndDevice()) { | |
sky
2017/05/25 02:54:03
What I was getting at with my earlier comment is t
ssid
2017/05/26 01:45:40
I think I have made changes as you suggested.
| |
78 std::list<const char*> optional_keys(std::begin(kOptionalMetakeys), | |
79 std::end(kOptionalMetakeys)); | |
80 codec.set_excluded_meta_info_keys(optional_keys); | |
81 } | |
82 | |
72 TimeTicks start_time = TimeTicks::Now(); | 83 TimeTicks start_time = TimeTicks::Now(); |
73 codec.Decode(details->bb_node(), details->other_folder_node(), | 84 codec.Decode(details->bb_node(), details->other_folder_node(), |
74 details->mobile_folder_node(), &max_node_id, *root.get()); | 85 details->mobile_folder_node(), &max_node_id, *root.get()); |
75 details->set_max_id(std::max(max_node_id, details->max_id())); | 86 details->set_max_id(std::max(max_node_id, details->max_id())); |
76 details->set_computed_checksum(codec.computed_checksum()); | 87 details->set_computed_checksum(codec.computed_checksum()); |
77 details->set_stored_checksum(codec.stored_checksum()); | 88 details->set_stored_checksum(codec.stored_checksum()); |
78 details->set_ids_reassigned(codec.ids_reassigned()); | 89 details->set_ids_reassigned(codec.ids_reassigned()); |
79 details->set_model_meta_info_map(codec.model_meta_info_map()); | 90 details->set_model_meta_info_map(codec.model_meta_info_map()); |
80 details->set_model_sync_transaction_version( | 91 details->set_model_sync_transaction_version( |
81 codec.model_sync_transaction_version()); | 92 codec.model_sync_transaction_version()); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 } | 240 } |
230 | 241 |
231 std::unique_ptr<std::string> data(new std::string); | 242 std::unique_ptr<std::string> data(new std::string); |
232 if (!SerializeData(data.get())) | 243 if (!SerializeData(data.get())) |
233 return false; | 244 return false; |
234 writer_.WriteNow(std::move(data)); | 245 writer_.WriteNow(std::move(data)); |
235 return true; | 246 return true; |
236 } | 247 } |
237 | 248 |
238 } // namespace bookmarks | 249 } // namespace bookmarks |
OLD | NEW |