OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 #include "chrome/browser/sync/util/get_session_name.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" |
| 10 #include "base/location.h" |
| 11 #include "base/message_loop_proxy.h" |
| 12 #include "base/sys_info.h" |
| 13 |
| 14 #if defined(OS_LINUX) |
| 15 #include "base/linux_util.h" |
| 16 #elif defined(OS_WIN) |
| 17 #include <windows.h> |
| 18 #endif |
| 19 |
| 20 namespace browser_sync { |
| 21 |
| 22 #if defined(OS_WIN) |
| 23 std::string GetComputerName() { |
| 24 char computer_name[MAX_COMPUTERNAME_LENGTH + 1]; |
| 25 DWORD size = sizeof(computer_name); |
| 26 if (GetComputerNameA(computer_name, &size)) |
| 27 return computer_name; |
| 28 return std::string(); |
| 29 } |
| 30 #endif |
| 31 |
| 32 namespace { |
| 33 |
| 34 void DoGetSessionNameTask(std::string* session_name) { |
| 35 #if defined(OS_CHROMEOS) |
| 36 *session_name = "Chromebook"; |
| 37 #elif defined(OS_LINUX) |
| 38 *session_name = base::GetLinuxDistro(); |
| 39 #elif defined(OS_MACOSX) |
| 40 *session_name = GetSessionNameTask::GetHardwareModelName(); |
| 41 #elif defined(OS_WIN) |
| 42 *session_name = GetSessionNameTask::GetComputerName(); |
| 43 #else |
| 44 session_name->clear(); |
| 45 #endif |
| 46 |
| 47 if (*session_name == "Unknown" || session_name->empty()) |
| 48 *session_name = base::SysInfo::OperatingSystemName(); |
| 49 } |
| 50 |
| 51 void GetSessionNameReply( |
| 52 const base::Callback<void(const std::string&)>& done_callback, |
| 53 std::string* session_name) { |
| 54 done_callback.Run(*session_name); |
| 55 } |
| 56 |
| 57 } // namespace |
| 58 |
| 59 void GetSessionName( |
| 60 const scoped_refptr<base::TaskRunner>& task_runner, |
| 61 const base::Callback<void(const std::string&)>& done_callback) { |
| 62 std::string* session_name = new std::string(); |
| 63 task_runner->PostTaskAndReply( |
| 64 FROM_HERE, |
| 65 base::Bind(&DoGetSessionNameTask, |
| 66 base::Unretained(session_name)), |
| 67 base::Bind(&GetSessionNameReply, |
| 68 done_callback, |
| 69 base::Owned(session_name))); |
| 70 } |
| 71 |
| 72 } // namespace browser_sync |
OLD | NEW |