blob: 38cddae10b1a7600e243bf8ba56db30ab630d7f7 [file] [log] [blame]
erikchen959039d2015-08-11 21:17:471// Copyright 2015 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef IPC_HANDLE_WIN_H_
6#define IPC_HANDLE_WIN_H_
7
8#include <windows.h>
9
erikchenb82097cc2015-10-12 23:27:5510#include <string>
11
erikchen959039d2015-08-11 21:17:4712#include "ipc/ipc_export.h"
erikchenb82097cc2015-10-12 23:27:5513#include "ipc/ipc_param_traits.h"
14
15namespace base {
16class PickleIterator;
17} // namespace base
erikchen959039d2015-08-11 21:17:4718
19namespace IPC {
20
erikchenb82097cc2015-10-12 23:27:5521class Message;
22
erikchen959039d2015-08-11 21:17:4723// HandleWin is a wrapper around a Windows HANDLE that can be transported
24// across Chrome IPC channels that support attachment brokering. The HANDLE will
25// be duplicated into the destination process.
erikchen17b34832015-12-04 21:20:1226//
27// The ownership semantics for the underlying |handle_| are complex. See
28// ipc/mach_port_mac.h (the OSX analog of this class) for an extensive
29// discussion.
erikchen959039d2015-08-11 21:17:4730class IPC_EXPORT HandleWin {
31 public:
32 enum Permissions {
33 // A placeholder value to be used by the receiving IPC channel, since the
34 // permissions information is only used by the broker process.
35 INVALID,
36 // The new HANDLE will have the same permissions as the old HANDLE.
37 DUPLICATE,
38 // The new HANDLE will have file read and write permissions.
39 FILE_READ_WRITE,
40 MAX_PERMISSIONS = FILE_READ_WRITE
41 };
42
erikchen98daa732015-09-25 18:30:0343 // Default constructor makes an invalid HANDLE.
44 HandleWin();
erikchen959039d2015-08-11 21:17:4745 HandleWin(const HANDLE& handle, Permissions permissions);
46
47 HANDLE get_handle() const { return handle_; }
48 void set_handle(HANDLE handle) { handle_ = handle; }
49 Permissions get_permissions() const { return permissions_; }
50
51 private:
52 HANDLE handle_;
53 Permissions permissions_;
54};
55
56template <>
57struct IPC_EXPORT ParamTraits<HandleWin> {
58 typedef HandleWin param_type;
59 static void Write(Message* m, const param_type& p);
60 static bool Read(const Message* m, base::PickleIterator* iter, param_type* p);
61 static void Log(const param_type& p, std::string* l);
62};
63
64} // namespace IPC
65
66#endif // IPC_HANDLE_WIN_H_