Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1118)

Side by Side Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_model_observer_for_cocoa.h

Issue 6542027: Out of line cleanups for Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Killer rebase. :( Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 23 matching lines...) Expand all
34 // IBOutlet. The arg passed is nil. 34 // IBOutlet. The arg passed is nil.
35 // Many notifications happen independently of node 35 // Many notifications happen independently of node
36 // (e.g. BeingDeleted), so |node| can be nil. 36 // (e.g. BeingDeleted), so |node| can be nil.
37 // 37 //
38 // |object| is NOT retained, since the expected use case is for 38 // |object| is NOT retained, since the expected use case is for
39 // ||object| to own the BookmarkModelObserverForCocoa and we don't 39 // ||object| to own the BookmarkModelObserverForCocoa and we don't
40 // want a retain cycle. 40 // want a retain cycle.
41 BookmarkModelObserverForCocoa(const BookmarkNode* node, 41 BookmarkModelObserverForCocoa(const BookmarkNode* node,
42 BookmarkModel* model, 42 BookmarkModel* model,
43 NSObject* object, 43 NSObject* object,
44 SEL selector) { 44 SEL selector);
45 DCHECK(model); 45 virtual ~BookmarkModelObserverForCocoa();
46 node_ = node;
47 model_ = model;
48 object_ = object;
49 selector_ = selector;
50 model_->AddObserver(this);
51 }
52 virtual ~BookmarkModelObserverForCocoa() {
53 model_->RemoveObserver(this);
54 }
55 46
56 virtual void BookmarkModelBeingDeleted(BookmarkModel* model) { 47 virtual void BookmarkModelBeingDeleted(BookmarkModel* model);
57 Notify();
58 }
59 virtual void BookmarkNodeMoved(BookmarkModel* model, 48 virtual void BookmarkNodeMoved(BookmarkModel* model,
60 const BookmarkNode* old_parent, 49 const BookmarkNode* old_parent,
61 int old_index, 50 int old_index,
62 const BookmarkNode* new_parent, 51 const BookmarkNode* new_parent,
63 int new_index) { 52 int new_index);
64 // Editors often have a tree of parents, so movement of folders
65 // must cause a cancel.
66 Notify();
67 }
68 virtual void BookmarkNodeRemoved(BookmarkModel* model, 53 virtual void BookmarkNodeRemoved(BookmarkModel* model,
69 const BookmarkNode* parent, 54 const BookmarkNode* parent,
70 int old_index, 55 int old_index,
71 const BookmarkNode* node) { 56 const BookmarkNode* node);
72 // See comment in BookmarkNodeMoved.
73 Notify();
74 }
75 virtual void BookmarkNodeChanged(BookmarkModel* model, 57 virtual void BookmarkNodeChanged(BookmarkModel* model,
76 const BookmarkNode* node) { 58 const BookmarkNode* node);
77 if ((node_ == node) || (!node_)) 59 virtual void BookmarkImportBeginning(BookmarkModel* model);
78 Notify();
79 }
80 virtual void BookmarkImportBeginning(BookmarkModel* model) {
81 // Be conservative.
82 Notify();
83 }
84 60
85 // Some notifications we don't care about, but by being pure virtual 61 // Some notifications we don't care about, but by being pure virtual
86 // in the base class we must implement them. 62 // in the base class we must implement them.
87 virtual void Loaded(BookmarkModel* model) { 63 virtual void Loaded(BookmarkModel* model) {
88 } 64 }
89 virtual void BookmarkNodeAdded(BookmarkModel* model, 65 virtual void BookmarkNodeAdded(BookmarkModel* model,
90 const BookmarkNode* parent, 66 const BookmarkNode* parent,
91 int index) { 67 int index) {
92 } 68 }
93 virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, 69 virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
94 const BookmarkNode* node) { 70 const BookmarkNode* node) {
95 } 71 }
96 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, 72 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
97 const BookmarkNode* node) { 73 const BookmarkNode* node) {
98 } 74 }
99 75
100 virtual void BookmarkImportEnding(BookmarkModel* model) { 76 virtual void BookmarkImportEnding(BookmarkModel* model) {
101 } 77 }
102 78
103 private: 79 private:
104 const BookmarkNode* node_; // Weak; owned by a BookmarkModel. 80 const BookmarkNode* node_; // Weak; owned by a BookmarkModel.
105 BookmarkModel* model_; // Weak; it is owned by a Profile. 81 BookmarkModel* model_; // Weak; it is owned by a Profile.
106 NSObject* object_; // Weak, like a delegate. 82 NSObject* object_; // Weak, like a delegate.
107 SEL selector_; 83 SEL selector_;
108 84
109 void Notify() { 85 void Notify();
110 [object_ performSelector:selector_ withObject:nil];
111 }
112 86
113 DISALLOW_COPY_AND_ASSIGN(BookmarkModelObserverForCocoa); 87 DISALLOW_COPY_AND_ASSIGN(BookmarkModelObserverForCocoa);
114 }; 88 };
115 89
116 #endif // CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_MODEL_OBSERVER_FOR_COCOA_H 90 #endif // CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_MODEL_OBSERVER_FOR_COCOA_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698