Chromium Code Reviews| Index: components/arc/instance_holder.h |
| diff --git a/components/arc/instance_holder.h b/components/arc/instance_holder.h |
| index 8455814581c61997f4d4ec602c6373cdbd9bb41b..4387da5c6ae1f82a1f7529ad75ade7f82df76f53 100644 |
| --- a/components/arc/instance_holder.h |
| +++ b/components/arc/instance_holder.h |
| @@ -12,6 +12,7 @@ |
| #include "base/macros.h" |
| #include "base/observer_list.h" |
| #include "base/threading/thread_checker.h" |
| +#include "mojo/public/cpp/bindings/interface_traits.h" |
| namespace arc { |
| @@ -63,6 +64,23 @@ class InstanceHolder { |
| return instance_; |
| } |
| + template <uint32_t MethodIndex> |
| + T* GetInstanceForMethod() { |
| + 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
|
| + if (!instance_) { |
| + VLOG(1) << "Instance for " << T::Name_ << "::" << Method::Name() |
| + << " not available."; |
| + return nullptr; |
| + } |
| + if (version_ < Method::MinVersion()) { |
| + LOG(ERROR) << "Instance for " << T::Name_ << "::" << Method::Name() |
| + << " version mismatch. Expected " << Method::MinVersion() |
| + << " got " << version_; |
| + return nullptr; |
| + } |
| + return instance_; |
| + } |
| + |
| // Same as the above, but for the version zero. |
| T* GetInstanceForMethod(const std::string& method_name_for_logging) { |
| return GetInstanceForMethod(method_name_for_logging, 0u); |