| 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #if defined(OS_POSIX) | 7 #if defined(OS_POSIX) |
| 8 #if defined(OS_MACOSX) | 8 #if defined(OS_MACOSX) |
| 9 extern "C" { | 9 extern "C" { |
| 10 #include <sandbox.h> | 10 #include <sandbox.h> |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | 52 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { |
| 53 PickleIterator iter(message); | 53 PickleIterator iter(message); |
| 54 | 54 |
| 55 ++num_fds_received_; | 55 ++num_fds_received_; |
| 56 base::FileDescriptor descriptor; | 56 base::FileDescriptor descriptor; |
| 57 | 57 |
| 58 IPC::ParamTraits<base::FileDescriptor>::Read(&message, &iter, &descriptor); | 58 IPC::ParamTraits<base::FileDescriptor>::Read(&message, &iter, &descriptor); |
| 59 | 59 |
| 60 VerifyAndCloseDescriptor(descriptor.fd, expected_inode_num_); | 60 VerifyAndCloseDescriptor(descriptor.fd, expected_inode_num_); |
| 61 if (num_fds_received_ == kNumFDsToSend) | 61 if (num_fds_received_ == kNumFDsToSend) |
| 62 MessageLoop::current()->Quit(); | 62 base::MessageLoop::current()->Quit(); |
| 63 | 63 |
| 64 return true; | 64 return true; |
| 65 } | 65 } |
| 66 | 66 |
| 67 virtual void OnChannelError() OVERRIDE { | 67 virtual void OnChannelError() OVERRIDE { |
| 68 MessageLoop::current()->Quit(); | 68 base::MessageLoop::current()->Quit(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 bool GotExpectedNumberOfDescriptors() const { | 71 bool GotExpectedNumberOfDescriptors() const { |
| 72 return num_fds_received_ == kNumFDsToSend; | 72 return num_fds_received_ == kNumFDsToSend; |
| 73 } | 73 } |
| 74 | 74 |
| 75 private: | 75 private: |
| 76 ino_t expected_inode_num_; | 76 ino_t expected_inode_num_; |
| 77 unsigned num_fds_received_; | 77 unsigned num_fds_received_; |
| 78 }; | 78 }; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 91 ASSERT_GE(fd, 0); | 91 ASSERT_GE(fd, 0); |
| 92 base::FileDescriptor descriptor(fd, true); | 92 base::FileDescriptor descriptor(fd, true); |
| 93 | 93 |
| 94 IPC::Message* message = | 94 IPC::Message* message = |
| 95 new IPC::Message(0, 3, IPC::Message::PRIORITY_NORMAL); | 95 new IPC::Message(0, 3, IPC::Message::PRIORITY_NORMAL); |
| 96 IPC::ParamTraits<base::FileDescriptor>::Write(message, descriptor); | 96 IPC::ParamTraits<base::FileDescriptor>::Write(message, descriptor); |
| 97 ASSERT_TRUE(sender()->Send(message)); | 97 ASSERT_TRUE(sender()->Send(message)); |
| 98 } | 98 } |
| 99 | 99 |
| 100 // Run message loop. | 100 // Run message loop. |
| 101 MessageLoop::current()->Run(); | 101 base::MessageLoop::current()->Run(); |
| 102 | 102 |
| 103 // Close the channel so the client's OnChannelError() gets fired. | 103 // Close the channel so the client's OnChannelError() gets fired. |
| 104 channel()->Close(); | 104 channel()->Close(); |
| 105 | 105 |
| 106 EXPECT_TRUE(WaitForClientShutdown()); | 106 EXPECT_TRUE(WaitForClientShutdown()); |
| 107 DestroyChannel(); | 107 DestroyChannel(); |
| 108 } | 108 } |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 TEST_F(IPCSendFdsTest, DescriptorTest) { | 111 TEST_F(IPCSendFdsTest, DescriptorTest) { |
| 112 Init("SendFdsClient"); | 112 Init("SendFdsClient"); |
| 113 RunServer(); | 113 RunServer(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 int SendFdsClientCommon(const std::string& test_client_name, | 116 int SendFdsClientCommon(const std::string& test_client_name, |
| 117 ino_t expected_inode_num) { | 117 ino_t expected_inode_num) { |
| 118 MessageLoopForIO main_message_loop; | 118 base::MessageLoopForIO main_message_loop; |
| 119 MyChannelDescriptorListener listener(expected_inode_num); | 119 MyChannelDescriptorListener listener(expected_inode_num); |
| 120 | 120 |
| 121 // Set up IPC channel. | 121 // Set up IPC channel. |
| 122 IPC::Channel channel(IPCTestBase::GetChannelName(test_client_name), | 122 IPC::Channel channel(IPCTestBase::GetChannelName(test_client_name), |
| 123 IPC::Channel::MODE_CLIENT, | 123 IPC::Channel::MODE_CLIENT, |
| 124 &listener); | 124 &listener); |
| 125 CHECK(channel.Connect()); | 125 CHECK(channel.Connect()); |
| 126 | 126 |
| 127 // Run message loop. | 127 // Run message loop. |
| 128 MessageLoop::current()->Run(); | 128 base::MessageLoop::current()->Run(); |
| 129 | 129 |
| 130 // Verify that the message loop was exited due to getting the correct number | 130 // Verify that the message loop was exited due to getting the correct number |
| 131 // of descriptors, and not because of the channel closing unexpectedly. | 131 // of descriptors, and not because of the channel closing unexpectedly. |
| 132 CHECK(listener.GotExpectedNumberOfDescriptors()); | 132 CHECK(listener.GotExpectedNumberOfDescriptors()); |
| 133 | 133 |
| 134 return 0; | 134 return 0; |
| 135 } | 135 } |
| 136 | 136 |
| 137 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendFdsClient) { | 137 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendFdsClient) { |
| 138 struct stat st; | 138 struct stat st; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 } | 174 } |
| 175 | 175 |
| 176 // See if we can receive a file descriptor. | 176 // See if we can receive a file descriptor. |
| 177 return SendFdsClientCommon("SendFdsSandboxedClient", st.st_ino); | 177 return SendFdsClientCommon("SendFdsSandboxedClient", st.st_ino); |
| 178 } | 178 } |
| 179 #endif // defined(OS_MACOSX) | 179 #endif // defined(OS_MACOSX) |
| 180 | 180 |
| 181 } // namespace | 181 } // namespace |
| 182 | 182 |
| 183 #endif // defined(OS_POSIX) | 183 #endif // defined(OS_POSIX) |
| OLD | NEW |