Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / bookmarks / bookmark_model_observer_for_cocoa.mm
blob3976e0f62f55735bc04ec30d0920ecc1a9ff34ce
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 using bookmarks::BookmarkModel;
8 using bookmarks::BookmarkNode;
10 BookmarkModelObserverForCocoa::BookmarkModelObserverForCocoa(
11     BookmarkModel* model,
12     ChangeCallback callback) {
13   DCHECK(model);
14   callback_.reset(Block_copy(callback));
15   model_ = model;
16   model_->AddObserver(this);
19 BookmarkModelObserverForCocoa::~BookmarkModelObserverForCocoa() {
20   model_->RemoveObserver(this);
23 void BookmarkModelObserverForCocoa::StartObservingNode(
24     const BookmarkNode* node) {
25   nodes_.insert(node);
28 void BookmarkModelObserverForCocoa::StopObservingNode(
29     const BookmarkNode* node) {
30   nodes_.erase(node);
33 void BookmarkModelObserverForCocoa::BookmarkModelBeingDeleted(
34     BookmarkModel* model) {
35   Notify();
38 void BookmarkModelObserverForCocoa::BookmarkNodeMoved(
39     BookmarkModel* model,
40     const BookmarkNode* old_parent,
41     int old_index,
42     const BookmarkNode* new_parent,
43     int new_index) {
44   // Editors often have a tree of parents, so movement of folders
45   // must cause a cancel.
46   Notify();
49 void BookmarkModelObserverForCocoa::BookmarkNodeRemoved(
50     BookmarkModel* model,
51     const BookmarkNode* parent,
52     int old_index,
53     const BookmarkNode* node,
54     const std::set<GURL>& removed_urls) {
55   // See comment in BookmarkNodeMoved.
56   Notify();
59 void BookmarkModelObserverForCocoa::BookmarkAllUserNodesRemoved(
60     BookmarkModel* model,
61     const std::set<GURL>& removed_urls) {
62   Notify();
65 void BookmarkModelObserverForCocoa::BookmarkNodeChanged(
66     BookmarkModel* model,
67     const BookmarkNode* node) {
68   if (!nodes_.size() || nodes_.find(node) != nodes_.end())
69     Notify();
72 void BookmarkModelObserverForCocoa::Notify() {
73   callback_.get()();