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

Side by Side Diff: mojo/common/strong_binding_set.h

Issue 1556803002: Add helpers for creating UI components. (Closed) Base URL: git@github.com:domokit/mojo.git@moz-13
Patch Set: Created 4 years, 11 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
« no previous file with comments | « mojo/BUILD.gn ('k') | mojo/ui/BUILD.gn » ('j') | mojo/ui/BUILD.gn » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef MOJO_COMMON_STRONG_BINDING_SET_H_ 5 #ifndef MOJO_COMMON_STRONG_BINDING_SET_H_
6 #define MOJO_COMMON_STRONG_BINDING_SET_H_ 6 #define MOJO_COMMON_STRONG_BINDING_SET_H_
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
(...skipping 26 matching lines...) Expand all
37 std::find_if(bindings_.begin(), bindings_.end(), 37 std::find_if(bindings_.begin(), bindings_.end(),
38 [binding](const std::unique_ptr<Binding<Interface>>& b) { 38 [binding](const std::unique_ptr<Binding<Interface>>& b) {
39 return (b.get() == binding); 39 return (b.get() == binding);
40 }); 40 });
41 DCHECK(it != bindings_.end()); 41 DCHECK(it != bindings_.end());
42 delete binding->impl(); 42 delete binding->impl();
43 bindings_.erase(it); 43 bindings_.erase(it);
44 }); 44 });
45 } 45 }
46 46
47 // Removes all bindings for the specified interface implementation.
48 // The implementation object is not destroyed.
49 void RemoveBindings(Interface* impl) {
50 bindings_.erase(
51 std::remove_if(bindings_.begin(), bindings_.end(),
52 [impl](const std::unique_ptr<Binding<Interface>>& b) {
53 return (b->impl() == impl);
54 }));
55 }
56
47 // Closes all bindings and deletes their associated interfaces. 57 // Closes all bindings and deletes their associated interfaces.
48 void CloseAllBindings() { 58 void CloseAllBindings() {
49 for (auto it = bindings_.begin(); it != bindings_.end(); ++it) { 59 for (auto it = bindings_.begin(); it != bindings_.end(); ++it) {
50 delete (*it)->impl(); 60 delete (*it)->impl();
51 } 61 }
52 bindings_.clear(); 62 bindings_.clear();
53 } 63 }
54 64
55 size_t size() const { return bindings_.size(); } 65 size_t size() const { return bindings_.size(); }
56 66
57 private: 67 private:
58 std::vector<std::unique_ptr<Binding<Interface>>> bindings_; 68 std::vector<std::unique_ptr<Binding<Interface>>> bindings_;
59 69
60 DISALLOW_COPY_AND_ASSIGN(StrongBindingSet); 70 DISALLOW_COPY_AND_ASSIGN(StrongBindingSet);
61 }; 71 };
62 72
63 } // namespace mojo 73 } // namespace mojo
64 74
65 #endif // MOJO_COMMON_STRONG_BINDING_SET_H_ 75 #endif // MOJO_COMMON_STRONG_BINDING_SET_H_
OLDNEW
« no previous file with comments | « mojo/BUILD.gn ('k') | mojo/ui/BUILD.gn » ('j') | mojo/ui/BUILD.gn » ('J')

Powered by Google App Engine
This is Rietveld 408576698