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.
5 #include "sync/util/get_session_name.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"
15 #if defined(OS_CHROMEOS)
16 #include "chromeos/system/devicetype.h"
17 #elif defined(OS_LINUX)
18 #include "sync/util/get_session_name_linux.h"
20 #include "sync/util/get_session_name_ios.h"
21 #elif defined(OS_MACOSX)
22 #include "sync/util/get_session_name_mac.h"
24 #include "sync/util/get_session_name_win.h"
25 #elif defined(OS_ANDROID)
26 #include "base/android/build_info.h"
33 std::string
GetSessionNameSynchronously() {
34 std::string session_name
;
35 #if defined(OS_CHROMEOS)
36 switch (chromeos::GetDeviceType()) {
37 case chromeos::DeviceType::kChromebase
:
38 session_name
= "Chromebase";
40 case chromeos::DeviceType::kChromebit
:
41 session_name
= "Chromebit";
43 case chromeos::DeviceType::kChromebook
:
44 session_name
= "Chromebook";
46 case chromeos::DeviceType::kChromebox
:
47 session_name
= "Chromebox";
49 case chromeos::DeviceType::kUnknown
:
50 session_name
= "Chromebook";
53 #elif defined(OS_LINUX)
54 session_name
= internal::GetHostname();
56 session_name
= internal::GetComputerName();
57 #elif defined(OS_MACOSX)
58 session_name
= internal::GetHardwareModelName();
60 session_name
= internal::GetComputerName();
61 #elif defined(OS_ANDROID)
62 base::android::BuildInfo
* android_build_info
=
63 base::android::BuildInfo::GetInstance();
64 session_name
= android_build_info
->model();
67 if (session_name
== "Unknown" || session_name
.empty())
68 session_name
= base::SysInfo::OperatingSystemName();
70 DCHECK(base::IsStringUTF8(session_name
));
74 void FillSessionName(std::string
* session_name
) {
75 *session_name
= GetSessionNameSynchronously();
78 void OnSessionNameFilled(
79 const base::Callback
<void(const std::string
&)>& done_callback
,
80 std::string
* session_name
) {
81 done_callback
.Run(*session_name
);
87 const scoped_refptr
<base::TaskRunner
>& task_runner
,
88 const base::Callback
<void(const std::string
&)>& done_callback
) {
89 std::string
* session_name
= new std::string();
90 task_runner
->PostTaskAndReply(
92 base::Bind(&FillSessionName
,
93 base::Unretained(session_name
)),
94 base::Bind(&OnSessionNameFilled
,
96 base::Owned(session_name
)));
99 std::string
GetSessionNameSynchronouslyForTesting() {
100 return GetSessionNameSynchronously();
103 } // namespace syncer