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

Unified Diff: components/arc/instance_holder.h

Issue 2599673005: arc: Use GET_INTERFACE_FOR_METHOD macro (Closed)
Patch Set: Addressed feedback Created 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/arc/ime/arc_ime_bridge_impl.cc ('k') | components/arc/intent_helper/arc_intent_helper_bridge.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/arc/instance_holder.h
diff --git a/components/arc/instance_holder.h b/components/arc/instance_holder.h
index 8455814581c61997f4d4ec602c6373cdbd9bb41b..4918cd2d5616cce7790630b621b2d960f8d9ee06 100644
--- a/components/arc/instance_holder.h
+++ b/components/arc/instance_holder.h
@@ -6,6 +6,7 @@
#define COMPONENTS_ARC_INSTANCE_HOLDER_H_
#include <string>
+#include <type_traits>
#include <utility>
#include "base/bind.h"
@@ -13,6 +14,16 @@
#include "base/observer_list.h"
#include "base/threading/thread_checker.h"
+// A convenience macro to call arc::InstanceHolder<T>::GetInstanceForVersion().
+// In order to avoid exposing method names from within the Mojo bindings, we
+// will rely on stringification and the fact that the method min versions have a
+// consistent naming scheme.
+#define ARC_GET_INSTANCE_FOR_METHOD(holder, method_name) \
+ (holder)->GetInstanceForVersion( \
+ std::remove_pointer<decltype( \
+ holder)>::type::Instance::k##method_name##MinVersion, \
+ #method_name)
+
namespace arc {
// Holds a Mojo instance+version pair. This also allows for listening for state
@@ -34,6 +45,8 @@ class InstanceHolder {
virtual ~Observer() = default;
};
+ using Instance = T;
+
InstanceHolder() = default;
// Returns true if the Mojo interface is ready at least for its version 0
@@ -45,9 +58,10 @@ class InstanceHolder {
// |method_name_for_logging|, but only if its reported version is at least
// |min_version|. Returns nullptr if the instance is either not ready or does
// not have the requested version, and logs appropriately.
- // TODO(lhchavez): Improve the API. (crbug.com/649782)
- T* GetInstanceForMethod(const std::string& method_name_for_logging,
- uint32_t min_version) {
+ // This function should not be called directly. Instead, use the
+ // ARC_GET_INSTANCE_FOR_METHOD() macro.
+ T* GetInstanceForVersion(uint32_t min_version,
+ const char method_name_for_logging[]) {
if (!instance_) {
VLOG(1) << "Instance for " << T::Name_ << "::" << method_name_for_logging
<< " not available.";
@@ -63,11 +77,6 @@ class InstanceHolder {
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);
- }
-
// Adds or removes observers. This can only be called on the thread that this
// class was created on. RemoveObserver does nothing if |observer| is not in
// the list.
« no previous file with comments | « components/arc/ime/arc_ime_bridge_impl.cc ('k') | components/arc/intent_helper/arc_intent_helper_bridge.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698