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 namespace internal { |
| 24 |
| 25 std::string GetComputerName() { |
| 26 char computer_name[MAX_COMPUTERNAME_LENGTH + 1]; |
| 27 DWORD size = sizeof(computer_name); |
| 28 if (GetComputerNameA(computer_name, &size)) |
| 29 return computer_name; |
| 30 return std::string(); |
| 31 } |
| 32 |
| 33 } // namespace internal |
| 34 #endif |
| 35 |
| 36 namespace { |
| 37 |
| 38 void DoGetSessionNameTask(std::string* session_name) { |
| 39 #if defined(OS_CHROMEOS) |
| 40 *session_name = "Chromebook"; |
| 41 #elif defined(OS_LINUX) |
| 42 *session_name = base::GetLinuxDistro(); |
| 43 #elif defined(OS_MACOSX) |
| 44 *session_name = internal::GetHardwareModelName(); |
| 45 #elif defined(OS_WIN) |
| 46 *session_name = internal::GetComputerName(); |
| 47 #else |
| 48 session_name->clear(); |
| 49 #endif |
| 50 |
| 51 if (*session_name == "Unknown" || session_name->empty()) |
| 52 *session_name = base::SysInfo::OperatingSystemName(); |
| 53 } |
| 54 |
| 55 void GetSessionNameReply( |
| 56 const base::Callback<void(const std::string&)>& done_callback, |
| 57 std::string* session_name) { |
| 58 done_callback.Run(*session_name); |
| 59 } |
| 60 |
| 61 } // namespace |
| 62 |
| 63 void GetSessionName( |
| 64 const scoped_refptr<base::TaskRunner>& task_runner, |
| 65 const base::Callback<void(const std::string&)>& done_callback) { |
| 66 std::string* session_name = new std::string(); |
| 67 task_runner->PostTaskAndReply( |
| 68 FROM_HERE, |
| 69 base::Bind(&DoGetSessionNameTask, |
| 70 base::Unretained(session_name)), |
| 71 base::Bind(&GetSessionNameReply, |
| 72 done_callback, |
| 73 base::Owned(session_name))); |
| 74 } |
| 75 |
| 76 } // namespace browser_sync |
OLD | NEW |