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

Side by Side Diff: ipc/mojo/ipc_channel_mojo_unittest.cc

Issue 583473002: IPC: Get rid of FileDescriptor usage from FileDescriptorSet and Message (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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/mojo/ipc_channel_mojo_readers.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ipc/mojo/ipc_channel_mojo.h" 5 #include "ipc/mojo/ipc_channel_mojo.h"
6 6
7 #include "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/files/file.h" 8 #include "base/files/file.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 #if defined(OS_POSIX) 274 #if defined(OS_POSIX)
275 class ListenerThatExpectsFile : public IPC::Listener { 275 class ListenerThatExpectsFile : public IPC::Listener {
276 public: 276 public:
277 ListenerThatExpectsFile() 277 ListenerThatExpectsFile()
278 : sender_(NULL) {} 278 : sender_(NULL) {}
279 279
280 virtual ~ListenerThatExpectsFile() {} 280 virtual ~ListenerThatExpectsFile() {}
281 281
282 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { 282 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE {
283 PickleIterator iter(message); 283 PickleIterator iter(message);
284 base::FileDescriptor desc; 284
285 EXPECT_TRUE(message.ReadFileDescriptor(&iter, &desc)); 285 base::ScopedFD fd;
286 EXPECT_TRUE(message.ReadFile(&iter, &fd));
287 base::File file(fd.release());
286 std::string content(GetSendingFileContent().size(), ' '); 288 std::string content(GetSendingFileContent().size(), ' ');
287 base::File file(desc.fd);
288 file.Read(0, &content[0], content.size()); 289 file.Read(0, &content[0], content.size());
289 EXPECT_EQ(content, GetSendingFileContent()); 290 EXPECT_EQ(content, GetSendingFileContent());
290 base::MessageLoop::current()->Quit(); 291 base::MessageLoop::current()->Quit();
291 ListenerThatExpectsOK::SendOK(sender_); 292 ListenerThatExpectsOK::SendOK(sender_);
292 return true; 293 return true;
293 } 294 }
294 295
295 virtual void OnChannelError() OVERRIDE { 296 virtual void OnChannelError() OVERRIDE {
296 NOTREACHED(); 297 NOTREACHED();
297 } 298 }
298 299
299 static std::string GetSendingFileContent() { 300 static std::string GetSendingFileContent() {
300 return "Hello"; 301 return "Hello";
301 } 302 }
302 303
303 static base::FilePath GetSendingFilePath() { 304 static base::FilePath GetSendingFilePath() {
304 base::FilePath path; 305 base::FilePath path;
305 bool ok = PathService::Get(base::DIR_CACHE, &path); 306 bool ok = PathService::Get(base::DIR_CACHE, &path);
306 EXPECT_TRUE(ok); 307 EXPECT_TRUE(ok);
307 return path.Append("ListenerThatExpectsFile.txt"); 308 return path.Append("ListenerThatExpectsFile.txt");
308 } 309 }
309 310
310 static void WriteAndSendFile(IPC::Sender* sender, base::File& file) { 311 static void WriteAndSendFile(IPC::Sender* sender, base::File& file) {
311 std::string content = GetSendingFileContent(); 312 std::string content = GetSendingFileContent();
312 file.WriteAtCurrentPos(content.data(), content.size()); 313 file.WriteAtCurrentPos(content.data(), content.size());
313 file.Flush(); 314 file.Flush();
314 IPC::Message* message = new IPC::Message( 315 IPC::Message* message = new IPC::Message(
315 0, 2, IPC::Message::PRIORITY_NORMAL); 316 0, 2, IPC::Message::PRIORITY_NORMAL);
316 message->WriteFileDescriptor( 317 message->WriteFile(base::ScopedFD(file.TakePlatformFile()));
317 base::FileDescriptor(file.TakePlatformFile(), false));
318 ASSERT_TRUE(sender->Send(message)); 318 ASSERT_TRUE(sender->Send(message));
319 } 319 }
320 320
321 void set_sender(IPC::Sender* sender) { sender_ = sender; } 321 void set_sender(IPC::Sender* sender) { sender_ = sender; }
322 322
323 private: 323 private:
324 IPC::Sender* sender_; 324 IPC::Sender* sender_;
325 }; 325 };
326 326
327 327
(...skipping 24 matching lines...) Expand all
352 client.Connect(); 352 client.Connect();
353 listener.set_sender(client.channel()); 353 listener.set_sender(client.channel());
354 354
355 base::MessageLoop::current()->Run(); 355 base::MessageLoop::current()->Run();
356 356
357 return 0; 357 return 0;
358 } 358 }
359 #endif 359 #endif
360 360
361 } // namespace 361 } // namespace
OLDNEW
« no previous file with comments | « ipc/mojo/ipc_channel_mojo_readers.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698