OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "components/bookmarks/browser/bookmark_model.h" | 5 #include "components/bookmarks/browser/bookmark_model.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... |
40 return const_cast<BookmarkNode*>(node); | 40 return const_cast<BookmarkNode*>(node); |
41 } | 41 } |
42 | 42 |
43 // Helper to get a mutable permanent bookmark node. | 43 // Helper to get a mutable permanent bookmark node. |
44 BookmarkPermanentNode* AsMutable(const BookmarkPermanentNode* node) { | 44 BookmarkPermanentNode* AsMutable(const BookmarkPermanentNode* node) { |
45 return const_cast<BookmarkPermanentNode*>(node); | 45 return const_cast<BookmarkPermanentNode*>(node); |
46 } | 46 } |
47 | 47 |
48 // Comparator used when sorting permanent nodes. Nodes that are initially | 48 // Comparator used when sorting permanent nodes. Nodes that are initially |
49 // visible are sorted before nodes that are initially hidden. | 49 // visible are sorted before nodes that are initially hidden. |
50 class VisibilityComparator | 50 class VisibilityComparator { |
51 : public std::binary_function<const BookmarkPermanentNode*, | |
52 const BookmarkPermanentNode*, | |
53 bool> { | |
54 public: | 51 public: |
55 explicit VisibilityComparator(BookmarkClient* client) : client_(client) {} | 52 explicit VisibilityComparator(BookmarkClient* client) : client_(client) {} |
56 | 53 |
57 // Returns true if |n1| preceeds |n2|. | 54 // Returns true if |n1| preceeds |n2|. |
58 bool operator()(const BookmarkPermanentNode* n1, | 55 bool operator()(const BookmarkPermanentNode* n1, |
59 const BookmarkPermanentNode* n2) { | 56 const BookmarkPermanentNode* n2) { |
60 bool n1_visible = client_->IsPermanentNodeVisible(n1); | 57 bool n1_visible = client_->IsPermanentNodeVisible(n1); |
61 bool n2_visible = client_->IsPermanentNodeVisible(n2); | 58 bool n2_visible = client_->IsPermanentNodeVisible(n2); |
62 return n1_visible != n2_visible && n1_visible; | 59 return n1_visible != n2_visible && n1_visible; |
63 } | 60 } |
64 | 61 |
65 private: | 62 private: |
66 BookmarkClient* client_; | 63 BookmarkClient* client_; |
67 }; | 64 }; |
68 | 65 |
69 // Comparator used when sorting bookmarks. Folders are sorted first, then | 66 // Comparator used when sorting bookmarks. Folders are sorted first, then |
70 // bookmarks. | 67 // bookmarks. |
71 class SortComparator : public std::binary_function<const BookmarkNode*, | 68 class SortComparator { |
72 const BookmarkNode*, | |
73 bool> { | |
74 public: | 69 public: |
75 explicit SortComparator(icu::Collator* collator) : collator_(collator) {} | 70 explicit SortComparator(icu::Collator* collator) : collator_(collator) {} |
76 | 71 |
77 // Returns true if |n1| preceeds |n2|. | 72 // Returns true if |n1| preceeds |n2|. |
78 bool operator()(const BookmarkNode* n1, const BookmarkNode* n2) { | 73 bool operator()(const BookmarkNode* n1, const BookmarkNode* n2) { |
79 if (n1->type() == n2->type()) { | 74 if (n1->type() == n2->type()) { |
80 // Types are the same, compare the names. | 75 // Types are the same, compare the names. |
81 if (!collator_) | 76 if (!collator_) |
82 return n1->GetTitle() < n2->GetTitle(); | 77 return n1->GetTitle() < n2->GetTitle(); |
83 return base::i18n::CompareString16WithCollator( | 78 return base::i18n::CompareString16WithCollator( |
(...skipping 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1116 undo_delegate_ = undo_delegate; | 1111 undo_delegate_ = undo_delegate; |
1117 if (undo_delegate_) | 1112 if (undo_delegate_) |
1118 undo_delegate_->SetUndoProvider(this); | 1113 undo_delegate_->SetUndoProvider(this); |
1119 } | 1114 } |
1120 | 1115 |
1121 BookmarkUndoDelegate* BookmarkModel::undo_delegate() const { | 1116 BookmarkUndoDelegate* BookmarkModel::undo_delegate() const { |
1122 return undo_delegate_ ? undo_delegate_ : empty_undo_delegate_.get(); | 1117 return undo_delegate_ ? undo_delegate_ : empty_undo_delegate_.get(); |
1123 } | 1118 } |
1124 | 1119 |
1125 } // namespace bookmarks | 1120 } // namespace bookmarks |
OLD | NEW |