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

Unified Diff: chrome/browser/bookmarks/chrome_bookmark_client.cc

Issue 306293006: Introduce ChromeBookmarkClientFactory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@364865
Patch Set: Add missing dependency in components/policy/policy_browser.gypi 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/bookmarks/chrome_bookmark_client.cc
diff --git a/chrome/browser/bookmarks/chrome_bookmark_client.cc b/chrome/browser/bookmarks/chrome_bookmark_client.cc
index a3b8db7c6cadd8d3b7f4cd10081f41cd16a34bbb..bd8453cd1782348a180b43f1f3c70f905c874a97 100644
--- a/chrome/browser/bookmarks/chrome_bookmark_client.cc
+++ b/chrome/browser/bookmarks/chrome_bookmark_client.cc
@@ -42,16 +42,25 @@ void NotifyHistoryOfRemovedURLs(Profile* profile,
} // namespace
-ChromeBookmarkClient::ChromeBookmarkClient(Profile* profile, bool index_urls)
- : profile_(profile),
- model_(new BookmarkModel(this, index_urls)),
- managed_bookmarks_tracker_(
- model_.get(),
- profile_->GetPrefs(),
- base::Bind(&ChromeBookmarkClient::GetManagedBookmarksDomain,
- base::Unretained(this))),
- managed_node_(NULL) {
+ChromeBookmarkClient::ChromeBookmarkClient(Profile* profile)
+ : profile_(profile), model_(NULL) {
+}
+
+ChromeBookmarkClient::~ChromeBookmarkClient() {
+}
+
+void ChromeBookmarkClient::Init(BookmarkModel* model) {
+ DCHECK(model);
+ DCHECK(!model_);
+ model_ = model;
model_->AddObserver(this);
+
+ managed_bookmarks_tracker_.reset(new policy::ManagedBookmarksTracker(
+ model_,
+ profile_->GetPrefs(),
+ base::Bind(&ChromeBookmarkClient::GetManagedBookmarksDomain,
+ base::Unretained(this))));
+
// Listen for changes to favicons so that we can update the favicon of the
// node appropriately.
registrar_.Add(this,
@@ -59,10 +68,14 @@ ChromeBookmarkClient::ChromeBookmarkClient(Profile* profile, bool index_urls)
content::Source<Profile>(profile_));
}
-ChromeBookmarkClient::~ChromeBookmarkClient() {
- model_->RemoveObserver(this);
+void ChromeBookmarkClient::Shutdown() {
+ if (model_) {
+ registrar_.RemoveAll();
- registrar_.RemoveAll();
+ model_->RemoveObserver(this);
+ model_ = NULL;
+ }
+ BookmarkClient::Shutdown();
}
bool ChromeBookmarkClient::IsDescendantOfManagedNode(const BookmarkNode* node) {
@@ -157,7 +170,7 @@ bookmarks::LoadExtraCallback ChromeBookmarkClient::GetLoadExtraNodesCallback() {
StartupTaskRunnerServiceFactory::GetForProfile(profile_)
->GetBookmarkTaskRunner(),
managed_node_,
- base::Passed(managed_bookmarks_tracker_.GetInitialManagedBookmarks()));
+ base::Passed(managed_bookmarks_tracker_->GetInitialManagedBookmarks()));
}
bool ChromeBookmarkClient::CanSetPermanentNodeTitle(
@@ -193,10 +206,6 @@ void ChromeBookmarkClient::Observe(
}
}
-void ChromeBookmarkClient::Shutdown() {
- model_->Shutdown();
-}
-
void ChromeBookmarkClient::BookmarkModelChanged() {
}
@@ -220,7 +229,7 @@ void ChromeBookmarkClient::BookmarkModelLoaded(BookmarkModel* model,
// Start tracking the managed bookmarks. This will detect any changes that
// may have occurred while the initial managed bookmarks were being loaded
// on the background.
- managed_bookmarks_tracker_.Init(managed_node_);
+ managed_bookmarks_tracker_->Init(managed_node_);
}
// static
« no previous file with comments | « chrome/browser/bookmarks/chrome_bookmark_client.h ('k') | chrome/browser/bookmarks/chrome_bookmark_client_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698