1 // Copyright 2016 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 MOJO_EDK_EMBEDDER_NAMED_PLATFORM_HANDLE_H_ 6 #define MOJO_EDK_EMBEDDER_NAMED_PLATFORM_HANDLE_H_ 7 8 #include <string> 9 10 #include "base/strings/string16.h" 11 #include "base/strings/string_piece.h" 12 #include "base/strings/utf_string_conversions.h" 13 #include "build/build_config.h" 14 #include "mojo/edk/system/system_impl_export.h" 15 16 namespace mojo { 17 namespace edk { 18 19 #if defined(OS_POSIX) 20 struct MOJO_SYSTEM_IMPL_EXPORT NamedPlatformHandle { 21 NamedPlatformHandle() {} 22 explicit NamedPlatformHandle(const base::StringPiece& name) 23 : name(name.as_string()) {} 24 25 bool is_valid() const { return !name.empty(); } 26 27 std::string name; 28 }; 29 #elif defined(OS_WIN) 30 struct MOJO_SYSTEM_IMPL_EXPORT NamedPlatformHandle { 31 NamedPlatformHandle() {} 32 explicit NamedPlatformHandle(const base::StringPiece& name) 33 : name(base::UTF8ToUTF16(name)) {} 34 35 explicit NamedPlatformHandle(const base::StringPiece16& name) 36 : name(name.as_string()) {} 37 38 bool is_valid() const { return !name.empty(); } 39 40 base::string16 pipe_name() const { return L"\\\\.\\pipe\\mojo." + name; } 41 42 base::string16 name; 43 }; 44 #else 45 #error "Platform not yet supported." 46 #endif 47 48 } // namespace edk 49 } // namespace mojo 50 51 #endif // MOJO_EDK_EMBEDDER_NAMED_PLATFORM_HANDLE_H_ 52