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

Unified Diff: chrome/browser/sync/util/get_session_name.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, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/sync/util/get_session_name.h ('k') | chrome/browser/sync/util/get_session_name_mac.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/sync/util/get_session_name.cc
diff --git a/chrome/browser/sync/util/get_session_name.cc b/chrome/browser/sync/util/get_session_name.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4e1a31bc646fe864fffbf0fa2cfb4d5e986d4791
--- /dev/null
+++ b/chrome/browser/sync/util/get_session_name.cc
@@ -0,0 +1,76 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/sync/util/get_session_name.h"
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/callback.h"
+#include "base/location.h"
+#include "base/message_loop_proxy.h"
+#include "base/sys_info.h"
+
+#if defined(OS_LINUX)
+#include "base/linux_util.h"
+#elif defined(OS_WIN)
+#include <windows.h>
+#endif
+
+namespace browser_sync {
+
+#if defined(OS_WIN)
+namespace internal {
+
+std::string GetComputerName() {
+ char computer_name[MAX_COMPUTERNAME_LENGTH + 1];
+ DWORD size = sizeof(computer_name);
+ if (GetComputerNameA(computer_name, &size))
+ return computer_name;
+ return std::string();
+}
+
+} // namespace internal
+#endif
+
+namespace {
+
+void DoGetSessionNameTask(std::string* session_name) {
+#if defined(OS_CHROMEOS)
+ *session_name = "Chromebook";
+#elif defined(OS_LINUX)
+ *session_name = base::GetLinuxDistro();
+#elif defined(OS_MACOSX)
+ *session_name = internal::GetHardwareModelName();
+#elif defined(OS_WIN)
+ *session_name = internal::GetComputerName();
+#else
+ session_name->clear();
+#endif
+
+ if (*session_name == "Unknown" || session_name->empty())
+ *session_name = base::SysInfo::OperatingSystemName();
+}
+
+void GetSessionNameReply(
+ const base::Callback<void(const std::string&)>& done_callback,
+ std::string* session_name) {
+ done_callback.Run(*session_name);
+}
+
+} // namespace
+
+void GetSessionName(
+ const scoped_refptr<base::TaskRunner>& task_runner,
+ const base::Callback<void(const std::string&)>& done_callback) {
+ std::string* session_name = new std::string();
+ task_runner->PostTaskAndReply(
+ FROM_HERE,
+ base::Bind(&DoGetSessionNameTask,
+ base::Unretained(session_name)),
+ base::Bind(&GetSessionNameReply,
+ done_callback,
+ base::Owned(session_name)));
+}
+
+} // namespace browser_sync
« no previous file with comments | « chrome/browser/sync/util/get_session_name.h ('k') | chrome/browser/sync/util/get_session_name_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698