Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: components/bookmarks/browser/bookmark_storage.cc

Issue 2883523002: Reduce the memory usage of bookmarks storage (Closed)
Patch Set: remove client interface Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 16 matching lines...) Expand all
27 namespace bookmarks { 27 namespace bookmarks {
28 28
29 namespace { 29 namespace {
30 30
31 // Extension used for backup files (copy of main file created during startup). 31 // Extension used for backup files (copy of main file created during startup).
32 const base::FilePath::CharType kBackupExtension[] = FILE_PATH_LITERAL("bak"); 32 const base::FilePath::CharType kBackupExtension[] = FILE_PATH_LITERAL("bak");
33 33
34 // How often we save. 34 // How often we save.
35 const int kSaveDelayMS = 2500; 35 const int kSaveDelayMS = 2500;
36 36
37 // Keys in meta info of bookmark node that should be excluded after removing
38 // enhanced bookmarks feature crrev.com/1638413003.
39 const char* const kExcludedMetaInfoKeys[] = {"stars."};
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
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 std::vector<std::string> excluded_keys;
77 excluded_keys.insert(excluded_keys.end(),
78 std::begin(kExcludedMetaInfoKeys),
79 std::end(kExcludedMetaInfoKeys));
80 codec.set_excluded_meta_info_keys(excluded_keys);
81
72 TimeTicks start_time = TimeTicks::Now(); 82 TimeTicks start_time = TimeTicks::Now();
73 codec.Decode(details->bb_node(), details->other_folder_node(), 83 codec.Decode(details->bb_node(), details->other_folder_node(),
74 details->mobile_folder_node(), &max_node_id, *root.get()); 84 details->mobile_folder_node(), &max_node_id, *root.get());
75 details->set_max_id(std::max(max_node_id, details->max_id())); 85 details->set_max_id(std::max(max_node_id, details->max_id()));
76 details->set_computed_checksum(codec.computed_checksum()); 86 details->set_computed_checksum(codec.computed_checksum());
77 details->set_stored_checksum(codec.stored_checksum()); 87 details->set_stored_checksum(codec.stored_checksum());
78 details->set_ids_reassigned(codec.ids_reassigned()); 88 details->set_ids_reassigned(codec.ids_reassigned());
79 details->set_model_meta_info_map(codec.model_meta_info_map()); 89 details->set_model_meta_info_map(codec.model_meta_info_map());
80 details->set_model_sync_transaction_version( 90 details->set_model_sync_transaction_version(
81 codec.model_sync_transaction_version()); 91 codec.model_sync_transaction_version());
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 } 239 }
230 240
231 std::unique_ptr<std::string> data(new std::string); 241 std::unique_ptr<std::string> data(new std::string);
232 if (!SerializeData(data.get())) 242 if (!SerializeData(data.get()))
233 return false; 243 return false;
234 writer_.WriteNow(std::move(data)); 244 writer_.WriteNow(std::move(data));
235 return true; 245 return true;
236 } 246 }
237 247
238 } // namespace bookmarks 248 } // namespace bookmarks
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698