[go: nahoru, domu]

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