| 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 #ifndef CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_MODEL_OBSERVER_FOR_COCOA_H_ |
| 6 #define CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_MODEL_OBSERVER_FOR_COCOA_H_ |
| 7 |
| 8 #import <Cocoa/Cocoa.h> |
| 9 |
| 10 #include <set> |
| 11 |
| 12 #include "base/mac/scoped_block.h" |
| 13 #include "base/macros.h" |
| 14 #include "components/bookmarks/browser/bookmark_model.h" |
| 15 #include "components/bookmarks/browser/bookmark_model_observer.h" |
| 16 |
| 5 // C++ bridge class to send a selector to a Cocoa object when the | 17 // C++ bridge class to send a selector to a Cocoa object when the |
| 6 // bookmark model changes. Some Cocoa objects edit the bookmark model | 18 // bookmark model changes. Some Cocoa objects edit the bookmark model |
| 7 // and temporarily save a copy of the state (e.g. bookmark button | 19 // 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 | 20 // 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 | 21 // model changes out from under them. For example, if you have the |
| 10 // bookmark button editor sheet open, then edit the bookmark in the | 22 // bookmark button editor sheet open, then edit the bookmark in the |
| 11 // bookmark manager, we'd want to simply cancel the editor. | 23 // bookmark manager, we'd want to simply cancel the editor. |
| 12 // | 24 // |
| 13 // This class is conservative and may result in notifications which | 25 // This class is conservative and may result in notifications which |
| 14 // aren't strictly necessary. For example, node removal only needs to | 26 // 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 | 27 // 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 | 28 // a list of "new parents"). But, just to be sure, notification |
| 17 // happens on any removal. | 29 // happens on any removal. |
| 18 | |
| 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_ | |
| 21 | |
| 22 #import <Cocoa/Cocoa.h> | |
| 23 | |
| 24 #include <set> | |
| 25 | |
| 26 #include "base/mac/scoped_block.h" | |
| 27 #include "base/macros.h" | |
| 28 #include "components/bookmarks/browser/bookmark_model.h" | |
| 29 #include "components/bookmarks/browser/bookmark_model_observer.h" | |
| 30 | |
| 31 class BookmarkModelObserverForCocoa : public bookmarks::BookmarkModelObserver { | 30 class BookmarkModelObserverForCocoa : public bookmarks::BookmarkModelObserver { |
| 32 public: | 31 public: |
| 33 // Callback called on a significant model change. | 32 // Callback called on a significant model change. |
| 34 typedef void (^ChangeCallback)(); | 33 typedef void (^ChangeCallback)(); |
| 35 | 34 |
| 36 // When a |model| changes, or an observed node within it does, call a | 35 // When a |model| changes, or an observed node within it does, call a |
| 37 // |callback|. | 36 // |callback|. |
| 38 BookmarkModelObserverForCocoa(bookmarks::BookmarkModel* model, | 37 BookmarkModelObserverForCocoa(bookmarks::BookmarkModel* model, |
| 39 ChangeCallback callback); | 38 ChangeCallback callback); |
| 40 ~BookmarkModelObserverForCocoa() override; | 39 ~BookmarkModelObserverForCocoa() override; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 nodes_; // Weak items owned by a BookmarkModel. | 87 nodes_; // Weak items owned by a BookmarkModel. |
| 89 base::mac::ScopedBlock<ChangeCallback> callback_; | 88 base::mac::ScopedBlock<ChangeCallback> callback_; |
| 90 | 89 |
| 91 // Send a notification to the client. | 90 // Send a notification to the client. |
| 92 void Notify(); | 91 void Notify(); |
| 93 | 92 |
| 94 DISALLOW_COPY_AND_ASSIGN(BookmarkModelObserverForCocoa); | 93 DISALLOW_COPY_AND_ASSIGN(BookmarkModelObserverForCocoa); |
| 95 }; | 94 }; |
| 96 | 95 |
| 97 #endif // CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_MODEL_OBSERVER_FOR_COCOA_H
_ | 96 #endif // CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_MODEL_OBSERVER_FOR_COCOA_H
_ |
| OLD | NEW |