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"
16 #include "sync/util/get_session_name_linux.h"
18 #include "sync/util/get_session_name_ios.h"
19 #elif defined(OS_MACOSX)
20 #include "sync/util/get_session_name_mac.h"
22 #include "sync/util/get_session_name_win.h"
23 #elif defined(OS_ANDROID)
24 #include "base/android/build_info.h"
31 std::string
GetSessionNameSynchronously() {
32 std::string session_name
;
33 #if defined(OS_CHROMEOS)
34 std::string board
= base::SysInfo::GetLsbReleaseBoard();
35 // Currently, only "stumpy" type of board is considered Chromebox, and
36 // anything else is Chromebook. On these devices, session_name should look
37 // like "stumpy-signed-mp-v2keys" etc. The information can be checked on
38 // "CHROMEOS_RELEASE_BOARD" line in chrome://system.
39 session_name
= board
.substr(0, 6) == "stumpy" ? "Chromebox" : "Chromebook";
40 #elif defined(OS_LINUX)
41 session_name
= internal::GetHostname();
43 session_name
= internal::GetComputerName();
44 #elif defined(OS_MACOSX)
45 session_name
= internal::GetHardwareModelName();
47 session_name
= internal::GetComputerName();
48 #elif defined(OS_ANDROID)
49 base::android::BuildInfo
* android_build_info
=
50 base::android::BuildInfo::GetInstance();
51 session_name
= android_build_info
->model();
54 if (session_name
== "Unknown" || session_name
.empty())
55 session_name
= base::SysInfo::OperatingSystemName();
57 DCHECK(base::IsStringUTF8(session_name
));
61 void FillSessionName(std::string
* session_name
) {
62 *session_name
= GetSessionNameSynchronously();
65 void OnSessionNameFilled(
66 const base::Callback
<void(const std::string
&)>& done_callback
,
67 std::string
* session_name
) {
68 done_callback
.Run(*session_name
);
74 const scoped_refptr
<base::TaskRunner
>& task_runner
,
75 const base::Callback
<void(const std::string
&)>& done_callback
) {
76 std::string
* session_name
= new std::string();
77 task_runner
->PostTaskAndReply(
79 base::Bind(&FillSessionName
,
80 base::Unretained(session_name
)),
81 base::Bind(&OnSessionNameFilled
,
83 base::Owned(session_name
)));
86 std::string
GetSessionNameSynchronouslyForTesting() {
87 return GetSessionNameSynchronously();