[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / bookmarks / bookmark_bar_bridge.mm
bloba371a62679d3f67a3f3f8e0718d06c61bcd11b90
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"
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(
70     BookmarkModel* model,
71     const BookmarkNode* parent,
72     int old_index,
73     const BookmarkNode* node,
74     const std::set<GURL>& removed_urls) {
75   if (!batch_mode_)
76     [controller_ nodeRemoved:model parent:parent index:old_index];
79 void BookmarkBarBridge::BookmarkAllNodesRemoved(
80     BookmarkModel* model,
81     const std::set<GURL>& removed_urls) {
82   [controller_ loaded:model];
85 void BookmarkBarBridge::BookmarkNodeChanged(BookmarkModel* model,
86                                             const BookmarkNode* node) {
87   if (!batch_mode_)
88     [controller_ nodeChanged:model node:node];
91 void BookmarkBarBridge::BookmarkNodeFaviconChanged(BookmarkModel* model,
92                                                    const BookmarkNode* node) {
93   if (!batch_mode_)
94     [controller_ nodeFaviconLoaded:model node:node];
97 void BookmarkBarBridge::BookmarkNodeChildrenReordered(
98     BookmarkModel* model, const BookmarkNode* node) {
99   if (!batch_mode_)
100     [controller_ nodeChildrenReordered:model node:node];
103 void BookmarkBarBridge::ExtensiveBookmarkChangesBeginning(
104     BookmarkModel* model) {
105   batch_mode_ = true;
108 void BookmarkBarBridge::ExtensiveBookmarkChangesEnded(BookmarkModel* model) {
109   batch_mode_ = false;
110   [controller_ loaded:model];
113 void BookmarkBarBridge::OnAppsPageShortcutVisibilityPrefChanged() {
114   [controller_ updateAppsPageShortcutButtonVisibility];