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

Side by Side Diff: chrome/browser/bookmarks/bookmark_model.cc

Issue 12952005: Delay bookmarks load while the profile is loading. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix nits. Created 7 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/bookmarks/bookmark_model.h" 5 #include "chrome/browser/bookmarks/bookmark_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/deferred_sequenced_task_runner.h"
12 #include "base/json/json_string_value_serializer.h" 13 #include "base/json/json_string_value_serializer.h"
13 #include "base/sequenced_task_runner.h" 14 #include "base/sequenced_task_runner.h"
14 #include "base/string_util.h" 15 #include "base/string_util.h"
15 #include "base/values.h" 16 #include "base/values.h"
16 #include "build/build_config.h" 17 #include "build/build_config.h"
17 #include "chrome/browser/bookmarks/bookmark_expanded_state_tracker.h" 18 #include "chrome/browser/bookmarks/bookmark_expanded_state_tracker.h"
18 #include "chrome/browser/bookmarks/bookmark_index.h" 19 #include "chrome/browser/bookmarks/bookmark_index.h"
19 #include "chrome/browser/bookmarks/bookmark_model_observer.h" 20 #include "chrome/browser/bookmarks/bookmark_model_observer.h"
20 #include "chrome/browser/bookmarks/bookmark_storage.h" 21 #include "chrome/browser/bookmarks/bookmark_storage.h"
21 #include "chrome/browser/bookmarks/bookmark_utils.h" 22 #include "chrome/browser/bookmarks/bookmark_utils.h"
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 227
227 void BookmarkModel::Shutdown() { 228 void BookmarkModel::Shutdown() {
228 if (loaded_) 229 if (loaded_)
229 return; 230 return;
230 231
231 // See comment in HistoryService::ShutdownOnUIThread where this is invoked for 232 // See comment in HistoryService::ShutdownOnUIThread where this is invoked for
232 // details. It is also called when the BookmarkModel is deleted. 233 // details. It is also called when the BookmarkModel is deleted.
233 loaded_signal_.Signal(); 234 loaded_signal_.Signal();
234 } 235 }
235 236
237 scoped_refptr<base::DeferredSequencedTaskRunner>
238 BookmarkModel::GetBookmarkTaskRunner() {
239 if (!bookmark_task_runner_) {
240 bookmark_task_runner_ =
241 new base::DeferredSequencedTaskRunner(profile_->GetIOTaskRunner());
242 }
243 return bookmark_task_runner_;
244 }
245
236 void BookmarkModel::Load() { 246 void BookmarkModel::Load() {
237 if (store_.get()) { 247 if (store_.get()) {
238 // If the store is non-null, it means Load was already invoked. Load should 248 // If the store is non-null, it means Load was already invoked. Load should
239 // only be invoked once. 249 // only be invoked once.
240 NOTREACHED(); 250 NOTREACHED();
241 return; 251 return;
242 } 252 }
243 253
244 expanded_state_tracker_.reset(new BookmarkExpandedStateTracker( 254 expanded_state_tracker_.reset(new BookmarkExpandedStateTracker(
245 profile_, this)); 255 profile_, this));
246 256
247 // Listen for changes to favicons so that we can update the favicon of the 257 // Listen for changes to favicons so that we can update the favicon of the
248 // node appropriately. 258 // node appropriately.
249 registrar_.Add(this, chrome::NOTIFICATION_FAVICON_CHANGED, 259 registrar_.Add(this, chrome::NOTIFICATION_FAVICON_CHANGED,
250 content::Source<Profile>(profile_)); 260 content::Source<Profile>(profile_));
251 261
252 // Load the bookmarks. BookmarkStorage notifies us when done. 262 // Load the bookmarks. BookmarkStorage notifies us when done.
253 store_ = new BookmarkStorage(profile_, this, profile_->GetIOTaskRunner()); 263 store_ = new BookmarkStorage(profile_, this, GetBookmarkTaskRunner());
254 store_->LoadBookmarks(CreateLoadDetails()); 264 store_->LoadBookmarks(CreateLoadDetails());
255 } 265 }
256 266
257 bool BookmarkModel::IsLoaded() const { 267 bool BookmarkModel::IsLoaded() const {
258 return loaded_; 268 return loaded_;
259 } 269 }
260 270
261 const BookmarkNode* BookmarkModel::GetParentForNewNodes() { 271 const BookmarkNode* BookmarkModel::GetParentForNewNodes() {
262 std::vector<const BookmarkNode*> nodes = 272 std::vector<const BookmarkNode*> nodes =
263 bookmark_utils::GetMostRecentlyModifiedFolders(this, 1); 273 bookmark_utils::GetMostRecentlyModifiedFolders(this, 1);
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 BookmarkPermanentNode* bb_node = 964 BookmarkPermanentNode* bb_node =
955 CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); 965 CreatePermanentNode(BookmarkNode::BOOKMARK_BAR);
956 BookmarkPermanentNode* other_node = 966 BookmarkPermanentNode* other_node =
957 CreatePermanentNode(BookmarkNode::OTHER_NODE); 967 CreatePermanentNode(BookmarkNode::OTHER_NODE);
958 BookmarkPermanentNode* mobile_node = 968 BookmarkPermanentNode* mobile_node =
959 CreatePermanentNode(BookmarkNode::MOBILE); 969 CreatePermanentNode(BookmarkNode::MOBILE);
960 return new BookmarkLoadDetails(bb_node, other_node, mobile_node, 970 return new BookmarkLoadDetails(bb_node, other_node, mobile_node,
961 new BookmarkIndex(profile_), 971 new BookmarkIndex(profile_),
962 next_node_id_); 972 next_node_id_);
963 } 973 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698