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

Side by Side Diff: ipc/mach_port_mac.h

Issue 1385143002: ipc: Update MachPortMac ownership semantics. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 | « no previous file | ipc/mach_port_mac.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #ifndef IPC_MACH_PORT_MAC_H_ 5 #ifndef IPC_MACH_PORT_MAC_H_
6 #define IPC_MACH_PORT_MAC_H_ 6 #define IPC_MACH_PORT_MAC_H_
7 7
8 #include <mach/mach.h> 8 #include <mach/mach.h>
9 9
10 #include "base/macros.h"
10 #include "ipc/ipc_export.h" 11 #include "ipc/ipc_export.h"
11 #include "ipc/ipc_message_macros.h" 12 #include "ipc/ipc_message_macros.h"
12 13
13 namespace IPC { 14 namespace IPC {
14 15
15 // MachPortMac is a wrapper around an OSX mach_port_t that can be transported 16 // MachPortMac is a wrapper around an OSX Mach port that can be transported
16 // across Chrome IPC channels that support attachment brokering. The mach_port_t 17 // across Chrome IPC channels that support attachment brokering. The Mach port
17 // will be duplicated into the destination process by the attachment broker. 18 // will be duplicated into the destination process by the attachment broker.
19 // For now, this class only supports Mach ports with a send right. If needed,
Tom Sepez 2015/10/06 16:09:09 Nit: Forgive my limited understanding, but I thoug
erikchen 2015/10/06 20:40:43 I do mean what you wrote, and I updated my comment
20 // attachment brokering can be trivially extended to support Mach ports with
21 // other rights.
18 class IPC_EXPORT MachPortMac { 22 class IPC_EXPORT MachPortMac {
19 public: 23 public:
20 MachPortMac() : mach_port_(MACH_PORT_NULL) {} 24 MachPortMac() : mach_port_(MACH_PORT_NULL) {}
21 explicit MachPortMac(const mach_port_t& mach_port) : mach_port_(mach_port) {} 25
26 // This constructor increments the ref count of |mach_port|.
27 explicit MachPortMac(const mach_port_t& mach_port);
Tom Sepez 2015/10/06 16:09:09 nit: is it really const if its being modified?
erikchen 2015/10/06 20:40:42 mach_port_t is typedefed to int - I changed the pa
22 28
23 mach_port_t get_mach_port() const { return mach_port_; } 29 mach_port_t get_mach_port() const { return mach_port_; }
30
31 // This method should only be used by ipc/ translation code.
24 void set_mach_port(mach_port_t mach_port) { mach_port_ = mach_port; } 32 void set_mach_port(mach_port_t mach_port) { mach_port_ = mach_port; }
Tom Sepez 2015/10/06 16:09:09 nit: do you want to pass by const reference here?
erikchen 2015/10/06 20:40:43 Nah, I got rid of the other const ref as well.
25 33
26 private: 34 private:
35 // The ownership semantics of |mach_port_| are a little confusing, and cannot
Tom Sepez 2015/10/06 16:09:09 nit: s/are a little confusing, and//.
erikchen 2015/10/06 20:40:43 Done.
36 // be easily expressed with a C++ scoped object. This is partly due to the
37 // mechanism by which Mach ports are brokered, and partly due to the
38 // architecture of Chrome IPC.
39 //
40 // From the sender process's perspective, this class is just a wrapper. It
Tom Sepez 2015/10/06 16:09:09 nit: what are the other perspectives? hmm. I get
erikchen 2015/10/06 20:40:43 Right - I removed the word "perspective" from the
41 // calls Send(new Message(MachPortMac(mach_port))) and continues on its merry
42 // way. Behind the scenes, this class increments the ref count on |mach_port_|
43 // to ensure that the object stays alive.
Tom Sepez 2015/10/06 16:09:09 nit: which object is that? I'm confused.
erikchen 2015/10/06 20:40:43 I got rid of this comment.
44 //
45 // The broker process receives a reference to the name of this Mach port. It
Tom Sepez 2015/10/06 16:09:09 nit: when does this happen? first time we mention
erikchen 2015/10/06 20:40:42 I updated the comments to add slightly more detail
46 // copies the right into the destination process, and then decrements the ref
Tom Sepez 2015/10/06 16:09:09 nit: send right
erikchen 2015/10/06 20:40:43 I updated the top level class comment to use "send
47 // count in the original process. Note that a different process is
Tom Sepez 2015/10/06 16:09:09 nit: why is the note important? The OS takes care
erikchen 2015/10/06 20:40:42 A different process is decrementing the ref count,
48 // decrementing the ref count!
49 //
50 // From the receiver process's perspective, a Mach port was magically inserted
51 // into its name space. The attachment broker is responsible for coupling the
52 // Mach port with Chrome IPC in the form of a MessageAttachment. When the
53 // client code receives a callback with the parameter MachPortMac, it then
54 // assumes ownership of the Mach port.
27 mach_port_t mach_port_; 55 mach_port_t mach_port_;
56 DISALLOW_COPY_AND_ASSIGN(MachPortMac);
28 }; 57 };
29 58
30 template <> 59 template <>
31 struct IPC_EXPORT ParamTraits<MachPortMac> { 60 struct IPC_EXPORT ParamTraits<MachPortMac> {
32 typedef MachPortMac param_type; 61 typedef MachPortMac param_type;
33 static void Write(Message* m, const param_type& p); 62 static void Write(Message* m, const param_type& p);
34 static bool Read(const Message* m, base::PickleIterator* iter, param_type* p); 63 static bool Read(const Message* m, base::PickleIterator* iter, param_type* p);
35 static void Log(const param_type& p, std::string* l); 64 static void Log(const param_type& p, std::string* l);
36 }; 65 };
37 66
38 } // namespace IPC 67 } // namespace IPC
39 68
40 #endif // IPC_MACH_PORT_MAC_H_ 69 #endif // IPC_MACH_PORT_MAC_H_
OLDNEW
« no previous file with comments | « no previous file | ipc/mach_port_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698