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/sys_info.h"
12 #include "base/task_runner.h"
15 #include "sync/util/get_session_name_linux.h"
17 #include "sync/util/get_session_name_ios.h"
18 #elif defined(OS_MACOSX)
19 #include "sync/util/get_session_name_mac.h"
21 #include "sync/util/get_session_name_win.h"
22 #elif defined(OS_ANDROID)
23 #include "base/android/build_info.h"
30 std::string
GetSessionNameSynchronously() {
31 std::string session_name
;
32 #if defined(OS_CHROMEOS)
33 std::string board
= base::SysInfo::GetLsbReleaseBoard();
34 // Currently, only "stumpy" type of board is considered Chromebox, and
35 // anything else is Chromebook. On these devices, session_name should look
36 // like "stumpy-signed-mp-v2keys" etc. The information can be checked on
37 // "CHROMEOS_RELEASE_BOARD" line in chrome://system.
38 session_name
= board
.substr(0, 6) == "stumpy" ? "Chromebox" : "Chromebook";
39 #elif defined(OS_LINUX)
40 session_name
= internal::GetHostname();
42 session_name
= internal::GetComputerName();
43 #elif defined(OS_MACOSX)
44 session_name
= internal::GetHardwareModelName();
46 session_name
= internal::GetComputerName();
47 #elif defined(OS_ANDROID)
48 base::android::BuildInfo
* android_build_info
=
49 base::android::BuildInfo::GetInstance();
50 session_name
= android_build_info
->model();
53 if (session_name
== "Unknown" || session_name
.empty())
54 session_name
= base::SysInfo::OperatingSystemName();
59 void FillSessionName(std::string
* session_name
) {
60 *session_name
= GetSessionNameSynchronously();
63 void OnSessionNameFilled(
64 const base::Callback
<void(const std::string
&)>& done_callback
,
65 std::string
* session_name
) {
66 done_callback
.Run(*session_name
);
72 const scoped_refptr
<base::TaskRunner
>& task_runner
,
73 const base::Callback
<void(const std::string
&)>& done_callback
) {
74 std::string
* session_name
= new std::string();
75 task_runner
->PostTaskAndReply(
77 base::Bind(&FillSessionName
,
78 base::Unretained(session_name
)),
79 base::Bind(&OnSessionNameFilled
,
81 base::Owned(session_name
)));
84 std::string
GetSessionNameSynchronouslyForTesting() {
85 return GetSessionNameSynchronously();