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

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: Minor clean-up. Created 3 years, 11 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
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 void set_heap_profiler_tag(const std::string& heap_profiler_tag) {
79 heap_profiler_tag_ = heap_profiler_tag;
80 }
81
77 private: 82 private:
78 void OnHandleReady(MojoResult result); 83 void OnHandleReady(MojoResult result);
79 84
80 static void CallOnHandleReady(uintptr_t context, 85 static void CallOnHandleReady(uintptr_t context,
81 MojoResult result, 86 MojoResult result,
82 MojoHandleSignalsState signals_state, 87 MojoHandleSignalsState signals_state,
83 MojoWatchNotificationFlags flags); 88 MojoWatchNotificationFlags flags);
84 89
85 base::ThreadChecker thread_checker_; 90 base::ThreadChecker thread_checker_;
86 91
(...skipping 10 matching lines...) Expand all
97 base::WeakPtr<Watcher> weak_self_; 102 base::WeakPtr<Watcher> weak_self_;
98 103
99 // Fields below must only be accessed on the Watcher's owning thread. 104 // Fields below must only be accessed on the Watcher's owning thread.
100 105
101 // The handle currently under watch. Not owned. 106 // The handle currently under watch. Not owned.
102 Handle handle_; 107 Handle handle_;
103 108
104 // The callback to call when the handle is signaled. 109 // The callback to call when the handle is signaled.
105 ReadyCallback callback_; 110 ReadyCallback callback_;
106 111
112 // Tag used to ID memory allocation triggered by this watcher.
113 std::string heap_profiler_tag_;
114
107 base::WeakPtrFactory<Watcher> weak_factory_; 115 base::WeakPtrFactory<Watcher> weak_factory_;
108 116
109 DISALLOW_COPY_AND_ASSIGN(Watcher); 117 DISALLOW_COPY_AND_ASSIGN(Watcher);
110 }; 118 };
111 119
112 } // namespace mojo 120 } // namespace mojo
113 121
114 #endif // MOJO_PUBLIC_CPP_SYSTEM_WATCHER_H_ 122 #endif // MOJO_PUBLIC_CPP_SYSTEM_WATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698