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

Unified Diff: components/arc/instance_holder.h

Issue 2347293002: arc: Add InstanceHelper::GetInstanceForMethod() (Closed)
Patch Set: git cl format/lint Created 4 years, 3 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
Index: components/arc/instance_holder.h
diff --git a/components/arc/instance_holder.h b/components/arc/instance_holder.h
index 4fb5b37023eac07e6303f0c9928c0e8752c8f547..4df2302593b571ac7c6edcbab826bdbc505a3dc2 100644
--- a/components/arc/instance_holder.h
+++ b/components/arc/instance_holder.h
@@ -42,6 +42,38 @@ class InstanceHolder {
T* instance() const { return instance_; }
uint32_t version() const { return version_; }
Yusuke Sato 2016/09/16 23:58:48 Can we remove this now? If not, what's preventing
Luis Héctor Chávez 2016/09/17 00:30:53 GetIntentHelperInstanceWithErrorCode() still needs
+ // 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) {
+ if (!instance_) {
+ VLOG(2) << __func__ << " Instance not available.";
+ return nullptr;
+ }
+ if (version_ < min_version) {
+ VLOG(2) << __func__ << " 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) {
Yusuke Sato 2016/09/16 23:58:48 Passing the method_name every time only for loggin
Luis Héctor Chávez 2016/09/17 00:30:53 We can't query the method name from |min_version|
Yusuke Sato 2016/09/17 01:38:56 Acknowledged. I guess typeid() won't always work a
+ if (!instance_) {
+ VLOG(2) << __func__ << " Instance not available to call " << method_name
+ << ".";
+ return nullptr;
+ }
+ if (version_ < min_version) {
+ VLOG(2) << __func__ << " 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.

Powered by Google App Engine
This is Rietveld 408576698