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 | |
| 10 | #include "ipc/ipc_export.h" |
| 11 | #include "ipc/ipc_message_macros.h" |
| 12 | |
| 13 | namespace IPC { |
| 14 | |
| 15 | // HandleWin is a wrapper around a Windows HANDLE that can be transported |
| 16 | // across Chrome IPC channels that support attachment brokering. The HANDLE will |
| 17 | // be duplicated into the destination process. |
| 18 | class IPC_EXPORT HandleWin { |
| 19 | public: |
| 20 | enum Permissions { |
| 21 | // A placeholder value to be used by the receiving IPC channel, since the |
| 22 | // permissions information is only used by the broker process. |
| 23 | INVALID, |
| 24 | // The new HANDLE will have the same permissions as the old HANDLE. |
| 25 | DUPLICATE, |
| 26 | // The new HANDLE will have file read and write permissions. |
| 27 | FILE_READ_WRITE, |
| 28 | MAX_PERMISSIONS = FILE_READ_WRITE |
| 29 | }; |
| 30 | |
erikchen | 37a2e0b6 | 2015-08-22 00:26:36 | [diff] [blame] | 31 | // Default constructor makes an invalid HANDLE. |
| 32 | HandleWin(); |
erikchen | 959039d | 2015-08-11 21:17:47 | [diff] [blame] | 33 | HandleWin(const HANDLE& handle, Permissions permissions); |
| 34 | |
| 35 | HANDLE get_handle() const { return handle_; } |
| 36 | void set_handle(HANDLE handle) { handle_ = handle; } |
| 37 | Permissions get_permissions() const { return permissions_; } |
| 38 | |
| 39 | private: |
| 40 | HANDLE handle_; |
| 41 | Permissions permissions_; |
| 42 | }; |
| 43 | |
| 44 | template <> |
| 45 | struct IPC_EXPORT ParamTraits<HandleWin> { |
| 46 | typedef HandleWin param_type; |
| 47 | static void Write(Message* m, const param_type& p); |
| 48 | static bool Read(const Message* m, base::PickleIterator* iter, param_type* p); |
| 49 | static void Log(const param_type& p, std::string* l); |
| 50 | }; |
| 51 | |
| 52 | } // namespace IPC |
| 53 | |
| 54 | #endif // IPC_HANDLE_WIN_H_ |