Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / bookmarks / bookmark_bar_bridge.mm
blobcac54379ca9052b6e5ff2dbd21de5d3c641b9a20
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/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,
19                                      BookmarkModel* model)
20     : controller_(controller),
21       model_(model),
22       batch_mode_(false) {
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.
27   if (model->loaded())
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() {
44   if (model_)
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);
56   model_ = nullptr;
59 void BookmarkBarBridge::BookmarkNodeMoved(BookmarkModel* model,
60                                           const BookmarkNode* old_parent,
61                                           int old_index,
62                                           const BookmarkNode* new_parent,
63                                           int new_index) {
64   if (!batch_mode_) {
65     [controller_ nodeMoved:model
66                  oldParent:old_parent oldIndex:old_index
67                  newParent:new_parent newIndex:new_index];
68   }
71 void BookmarkBarBridge::BookmarkNodeAdded(BookmarkModel* model,
72                                           const BookmarkNode* parent,
73                                           int index) {
74   if (!batch_mode_)
75     [controller_ nodeAdded:model parent:parent index:index];
78 void BookmarkBarBridge::BookmarkNodeRemoved(
79     BookmarkModel* model,
80     const BookmarkNode* parent,
81     int old_index,
82     const BookmarkNode* node,
83     const std::set<GURL>& removed_urls) {
84   if (!batch_mode_)
85     [controller_ nodeRemoved:model parent:parent index:old_index];
88 void BookmarkBarBridge::BookmarkAllUserNodesRemoved(
89     BookmarkModel* model,
90     const std::set<GURL>& removed_urls) {
91   [controller_ loaded:model];
94 void BookmarkBarBridge::BookmarkNodeChanged(BookmarkModel* model,
95                                             const BookmarkNode* node) {
96   if (!batch_mode_)
97     [controller_ nodeChanged:model node:node];
100 void BookmarkBarBridge::BookmarkNodeFaviconChanged(BookmarkModel* model,
101                                                    const BookmarkNode* node) {
102   if (!batch_mode_)
103     [controller_ nodeFaviconLoaded:model node:node];
106 void BookmarkBarBridge::BookmarkNodeChildrenReordered(
107     BookmarkModel* model, const BookmarkNode* node) {
108   if (!batch_mode_)
109     [controller_ nodeChildrenReordered:model node:node];
112 void BookmarkBarBridge::ExtensiveBookmarkChangesBeginning(
113     BookmarkModel* model) {
114   batch_mode_ = true;
117 void BookmarkBarBridge::ExtensiveBookmarkChangesEnded(BookmarkModel* model) {
118   batch_mode_ = false;
119   [controller_ loaded:model];
122 void BookmarkBarBridge::OnExtraButtonsVisibilityChanged() {
123   [controller_ updateExtraButtonsVisibility];