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"
15 BookmarkBarBridge::BookmarkBarBridge(Profile* profile,
16 BookmarkBarController* controller,
18 : controller_(controller),
21 model_->AddObserver(this);
23 // Bookmark loading is async; it may may not have happened yet.
24 // We will be notified when that happens with the AddObserver() call.
26 BookmarkModelLoaded(model, false);
28 profile_pref_registrar_.Init(profile->GetPrefs());
29 profile_pref_registrar_.Add(
30 prefs::kShowAppsShortcutInBookmarkBar,
31 base::Bind(&BookmarkBarBridge::OnAppsPageShortcutVisibilityPrefChanged,
32 base::Unretained(this)));
34 [controller_ updateAppsPageShortcutButtonVisibility];
37 BookmarkBarBridge::~BookmarkBarBridge() {
38 model_->RemoveObserver(this);
41 void BookmarkBarBridge::BookmarkModelLoaded(BookmarkModel* model,
42 bool ids_reassigned) {
43 [controller_ loaded:model];
46 void BookmarkBarBridge::BookmarkModelBeingDeleted(BookmarkModel* model) {
47 [controller_ beingDeleted:model];
50 void BookmarkBarBridge::BookmarkNodeMoved(BookmarkModel* model,
51 const BookmarkNode* old_parent,
53 const BookmarkNode* new_parent,
56 [controller_ nodeMoved:model
57 oldParent:old_parent oldIndex:old_index
58 newParent:new_parent newIndex:new_index];
62 void BookmarkBarBridge::BookmarkNodeAdded(BookmarkModel* model,
63 const BookmarkNode* parent,
66 [controller_ nodeAdded:model parent:parent index:index];
69 void BookmarkBarBridge::BookmarkNodeRemoved(
71 const BookmarkNode* parent,
73 const BookmarkNode* node,
74 const std::set<GURL>& removed_urls) {
76 [controller_ nodeRemoved:model parent:parent index:old_index];
79 void BookmarkBarBridge::BookmarkAllNodesRemoved(
81 const std::set<GURL>& removed_urls) {
82 [controller_ loaded:model];
85 void BookmarkBarBridge::BookmarkNodeChanged(BookmarkModel* model,
86 const BookmarkNode* node) {
88 [controller_ nodeChanged:model node:node];
91 void BookmarkBarBridge::BookmarkNodeFaviconChanged(BookmarkModel* model,
92 const BookmarkNode* node) {
94 [controller_ nodeFaviconLoaded:model node:node];
97 void BookmarkBarBridge::BookmarkNodeChildrenReordered(
98 BookmarkModel* model, const BookmarkNode* node) {
100 [controller_ nodeChildrenReordered:model node:node];
103 void BookmarkBarBridge::ExtensiveBookmarkChangesBeginning(
104 BookmarkModel* model) {
108 void BookmarkBarBridge::ExtensiveBookmarkChangesEnded(BookmarkModel* model) {
110 [controller_ loaded:model];
113 void BookmarkBarBridge::OnAppsPageShortcutVisibilityPrefChanged() {
114 [controller_ updateAppsPageShortcutButtonVisibility];