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

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

Issue 2623263005: Tag some of Mojo heap allocations for the heap profiler. (Closed)
Patch Set: Synced Created 3 years, 10 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 | « mojo/public/cpp/system/tests/watcher_unittest.cc ('k') | mojo/public/cpp/system/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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_WATCHER_H_ 5 #ifndef MOJO_PUBLIC_CPP_SYSTEM_WATCHER_H_
6 #define MOJO_PUBLIC_CPP_SYSTEM_WATCHER_H_ 6 #define MOJO_PUBLIC_CPP_SYSTEM_WATCHER_H_
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 18 matching lines...) Expand all
29 // 29 //
30 // |MOJO_RESULT_OK|: One or more of the signals being watched is satisfied. 30 // |MOJO_RESULT_OK|: One or more of the signals being watched is satisfied.
31 // 31 //
32 // |MOJO_RESULT_FAILED_PRECONDITION|: None of the signals being watched can 32 // |MOJO_RESULT_FAILED_PRECONDITION|: None of the signals being watched can
33 // ever be satisfied again. 33 // ever be satisfied again.
34 // 34 //
35 // |MOJO_RESULT_CANCELLED|: The handle has been closed and the watch has 35 // |MOJO_RESULT_CANCELLED|: The handle has been closed and the watch has
36 // been cancelled implicitly. 36 // been cancelled implicitly.
37 using ReadyCallback = base::Callback<void(MojoResult result)>; 37 using ReadyCallback = base::Callback<void(MojoResult result)>;
38 38
39 explicit Watcher(scoped_refptr<base::SingleThreadTaskRunner> runner = 39 Watcher(const tracked_objects::Location& from_here,
40 base::ThreadTaskRunnerHandle::Get()); 40 scoped_refptr<base::SingleThreadTaskRunner> runner =
41 base::ThreadTaskRunnerHandle::Get());
41 42
42 // NOTE: This destructor automatically calls |Cancel()| if the Watcher is 43 // NOTE: This destructor automatically calls |Cancel()| if the Watcher is
43 // still active. 44 // still active.
44 ~Watcher(); 45 ~Watcher();
45 46
46 // Indicates if the Watcher is currently watching a handle. 47 // Indicates if the Watcher is currently watching a handle.
47 bool IsWatching() const; 48 bool IsWatching() const;
48 49
49 // Starts watching |handle|. A Watcher may only watch one handle at a time, 50 // Starts watching |handle|. A Watcher may only watch one handle at a time,
50 // but it is safe to call this more than once as long as the previous watch 51 // but it is safe to call this more than once as long as the previous watch
(...skipping 16 matching lines...) Expand all
67 MojoHandleSignals signals, 68 MojoHandleSignals signals,
68 const ReadyCallback& callback); 69 const ReadyCallback& callback);
69 70
70 // Cancels the current watch. Once this returns, the callback previously 71 // Cancels the current watch. Once this returns, the callback previously
71 // passed to |Start()| will never be called again for this Watcher. 72 // passed to |Start()| will never be called again for this Watcher.
72 void Cancel(); 73 void Cancel();
73 74
74 Handle handle() const { return handle_; } 75 Handle handle() const { return handle_; }
75 ReadyCallback ready_callback() const { return callback_; } 76 ReadyCallback ready_callback() const { return callback_; }
76 77
78 // Sets the tag used by the heap profiler.
79 // |tag| must be a const string literal.
80 void set_heap_profiler_tag(const char* heap_profiler_tag) {
81 heap_profiler_tag_ = heap_profiler_tag;
82 }
83
77 private: 84 private:
78 void OnHandleReady(MojoResult result); 85 void OnHandleReady(MojoResult result);
79 86
80 static void CallOnHandleReady(uintptr_t context, 87 static void CallOnHandleReady(uintptr_t context,
81 MojoResult result, 88 MojoResult result,
82 MojoHandleSignalsState signals_state, 89 MojoHandleSignalsState signals_state,
83 MojoWatchNotificationFlags flags); 90 MojoWatchNotificationFlags flags);
84 91
85 base::ThreadChecker thread_checker_; 92 base::ThreadChecker thread_checker_;
86 93
(...skipping 10 matching lines...) Expand all
97 base::WeakPtr<Watcher> weak_self_; 104 base::WeakPtr<Watcher> weak_self_;
98 105
99 // Fields below must only be accessed on the Watcher's owning thread. 106 // Fields below must only be accessed on the Watcher's owning thread.
100 107
101 // The handle currently under watch. Not owned. 108 // The handle currently under watch. Not owned.
102 Handle handle_; 109 Handle handle_;
103 110
104 // The callback to call when the handle is signaled. 111 // The callback to call when the handle is signaled.
105 ReadyCallback callback_; 112 ReadyCallback callback_;
106 113
114 // Tag used to ID memory allocations that originated from notifications in
115 // this watcher.
116 const char* heap_profiler_tag_ = nullptr;
117
107 base::WeakPtrFactory<Watcher> weak_factory_; 118 base::WeakPtrFactory<Watcher> weak_factory_;
108 119
109 DISALLOW_COPY_AND_ASSIGN(Watcher); 120 DISALLOW_COPY_AND_ASSIGN(Watcher);
110 }; 121 };
111 122
112 } // namespace mojo 123 } // namespace mojo
113 124
114 #endif // MOJO_PUBLIC_CPP_SYSTEM_WATCHER_H_ 125 #endif // MOJO_PUBLIC_CPP_SYSTEM_WATCHER_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/system/tests/watcher_unittest.cc ('k') | mojo/public/cpp/system/watcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698