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"
14 #if defined(OS_CHROMEOS)
15 #include "chrome/browser/chromeos/system/statistics_provider.h"
16 #elif defined(OS_LINUX)
17 #include "base/linux_util.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 "sync/util/session_utils_android.h"
30 std::string
GetSessionNameSynchronously() {
31 std::string session_name
;
32 #if defined(OS_CHROMEOS)
33 // TODO(kochi): This is very ad hoc and fragile. http://crbug.com/126732.
35 const char kMachineInfoBoard
[] = "CHROMEOS_RELEASE_BOARD";
36 chromeos::system::StatisticsProvider
* provider
=
37 chromeos::system::StatisticsProvider::GetInstance();
38 if (!provider
->GetMachineStatistic(kMachineInfoBoard
, &board
))
39 LOG(ERROR
) << "Failed to get board information";
40 // Currently, only "stumpy" type of board is considered Chromebox, and
41 // anything else is Chromebook. On these devices, session_name should look
42 // like "stumpy-signed-mp-v2keys" etc. The information can be checked on
43 // "CHROMEOS_RELEASE_BOARD" line in chrome://system.
44 session_name
= board
.substr(0, 6) == "stumpy" ? "Chromebox" : "Chromebook";
45 #elif defined(OS_LINUX)
46 session_name
= base::GetLinuxDistro();
47 #elif defined(OS_MACOSX)
48 session_name
= internal::GetHardwareModelName();
50 session_name
= internal::GetComputerName();
51 #elif defined(OS_ANDROID)
52 session_name
= internal::GetModel();
55 if (session_name
== "Unknown" || session_name
.empty())
56 session_name
= base::SysInfo::OperatingSystemName();
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();