Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: chrome/browser/sync/util/get_session_name_task.cc

Issue 9565050: [Sync] Simplify GetSessionName interface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win compile failure Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 "chrome/browser/sync/util/get_session_name_task.h"
6
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/message_loop_proxy.h"
10 #include "base/sys_info.h"
11
12 #if defined(OS_LINUX)
13 #include "base/linux_util.h"
14 #elif defined(OS_WIN)
15 #include <windows.h>
16 #endif
17
18 namespace browser_sync {
19
20 GetSessionNameTask::GetSessionNameTask(
21 const GetSessionNameTask::OnSessionNameInitialized& callback)
22 : callback_(callback),
23 thread_(base::MessageLoopProxy::current()) {
24 }
25
26 GetSessionNameTask::~GetSessionNameTask() {}
27
28 void GetSessionNameTask::GetSessionNameAsync() {
29 #if defined(OS_CHROMEOS)
30 std::string session_name = "Chromebook";
31 #elif defined(OS_LINUX)
32 std::string session_name = base::GetLinuxDistro();
33 #elif defined(OS_MACOSX)
34 std::string session_name = GetSessionNameTask::GetHardwareModelName();
35 #elif defined(OS_WIN)
36 std::string session_name = GetSessionNameTask::GetComputerName();
37 #else
38 std::string session_name;
39 #endif
40
41 if (session_name == "Unknown" || session_name.empty())
42 session_name = base::SysInfo::OperatingSystemName();
43
44 thread_->PostTask(FROM_HERE,
45 base::Bind(&GetSessionNameTask::InvokeCallback,
46 this,
47 session_name));
48 }
49
50 void GetSessionNameTask::InvokeCallback(const std::string& session_name) {
51 callback_.Run(session_name);
52 }
53
54 #if defined(OS_WIN)
55 // static
56 std::string GetSessionNameTask::GetComputerName() {
57 char computer_name[MAX_COMPUTERNAME_LENGTH + 1];
58 DWORD size = sizeof(computer_name);
59 if (GetComputerNameA(computer_name, &size))
60 return computer_name;
61 return std::string();
62 }
63 #endif
64
65 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/util/get_session_name_task.h ('k') | chrome/browser/sync/util/get_session_name_task_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698