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 (StartsWith(user_name
, kLocalDomain
, true)) {
32 return GetLocalComputerName() +
33 user_name
.substr(arraysize(kLocalDomain
) - 2);
38 base::string16
GetCurrentUserName() {
40 base::string16 result
;
41 ::GetUserNameEx(::NameSamCompatible
, NULL
, &size
);
45 if (!::GetUserNameEx(::NameSamCompatible
, &result
[0], &size
))
46 return base::string16();
51 void CopyChromeSwitchesFromCurrentProcess(base::CommandLine
* destination
) {
52 static const char* const kSwitchesToCopy
[] = {
53 switches::kCloudPrintURL
,
54 switches::kCloudPrintXmppEndpoint
,
55 switches::kEnableCloudPrintXps
,
56 switches::kEnableLogging
,
57 switches::kIgnoreUrlFetcherCertRequests
,
61 destination
->CopySwitchesFrom(*base::CommandLine::ForCurrentProcess(),
63 arraysize(kSwitchesToCopy
));