Index: components/arc/instance_holder.h |
diff --git a/components/arc/instance_holder.h b/components/arc/instance_holder.h |
index 4fb5b37023eac07e6303f0c9928c0e8752c8f547..dc5480d52b4c1eed442833d40e016325ab9a6ca9 100644 |
--- a/components/arc/instance_holder.h |
+++ b/components/arc/instance_holder.h |
@@ -42,6 +42,38 @@ class InstanceHolder { |
T* instance() const { return instance_; } |
Yusuke Sato
2016/09/17 01:38:56
What about renaming this to GetInstanceForVersionZ
Luis Héctor Chávez
2016/09/17 03:52:14
Resolved to keep.
|
uint32_t version() const { return version_; } |
+ // Gets the Mojo interface for the instance, 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. |
+ T* GetInstanceForVersion(uint32_t min_version) { |
Yusuke Sato
2016/09/17 01:38:56
Providing two versions might not work as expected.
Luis Héctor Chávez
2016/09/17 01:56:11
If we go this route, I prefer the following:
GetI
Yusuke Sato
2016/09/17 02:42:53
We can still remove instance() (or at least rename
Luis Héctor Chávez
2016/09/17 03:16:34
i'd still like to keep it for the few cases where
Yusuke Sato
2016/09/17 03:22:06
Sure, thanks for the explanation. All you mentione
Luis Héctor Chávez
2016/09/17 03:52:14
Done (hooray for regex!)
|
+ if (!instance_) { |
+ VLOG(1) << __PRETTY_FUNCTION__ << " Instance not available."; |
+ return nullptr; |
+ } |
+ if (version_ < min_version) { |
+ VLOG(1) << __PRETTY_FUNCTION__ << " Instance version mismatch. Expected " |
+ << min_version << " got " << version_; |
+ return nullptr; |
+ } |
+ return instance_; |
+ } |
+ |
+ // Same as the above, but with an explicit method name for better logging. |
+ T* GetInstanceForVersion(uint32_t min_version, const char* method_name) { |
+ if (!instance_) { |
Yusuke Sato
2016/09/17 01:38:57
If we add GetInstanceForVersionZero(), we can/shou
Luis Héctor Chávez
2016/09/17 03:52:14
Done.
|
+ VLOG(1) << __PRETTY_FUNCTION__ << " Instance not available to call " |
+ << method_name << "."; |
+ return nullptr; |
+ } |
+ if (version_ < min_version) { |
+ VLOG(1) << __PRETTY_FUNCTION__ << " Instance version mismatch to call " |
+ << method_name << ". Expected " << min_version << " got " |
+ << version_; |
+ return nullptr; |
+ } |
+ return instance_; |
+ } |
+ |
// 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. |