| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // C++ bridge class to send a selector to a Cocoa object when the | 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 | 6 // bookmark model changes. Some Cocoa objects edit the bookmark model |
| 7 // and temporarily save a copy of the state (e.g. bookmark button | 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 | 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 | 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 | 10 // bookmark button editor sheet open, then edit the bookmark in the |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 typedef void(^ChangeCallback)(BOOL nodeWasDeleted); | 35 typedef void(^ChangeCallback)(BOOL nodeWasDeleted); |
| 36 | 36 |
| 37 // When a |model| changes, or an observed node within it does, call a | 37 // When a |model| changes, or an observed node within it does, call a |
| 38 // |callback|. | 38 // |callback|. |
| 39 BookmarkModelObserverForCocoa(bookmarks::BookmarkModel* model, | 39 BookmarkModelObserverForCocoa(bookmarks::BookmarkModel* model, |
| 40 ChangeCallback callback); | 40 ChangeCallback callback); |
| 41 ~BookmarkModelObserverForCocoa() override; | 41 ~BookmarkModelObserverForCocoa() override; |
| 42 | 42 |
| 43 // Starts and stops observing a specified |node|; the node must be contained | 43 // Starts and stops observing a specified |node|; the node must be contained |
| 44 // within the model. | 44 // within the model. |
| 45 void StartObservingNode(const BookmarkNode* node); | 45 void StartObservingNode(const bookmarks::BookmarkNode* node); |
| 46 void StopObservingNode(const BookmarkNode* node); | 46 void StopObservingNode(const bookmarks::BookmarkNode* node); |
| 47 | 47 |
| 48 // bookmarks::BookmarkModelObserver: | 48 // bookmarks::BookmarkModelObserver: |
| 49 void BookmarkModelBeingDeleted(bookmarks::BookmarkModel* model) override; | 49 void BookmarkModelBeingDeleted(bookmarks::BookmarkModel* model) override; |
| 50 void BookmarkNodeMoved(bookmarks::BookmarkModel* model, | 50 void BookmarkNodeMoved(bookmarks::BookmarkModel* model, |
| 51 const BookmarkNode* old_parent, | 51 const bookmarks::BookmarkNode* old_parent, |
| 52 int old_index, | 52 int old_index, |
| 53 const BookmarkNode* new_parent, | 53 const bookmarks::BookmarkNode* new_parent, |
| 54 int new_index) override; | 54 int new_index) override; |
| 55 void BookmarkNodeRemoved(bookmarks::BookmarkModel* model, | 55 void BookmarkNodeRemoved(bookmarks::BookmarkModel* model, |
| 56 const BookmarkNode* parent, | 56 const bookmarks::BookmarkNode* parent, |
| 57 int old_index, | 57 int old_index, |
| 58 const BookmarkNode* node, | 58 const bookmarks::BookmarkNode* node, |
| 59 const std::set<GURL>& removed_urls) override; | 59 const std::set<GURL>& removed_urls) override; |
| 60 void BookmarkAllUserNodesRemoved(bookmarks::BookmarkModel* model, | 60 void BookmarkAllUserNodesRemoved(bookmarks::BookmarkModel* model, |
| 61 const std::set<GURL>& removed_urls) override; | 61 const std::set<GURL>& removed_urls) override; |
| 62 void BookmarkNodeChanged(bookmarks::BookmarkModel* model, | 62 void BookmarkNodeChanged(bookmarks::BookmarkModel* model, |
| 63 const BookmarkNode* node) override; | 63 const bookmarks::BookmarkNode* node) override; |
| 64 | 64 |
| 65 // Some notifications we don't care about, but by being pure virtual | 65 // Some notifications we don't care about, but by being pure virtual |
| 66 // in the base class we must implement them. | 66 // in the base class we must implement them. |
| 67 | 67 |
| 68 void BookmarkModelLoaded(bookmarks::BookmarkModel* model, | 68 void BookmarkModelLoaded(bookmarks::BookmarkModel* model, |
| 69 bool ids_reassigned) override {} | 69 bool ids_reassigned) override {} |
| 70 void BookmarkNodeAdded(bookmarks::BookmarkModel* model, | 70 void BookmarkNodeAdded(bookmarks::BookmarkModel* model, |
| 71 const BookmarkNode* parent, | 71 const bookmarks::BookmarkNode* parent, |
| 72 int index) override {} | 72 int index) override {} |
| 73 void BookmarkNodeFaviconChanged(bookmarks::BookmarkModel* model, | 73 void BookmarkNodeFaviconChanged( |
| 74 const BookmarkNode* node) override {} | 74 bookmarks::BookmarkModel* model, |
| 75 void BookmarkNodeChildrenReordered(bookmarks::BookmarkModel* model, | 75 const bookmarks::BookmarkNode* node) override {} |
| 76 const BookmarkNode* node) override {} | 76 void BookmarkNodeChildrenReordered( |
| 77 bookmarks::BookmarkModel* model, |
| 78 const bookmarks::BookmarkNode* node) override {} |
| 77 | 79 |
| 78 void ExtensiveBookmarkChangesBeginning( | 80 void ExtensiveBookmarkChangesBeginning( |
| 79 bookmarks::BookmarkModel* model) override {} | 81 bookmarks::BookmarkModel* model) override {} |
| 80 | 82 |
| 81 void ExtensiveBookmarkChangesEnded(bookmarks::BookmarkModel* model) override { | 83 void ExtensiveBookmarkChangesEnded(bookmarks::BookmarkModel* model) override { |
| 82 } | 84 } |
| 83 | 85 |
| 84 private: | 86 private: |
| 85 bookmarks::BookmarkModel* model_; // Weak; it is owned by a Profile. | 87 bookmarks::BookmarkModel* model_; // Weak; it is owned by a Profile. |
| 86 std::set<const BookmarkNode*> nodes_; // Weak items owned by a BookmarkModel. | 88 std::set<const bookmarks::BookmarkNode*> |
| 89 nodes_; // Weak items owned by a BookmarkModel. |
| 87 base::mac::ScopedBlock<ChangeCallback> callback_; | 90 base::mac::ScopedBlock<ChangeCallback> callback_; |
| 88 | 91 |
| 89 // Send a notification to the client; |deleted| is YES if an observed node was | 92 // Send a notification to the client; |deleted| is YES if an observed node was |
| 90 // deleted in the change. | 93 // deleted in the change. |
| 91 void Notify(BOOL deleted); | 94 void Notify(BOOL deleted); |
| 92 | 95 |
| 93 DISALLOW_COPY_AND_ASSIGN(BookmarkModelObserverForCocoa); | 96 DISALLOW_COPY_AND_ASSIGN(BookmarkModelObserverForCocoa); |
| 94 }; | 97 }; |
| 95 | 98 |
| 96 #endif // CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_MODEL_OBSERVER_FOR_COCOA_H | 99 #endif // CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_MODEL_OBSERVER_FOR_COCOA_H |
| OLD | NEW |