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

Unified Diff: ipc/ipc_message_utils.cc

Issue 2849243002: Get rid of all pid references from base::SharedMemoryHandle. (Closed)
Patch Set: fix invalid handle Chrome IPC. Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/metrics/field_trial.cc ('k') | mojo/edk/embedder/platform_shared_buffer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ipc/ipc_message_utils.cc
diff --git a/ipc/ipc_message_utils.cc b/ipc/ipc_message_utils.cc
index a36f51b123c7bd394f9db984c4a673c08b751c3d..a173226180bbaaac51b926fba76ca9962c0a80b6 100644
--- a/ipc/ipc_message_utils.cc
+++ b/ipc/ipc_message_utils.cc
@@ -709,8 +709,7 @@ bool ParamTraits<base::SharedMemoryHandle>::Read(const base::Pickle* m,
return false;
*r = base::SharedMemoryHandle(mach_port_mac.get_mach_port(),
- static_cast<size_t>(size),
- base::GetCurrentProcId());
+ static_cast<size_t>(size));
return true;
}
@@ -723,60 +722,49 @@ void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p,
#elif defined(OS_WIN)
void ParamTraits<base::SharedMemoryHandle>::GetSize(base::PickleSizer* s,
const param_type& p) {
- GetParamSize(s, p.NeedsBrokering());
- if (p.NeedsBrokering()) {
+ GetParamSize(s, p.IsValid());
+ if (p.IsValid())
GetParamSize(s, p.GetHandle());
- } else {
- GetParamSize(s, HandleToLong(p.GetHandle()));
- }
}
void ParamTraits<base::SharedMemoryHandle>::Write(base::Pickle* m,
const param_type& p) {
- m->WriteBool(p.NeedsBrokering());
+ const bool valid = p.IsValid();
+ WriteParam(m, valid);
- if (p.NeedsBrokering()) {
- HandleWin handle_win(p.GetHandle(), HandleWin::DUPLICATE);
- ParamTraits<HandleWin>::Write(m, handle_win);
+ if (!valid)
+ return;
- // If the caller intended to pass ownership to the IPC stack, release a
- // reference.
- if (p.OwnershipPassesToIPC() && p.BelongsToCurrentProcess())
- p.Close();
- } else {
- m->WriteInt(HandleToLong(p.GetHandle()));
- }
+ HandleWin handle_win(p.GetHandle(), HandleWin::DUPLICATE);
+ ParamTraits<HandleWin>::Write(m, handle_win);
+
+ // If the caller intended to pass ownership to the IPC stack, release a
+ // reference.
+ if (p.OwnershipPassesToIPC())
+ p.Close();
}
bool ParamTraits<base::SharedMemoryHandle>::Read(const base::Pickle* m,
base::PickleIterator* iter,
param_type* r) {
- bool needs_brokering;
- if (!iter->ReadBool(&needs_brokering))
- return false;
+ *r = base::SharedMemoryHandle();
- if (needs_brokering) {
- HandleWin handle_win;
- if (!ParamTraits<HandleWin>::Read(m, iter, &handle_win))
- return false;
- *r = base::SharedMemoryHandle(handle_win.get_handle(),
- base::GetCurrentProcId());
+ bool valid;
+ if (!ReadParam(m, iter, &valid))
+ return false;
+ if (!valid)
return true;
- }
- int handle_int;
- if (!iter->ReadInt(&handle_int))
+ HandleWin handle_win;
+ if (!ParamTraits<HandleWin>::Read(m, iter, &handle_win))
return false;
- HANDLE handle = LongToHandle(handle_int);
- *r = base::SharedMemoryHandle(handle, base::GetCurrentProcId());
+ *r = base::SharedMemoryHandle(handle_win.get_handle());
return true;
}
void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p,
std::string* l) {
LogParam(p.GetHandle(), l);
- l->append(" needs brokering: ");
- LogParam(p.NeedsBrokering(), l);
}
#elif defined(OS_POSIX)
void ParamTraits<base::SharedMemoryHandle>::GetSize(base::PickleSizer* sizer,
« no previous file with comments | « base/metrics/field_trial.cc ('k') | mojo/edk/embedder/platform_shared_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698