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

Side by Side Diff: components/arc/instance_holder.h

Issue 2594203002: [mojo] Expose interface method min_versions (Closed)
Patch Set: Created 4 years 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 COMPONENTS_ARC_INSTANCE_HOLDER_H_ 5 #ifndef COMPONENTS_ARC_INSTANCE_HOLDER_H_
6 #define COMPONENTS_ARC_INSTANCE_HOLDER_H_ 6 #define COMPONENTS_ARC_INSTANCE_HOLDER_H_
7 7
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/observer_list.h" 13 #include "base/observer_list.h"
14 #include "base/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
15 #include "mojo/public/cpp/bindings/interface_traits.h"
15 16
16 namespace arc { 17 namespace arc {
17 18
18 // Holds a Mojo instance+version pair. This also allows for listening for state 19 // Holds a Mojo instance+version pair. This also allows for listening for state
19 // changes for the particular instance. T should be a Mojo interface type 20 // changes for the particular instance. T should be a Mojo interface type
20 // (arc::mojom::XxxInstance). 21 // (arc::mojom::XxxInstance).
21 template <typename T> 22 template <typename T>
22 class InstanceHolder { 23 class InstanceHolder {
23 public: 24 public:
24 // Notifies about connection events for individual instances. 25 // Notifies about connection events for individual instances.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 if (version_ < min_version) { 57 if (version_ < min_version) {
57 LOG(ERROR) << "Instance for " << T::Name_ 58 LOG(ERROR) << "Instance for " << T::Name_
58 << "::" << method_name_for_logging 59 << "::" << method_name_for_logging
59 << " version mismatch. Expected " << min_version << " got " 60 << " version mismatch. Expected " << min_version << " got "
60 << version_; 61 << version_;
61 return nullptr; 62 return nullptr;
62 } 63 }
63 return instance_; 64 return instance_;
64 } 65 }
65 66
67 template <uint32_t MethodIndex>
68 T* GetInstanceForMethod() {
69 using Method = mojo::MethodTraits<T, MethodIndex>;
yzshen1 2016/12/22 18:53:28 I feel that mojo::MethodTraits is not needed, we c
yzshen1 2016/12/22 19:01:09 But please see my comments in the other file. If w
70 if (!instance_) {
71 VLOG(1) << "Instance for " << T::Name_ << "::" << Method::Name()
72 << " not available.";
73 return nullptr;
74 }
75 if (version_ < Method::MinVersion()) {
76 LOG(ERROR) << "Instance for " << T::Name_ << "::" << Method::Name()
77 << " version mismatch. Expected " << Method::MinVersion()
78 << " got " << version_;
79 return nullptr;
80 }
81 return instance_;
82 }
83
66 // Same as the above, but for the version zero. 84 // Same as the above, but for the version zero.
67 T* GetInstanceForMethod(const std::string& method_name_for_logging) { 85 T* GetInstanceForMethod(const std::string& method_name_for_logging) {
68 return GetInstanceForMethod(method_name_for_logging, 0u); 86 return GetInstanceForMethod(method_name_for_logging, 0u);
69 } 87 }
70 88
71 // Adds or removes observers. This can only be called on the thread that this 89 // Adds or removes observers. This can only be called on the thread that this
72 // class was created on. RemoveObserver does nothing if |observer| is not in 90 // class was created on. RemoveObserver does nothing if |observer| is not in
73 // the list. 91 // the list.
74 void AddObserver(Observer* observer) { 92 void AddObserver(Observer* observer) {
75 DCHECK(thread_checker_.CalledOnValidThread()); 93 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 133
116 base::ThreadChecker thread_checker_; 134 base::ThreadChecker thread_checker_;
117 base::ObserverList<Observer> observer_list_; 135 base::ObserverList<Observer> observer_list_;
118 136
119 DISALLOW_COPY_AND_ASSIGN(InstanceHolder<T>); 137 DISALLOW_COPY_AND_ASSIGN(InstanceHolder<T>);
120 }; 138 };
121 139
122 } // namespace arc 140 } // namespace arc
123 141
124 #endif // COMPONENTS_ARC_INSTANCE_HOLDER_H_ 142 #endif // COMPONENTS_ARC_INSTANCE_HOLDER_H_
OLDNEW
« no previous file with comments | « no previous file | components/arc/net/arc_net_host_impl.cc » ('j') | mojo/public/cpp/bindings/interface_traits.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698