erikchen | 959039d | 2015-08-11 21:17:47 | [diff] [blame] | 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 |
| 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 | |
erikchen | b82097cc | 2015-10-12 23:27:55 | [diff] [blame] | 10 | #include <string> |
| 11 | |
erikchen | 959039d | 2015-08-11 21:17:47 | [diff] [blame] | 12 | #include "ipc/ipc_export.h" |
erikchen | b82097cc | 2015-10-12 23:27:55 | [diff] [blame] | 13 | #include "ipc/ipc_param_traits.h" |
| 14 | |
| 15 | namespace base { |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 16 | class Pickle; |
erikchen | b82097cc | 2015-10-12 23:27:55 | [diff] [blame] | 17 | class PickleIterator; |
| 18 | } // namespace base |
erikchen | 959039d | 2015-08-11 21:17:47 | [diff] [blame] | 19 | |
| 20 | namespace 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. |
erikchen | 17b3483 | 2015-12-04 21:20:12 | [diff] [blame] | 25 | // |
| 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. |
erikchen | 959039d | 2015-08-11 21:17:47 | [diff] [blame] | 29 | class 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 | |
erikchen | 98daa73 | 2015-09-25 18:30:03 | [diff] [blame] | 42 | // Default constructor makes an invalid HANDLE. |
| 43 | HandleWin(); |
erikchen | 959039d | 2015-08-11 21:17:47 | [diff] [blame] | 44 | 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 | |
| 55 | template <> |
| 56 | struct IPC_EXPORT ParamTraits<HandleWin> { |
| 57 | typedef HandleWin param_type; |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 58 | 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); |
erikchen | 959039d | 2015-08-11 21:17:47 | [diff] [blame] | 62 | static void Log(const param_type& p, std::string* l); |
| 63 | }; |
| 64 | |
| 65 | } // namespace IPC |
| 66 | |
| 67 | #endif // IPC_HANDLE_WIN_H_ |