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

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

Issue 1250463002: Renames WeakBindingSet to BindingSet. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Rebasing Created 5 years, 5 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/common/binding_set_unittest.cc ('k') | mojo/common/weak_binding_set_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef MOJO_COMMON_WEAK_BINDING_SET_H_
6 #define MOJO_COMMON_WEAK_BINDING_SET_H_
7
8 #include <algorithm>
9 #include <vector>
10
11 #include "base/memory/weak_ptr.h"
12 #include "mojo/public/cpp/bindings/binding.h"
13
14 namespace mojo {
15
16 // Use this class to manage a set of bindings each of which is
17 // owned by the pipe it is bound to.
18 template <typename Interface>
19 class WeakBindingSet {
20 public:
21 WeakBindingSet() {}
22 ~WeakBindingSet() { CloseAllBindings(); }
23
24 void AddBinding(Interface* impl, InterfaceRequest<Interface> request) {
25 bindings_.emplace_back(new Binding<Interface>(impl, request.Pass()));
26 auto* binding = bindings_.back().get();
27 // Set the connection error handler for the newly added Binding to be a
28 // function that will erase it from the vector.
29 binding->set_connection_error_handler([this, binding]() {
30 auto it =
31 std::find_if(bindings_.begin(), bindings_.end(),
32 [binding](const std::unique_ptr<Binding<Interface>>& b) {
33 return (b.get() == binding);
34 });
35 DCHECK(it != bindings_.end());
36 bindings_.erase(it);
37 });
38 }
39
40 void CloseAllBindings() {
41 bindings_.clear();
42 }
43
44 size_t size() const { return bindings_.size(); }
45
46 private:
47 std::vector<std::unique_ptr<Binding<Interface>>> bindings_;
48
49 DISALLOW_COPY_AND_ASSIGN(WeakBindingSet);
50 };
51
52 } // namespace mojo
53
54 #endif // MOJO_COMMON_WEAK_BINDING_SET_H_
OLDNEW
« no previous file with comments | « mojo/common/binding_set_unittest.cc ('k') | mojo/common/weak_binding_set_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698