blob: 96c1b0b423c1ed848c1f9255874a9e841b5cb1cc [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 {
rockot502c94f2016-02-03 20:20:1616class Pickle;
erikchenb82097cc2015-10-12 23:27:5517class PickleIterator;
18} // namespace base
erikchen959039d2015-08-11 21:17:4719
20namespace IPC {
21
22// HandleWin is a wrapper around a Windows HANDLE that can be transported
23// across Chrome IPC channels that support attachment brokering. The HANDLE will
24// be duplicated into the destination process.
erikchen17b34832015-12-04 21:20:1225//
26// The ownership semantics for the underlying |handle_| are complex. See
27// ipc/mach_port_mac.h (the OSX analog of this class) for an extensive
28// discussion.
erikchen959039d2015-08-11 21:17:4729class IPC_EXPORT HandleWin {
30 public:
31 enum Permissions {
32 // A placeholder value to be used by the receiving IPC channel, since the
33 // permissions information is only used by the broker process.
34 INVALID,
35 // The new HANDLE will have the same permissions as the old HANDLE.
36 DUPLICATE,
37 // The new HANDLE will have file read and write permissions.
38 FILE_READ_WRITE,
39 MAX_PERMISSIONS = FILE_READ_WRITE
40 };
41
erikchen98daa732015-09-25 18:30:0342 // Default constructor makes an invalid HANDLE.
43 HandleWin();
erikchen959039d2015-08-11 21:17:4744 HandleWin(const HANDLE& handle, Permissions permissions);
45
46 HANDLE get_handle() const { return handle_; }
47 void set_handle(HANDLE handle) { handle_ = handle; }
48 Permissions get_permissions() const { return permissions_; }
49
50 private:
51 HANDLE handle_;
52 Permissions permissions_;
53};
54
55template <>
56struct IPC_EXPORT ParamTraits<HandleWin> {
57 typedef HandleWin param_type;
rockot502c94f2016-02-03 20:20:1658 static void Write(base::Pickle* m, const param_type& p);
59 static bool Read(const base::Pickle* m,
60 base::PickleIterator* iter,
61 param_type* p);
erikchen959039d2015-08-11 21:17:4762 static void Log(const param_type& p, std::string* l);
63};
64
65} // namespace IPC
66
67#endif // IPC_HANDLE_WIN_H_