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

Side by Side Diff: chrome/common/profiling/memlog_sender_pipe_win.cc

Issue 2940003002: Add pipe implementation for OOP memory logging (Closed)
Patch Set: Explicit 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 #include "chrome/common/profiling/memlog_sender_pipe_win.h"
6
7 #include "base/logging.h"
8 #include "chrome/common/profiling/memlog_stream.h"
9
10 namespace profiling {
11
12 MemlogSenderPipe::MemlogSenderPipe(const base::string16& pipe_id)
13 : pipe_id_(pipe_id), handle_(INVALID_HANDLE_VALUE) {}
14
15 MemlogSenderPipe::~MemlogSenderPipe() {
16 if (handle_ != INVALID_HANDLE_VALUE)
17 ::CloseHandle(handle_);
18 }
19
20 bool MemlogSenderPipe::Connect() {
21 DCHECK(handle_ == INVALID_HANDLE_VALUE);
22
23 base::string16 pipe_name = kWindowsPipePrefix;
24 pipe_name.append(pipe_id_);
25
26 do {
27 if (!::WaitNamedPipe(pipe_name.c_str(), NMPWAIT_WAIT_FOREVER)) {
28 // Since it will wait "forever", the only time WaitNamedPipe should fail
29 // is if the pipe doesn't exist.
30 return false;
31 }
32 handle_ = ::CreateFile(pipe_name.c_str(), GENERIC_READ | GENERIC_WRITE, 0,
Boris Vidolov 2017/06/15 22:25:45 Is it a bidirectional pipe? These are not fun, as
brettw 2017/06/15 22:53:10 It is but I don't need that. I changed it to a sin
33 NULL, OPEN_EXISTING, 0, NULL);
34 // Need to loop since there is a race condition waiting for a connection to
35 // be available and actually connecting to it.
36 } while (handle_ == INVALID_HANDLE_VALUE);
Boris Vidolov 2017/06/15 22:25:45 Consider timeout. Maybe die after 30 seconds. The
brettw 2017/06/15 22:53:10 Done.
37
38 return true;
39 }
40
41 bool MemlogSenderPipe::Send(const void* data, size_t sz) {
awong 2017/06/15 21:32:46 Can we check fail that sz fits in a DWORD?
brettw 2017/06/15 22:12:21 You asking me this made me realize that we can't c
42 // The pipe uses a blocking wait mode (it doesn't specify PIPE_NOWAIT) so
43 // WriteFile should do only complete writes.
44 DWORD bytes_written = 0;
45 if (!::WriteFile(handle_, data, static_cast<DWORD>(sz), &bytes_written, NULL))
46 return false;
47 DCHECK(bytes_written == static_cast<DWORD>(sz));
awong 2017/06/15 21:32:46 DCHECK_EQ
48 return true;
49 }
50
51 } // namespace profiling
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698