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

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

Issue 2347293002: arc: Add InstanceHelper::GetInstanceForMethod() (Closed)
Patch Set: No more DCHECK 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 if (!instance_) {
52 VLOG(1) << "Instance for " << T::Name_ << "::" << method_name_for_logging
53 << " not available.";
54 return nullptr;
55 }
56 if (version_ < min_version) {
57 VLOG(1) << "Instance for " << T::Name_ << "::" << method_name_for_logging
58 << " version mismatch. Expected " << min_version << " got "
59 << version_;
60 return nullptr;
61 }
62 return instance_;
63 }
64
65 // Same as the above, but for the version zero.
66 T* GetInstanceForMethod(const char* method_name_for_logging) {
67 return GetInstanceForMethod(method_name_for_logging, 0u);
68 }
69
45 // Adds or removes observers. This can only be called on the thread that this 70 // 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 71 // class was created on. RemoveObserver does nothing if |observer| is not in
47 // the list. 72 // the list.
48 void AddObserver(Observer* observer) { 73 void AddObserver(Observer* observer) {
49 DCHECK(thread_checker_.CalledOnValidThread()); 74 DCHECK(thread_checker_.CalledOnValidThread());
50 observer_list_.AddObserver(observer); 75 observer_list_.AddObserver(observer);
51 76
52 if (instance()) 77 if (instance())
53 observer->OnInstanceReady(); 78 observer->OnInstanceReady();
54 } 79 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 112
88 base::ThreadChecker thread_checker_; 113 base::ThreadChecker thread_checker_;
89 base::ObserverList<Observer> observer_list_; 114 base::ObserverList<Observer> observer_list_;
90 115
91 DISALLOW_COPY_AND_ASSIGN(InstanceHolder<T>); 116 DISALLOW_COPY_AND_ASSIGN(InstanceHolder<T>);
92 }; 117 };
93 118
94 } // namespace arc 119 } // namespace arc
95 120
96 #endif // COMPONENTS_ARC_INSTANCE_HOLDER_H_ 121 #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