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

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: Address mirandac's comments: add BookmarkModel::StartLoading Created 7 years, 9 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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 244
244 expanded_state_tracker_.reset(new BookmarkExpandedStateTracker( 245 expanded_state_tracker_.reset(new BookmarkExpandedStateTracker(
245 profile_, this)); 246 profile_, this));
246 247
247 // Listen for changes to favicons so that we can update the favicon of the 248 // Listen for changes to favicons so that we can update the favicon of the
248 // node appropriately. 249 // node appropriately.
249 registrar_.Add(this, chrome::NOTIFICATION_FAVICON_CHANGED, 250 registrar_.Add(this, chrome::NOTIFICATION_FAVICON_CHANGED,
250 content::Source<Profile>(profile_)); 251 content::Source<Profile>(profile_));
251 252
252 // Load the bookmarks. BookmarkStorage notifies us when done. 253 // Load the bookmarks. BookmarkStorage notifies us when done.
253 store_ = new BookmarkStorage(profile_, this, profile_->GetIOTaskRunner()); 254 store_ = new BookmarkStorage(profile_, this, GetBookmarkTaskRunner());
254 store_->LoadBookmarks(CreateLoadDetails()); 255 store_->LoadBookmarks(CreateLoadDetails());
255 } 256 }
256 257
258 void BookmarkModel::StartLoading() {
259 GetBookmarkTaskRunner()->Start();
260 }
261
257 bool BookmarkModel::IsLoaded() const { 262 bool BookmarkModel::IsLoaded() const {
258 return loaded_; 263 return loaded_;
259 } 264 }
260 265
261 const BookmarkNode* BookmarkModel::GetParentForNewNodes() { 266 const BookmarkNode* BookmarkModel::GetParentForNewNodes() {
262 std::vector<const BookmarkNode*> nodes = 267 std::vector<const BookmarkNode*> nodes =
263 bookmark_utils::GetMostRecentlyModifiedFolders(this, 1); 268 bookmark_utils::GetMostRecentlyModifiedFolders(this, 1);
264 DCHECK(!nodes.empty()); // This list is always padded with default folders. 269 DCHECK(!nodes.empty()); // This list is always padded with default folders.
265 return nodes[0]; 270 return nodes[0];
266 } 271 }
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 BookmarkPermanentNode* bb_node = 959 BookmarkPermanentNode* bb_node =
955 CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); 960 CreatePermanentNode(BookmarkNode::BOOKMARK_BAR);
956 BookmarkPermanentNode* other_node = 961 BookmarkPermanentNode* other_node =
957 CreatePermanentNode(BookmarkNode::OTHER_NODE); 962 CreatePermanentNode(BookmarkNode::OTHER_NODE);
958 BookmarkPermanentNode* mobile_node = 963 BookmarkPermanentNode* mobile_node =
959 CreatePermanentNode(BookmarkNode::MOBILE); 964 CreatePermanentNode(BookmarkNode::MOBILE);
960 return new BookmarkLoadDetails(bb_node, other_node, mobile_node, 965 return new BookmarkLoadDetails(bb_node, other_node, mobile_node,
961 new BookmarkIndex(profile_), 966 new BookmarkIndex(profile_),
962 next_node_id_); 967 next_node_id_);
963 } 968 }
969
970 scoped_refptr<base::DeferredSequencedTaskRunner>
971 BookmarkModel::GetBookmarkTaskRunner() {
972 if (!bookmark_task_runner_) {
973 bookmark_task_runner_ =
974 new base::DeferredSequencedTaskRunner(profile_->GetIOTaskRunner());
tfarina 2013/03/28 22:57:01 Can we do something similar to |blocking_task_runn
msarda 2013/03/29 14:40:03 I think so. We should probably have a similar star
975 }
976 return bookmark_task_runner_;
977 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698