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 "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/strings/string_util.h" | |
12 #include "base/sys_info.h" | |
13 #include "base/task_runner.h" | |
14 #include "build/build_config.h" | |
15 | |
16 #if defined(OS_CHROMEOS) | |
17 #include "chromeos/system/devicetype.h" | |
18 #elif defined(OS_LINUX) | |
19 #include "sync/util/get_session_name_linux.h" | |
20 #elif defined(OS_IOS) | |
21 #include "sync/util/get_session_name_ios.h" | |
22 #elif defined(OS_MACOSX) | |
23 #include "sync/util/get_session_name_mac.h" | |
24 #elif defined(OS_WIN) | |
25 #include "sync/util/get_session_name_win.h" | |
26 #elif defined(OS_ANDROID) | |
27 #include "base/android/build_info.h" | |
28 #endif | |
29 | |
30 namespace syncer { | |
31 | |
32 namespace { | |
33 | |
34 std::string GetSessionNameSynchronously() { | |
35 std::string session_name; | |
36 #if defined(OS_CHROMEOS) | |
37 switch (chromeos::GetDeviceType()) { | |
38 case chromeos::DeviceType::kChromebase: | |
39 session_name = "Chromebase"; | |
40 break; | |
41 case chromeos::DeviceType::kChromebit: | |
42 session_name = "Chromebit"; | |
43 break; | |
44 case chromeos::DeviceType::kChromebook: | |
45 session_name = "Chromebook"; | |
46 break; | |
47 case chromeos::DeviceType::kChromebox: | |
48 session_name = "Chromebox"; | |
49 break; | |
50 case chromeos::DeviceType::kUnknown: | |
51 session_name = "Chromebook"; | |
52 break; | |
53 } | |
54 #elif defined(OS_LINUX) | |
55 session_name = internal::GetHostname(); | |
56 #elif defined(OS_IOS) | |
57 session_name = internal::GetComputerName(); | |
58 #elif defined(OS_MACOSX) | |
59 session_name = internal::GetHardwareModelName(); | |
60 #elif defined(OS_WIN) | |
61 session_name = internal::GetComputerName(); | |
62 #elif defined(OS_ANDROID) | |
63 base::android::BuildInfo* android_build_info = | |
64 base::android::BuildInfo::GetInstance(); | |
65 session_name = android_build_info->model(); | |
66 #endif | |
67 | |
68 if (session_name == "Unknown" || session_name.empty()) | |
69 session_name = base::SysInfo::OperatingSystemName(); | |
70 | |
71 DCHECK(base::IsStringUTF8(session_name)); | |
72 return session_name; | |
73 } | |
74 | |
75 void FillSessionName(std::string* session_name) { | |
76 *session_name = GetSessionNameSynchronously(); | |
77 } | |
78 | |
79 void OnSessionNameFilled( | |
80 const base::Callback<void(const std::string&)>& done_callback, | |
81 std::string* session_name) { | |
82 done_callback.Run(*session_name); | |
83 } | |
84 | |
85 } // namespace | |
86 | |
87 void GetSessionName( | |
88 const scoped_refptr<base::TaskRunner>& task_runner, | |
89 const base::Callback<void(const std::string&)>& done_callback) { | |
90 std::string* session_name = new std::string(); | |
91 task_runner->PostTaskAndReply( | |
92 FROM_HERE, | |
93 base::Bind(&FillSessionName, | |
94 base::Unretained(session_name)), | |
95 base::Bind(&OnSessionNameFilled, | |
96 done_callback, | |
97 base::Owned(session_name))); | |
98 } | |
99 | |
100 std::string GetSessionNameSynchronouslyForTesting() { | |
101 return GetSessionNameSynchronously(); | |
102 } | |
103 | |
104 } // namespace syncer | |
OLD | NEW |