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

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

Issue 2347293002: arc: Add InstanceHelper::GetInstanceForMethod() (Closed)
Patch Set: Slightly better logging 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 unified diff | Download patch
« no previous file with comments | « components/arc/ime/arc_ime_bridge_impl.cc ('k') | components/arc/net/arc_net_host_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 24 matching lines...) Expand all
35 35
36 InstanceHolder() = default; 36 InstanceHolder() = default;
37 37
38 // Gets the Mojo interface for all the instance services. This will return 38 // Gets the Mojo interface for all the instance services. This will return
39 // nullptr if that particular service is not ready yet. Use an Observer if you 39 // nullptr if that particular service is not ready yet. Use an Observer if you
40 // want to be notified when this is ready. This can only be called on the 40 // want to be notified when this is ready. This can only be called on the
41 // thread that this class was created on. 41 // thread that this class was created on.
42 T* instance() const { return instance_; } 42 T* instance() const { return instance_; }
43 uint32_t version() const { return version_; } 43 uint32_t version() const { return version_; }
44 44
45 // Gets the Mojo interface that's intended to call for
46 // |method_name_for_logging|, but only if its reported version is at least
47 // |min_version|. Returns nullptr if the instance is either not ready or does
48 // not have the requested version, and logs appropriately.
49 T* GetInstanceForMethod(const char* method_name_for_logging,
50 uint32_t min_version) {
51 DCHECK_LT(0u, min_version) << T::Name_ << "::" << method_name_for_logging;
Yusuke Sato 2016/09/17 04:28:05 nit: you can't have this check anymore since line
Luis Héctor Chávez 2016/09/19 15:33:11 Done.
52 if (!instance_) {
53 VLOG(1) << "Instance for " << T::Name_ << "::" << method_name_for_logging
54 << " not available.";
55 return nullptr;
56 }
57 if (version_ < min_version) {
58 VLOG(1) << "Instance for " << T::Name_ << "::" << method_name_for_logging
59 << " version mismatch. Expected " << min_version << " got "
60 << version_;
61 return nullptr;
62 }
63 return instance_;
64 }
65
66 // Same as the above, but for the version zero.
67 T* GetInstanceForMethod(const char* method_name_for_logging) {
68 return GetInstanceForMethod(method_name_for_logging, 0u);
69 }
70
45 // Adds or removes observers. This can only be called on the thread that this 71 // Adds or removes observers. This can only be called on the thread that this
46 // class was created on. RemoveObserver does nothing if |observer| is not in 72 // class was created on. RemoveObserver does nothing if |observer| is not in
47 // the list. 73 // the list.
48 void AddObserver(Observer* observer) { 74 void AddObserver(Observer* observer) {
49 DCHECK(thread_checker_.CalledOnValidThread()); 75 DCHECK(thread_checker_.CalledOnValidThread());
50 observer_list_.AddObserver(observer); 76 observer_list_.AddObserver(observer);
51 77
52 if (instance()) 78 if (instance())
53 observer->OnInstanceReady(); 79 observer->OnInstanceReady();
54 } 80 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 113
88 base::ThreadChecker thread_checker_; 114 base::ThreadChecker thread_checker_;
89 base::ObserverList<Observer> observer_list_; 115 base::ObserverList<Observer> observer_list_;
90 116
91 DISALLOW_COPY_AND_ASSIGN(InstanceHolder<T>); 117 DISALLOW_COPY_AND_ASSIGN(InstanceHolder<T>);
92 }; 118 };
93 119
94 } // namespace arc 120 } // namespace arc
95 121
96 #endif // COMPONENTS_ARC_INSTANCE_HOLDER_H_ 122 #endif // COMPONENTS_ARC_INSTANCE_HOLDER_H_
OLDNEW
« no previous file with comments | « components/arc/ime/arc_ime_bridge_impl.cc ('k') | components/arc/net/arc_net_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698