Loosen up heuristics for detecting account creation forms.
[chromium-blink-merge.git] / sync / util / get_session_name.cc
blob3eede5af9db9b7b8bfbe9b56e3cf8d32a6f6bd9c
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_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"
20 #elif defined(OS_WIN)
21 #include "sync/util/get_session_name_win.h"
22 #elif defined(OS_ANDROID)
23 #include "sync/util/session_utils_android.h"
24 #endif
26 namespace syncer {
28 namespace {
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.
34 std::string board;
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();
49 #elif defined(OS_WIN)
50 session_name = internal::GetComputerName();
51 #elif defined(OS_ANDROID)
52 session_name = internal::GetModel();
53 #endif
55 if (session_name == "Unknown" || session_name.empty())
56 session_name = base::SysInfo::OperatingSystemName();
58 return session_name;
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);
71 } // namespace
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)));
86 std::string GetSessionNameSynchronouslyForTesting() {
87 return GetSessionNameSynchronously();
90 } // namespace syncer