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 | |
erikchen | b82097cc | 2015-10-12 23:27:55 | [diff] [blame] | 22 | class Message; |
| 23 | |
erikchen | 959039d | 2015-08-11 21:17:47 | [diff] [blame] | 24 | // 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. |
erikchen | 17b3483 | 2015-12-04 21:20:12 | [diff] [blame] | 27 | // |
| 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. |
erikchen | 959039d | 2015-08-11 21:17:47 | [diff] [blame] | 31 | class 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 | |
erikchen | 98daa73 | 2015-09-25 18:30:03 | [diff] [blame] | 44 | // Default constructor makes an invalid HANDLE. |
| 45 | HandleWin(); |
erikchen | 959039d | 2015-08-11 21:17:47 | [diff] [blame] | 46 | 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 | |
| 57 | template <> |
| 58 | struct IPC_EXPORT ParamTraits<HandleWin> { |
| 59 | typedef HandleWin param_type; |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 60 | 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); |
erikchen | 959039d | 2015-08-11 21:17:47 | [diff] [blame] | 64 | static void Log(const param_type& p, std::string* l); |
| 65 | }; |
| 66 | |
| 67 | } // namespace IPC |
| 68 | |
| 69 | #endif // IPC_HANDLE_WIN_H_ |