OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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_task.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/location.h" | |
9 #include "base/message_loop_proxy.h" | |
10 #include "base/sys_info.h" | |
11 | |
12 #if defined(OS_LINUX) | |
13 #include "base/linux_util.h" | |
14 #elif defined(OS_WIN) | |
15 #include <windows.h> | |
16 #endif | |
17 | |
18 namespace browser_sync { | |
19 | |
20 GetSessionNameTask::GetSessionNameTask( | |
21 const GetSessionNameTask::OnSessionNameInitialized& callback) | |
22 : callback_(callback), | |
23 thread_(base::MessageLoopProxy::current()) { | |
24 } | |
25 | |
26 GetSessionNameTask::~GetSessionNameTask() {} | |
27 | |
28 void GetSessionNameTask::GetSessionNameAsync() { | |
29 #if defined(OS_CHROMEOS) | |
30 std::string session_name = "Chromebook"; | |
31 #elif defined(OS_LINUX) | |
32 std::string session_name = base::GetLinuxDistro(); | |
33 #elif defined(OS_MACOSX) | |
34 std::string session_name = GetSessionNameTask::GetHardwareModelName(); | |
35 #elif defined(OS_WIN) | |
36 std::string session_name = GetSessionNameTask::GetComputerName(); | |
37 #else | |
38 std::string session_name; | |
39 #endif | |
40 | |
41 if (session_name == "Unknown" || session_name.empty()) | |
42 session_name = base::SysInfo::OperatingSystemName(); | |
43 | |
44 thread_->PostTask(FROM_HERE, | |
45 base::Bind(&GetSessionNameTask::InvokeCallback, | |
46 this, | |
47 session_name)); | |
48 } | |
49 | |
50 void GetSessionNameTask::InvokeCallback(const std::string& session_name) { | |
51 callback_.Run(session_name); | |
52 } | |
53 | |
54 #if defined(OS_WIN) | |
55 // static | |
56 std::string GetSessionNameTask::GetComputerName() { | |
57 char computer_name[MAX_COMPUTERNAME_LENGTH + 1]; | |
58 DWORD size = sizeof(computer_name); | |
59 if (GetComputerNameA(computer_name, &size)) | |
60 return computer_name; | |
61 return std::string(); | |
62 } | |
63 #endif | |
64 | |
65 } // namespace browser_sync | |
OLD | NEW |