handle_win.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #ifndef IPC_HANDLE_WIN_H_
  5. #define IPC_HANDLE_WIN_H_
  6. #include <windows.h>
  7. #include <string>
  8. #include "ipc/ipc_message_support_export.h"
  9. #include "ipc/ipc_param_traits.h"
  10. namespace base {
  11. class Pickle;
  12. class PickleIterator;
  13. } // namespace base
  14. namespace IPC {
  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. //
  19. // The ownership semantics for the underlying |handle_| are complex. See
  20. // ipc/mach_port_mac.h (the OSX analog of this class) for an extensive
  21. // discussion.
  22. class IPC_MESSAGE_SUPPORT_EXPORT HandleWin {
  23. public:
  24. // Default constructor makes an invalid HANDLE.
  25. HandleWin();
  26. explicit HandleWin(const HANDLE& handle);
  27. HANDLE get_handle() const { return handle_; }
  28. void set_handle(HANDLE handle) { handle_ = handle; }
  29. private:
  30. HANDLE handle_;
  31. };
  32. template <>
  33. struct IPC_MESSAGE_SUPPORT_EXPORT ParamTraits<HandleWin> {
  34. typedef HandleWin param_type;
  35. static void Write(base::Pickle* m, const param_type& p);
  36. static bool Read(const base::Pickle* m,
  37. base::PickleIterator* iter,
  38. param_type* p);
  39. static void Log(const param_type& p, std::string* l);
  40. };
  41. } // namespace IPC
  42. #endif // IPC_HANDLE_WIN_H_