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

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: Updated 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
« ipc/ipc_message_utils.cc ('K') | « ipc/mojo/ipc_channel_mojo.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 base::File file;
285 EXPECT_TRUE(message.ReadFileDescriptor(&iter, &desc)); 285 EXPECT_TRUE(message.ReadFile(&iter, &file));
286 std::string content(GetSendingFileContent().size(), ' '); 286 std::string content(GetSendingFileContent().size(), ' ');
287 base::File file(desc.fd);
288 file.Read(0, &content[0], content.size()); 287 file.Read(0, &content[0], content.size());
289 EXPECT_EQ(content, GetSendingFileContent()); 288 EXPECT_EQ(content, GetSendingFileContent());
290 base::MessageLoop::current()->Quit(); 289 base::MessageLoop::current()->Quit();
291 ListenerThatExpectsOK::SendOK(sender_); 290 ListenerThatExpectsOK::SendOK(sender_);
292 return true; 291 return true;
293 } 292 }
294 293
295 virtual void OnChannelError() OVERRIDE { 294 virtual void OnChannelError() OVERRIDE {
296 NOTREACHED(); 295 NOTREACHED();
297 } 296 }
298 297
299 static std::string GetSendingFileContent() { 298 static std::string GetSendingFileContent() {
300 return "Hello"; 299 return "Hello";
301 } 300 }
302 301
303 static base::FilePath GetSendingFilePath() { 302 static base::FilePath GetSendingFilePath() {
304 base::FilePath path; 303 base::FilePath path;
305 bool ok = PathService::Get(base::DIR_CACHE, &path); 304 bool ok = PathService::Get(base::DIR_CACHE, &path);
306 EXPECT_TRUE(ok); 305 EXPECT_TRUE(ok);
307 return path.Append("ListenerThatExpectsFile.txt"); 306 return path.Append("ListenerThatExpectsFile.txt");
308 } 307 }
309 308
310 static void WriteAndSendFile(IPC::Sender* sender, base::File& file) { 309 static void WriteAndSendFile(IPC::Sender* sender, base::File& file) {
311 std::string content = GetSendingFileContent(); 310 std::string content = GetSendingFileContent();
312 file.WriteAtCurrentPos(content.data(), content.size()); 311 file.WriteAtCurrentPos(content.data(), content.size());
313 file.Flush(); 312 file.Flush();
314 IPC::Message* message = new IPC::Message( 313 IPC::Message* message = new IPC::Message(
315 0, 2, IPC::Message::PRIORITY_NORMAL); 314 0, 2, IPC::Message::PRIORITY_NORMAL);
316 message->WriteFileDescriptor( 315 message->WriteFile(file.Pass());
317 base::FileDescriptor(file.TakePlatformFile(), false));
318 ASSERT_TRUE(sender->Send(message)); 316 ASSERT_TRUE(sender->Send(message));
319 } 317 }
320 318
321 void set_sender(IPC::Sender* sender) { sender_ = sender; } 319 void set_sender(IPC::Sender* sender) { sender_ = sender; }
322 320
323 private: 321 private:
324 IPC::Sender* sender_; 322 IPC::Sender* sender_;
325 }; 323 };
326 324
327 325
(...skipping 24 matching lines...) Expand all
352 client.Connect(); 350 client.Connect();
353 listener.set_sender(client.channel()); 351 listener.set_sender(client.channel());
354 352
355 base::MessageLoop::current()->Run(); 353 base::MessageLoop::current()->Run();
356 354
357 return 0; 355 return 0;
358 } 356 }
359 #endif 357 #endif
360 358
361 } // namespace 359 } // namespace
OLDNEW
« ipc/ipc_message_utils.cc ('K') | « ipc/mojo/ipc_channel_mojo.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698