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

Side by Side Diff: ipc/unix_domain_socket_util_unittest.cc

Issue 1127153003: ipc: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 5 years, 7 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 | « ipc/sync_socket_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include <sys/socket.h> 5 #include <sys/socket.h>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/location.h"
9 #include "base/path_service.h" 10 #include "base/path_service.h"
10 #include "base/posix/eintr_wrapper.h" 11 #include "base/posix/eintr_wrapper.h"
12 #include "base/single_thread_task_runner.h"
11 #include "base/synchronization/waitable_event.h" 13 #include "base/synchronization/waitable_event.h"
12 #include "base/threading/thread.h" 14 #include "base/threading/thread.h"
13 #include "base/threading/thread_restrictions.h" 15 #include "base/threading/thread_restrictions.h"
14 #include "ipc/unix_domain_socket_util.h" 16 #include "ipc/unix_domain_socket_util.h"
15 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
16 18
17 namespace { 19 namespace {
18 20
19 class SocketAcceptor : public base::MessageLoopForIO::Watcher { 21 class SocketAcceptor : public base::MessageLoopForIO::Watcher {
20 public: 22 public:
21 SocketAcceptor(int fd, base::MessageLoopProxy* target_thread) 23 SocketAcceptor(int fd, base::SingleThreadTaskRunner* target_thread)
22 : server_fd_(-1), 24 : server_fd_(-1),
23 target_thread_(target_thread), 25 target_thread_(target_thread),
24 started_watching_event_(false, false), 26 started_watching_event_(false, false),
25 accepted_event_(false, false) { 27 accepted_event_(false, false) {
26 target_thread->PostTask(FROM_HERE, 28 target_thread->PostTask(FROM_HERE,
27 base::Bind(&SocketAcceptor::StartWatching, base::Unretained(this), fd)); 29 base::Bind(&SocketAcceptor::StartWatching, base::Unretained(this), fd));
28 } 30 }
29 31
30 ~SocketAcceptor() override { 32 ~SocketAcceptor() override {
31 Close(); 33 Close();
(...skipping 30 matching lines...) Expand all
62 } 64 }
63 void OnFileCanReadWithoutBlocking(int fd) override { 65 void OnFileCanReadWithoutBlocking(int fd) override {
64 ASSERT_EQ(-1, server_fd_); 66 ASSERT_EQ(-1, server_fd_);
65 IPC::ServerAcceptConnection(fd, &server_fd_); 67 IPC::ServerAcceptConnection(fd, &server_fd_);
66 watcher_->StopWatchingFileDescriptor(); 68 watcher_->StopWatchingFileDescriptor();
67 accepted_event_.Signal(); 69 accepted_event_.Signal();
68 } 70 }
69 void OnFileCanWriteWithoutBlocking(int fd) override {} 71 void OnFileCanWriteWithoutBlocking(int fd) override {}
70 72
71 int server_fd_; 73 int server_fd_;
72 base::MessageLoopProxy* target_thread_; 74 base::SingleThreadTaskRunner* target_thread_;
73 scoped_ptr<base::MessageLoopForIO::FileDescriptorWatcher> watcher_; 75 scoped_ptr<base::MessageLoopForIO::FileDescriptorWatcher> watcher_;
74 base::WaitableEvent started_watching_event_; 76 base::WaitableEvent started_watching_event_;
75 base::WaitableEvent accepted_event_; 77 base::WaitableEvent accepted_event_;
76 78
77 DISALLOW_COPY_AND_ASSIGN(SocketAcceptor); 79 DISALLOW_COPY_AND_ASSIGN(SocketAcceptor);
78 }; 80 };
79 81
80 const base::FilePath GetChannelDir() { 82 const base::FilePath GetChannelDir() {
81 base::FilePath tmp_dir; 83 base::FilePath tmp_dir;
82 PathService::Get(base::DIR_TEMP, &tmp_dir); 84 PathService::Get(base::DIR_TEMP, &tmp_dir);
(...skipping 13 matching lines...) Expand all
96 worker_.StartWithOptions(options); 98 worker_.StartWithOptions(options);
97 } 99 }
98 100
99 bool CreateServerSocket() { 101 bool CreateServerSocket() {
100 IPC::CreateServerUnixDomainSocket(socket_name_, &server_listen_fd_); 102 IPC::CreateServerUnixDomainSocket(socket_name_, &server_listen_fd_);
101 if (server_listen_fd_ < 0) 103 if (server_listen_fd_ < 0)
102 return false; 104 return false;
103 struct stat socket_stat; 105 struct stat socket_stat;
104 stat(socket_name_.value().c_str(), &socket_stat); 106 stat(socket_name_.value().c_str(), &socket_stat);
105 EXPECT_TRUE(S_ISSOCK(socket_stat.st_mode)); 107 EXPECT_TRUE(S_ISSOCK(socket_stat.st_mode));
106 acceptor_.reset(new SocketAcceptor(server_listen_fd_, 108 acceptor_.reset(
107 worker_.message_loop_proxy().get())); 109 new SocketAcceptor(server_listen_fd_, worker_.task_runner().get()));
108 acceptor_->WaitUntilReady(); 110 acceptor_->WaitUntilReady();
109 return true; 111 return true;
110 } 112 }
111 113
112 bool CreateClientSocket() { 114 bool CreateClientSocket() {
113 DCHECK(server_listen_fd_ >= 0); 115 DCHECK(server_listen_fd_ >= 0);
114 IPC::CreateClientUnixDomainSocket(socket_name_, &client_fd_); 116 IPC::CreateClientUnixDomainSocket(socket_name_, &client_fd_);
115 if (client_fd_ < 0) 117 if (client_fd_ < 0)
116 return false; 118 return false;
117 acceptor_->WaitForAccept(); 119 acceptor_->WaitForAccept();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 HANDLE_EINTR(send(connection.client_fd(), buffer, buf_len, 0)); 164 HANDLE_EINTR(send(connection.client_fd(), buffer, buf_len, 0));
163 ASSERT_EQ(buf_len, sent_bytes); 165 ASSERT_EQ(buf_len, sent_bytes);
164 char recv_buf[sizeof(buffer)]; 166 char recv_buf[sizeof(buffer)];
165 size_t received_bytes = 167 size_t received_bytes =
166 HANDLE_EINTR(recv(connection.server_fd(), recv_buf, buf_len, 0)); 168 HANDLE_EINTR(recv(connection.server_fd(), recv_buf, buf_len, 0));
167 ASSERT_EQ(buf_len, received_bytes); 169 ASSERT_EQ(buf_len, received_bytes);
168 ASSERT_EQ(0, memcmp(recv_buf, buffer, buf_len)); 170 ASSERT_EQ(0, memcmp(recv_buf, buffer, buf_len));
169 } 171 }
170 172
171 } // namespace 173 } // namespace
OLDNEW
« no previous file with comments | « ipc/sync_socket_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698