Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / sync / util / get_session_name.cc
blob3a09c51379d393d168fa0fe1d91bb253b81ed1ca
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"
7 #include "base/bind.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_LINUX)
15 #include "sync/util/get_session_name_linux.h"
16 #elif defined(OS_IOS)
17 #include "sync/util/get_session_name_ios.h"
18 #elif defined(OS_MACOSX)
19 #include "sync/util/get_session_name_mac.h"
20 #elif defined(OS_WIN)
21 #include "sync/util/get_session_name_win.h"
22 #elif defined(OS_ANDROID)
23 #include "base/android/build_info.h"
24 #endif
26 namespace syncer {
28 namespace {
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();
41 #elif defined(OS_IOS)
42 session_name = internal::GetComputerName();
43 #elif defined(OS_MACOSX)
44 session_name = internal::GetHardwareModelName();
45 #elif defined(OS_WIN)
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();
51 #endif
53 if (session_name == "Unknown" || session_name.empty())
54 session_name = base::SysInfo::OperatingSystemName();
56 return session_name;
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);
69 } // namespace
71 void GetSessionName(
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(
76 FROM_HERE,
77 base::Bind(&FillSessionName,
78 base::Unretained(session_name)),
79 base::Bind(&OnSessionNameFilled,
80 done_callback,
81 base::Owned(session_name)));
84 std::string GetSessionNameSynchronouslyForTesting() {
85 return GetSessionNameSynchronously();
88 } // namespace syncer