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 "base/command_line.h"
16 #include "chromeos/chromeos_switches.h"
17 #elif defined(OS_LINUX)
18 #include "base/linux_util.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 // The approach below is similar to that used by the CrOs implementation of
37 // StatisticsProvider::GetMachineStatistic(CHROMEOS_RELEASE_BOARD).
38 // See chrome/browser/chromeos/system/statistics_provider.{h|cc}.
40 // We cannot use StatisticsProvider here because of the mutual dependency
41 // it creates between sync.gyp:sync and chrome.gyp:browser.
43 // Even though this code is ad hoc and fragile, it remains the only means of
44 // determining the Chrome OS hardware platform so we can display the right
45 // device name in the "Other devices" section of the new tab page.
46 // TODO(rsimha): Change this once a better alternative is available.
47 // See http://crbug.com/126732.
49 const CommandLine
* command_line
= CommandLine::ForCurrentProcess();
50 if (command_line
->HasSwitch(chromeos::switches::kChromeOSReleaseBoard
)) {
51 board
= command_line
->
52 GetSwitchValueASCII(chromeos::switches::kChromeOSReleaseBoard
);
54 LOG(ERROR
) << "Failed to get board information";
57 // Currently, only "stumpy" type of board is considered Chromebox, and
58 // anything else is Chromebook. On these devices, session_name should look
59 // like "stumpy-signed-mp-v2keys" etc. The information can be checked on
60 // "CHROMEOS_RELEASE_BOARD" line in chrome://system.
61 session_name
= board
.substr(0, 6) == "stumpy" ? "Chromebox" : "Chromebook";
62 #elif defined(OS_LINUX)
63 session_name
= base::GetLinuxDistro();
65 session_name
= internal::GetComputerName();
66 #elif defined(OS_MACOSX)
67 session_name
= internal::GetHardwareModelName();
69 session_name
= internal::GetComputerName();
70 #elif defined(OS_ANDROID)
71 base::android::BuildInfo
* android_build_info
=
72 base::android::BuildInfo::GetInstance();
73 session_name
= android_build_info
->model();
76 if (session_name
== "Unknown" || session_name
.empty())
77 session_name
= base::SysInfo::OperatingSystemName();
82 void FillSessionName(std::string
* session_name
) {
83 *session_name
= GetSessionNameSynchronously();
86 void OnSessionNameFilled(
87 const base::Callback
<void(const std::string
&)>& done_callback
,
88 std::string
* session_name
) {
89 done_callback
.Run(*session_name
);
95 const scoped_refptr
<base::TaskRunner
>& task_runner
,
96 const base::Callback
<void(const std::string
&)>& done_callback
) {
97 std::string
* session_name
= new std::string();
98 task_runner
->PostTaskAndReply(
100 base::Bind(&FillSessionName
,
101 base::Unretained(session_name
)),
102 base::Bind(&OnSessionNameFilled
,
104 base::Owned(session_name
)));
107 std::string
GetSessionNameSynchronouslyForTesting() {
108 return GetSessionNameSynchronously();
111 } // namespace syncer