[Android] Remove unused code in content
[chromium-blink-merge.git] / sync / util / get_session_name.cc
blob5d0255368579422cb518b74d2f519f568e2438d7
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/strings/string_util.h"
12 #include "base/sys_info.h"
13 #include "base/task_runner.h"
15 #if defined(OS_CHROMEOS)
16 #include "chromeos/system/devicetype.h"
17 #elif defined(OS_LINUX)
18 #include "sync/util/get_session_name_linux.h"
19 #elif defined(OS_IOS)
20 #include "sync/util/get_session_name_ios.h"
21 #elif defined(OS_MACOSX)
22 #include "sync/util/get_session_name_mac.h"
23 #elif defined(OS_WIN)
24 #include "sync/util/get_session_name_win.h"
25 #elif defined(OS_ANDROID)
26 #include "base/android/build_info.h"
27 #endif
29 namespace syncer {
31 namespace {
33 std::string GetSessionNameSynchronously() {
34 std::string session_name;
35 #if defined(OS_CHROMEOS)
36 switch (chromeos::GetDeviceType()) {
37 case chromeos::DeviceType::kChromebase:
38 session_name = "Chromebase";
39 break;
40 case chromeos::DeviceType::kChromebit:
41 session_name = "Chromebit";
42 break;
43 case chromeos::DeviceType::kChromebook:
44 session_name = "Chromebook";
45 break;
46 case chromeos::DeviceType::kChromebox:
47 session_name = "Chromebox";
48 break;
49 case chromeos::DeviceType::kUnknown:
50 session_name = "Chromebook";
51 break;
53 #elif defined(OS_LINUX)
54 session_name = internal::GetHostname();
55 #elif defined(OS_IOS)
56 session_name = internal::GetComputerName();
57 #elif defined(OS_MACOSX)
58 session_name = internal::GetHardwareModelName();
59 #elif defined(OS_WIN)
60 session_name = internal::GetComputerName();
61 #elif defined(OS_ANDROID)
62 base::android::BuildInfo* android_build_info =
63 base::android::BuildInfo::GetInstance();
64 session_name = android_build_info->model();
65 #endif
67 if (session_name == "Unknown" || session_name.empty())
68 session_name = base::SysInfo::OperatingSystemName();
70 DCHECK(base::IsStringUTF8(session_name));
71 return session_name;
74 void FillSessionName(std::string* session_name) {
75 *session_name = GetSessionNameSynchronously();
78 void OnSessionNameFilled(
79 const base::Callback<void(const std::string&)>& done_callback,
80 std::string* session_name) {
81 done_callback.Run(*session_name);
84 } // namespace
86 void GetSessionName(
87 const scoped_refptr<base::TaskRunner>& task_runner,
88 const base::Callback<void(const std::string&)>& done_callback) {
89 std::string* session_name = new std::string();
90 task_runner->PostTaskAndReply(
91 FROM_HERE,
92 base::Bind(&FillSessionName,
93 base::Unretained(session_name)),
94 base::Bind(&OnSessionNameFilled,
95 done_callback,
96 base::Owned(session_name)));
99 std::string GetSessionNameSynchronouslyForTesting() {
100 return GetSessionNameSynchronously();
103 } // namespace syncer