[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / bookmarks / bookmark_model_observer_for_cocoa.mm
blob679e5c186a648fa2b54d4ef83564c0e0469243d4
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_model_observer_for_cocoa.h"
7 BookmarkModelObserverForCocoa::BookmarkModelObserverForCocoa(
8     BookmarkModel* model,
9     ChangeCallback callback) {
10   DCHECK(model);
11   callback_.reset(Block_copy(callback));
12   model_ = model;
13   model_->AddObserver(this);
16 BookmarkModelObserverForCocoa::~BookmarkModelObserverForCocoa() {
17   model_->RemoveObserver(this);
20 void BookmarkModelObserverForCocoa::StartObservingNode(
21     const BookmarkNode* node) {
22   nodes_.insert(node);
25 void BookmarkModelObserverForCocoa::StopObservingNode(
26     const BookmarkNode* node) {
27   nodes_.erase(node);
30 void BookmarkModelObserverForCocoa::BookmarkModelBeingDeleted(
31     BookmarkModel* model) {
32   Notify(YES);
35 void BookmarkModelObserverForCocoa::BookmarkNodeMoved(
36     BookmarkModel* model,
37     const BookmarkNode* old_parent,
38     int old_index,
39     const BookmarkNode* new_parent,
40     int new_index) {
41   // Editors often have a tree of parents, so movement of folders
42   // must cause a cancel.
43   Notify(NO);
46 void BookmarkModelObserverForCocoa::BookmarkNodeRemoved(
47     BookmarkModel* model,
48     const BookmarkNode* parent,
49     int old_index,
50     const BookmarkNode* node,
51     const std::set<GURL>& removed_urls) {
52   // See comment in BookmarkNodeMoved.
53   Notify(YES);
56 void BookmarkModelObserverForCocoa::BookmarkAllNodesRemoved(
57     BookmarkModel* model,
58     const std::set<GURL>& removed_urls) {
59   Notify(YES);
62 void BookmarkModelObserverForCocoa::BookmarkNodeChanged(
63     BookmarkModel* model,
64     const BookmarkNode* node) {
65   if (!nodes_.size() || nodes_.find(node) != nodes_.end())
66     Notify(NO);
69 void BookmarkModelObserverForCocoa::Notify(BOOL deleted) {
70   callback_.get()(deleted);