Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / bookmarks / bookmark_bar_bridge.mm
bloba1b6c2824fb43fc900e281f86f90da738d791d7b
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"
7 #include "base/bind.h"
8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/bookmarks/bookmark_model.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h"
12 #include "chrome/common/pref_names.h"
15 BookmarkBarBridge::BookmarkBarBridge(Profile* profile,
16                                      BookmarkBarController* controller,
17                                      BookmarkModel* model)
18     : controller_(controller),
19       model_(model),
20       batch_mode_(false) {
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.
25   if (model->loaded())
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,
52                                           int old_index,
53                                           const BookmarkNode* new_parent,
54                                           int new_index) {
55   if (!batch_mode_) {
56     [controller_ nodeMoved:model
57                  oldParent:old_parent oldIndex:old_index
58                  newParent:new_parent newIndex:new_index];
59   }
62 void BookmarkBarBridge::BookmarkNodeAdded(BookmarkModel* model,
63                                           const BookmarkNode* parent,
64                                           int index) {
65   if (!batch_mode_)
66     [controller_ nodeAdded:model parent:parent index:index];
69 void BookmarkBarBridge::BookmarkNodeRemoved(BookmarkModel* model,
70                                             const BookmarkNode* parent,
71                                             int old_index,
72                                             const BookmarkNode* node) {
73   if (!batch_mode_)
74     [controller_ nodeRemoved:model parent:parent index:old_index];
77 void BookmarkBarBridge::BookmarkAllNodesRemoved(BookmarkModel* model) {
78   [controller_ loaded:model];
81 void BookmarkBarBridge::BookmarkNodeChanged(BookmarkModel* model,
82                                             const BookmarkNode* node) {
83   if (!batch_mode_)
84     [controller_ nodeChanged:model node:node];
87 void BookmarkBarBridge::BookmarkNodeFaviconChanged(BookmarkModel* model,
88                                                    const BookmarkNode* node) {
89   if (!batch_mode_)
90     [controller_ nodeFaviconLoaded:model node:node];
93 void BookmarkBarBridge::BookmarkNodeChildrenReordered(
94     BookmarkModel* model, const BookmarkNode* node) {
95   if (!batch_mode_)
96     [controller_ nodeChildrenReordered:model node:node];
99 void BookmarkBarBridge::ExtensiveBookmarkChangesBeginning(
100     BookmarkModel* model) {
101   batch_mode_ = true;
104 void BookmarkBarBridge::ExtensiveBookmarkChangesEnded(BookmarkModel* model) {
105   batch_mode_ = false;
106   [controller_ loaded:model];
109 void BookmarkBarBridge::OnAppsPageShortcutVisibilityPrefChanged() {
110   [controller_ updateAppsPageShortcutButtonVisibility];