| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/message_loop/message_pump_libevent.h" | 5 #include "base/message_loop/message_pump_libevent.h" |
| 6 | 6 |
| 7 #include <unistd.h> | 7 #include <unistd.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 70 |
| 71 // base:MessagePumpLibevent::Watcher interface | 71 // base:MessagePumpLibevent::Watcher interface |
| 72 void OnFileCanReadWithoutBlocking(int fd) override {} | 72 void OnFileCanReadWithoutBlocking(int fd) override {} |
| 73 void OnFileCanWriteWithoutBlocking(int fd) override {} | 73 void OnFileCanWriteWithoutBlocking(int fd) override {} |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 #if GTEST_HAS_DEATH_TEST && !defined(NDEBUG) | 76 #if GTEST_HAS_DEATH_TEST && !defined(NDEBUG) |
| 77 | 77 |
| 78 // Test to make sure that we catch calling WatchFileDescriptor off of the | 78 // Test to make sure that we catch calling WatchFileDescriptor off of the |
| 79 // wrong thread. | 79 // wrong thread. |
| 80 #if defined(OS_CHROMEOS) | 80 #if defined(OS_CHROMEOS) || defined(OS_LINUX) |
| 81 // Flaky on Chrome OS: crbug.com/138845. | 81 // Flaky on Chrome OS and Linux: crbug.com/138845. |
| 82 #define MAYBE_TestWatchingFromBadThread DISABLED_TestWatchingFromBadThread | 82 #define MAYBE_TestWatchingFromBadThread DISABLED_TestWatchingFromBadThread |
| 83 #else | 83 #else |
| 84 #define MAYBE_TestWatchingFromBadThread TestWatchingFromBadThread | 84 #define MAYBE_TestWatchingFromBadThread TestWatchingFromBadThread |
| 85 #endif | 85 #endif |
| 86 TEST_F(MessagePumpLibeventTest, MAYBE_TestWatchingFromBadThread) { | 86 TEST_F(MessagePumpLibeventTest, MAYBE_TestWatchingFromBadThread) { |
| 87 MessagePumpLibevent::FileDescriptorWatcher watcher; | 87 MessagePumpLibevent::FileDescriptorWatcher watcher; |
| 88 StupidWatcher delegate; | 88 StupidWatcher delegate; |
| 89 | 89 |
| 90 ASSERT_DEATH(io_loop()->WatchFileDescriptor( | 90 ASSERT_DEATH(io_loop()->WatchFileDescriptor( |
| 91 STDOUT_FILENO, false, MessageLoopForIO::WATCH_READ, &watcher, &delegate), | 91 STDOUT_FILENO, false, MessageLoopForIO::WATCH_READ, &watcher, &delegate), |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 TEST_F(MessagePumpLibeventTest, QuitWatcher) { | 239 TEST_F(MessagePumpLibeventTest, QuitWatcher) { |
| 240 // Delete the old MessageLoop so that we can manage our own one here. | 240 // Delete the old MessageLoop so that we can manage our own one here. |
| 241 ui_loop_.reset(); | 241 ui_loop_.reset(); |
| 242 | 242 |
| 243 MessagePumpLibevent* pump = new MessagePumpLibevent; // owned by |loop|. | 243 MessagePumpLibevent* pump = new MessagePumpLibevent; // owned by |loop|. |
| 244 MessageLoop loop(make_scoped_ptr(pump)); | 244 MessageLoop loop(make_scoped_ptr(pump)); |
| 245 RunLoop run_loop; | 245 RunLoop run_loop; |
| 246 MessagePumpLibevent::FileDescriptorWatcher controller; | 246 MessagePumpLibevent::FileDescriptorWatcher controller; |
| 247 QuitWatcher delegate(&controller, &run_loop); | 247 QuitWatcher delegate(&controller, &run_loop); |
| 248 WaitableEvent event(false /* manual_reset */, false /* initially_signaled */); | 248 WaitableEvent event(false /* manual_reset */, false /* initially_signaled */); |
| 249 WaitableEventWatcher watcher; | 249 scoped_ptr<WaitableEventWatcher> watcher(new WaitableEventWatcher); |
| 250 | 250 |
| 251 // Tell the pump to watch the pipe. | 251 // Tell the pump to watch the pipe. |
| 252 pump->WatchFileDescriptor(pipefds_[0], false, MessagePumpLibevent::WATCH_READ, | 252 pump->WatchFileDescriptor(pipefds_[0], false, MessagePumpLibevent::WATCH_READ, |
| 253 &controller, &delegate); | 253 &controller, &delegate); |
| 254 | 254 |
| 255 // Make the IO thread wait for |event| before writing to pipefds[1]. | 255 // Make the IO thread wait for |event| before writing to pipefds[1]. |
| 256 const char buf = 0; | 256 const char buf = 0; |
| 257 const WaitableEventWatcher::EventCallback write_fd_task = | 257 const WaitableEventWatcher::EventCallback write_fd_task = |
| 258 Bind(&WriteFDWrapper, pipefds_[1], &buf, 1); | 258 Bind(&WriteFDWrapper, pipefds_[1], &buf, 1); |
| 259 io_loop()->PostTask(FROM_HERE, | 259 io_loop()->PostTask(FROM_HERE, |
| 260 Bind(IgnoreResult(&WaitableEventWatcher::StartWatching), | 260 Bind(IgnoreResult(&WaitableEventWatcher::StartWatching), |
| 261 Unretained(&watcher), &event, write_fd_task)); | 261 Unretained(watcher.get()), &event, write_fd_task)); |
| 262 | 262 |
| 263 // Queue |event| to signal on |loop|. | 263 // Queue |event| to signal on |loop|. |
| 264 loop.PostTask(FROM_HERE, Bind(&WaitableEvent::Signal, Unretained(&event))); | 264 loop.PostTask(FROM_HERE, Bind(&WaitableEvent::Signal, Unretained(&event))); |
| 265 | 265 |
| 266 // Now run the MessageLoop. | 266 // Now run the MessageLoop. |
| 267 run_loop.Run(); | 267 run_loop.Run(); |
| 268 |
| 269 // StartWatching can move |watcher| to IO thread. Release on IO thread. |
| 270 io_loop()->PostTask(FROM_HERE, Bind(&WaitableEventWatcher::StopWatching, |
| 271 Owned(watcher.release()))); |
| 268 } | 272 } |
| 269 | 273 |
| 270 } // namespace | 274 } // namespace |
| 271 | 275 |
| 272 } // namespace base | 276 } // namespace base |
| OLD | NEW |