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.h
bloba0d1d47c3365db4705af92ac2b8ac4fe94d22036
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 // C++ bridge class to send a selector to a Cocoa object when the
6 // bookmark model changes. Some Cocoa objects edit the bookmark model
7 // and temporarily save a copy of the state (e.g. bookmark button
8 // editor). As a fail-safe, these objects want an easy cancel if the
9 // model changes out from under them. For example, if you have the
10 // bookmark button editor sheet open, then edit the bookmark in the
11 // bookmark manager, we'd want to simply cancel the editor.
13 // This class is conservative and may result in notifications which
14 // aren't strictly necessary. For example, node removal only needs to
15 // cancel an edit if the removed node is a folder (editors often have
16 // a list of "new parents"). But, just to be sure, notification
17 // happens on any removal.
19 #ifndef CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_MODEL_OBSERVER_FOR_COCOA_H
20 #define CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_MODEL_OBSERVER_FOR_COCOA_H
22 #import <Cocoa/Cocoa.h>
24 #include <set>
26 #include "base/basictypes.h"
27 #include "base/mac/scoped_block.h"
28 #include "components/bookmarks/browser/bookmark_model.h"
29 #include "components/bookmarks/browser/bookmark_model_observer.h"
31 class BookmarkModelObserverForCocoa : public bookmarks::BookmarkModelObserver {
32 public:
33 // Callback called on a significant model change.
34 typedef void (^ChangeCallback)();
36 // When a |model| changes, or an observed node within it does, call a
37 // |callback|.
38 BookmarkModelObserverForCocoa(bookmarks::BookmarkModel* model,
39 ChangeCallback callback);
40 ~BookmarkModelObserverForCocoa() override;
42 // Starts and stops observing a specified |node|; the node must be contained
43 // within the model.
44 void StartObservingNode(const bookmarks::BookmarkNode* node);
45 void StopObservingNode(const bookmarks::BookmarkNode* node);
47 // bookmarks::BookmarkModelObserver:
48 void BookmarkModelBeingDeleted(bookmarks::BookmarkModel* model) override;
49 void BookmarkNodeMoved(bookmarks::BookmarkModel* model,
50 const bookmarks::BookmarkNode* old_parent,
51 int old_index,
52 const bookmarks::BookmarkNode* new_parent,
53 int new_index) override;
54 void BookmarkNodeRemoved(bookmarks::BookmarkModel* model,
55 const bookmarks::BookmarkNode* parent,
56 int old_index,
57 const bookmarks::BookmarkNode* node,
58 const std::set<GURL>& removed_urls) override;
59 void BookmarkAllUserNodesRemoved(bookmarks::BookmarkModel* model,
60 const std::set<GURL>& removed_urls) override;
61 void BookmarkNodeChanged(bookmarks::BookmarkModel* model,
62 const bookmarks::BookmarkNode* node) override;
64 // Some notifications we don't care about, but by being pure virtual
65 // in the base class we must implement them.
67 void BookmarkModelLoaded(bookmarks::BookmarkModel* model,
68 bool ids_reassigned) override {}
69 void BookmarkNodeAdded(bookmarks::BookmarkModel* model,
70 const bookmarks::BookmarkNode* parent,
71 int index) override {}
72 void BookmarkNodeFaviconChanged(
73 bookmarks::BookmarkModel* model,
74 const bookmarks::BookmarkNode* node) override {}
75 void BookmarkNodeChildrenReordered(
76 bookmarks::BookmarkModel* model,
77 const bookmarks::BookmarkNode* node) override {}
79 void ExtensiveBookmarkChangesBeginning(
80 bookmarks::BookmarkModel* model) override {}
82 void ExtensiveBookmarkChangesEnded(bookmarks::BookmarkModel* model) override {
85 private:
86 bookmarks::BookmarkModel* model_; // Weak; it is owned by a Profile.
87 std::set<const bookmarks::BookmarkNode*>
88 nodes_; // Weak items owned by a BookmarkModel.
89 base::mac::ScopedBlock<ChangeCallback> callback_;
91 // Send a notification to the client.
92 void Notify();
94 DISALLOW_COPY_AND_ASSIGN(BookmarkModelObserverForCocoa);
97 #endif // CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_MODEL_OBSERVER_FOR_COCOA_H