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

Side by Side Diff: chrome/profiling/memlog_receiver_pipe_win.h

Issue 2940003002: Add pipe implementation for OOP memory logging (Closed)
Patch Set: Comment Created 3 years, 6 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_PROFILING_MEMLOG_RECEIVER_PIPE_WIN_H_
6 #define CHROME_PROFILING_MEMLOG_RECEIVER_PIPE_WIN_H_
7
8 #include <windows.h>
9
10 #include <string>
11
12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/message_loop/message_pump_win.h"
15 #include "base/strings/string16.h"
16 #include "build/build_config.h"
17
18 namespace base {
19 class TaskRunner;
20 }
21
22 namespace profiling {
23
24 class MemlogStreamReceiver;
25
26 class MemlogReceiverPipe
27 : public base::RefCountedThreadSafe<MemlogReceiverPipe> {
28 public:
29 // RegisterIOHandler can't change the callback ID of a handle once it has
30 // been registered. This class allows switching the callbacks from the
31 // server to the pipe once the pipe is created while keeping the IOHandler
32 // attached to the handle the same.
33 class CompletionThunk : public base::MessagePumpForIO::IOHandler {
34 public:
35 using Callback = base::RepeatingCallback<void(size_t, DWORD)>;
36
37 // Takes ownership of HANDLE and closes it when the class goes out of scope.
38 CompletionThunk(HANDLE handle, Callback cb);
39 ~CompletionThunk();
40
41 void set_callback(Callback cb) { callback_ = cb; }
42
43 HANDLE handle() { return handle_; }
44 OVERLAPPED* overlapped() { return &context_.overlapped; }
45
46 void ZeroOverlapped();
47
48 private:
49 // IOHandler implementation.
50 void OnIOCompleted(base::MessagePumpForIO::IOContext* context,
51 DWORD bytes_transfered,
52 DWORD error) override;
53
54 base::MessagePumpForIO::IOContext context_;
55
56 HANDLE handle_;
57 Callback callback_;
58
59 DISALLOW_COPY_AND_ASSIGN(CompletionThunk);
60 };
61
62 explicit MemlogReceiverPipe(std::unique_ptr<CompletionThunk> thunk);
63 ~MemlogReceiverPipe();
64
65 void StartReadingOnIOThread();
66
67 int GetRemoteProcessID();
68 void SetReceiver(scoped_refptr<base::TaskRunner> task_runner,
69 scoped_refptr<MemlogStreamReceiver> receiver);
70
71 private:
72 void OnIOCompleted(size_t bytes_transfered, DWORD error);
73
74 void ReadUntilBlocking();
75
76 std::unique_ptr<CompletionThunk> thunk_;
77
78 scoped_refptr<base::TaskRunner> receiver_task_runner_;
79 scoped_refptr<MemlogStreamReceiver> receiver_;
80
81 bool read_outstanding_ = false;
82
83 std::unique_ptr<char[]> read_buffer_;
84
85 DISALLOW_COPY_AND_ASSIGN(MemlogReceiverPipe);
86 };
87
88 } // namespace profiling
89
90 #endif // CHROME_PROFILING_MEMLOG_RECEIVER_PIPE_WIN_H_
OLDNEW
« no previous file with comments | « chrome/profiling/memlog_receiver_pipe_server_win.cc ('k') | chrome/profiling/memlog_receiver_pipe_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698