| OLD | NEW |
| (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_SERVER_WIN_H_ |
| 6 #define CHROME_PROFILING_MEMLOG_RECEIVER_PIPE_SERVER_WIN_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/callback_forward.h" |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/message_loop/message_pump_win.h" |
| 14 #include "base/strings/string16.h" |
| 15 #include "chrome/profiling/memlog_receiver_pipe_win.h" |
| 16 |
| 17 namespace base { |
| 18 class TaskRunner; |
| 19 } // namespace base |
| 20 |
| 21 namespace profiling { |
| 22 |
| 23 class MemlogReceiverPipe; |
| 24 |
| 25 // This class listens for new pipe connections and creates new |
| 26 // MemlogReceiverPipe objects for each one. |
| 27 class MemlogReceiverPipeServer |
| 28 : public base::RefCountedThreadSafe<MemlogReceiverPipeServer> { |
| 29 public: |
| 30 using NewConnectionCallback = |
| 31 base::RepeatingCallback<void(scoped_refptr<MemlogReceiverPipe>)>; |
| 32 |
| 33 // |io_runner| is the task runner for the I/O thread. When a new connection is |
| 34 // established, the |on_new_conn| callback is called with the pipe. |
| 35 MemlogReceiverPipeServer(base::TaskRunner* io_runner, |
| 36 const std::string& pipe_id, |
| 37 NewConnectionCallback on_new_conn); |
| 38 ~MemlogReceiverPipeServer(); |
| 39 |
| 40 void set_on_new_connection(NewConnectionCallback on_new_connection) { |
| 41 on_new_connection_ = on_new_connection; |
| 42 } |
| 43 |
| 44 // Starts the server which opens the pipe and begins accepting connections. |
| 45 void Start(); |
| 46 |
| 47 private: |
| 48 base::string16 GetPipeName() const; |
| 49 |
| 50 HANDLE CreatePipeInstance(bool first_instance) const; |
| 51 |
| 52 // Called on the IO thread. |
| 53 void ScheduleNewConnection(bool first_instance); |
| 54 |
| 55 void OnIOCompleted(size_t bytes_transfered, DWORD error); |
| 56 |
| 57 scoped_refptr<base::TaskRunner> io_runner_; |
| 58 base::string16 pipe_id_; |
| 59 NewConnectionCallback on_new_connection_; |
| 60 |
| 61 // Current connection we're waiting on creation for. |
| 62 std::unique_ptr<MemlogReceiverPipe::CompletionThunk> current_; |
| 63 }; |
| 64 |
| 65 } // namespace profiling |
| 66 |
| 67 #endif // CHROME_PROFILING_MEMLOG_RECEIVER_PIPE_SERVER_WIN_H_ |
| OLD | NEW |