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

Side by Side Diff: ipc/ipc_message_utils.cc

Issue 1200473003: Revert of Make SharedMemoryHandle a class on Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shared_memory_make_class3_base
Patch Set: Created 5 years, 6 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/ipc_message_utils.h ('k') | ppapi/proxy/nacl_message_scanner.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ipc/ipc_message_utils.h" 5 #include "ipc/ipc_message_utils.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/nullable_string16.h" 10 #include "base/strings/nullable_string16.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "ipc/ipc_channel_handle.h" 15 #include "ipc/ipc_channel_handle.h"
16 #include "ipc/ipc_message_attachment.h" 16 #include "ipc/ipc_message_attachment.h"
17 #include "ipc/ipc_message_attachment_set.h" 17 #include "ipc/ipc_message_attachment_set.h"
18 18
19 #if defined(OS_POSIX) 19 #if defined(OS_POSIX)
20 #include "ipc/ipc_platform_file_attachment_posix.h" 20 #include "ipc/ipc_platform_file_attachment_posix.h"
21 #endif 21 #endif
22 22
23 #if defined(OS_MACOSX) && !defined(OS_IOS)
24 #include "base/memory/shared_memory_handle.h"
25 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
26
27 #if defined(OS_WIN) 23 #if defined(OS_WIN)
28 #include <tchar.h> 24 #include <tchar.h>
29 #endif 25 #endif
30 26
31 namespace IPC { 27 namespace IPC {
32 28
33 namespace { 29 namespace {
34 30
35 const int kMaxRecursionDepth = 100; 31 const int kMaxRecursionDepth = 100;
36 32
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 void ParamTraits<base::FileDescriptor>::Log(const param_type& p, 509 void ParamTraits<base::FileDescriptor>::Log(const param_type& p,
514 std::string* l) { 510 std::string* l) {
515 if (p.auto_close) { 511 if (p.auto_close) {
516 l->append(base::StringPrintf("FD(%d auto-close)", p.fd)); 512 l->append(base::StringPrintf("FD(%d auto-close)", p.fd));
517 } else { 513 } else {
518 l->append(base::StringPrintf("FD(%d)", p.fd)); 514 l->append(base::StringPrintf("FD(%d)", p.fd));
519 } 515 }
520 } 516 }
521 #endif // defined(OS_POSIX) 517 #endif // defined(OS_POSIX)
522 518
523 #if defined(OS_MACOSX) && !defined(OS_IOS)
524 void ParamTraits<base::SharedMemoryHandle>::Write(Message* m,
525 const param_type& p) {
526 m->WriteInt(p.GetType());
527
528 if (p.GetType() == base::SharedMemoryHandle::POSIX)
529 ParamTraits<base::FileDescriptor>::Write(m, p.GetFileDescriptor());
530 }
531
532 bool ParamTraits<base::SharedMemoryHandle>::Read(const Message* m,
533 base::PickleIterator* iter,
534 param_type* r) {
535 base::SharedMemoryHandle::TypeWireFormat type;
536 if (!iter->ReadInt(&type))
537 return false;
538
539 base::SharedMemoryHandle::Type shm_type = base::SharedMemoryHandle::POSIX;
540 switch (type) {
541 case base::SharedMemoryHandle::POSIX:
542 case base::SharedMemoryHandle::MACH: {
543 shm_type = static_cast<base::SharedMemoryHandle::Type>(type);
544 break;
545 }
546 default:
547 return false;
548 }
549
550 if (shm_type == base::SharedMemoryHandle::POSIX) {
551 base::FileDescriptor file_descriptor;
552
553 bool success =
554 ParamTraits<base::FileDescriptor>::Read(m, iter, &file_descriptor);
555 if (!success)
556 return false;
557
558 *r = base::SharedMemoryHandle(file_descriptor.fd,
559 file_descriptor.auto_close);
560 return true;
561 }
562
563 return true;
564 }
565
566 void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p,
567 std::string* l) {
568 if (p.GetType() == base::SharedMemoryHandle::POSIX) {
569 l->append(base::StringPrintf("Mechanism POSIX Fd"));
570 ParamTraits<base::FileDescriptor>::Log(p.GetFileDescriptor(), l);
571 }
572 }
573 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
574
575 void ParamTraits<base::FilePath>::Write(Message* m, const param_type& p) { 519 void ParamTraits<base::FilePath>::Write(Message* m, const param_type& p) {
576 p.WriteToPickle(m); 520 p.WriteToPickle(m);
577 } 521 }
578 522
579 bool ParamTraits<base::FilePath>::Read(const Message* m, 523 bool ParamTraits<base::FilePath>::Read(const Message* m,
580 base::PickleIterator* iter, 524 base::PickleIterator* iter,
581 param_type* r) { 525 param_type* r) {
582 return r->ReadFromPickle(iter); 526 return r->ReadFromPickle(iter);
583 } 527 }
584 528
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 return result; 866 return result;
923 } 867 }
924 868
925 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { 869 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) {
926 l->append("<MSG>"); 870 l->append("<MSG>");
927 } 871 }
928 872
929 #endif // OS_WIN 873 #endif // OS_WIN
930 874
931 } // namespace IPC 875 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/ipc_message_utils.h ('k') | ppapi/proxy/nacl_message_scanner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698