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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_bridge.h"
8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h"
11 #include "chrome/common/pref_names.h"
12 #include "components/bookmarks/browser/bookmark_model.h"
14 using bookmarks::BookmarkModel;
15 using bookmarks::BookmarkNode;
17 BookmarkBarBridge::BookmarkBarBridge(Profile* profile,
18 BookmarkBarController* controller,
20 : controller_(controller),
23 model_->AddObserver(this);
25 // Bookmark loading is async; it may may not have happened yet.
26 // We will be notified when that happens with the AddObserver() call.
28 BookmarkModelLoaded(model, false);
30 profile_pref_registrar_.Init(profile->GetPrefs());
31 profile_pref_registrar_.Add(
32 bookmarks::prefs::kShowAppsShortcutInBookmarkBar,
33 base::Bind(&BookmarkBarBridge::OnExtraButtonsVisibilityChanged,
34 base::Unretained(this)));
35 profile_pref_registrar_.Add(
36 bookmarks::prefs::kShowManagedBookmarksInBookmarkBar,
37 base::Bind(&BookmarkBarBridge::OnExtraButtonsVisibilityChanged,
38 base::Unretained(this)));
40 OnExtraButtonsVisibilityChanged();
43 BookmarkBarBridge::~BookmarkBarBridge() {
45 model_->RemoveObserver(this);
48 void BookmarkBarBridge::BookmarkModelLoaded(BookmarkModel* model,
49 bool ids_reassigned) {
50 [controller_ loaded:model];
53 void BookmarkBarBridge::BookmarkModelBeingDeleted(BookmarkModel* model) {
54 [controller_ beingDeleted:model];
55 model_->RemoveObserver(this);
59 void BookmarkBarBridge::BookmarkNodeMoved(BookmarkModel* model,
60 const BookmarkNode* old_parent,
62 const BookmarkNode* new_parent,
65 [controller_ nodeMoved:model
66 oldParent:old_parent oldIndex:old_index
67 newParent:new_parent newIndex:new_index];
71 void BookmarkBarBridge::BookmarkNodeAdded(BookmarkModel* model,
72 const BookmarkNode* parent,
75 [controller_ nodeAdded:model parent:parent index:index];
78 void BookmarkBarBridge::BookmarkNodeRemoved(
80 const BookmarkNode* parent,
82 const BookmarkNode* node,
83 const std::set<GURL>& removed_urls) {
85 [controller_ nodeRemoved:model parent:parent index:old_index];
88 void BookmarkBarBridge::BookmarkAllUserNodesRemoved(
90 const std::set<GURL>& removed_urls) {
91 [controller_ loaded:model];
94 void BookmarkBarBridge::BookmarkNodeChanged(BookmarkModel* model,
95 const BookmarkNode* node) {
97 [controller_ nodeChanged:model node:node];
100 void BookmarkBarBridge::BookmarkNodeFaviconChanged(BookmarkModel* model,
101 const BookmarkNode* node) {
103 [controller_ nodeFaviconLoaded:model node:node];
106 void BookmarkBarBridge::BookmarkNodeChildrenReordered(
107 BookmarkModel* model, const BookmarkNode* node) {
109 [controller_ nodeChildrenReordered:model node:node];
112 void BookmarkBarBridge::ExtensiveBookmarkChangesBeginning(
113 BookmarkModel* model) {
117 void BookmarkBarBridge::ExtensiveBookmarkChangesEnded(BookmarkModel* model) {
119 [controller_ loaded:model];
122 void BookmarkBarBridge::OnExtraButtonsVisibilityChanged() {
123 [controller_ updateExtraButtonsVisibility];