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. 4 5 #include "sync/util/get_session_name.h" 6 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" 14 15 #if defined(OS_LINUX) 16 #include "sync/util/get_session_name_linux.h" 17 #elif defined(OS_IOS) 18 #include "sync/util/get_session_name_ios.h" 19 #elif defined(OS_MACOSX) 20 #include "sync/util/get_session_name_mac.h" 21 #elif defined(OS_WIN) 22 #include "sync/util/get_session_name_win.h" 23 #elif defined(OS_ANDROID) 24 #include "base/android/build_info.h" 25 #endif 26 27 namespace syncer { 28 29 namespace { 30 31 std::string GetSessionNameSynchronously() { 32 std::string session_name; 33 #if defined(OS_CHROMEOS) 34 std::string board = base::SysInfo::GetLsbReleaseBoard(); 35 // Currently, only "stumpy" type of board is considered Chromebox, and 36 // anything else is Chromebook. On these devices, session_name should look 37 // like "stumpy-signed-mp-v2keys" etc. The information can be checked on 38 // "CHROMEOS_RELEASE_BOARD" line in chrome://system. 39 session_name = board.substr(0, 6) == "stumpy" ? "Chromebox" : "Chromebook"; 40 #elif defined(OS_LINUX) 41 session_name = internal::GetHostname(); 42 #elif defined(OS_IOS) 43 session_name = internal::GetComputerName(); 44 #elif defined(OS_MACOSX) 45 session_name = internal::GetHardwareModelName(); 46 #elif defined(OS_WIN) 47 session_name = internal::GetComputerName(); 48 #elif defined(OS_ANDROID) 49 base::android::BuildInfo* android_build_info = 50 base::android::BuildInfo::GetInstance(); 51 session_name = android_build_info->model(); 52 #endif 53 54 if (session_name == "Unknown" || session_name.empty()) 55 session_name = base::SysInfo::OperatingSystemName(); 56 57 DCHECK(base::IsStringUTF8(session_name)); 58 return session_name; 59 } 60 61 void FillSessionName(std::string* session_name) { 62 *session_name = GetSessionNameSynchronously(); 63 } 64 65 void OnSessionNameFilled( 66 const base::Callback<void(const std::string&)>& done_callback, 67 std::string* session_name) { 68 done_callback.Run(*session_name); 69 } 70 71 } // namespace 72 73 void GetSessionName( 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( 78 FROM_HERE, 79 base::Bind(&FillSessionName, 80 base::Unretained(session_name)), 81 base::Bind(&OnSessionNameFilled, 82 done_callback, 83 base::Owned(session_name))); 84 } 85 86 std::string GetSessionNameSynchronouslyForTesting() { 87 return GetSessionNameSynchronously(); 88 } 89 90 } // namespace syncer 91