summaryrefslogtreecommitdiffstats
path: root/sync
diff options
context:
space:
mode:
authormaniscalco <maniscalco@chromium.org>2014-08-28 14:38:44 -0700
committerCommit bot <commit-bot@chromium.org>2014-08-28 21:40:11 +0000
commit58cfacd2313c2a67aa52e02f1eccc352df427502 (patch)
treeca11b5c68beb5ac074e5c34ae41d996b6c69b56d /sync
parent6c9ccd1a53b92f8aef4f4bdd2bc8b665849cc02e (diff)
downloadchromium_src-58cfacd2313c2a67aa52e02f1eccc352df427502.zip
chromium_src-58cfacd2313c2a67aa52e02f1eccc352df427502.tar.gz
chromium_src-58cfacd2313c2a67aa52e02f1eccc352df427502.tar.bz2
Ensure syncer::internal::GetComputerName returns a UTF-8 string.
Prior to this change, on Windows, GetComputerName resulted in a call to GetComputerNameA, which returns an ANSI string (not ASCII, not UTF-8). Call GetComputerNameW instead and convert the returned wide string to UTF-8. Tested by adding U+00AB to the computer name. Saw in about:sync the name contained a U+FFFD instead (symbol for unrepresentable character). Performed sync dashboard clear, applied patch, saw that the name correctly contained U+00AB. This CL does not address corrupted device info that's already in the field. Depending on impact that may be addressed in a future CL. BUG=406470 Review URL: https://codereview.chromium.org/479703004 Cr-Commit-Position: refs/heads/master@{#292466}
Diffstat (limited to 'sync')
-rw-r--r--sync/util/get_session_name.cc2
-rw-r--r--sync/util/get_session_name.h1
-rw-r--r--sync/util/get_session_name_win.cc16
3 files changed, 15 insertions, 4 deletions
diff --git a/sync/util/get_session_name.cc b/sync/util/get_session_name.cc
index 3a09c51..c669e22 100644
--- a/sync/util/get_session_name.cc
+++ b/sync/util/get_session_name.cc
@@ -8,6 +8,7 @@
#include "base/bind_helpers.h"
#include "base/callback.h"
#include "base/location.h"
+#include "base/strings/string_util.h"
#include "base/sys_info.h"
#include "base/task_runner.h"
@@ -53,6 +54,7 @@ std::string GetSessionNameSynchronously() {
if (session_name == "Unknown" || session_name.empty())
session_name = base::SysInfo::OperatingSystemName();
+ DCHECK(base::IsStringUTF8(session_name));
return session_name;
}
diff --git a/sync/util/get_session_name.h b/sync/util/get_session_name.h
index 724ae3c..7ac34ad 100644
--- a/sync/util/get_session_name.h
+++ b/sync/util/get_session_name.h
@@ -17,6 +17,7 @@ class TaskRunner;
namespace syncer {
+// Invokes |done_callback| with the session name, a UTF-8 string.
SYNC_EXPORT void GetSessionName(
const scoped_refptr<base::TaskRunner>& task_runner,
const base::Callback<void(const std::string&)>& done_callback);
diff --git a/sync/util/get_session_name_win.cc b/sync/util/get_session_name_win.cc
index 101bcd4..58980a3 100644
--- a/sync/util/get_session_name_win.cc
+++ b/sync/util/get_session_name_win.cc
@@ -4,16 +4,24 @@
#include "sync/util/get_session_name_win.h"
+#include "base/logging.h"
+#include "base/macros.h"
+#include "base/strings/utf_string_conversions.h"
+
#include <windows.h>
namespace syncer {
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;
+ wchar_t computer_name[MAX_COMPUTERNAME_LENGTH + 1] = {0};
+ DWORD size = arraysize(computer_name);
+ if (::GetComputerNameW(computer_name, &size)) {
+ std::string result;
+ bool conversion_successful = base::WideToUTF8(computer_name, size, &result);
+ DCHECK(conversion_successful);
+ return result;
+ }
return std::string();
}