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

Side by Side Diff: mojo/public/cpp/system/simple_watcher.h

Issue 2754863002: Mojo: Don't hold a watch context ref in SimpleWatcher posted task (Closed)
Patch Set: . Created 3 years, 9 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 | « no previous file | mojo/public/cpp/system/simple_watcher.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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 MOJO_PUBLIC_CPP_SYSTEM_SIMPLE_WATCHER_H_ 5 #ifndef MOJO_PUBLIC_CPP_SYSTEM_SIMPLE_WATCHER_H_
6 #define MOJO_PUBLIC_CPP_SYSTEM_SIMPLE_WATCHER_H_ 6 #define MOJO_PUBLIC_CPP_SYSTEM_SIMPLE_WATCHER_H_
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 157
158 // Sets the tag used by the heap profiler. 158 // Sets the tag used by the heap profiler.
159 // |tag| must be a const string literal. 159 // |tag| must be a const string literal.
160 void set_heap_profiler_tag(const char* heap_profiler_tag) { 160 void set_heap_profiler_tag(const char* heap_profiler_tag) {
161 heap_profiler_tag_ = heap_profiler_tag; 161 heap_profiler_tag_ = heap_profiler_tag;
162 } 162 }
163 163
164 private: 164 private:
165 class Context; 165 class Context;
166 166
167 void OnHandleReady(scoped_refptr<const Context> context, MojoResult result); 167 void OnHandleReady(int watch_id, MojoResult result);
168 168
169 base::ThreadChecker thread_checker_; 169 base::ThreadChecker thread_checker_;
170 170
171 // The policy used to determine how this SimpleWatcher is armed. 171 // The policy used to determine how this SimpleWatcher is armed.
172 const ArmingPolicy arming_policy_; 172 const ArmingPolicy arming_policy_;
173 173
174 // The TaskRunner of this SimpleWatcher's owning thread. This field is safe to 174 // The TaskRunner of this SimpleWatcher's owning thread. This field is safe to
175 // access from any thread. 175 // access from any thread.
176 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 176 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
177 177
178 // Whether |task_runner_| is the same as base::ThreadTaskRunnerHandle::Get() 178 // Whether |task_runner_| is the same as base::ThreadTaskRunnerHandle::Get()
179 // for the thread. 179 // for the thread.
180 const bool is_default_task_runner_; 180 const bool is_default_task_runner_;
181 181
182 ScopedWatcherHandle watcher_handle_; 182 ScopedWatcherHandle watcher_handle_;
183 183
184 // A thread-safe context object corresponding to the currently active watch, 184 // A thread-safe context object corresponding to the currently active watch,
185 // if any. 185 // if any.
186 scoped_refptr<Context> context_; 186 scoped_refptr<Context> context_;
187 187
188 // Fields below must only be accessed on the SimpleWatcher's owning thread. 188 // Fields below must only be accessed on the SimpleWatcher's owning thread.
189 189
190 // The handle currently under watch. Not owned. 190 // The handle currently under watch. Not owned.
191 Handle handle_; 191 Handle handle_;
192 192
193 // A simple counter to disambiguate notifications from multiple watch contexts
194 // in the event that this SimpleWatcher cancels and watches multiple times.
195 int watch_id_ = 0;
196
193 // The callback to call when the handle is signaled. 197 // The callback to call when the handle is signaled.
194 ReadyCallback callback_; 198 ReadyCallback callback_;
195 199
196 // Tracks if the SimpleWatcher has already notified of unsatisfiability. This 200 // Tracks if the SimpleWatcher has already notified of unsatisfiability. This
197 // is used to prevent redundant notifications in AUTOMATIC mode. 201 // is used to prevent redundant notifications in AUTOMATIC mode.
198 bool unsatisfiable_ = false; 202 bool unsatisfiable_ = false;
199 203
200 // Tag used to ID memory allocations that originated from notifications in 204 // Tag used to ID memory allocations that originated from notifications in
201 // this watcher. 205 // this watcher.
202 const char* heap_profiler_tag_ = nullptr; 206 const char* heap_profiler_tag_ = nullptr;
203 207
204 base::WeakPtrFactory<SimpleWatcher> weak_factory_; 208 base::WeakPtrFactory<SimpleWatcher> weak_factory_;
205 209
206 DISALLOW_COPY_AND_ASSIGN(SimpleWatcher); 210 DISALLOW_COPY_AND_ASSIGN(SimpleWatcher);
207 }; 211 };
208 212
209 } // namespace mojo 213 } // namespace mojo
210 214
211 #endif // MOJO_PUBLIC_CPP_SYSTEM_SIMPLE_WATCHER_H_ 215 #endif // MOJO_PUBLIC_CPP_SYSTEM_SIMPLE_WATCHER_H_
OLDNEW
« no previous file with comments | « no previous file | mojo/public/cpp/system/simple_watcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698