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

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

Issue 305973004: BookmarkClient can add extra nodes to BookmarkModel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: renamed methods Created 6 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 | Annotate | Revision Log
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/json/json_file_value_serializer.h" 10 #include "base/json/json_file_value_serializer.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 AddBookmarksToIndex(details, node->GetChild(i)); 46 AddBookmarksToIndex(details, node->GetChild(i));
47 } 47 }
48 } 48 }
49 49
50 void LoadCallback(const base::FilePath& path, 50 void LoadCallback(const base::FilePath& path,
51 BookmarkStorage* storage, 51 BookmarkStorage* storage,
52 BookmarkLoadDetails* details, 52 BookmarkLoadDetails* details,
53 base::SequencedTaskRunner* task_runner) { 53 base::SequencedTaskRunner* task_runner) {
54 startup_metric_utils::ScopedSlowStartupUMA 54 startup_metric_utils::ScopedSlowStartupUMA
55 scoped_timer("Startup.SlowStartupBookmarksLoad"); 55 scoped_timer("Startup.SlowStartupBookmarksLoad");
56 bool load_index = false;
56 bool bookmark_file_exists = base::PathExists(path); 57 bool bookmark_file_exists = base::PathExists(path);
57 if (bookmark_file_exists) { 58 if (bookmark_file_exists) {
58 JSONFileValueSerializer serializer(path); 59 JSONFileValueSerializer serializer(path);
59 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, NULL)); 60 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, NULL));
60 61
61 if (root.get()) { 62 if (root.get()) {
62 // Building the index can take a while, so we do it on the background 63 // Building the index can take a while, so we do it on the background
63 // thread. 64 // thread.
64 int64 max_node_id = 0; 65 int64 max_node_id = 0;
65 BookmarkCodec codec; 66 BookmarkCodec codec;
66 TimeTicks start_time = TimeTicks::Now(); 67 TimeTicks start_time = TimeTicks::Now();
67 codec.Decode(details->bb_node(), details->other_folder_node(), 68 codec.Decode(details->bb_node(), details->other_folder_node(),
68 details->mobile_folder_node(), &max_node_id, *root.get()); 69 details->mobile_folder_node(), &max_node_id, *root.get());
69 details->set_max_id(std::max(max_node_id, details->max_id())); 70 details->set_max_id(std::max(max_node_id, details->max_id()));
70 details->set_computed_checksum(codec.computed_checksum()); 71 details->set_computed_checksum(codec.computed_checksum());
71 details->set_stored_checksum(codec.stored_checksum()); 72 details->set_stored_checksum(codec.stored_checksum());
72 details->set_ids_reassigned(codec.ids_reassigned()); 73 details->set_ids_reassigned(codec.ids_reassigned());
73 details->set_model_meta_info_map(codec.model_meta_info_map()); 74 details->set_model_meta_info_map(codec.model_meta_info_map());
74 details->set_model_sync_transaction_version( 75 details->set_model_sync_transaction_version(
75 codec.model_sync_transaction_version()); 76 codec.model_sync_transaction_version());
76 UMA_HISTOGRAM_TIMES("Bookmarks.DecodeTime", 77 UMA_HISTOGRAM_TIMES("Bookmarks.DecodeTime",
77 TimeTicks::Now() - start_time); 78 TimeTicks::Now() - start_time);
78 79
79 start_time = TimeTicks::Now(); 80 load_index = true;
80 AddBookmarksToIndex(details, details->bb_node());
81 AddBookmarksToIndex(details, details->other_folder_node());
82 AddBookmarksToIndex(details, details->mobile_folder_node());
83 UMA_HISTOGRAM_TIMES("Bookmarks.CreateBookmarkIndexTime",
84 TimeTicks::Now() - start_time);
85 } 81 }
86 } 82 }
87 83
84 // Load any extra root nodes now, after the IDs have been potentially
85 // reassigned.
86 details->LoadExtraNodes();
87
88 // Load the index if there are any bookmarks in the extra nodes.
89 const BookmarkPermanentNodeList& extra_nodes = details->extra_nodes();
90 for (size_t i = 0; i < extra_nodes.size(); ++i) {
91 if (!extra_nodes[i]->empty()) {
92 load_index = true;
93 break;
94 }
95 }
96
97 if (load_index) {
98 TimeTicks start_time = TimeTicks::Now();
99 AddBookmarksToIndex(details, details->bb_node());
100 AddBookmarksToIndex(details, details->other_folder_node());
101 AddBookmarksToIndex(details, details->mobile_folder_node());
102 for (size_t i = 0; i < extra_nodes.size(); ++i)
103 AddBookmarksToIndex(details, extra_nodes[i]);
104 UMA_HISTOGRAM_TIMES("Bookmarks.CreateBookmarkIndexTime",
105 TimeTicks::Now() - start_time);
106 }
107
88 task_runner->PostTask(FROM_HERE, 108 task_runner->PostTask(FROM_HERE,
89 base::Bind(&BookmarkStorage::OnLoadFinished, storage)); 109 base::Bind(&BookmarkStorage::OnLoadFinished, storage));
90 } 110 }
91 111
92 } // namespace 112 } // namespace
93 113
94 // BookmarkLoadDetails --------------------------------------------------------- 114 // BookmarkLoadDetails ---------------------------------------------------------
95 115
96 BookmarkLoadDetails::BookmarkLoadDetails( 116 BookmarkLoadDetails::BookmarkLoadDetails(
97 BookmarkPermanentNode* bb_node, 117 BookmarkPermanentNode* bb_node,
98 BookmarkPermanentNode* other_folder_node, 118 BookmarkPermanentNode* other_folder_node,
99 BookmarkPermanentNode* mobile_folder_node, 119 BookmarkPermanentNode* mobile_folder_node,
120 const LoadExtraCallback& load_extra_callback,
100 BookmarkIndex* index, 121 BookmarkIndex* index,
101 int64 max_id) 122 int64 max_id)
102 : bb_node_(bb_node), 123 : bb_node_(bb_node),
103 other_folder_node_(other_folder_node), 124 other_folder_node_(other_folder_node),
104 mobile_folder_node_(mobile_folder_node), 125 mobile_folder_node_(mobile_folder_node),
126 load_extra_callback_(load_extra_callback),
105 index_(index), 127 index_(index),
106 model_sync_transaction_version_( 128 model_sync_transaction_version_(
107 BookmarkNode::kInvalidSyncTransactionVersion), 129 BookmarkNode::kInvalidSyncTransactionVersion),
108 max_id_(max_id), 130 max_id_(max_id),
109 ids_reassigned_(false) { 131 ids_reassigned_(false) {
110 } 132 }
111 133
112 BookmarkLoadDetails::~BookmarkLoadDetails() { 134 BookmarkLoadDetails::~BookmarkLoadDetails() {
113 } 135 }
114 136
137 void BookmarkLoadDetails::LoadExtraNodes() {
138 extra_nodes_ = load_extra_callback_.Run(&max_id_);
139 }
140
115 // BookmarkStorage ------------------------------------------------------------- 141 // BookmarkStorage -------------------------------------------------------------
116 142
117 BookmarkStorage::BookmarkStorage( 143 BookmarkStorage::BookmarkStorage(
118 BookmarkModel* model, 144 BookmarkModel* model,
119 const base::FilePath& profile_path, 145 const base::FilePath& profile_path,
120 base::SequencedTaskRunner* sequenced_task_runner) 146 base::SequencedTaskRunner* sequenced_task_runner)
121 : model_(model), 147 : model_(model),
122 writer_(profile_path.Append(bookmarks::kBookmarksFileName), 148 writer_(profile_path.Append(bookmarks::kBookmarksFileName),
123 sequenced_task_runner) { 149 sequenced_task_runner) {
124 sequenced_task_runner_ = sequenced_task_runner; 150 sequenced_task_runner_ = sequenced_task_runner;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 } 208 }
183 209
184 std::string data; 210 std::string data;
185 if (!SerializeData(&data)) 211 if (!SerializeData(&data))
186 return false; 212 return false;
187 writer_.WriteNow(data); 213 writer_.WriteNow(data);
188 return true; 214 return true;
189 } 215 }
190 216
191 } // namespace bookmarks 217 } // namespace bookmarks
OLDNEW
« no previous file with comments | « components/bookmarks/browser/bookmark_storage.h ('k') | components/bookmarks/test/test_bookmark_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698