| OLD | NEW |
| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 | 732 |
| 733 // Create a file descriptor. Doesn't need to be readable or writable, | 733 // Create a file descriptor. Doesn't need to be readable or writable, |
| 734 // as we don't need to actually get any notifications. | 734 // as we don't need to actually get any notifications. |
| 735 // pipe() is just the easiest way to do it. | 735 // pipe() is just the easiest way to do it. |
| 736 int pipefds[2]; | 736 int pipefds[2]; |
| 737 int err = pipe(pipefds); | 737 int err = pipe(pipefds); |
| 738 ASSERT_EQ(0, err); | 738 ASSERT_EQ(0, err); |
| 739 int fd = pipefds[1]; | 739 int fd = pipefds[1]; |
| 740 { | 740 { |
| 741 // Arrange for controller to live longer than message loop. | 741 // Arrange for controller to live longer than message loop. |
| 742 MessageLoopForIO::FileDescriptorWatcher controller; | 742 MessageLoopForIO::FileDescriptorWatcher controller(FROM_HERE); |
| 743 { | 743 { |
| 744 MessageLoopForIO message_loop; | 744 MessageLoopForIO message_loop; |
| 745 | 745 |
| 746 QuitDelegate delegate; | 746 QuitDelegate delegate; |
| 747 message_loop.WatchFileDescriptor(fd, | 747 message_loop.WatchFileDescriptor(fd, |
| 748 true, MessageLoopForIO::WATCH_WRITE, &controller, &delegate); | 748 true, MessageLoopForIO::WATCH_WRITE, &controller, &delegate); |
| 749 // and don't run the message loop, just destroy it. | 749 // and don't run the message loop, just destroy it. |
| 750 } | 750 } |
| 751 } | 751 } |
| 752 if (IGNORE_EINTR(close(pipefds[0])) < 0) | 752 if (IGNORE_EINTR(close(pipefds[0])) < 0) |
| 753 PLOG(ERROR) << "close"; | 753 PLOG(ERROR) << "close"; |
| 754 if (IGNORE_EINTR(close(pipefds[1])) < 0) | 754 if (IGNORE_EINTR(close(pipefds[1])) < 0) |
| 755 PLOG(ERROR) << "close"; | 755 PLOG(ERROR) << "close"; |
| 756 } | 756 } |
| 757 | 757 |
| 758 TEST(MessageLoopTest, FileDescriptorWatcherDoubleStop) { | 758 TEST(MessageLoopTest, FileDescriptorWatcherDoubleStop) { |
| 759 // Verify that it's ok to call StopWatchingFileDescriptor(). | 759 // Verify that it's ok to call StopWatchingFileDescriptor(). |
| 760 // (Errors only showed up in valgrind.) | 760 // (Errors only showed up in valgrind.) |
| 761 int pipefds[2]; | 761 int pipefds[2]; |
| 762 int err = pipe(pipefds); | 762 int err = pipe(pipefds); |
| 763 ASSERT_EQ(0, err); | 763 ASSERT_EQ(0, err); |
| 764 int fd = pipefds[1]; | 764 int fd = pipefds[1]; |
| 765 { | 765 { |
| 766 // Arrange for message loop to live longer than controller. | 766 // Arrange for message loop to live longer than controller. |
| 767 MessageLoopForIO message_loop; | 767 MessageLoopForIO message_loop; |
| 768 { | 768 { |
| 769 MessageLoopForIO::FileDescriptorWatcher controller; | 769 MessageLoopForIO::FileDescriptorWatcher controller(FROM_HERE); |
| 770 | 770 |
| 771 QuitDelegate delegate; | 771 QuitDelegate delegate; |
| 772 message_loop.WatchFileDescriptor(fd, | 772 message_loop.WatchFileDescriptor(fd, |
| 773 true, MessageLoopForIO::WATCH_WRITE, &controller, &delegate); | 773 true, MessageLoopForIO::WATCH_WRITE, &controller, &delegate); |
| 774 controller.StopWatchingFileDescriptor(); | 774 controller.StopWatchingFileDescriptor(); |
| 775 } | 775 } |
| 776 } | 776 } |
| 777 if (IGNORE_EINTR(close(pipefds[0])) < 0) | 777 if (IGNORE_EINTR(close(pipefds[0])) < 0) |
| 778 PLOG(ERROR) << "close"; | 778 PLOG(ERROR) << "close"; |
| 779 if (IGNORE_EINTR(close(pipefds[1])) < 0) | 779 if (IGNORE_EINTR(close(pipefds[1])) < 0) |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1021 | 1021 |
| 1022 { | 1022 { |
| 1023 std::string kThreadName("bar"); | 1023 std::string kThreadName("bar"); |
| 1024 base::Thread thread(kThreadName); | 1024 base::Thread thread(kThreadName); |
| 1025 ASSERT_TRUE(thread.StartAndWaitForTesting()); | 1025 ASSERT_TRUE(thread.StartAndWaitForTesting()); |
| 1026 EXPECT_EQ(kThreadName, thread.message_loop()->GetThreadName()); | 1026 EXPECT_EQ(kThreadName, thread.message_loop()->GetThreadName()); |
| 1027 } | 1027 } |
| 1028 } | 1028 } |
| 1029 | 1029 |
| 1030 } // namespace base | 1030 } // namespace base |
| OLD | NEW |