1 // Copyright 2013 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 "cloud_print/service/win/service_utils.h"
6 #include "google_apis/gaia/gaia_switches.h"
9 #include <security.h> // NOLINT
11 #include "base/command_line.h"
12 #include "base/strings/string_util.h"
13 #include "chrome/common/chrome_switches.h"
14 #include "components/cloud_devices/common/cloud_devices_switches.h"
16 base::string16
GetLocalComputerName() {
18 base::string16 result
;
19 ::GetComputerName(NULL
, &size
);
23 if (!::GetComputerName(&result
[0], &size
))
24 return base::string16();
29 base::string16
ReplaceLocalHostInName(const base::string16
& user_name
) {
30 static const wchar_t kLocalDomain
[] = L
".\\";
31 if (base::StartsWith(user_name
, kLocalDomain
,
32 base::CompareCase::SENSITIVE
)) {
33 return GetLocalComputerName() +
34 user_name
.substr(arraysize(kLocalDomain
) - 2);
39 base::string16
GetCurrentUserName() {
41 base::string16 result
;
42 ::GetUserNameEx(::NameSamCompatible
, NULL
, &size
);
46 if (!::GetUserNameEx(::NameSamCompatible
, &result
[0], &size
))
47 return base::string16();
52 void CopyChromeSwitchesFromCurrentProcess(base::CommandLine
* destination
) {
53 static const char* const kSwitchesToCopy
[] = {
54 switches::kCloudPrintURL
,
55 switches::kCloudPrintXmppEndpoint
,
56 switches::kEnableCloudPrintXps
,
57 switches::kEnableLogging
,
58 switches::kIgnoreUrlFetcherCertRequests
,
62 destination
->CopySwitchesFrom(*base::CommandLine::ForCurrentProcess(),
64 arraysize(kSwitchesToCopy
));