OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/host/security_key/security_key_ipc_constants.h" | 5 #include "remoting/host/security_key/security_key_ipc_constants.h" |
6 | 6 |
7 #include "base/environment.h" | |
8 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "build/build_config.h" |
| 9 |
| 10 #if defined(OS_POSIX) |
| 11 #include "base/files/file_path.h" |
| 12 #include "base/files/file_util.h" |
| 13 #include "base/logging.h" |
| 14 #endif // defined(OS_POSIX) |
9 | 15 |
10 namespace { | 16 namespace { |
11 base::LazyInstance<std::string> g_security_key_ipc_channel_name = | 17 base::LazyInstance<std::string> g_security_key_ipc_channel_name = |
12 LAZY_INSTANCE_INITIALIZER; | 18 LAZY_INSTANCE_INITIALIZER; |
13 | 19 |
14 const char kSecurityKeyIpcChannelName[] = "security_key_ipc_channel"; | 20 const char kSecurityKeyIpcChannelName[] = "security_key_ipc_channel"; |
15 | 21 |
16 } // namespace | 22 } // namespace |
17 | 23 |
18 namespace remoting { | 24 namespace remoting { |
19 | 25 |
20 extern const char kSecurityKeyConnectionError[] = "ssh_connection_error"; | 26 const char kSecurityKeyConnectionError[] = "ssh_connection_error"; |
21 | 27 |
22 const std::string& GetSecurityKeyIpcChannelName() { | 28 const std::string& GetSecurityKeyIpcChannelName() { |
23 if (g_security_key_ipc_channel_name.Get().empty()) { | 29 if (g_security_key_ipc_channel_name.Get().empty()) { |
24 g_security_key_ipc_channel_name.Get() = kSecurityKeyIpcChannelName; | 30 g_security_key_ipc_channel_name.Get() = kSecurityKeyIpcChannelName; |
25 } | 31 } |
26 | 32 |
27 return g_security_key_ipc_channel_name.Get(); | 33 return g_security_key_ipc_channel_name.Get(); |
28 } | 34 } |
29 | 35 |
30 void SetSecurityKeyIpcChannelNameForTest(const std::string& channel_name) { | 36 void SetSecurityKeyIpcChannelNameForTest(const std::string& channel_name) { |
31 g_security_key_ipc_channel_name.Get() = channel_name; | 37 g_security_key_ipc_channel_name.Get() = channel_name; |
32 } | 38 } |
33 | 39 |
34 std::string GetChannelNamePathPrefixForTest() { | 40 std::string GetChannelNamePathPrefixForTest() { |
35 std::string path_prefix; | 41 std::string base_path; |
36 #if defined(OS_LINUX) | 42 #if defined(OS_POSIX) |
37 path_prefix = "/dev/socket/"; | 43 base::FilePath base_file_path; |
38 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 44 if (base::GetTempDir(&base_file_path)) { |
39 if (env->GetVar(base::env_vars::kHome, &path_prefix)) | 45 base_path = base_file_path.AsEndingWithSeparator().value(); |
40 path_prefix += "/"; | 46 } else { |
41 #endif | 47 LOG(ERROR) << "Failed to retrieve temporary directory."; |
42 return path_prefix; | 48 } |
| 49 #endif // defined(OS_POSIX) |
| 50 return base_path; |
43 } | 51 } |
44 | 52 |
45 } // namespace remoting | 53 } // namespace remoting |
OLD | NEW |