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. 4 5 #include "cloud_print/service/win/service_utils.h" 6 #include "google_apis/gaia/gaia_switches.h" 7 8 #include <windows.h> 9 #include <security.h> // NOLINT 10 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" 15 16 base::string16 GetLocalComputerName() { 17 DWORD size = 0; 18 base::string16 result; 19 ::GetComputerName(NULL, &size); 20 result.resize(size); 21 if (result.empty()) 22 return result; 23 if (!::GetComputerName(&result[0], &size)) 24 return base::string16(); 25 result.resize(size); 26 return result; 27 } 28 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); 34 } 35 return user_name; 36 } 37 38 base::string16 GetCurrentUserName() { 39 ULONG size = 0; 40 base::string16 result; 41 ::GetUserNameEx(::NameSamCompatible, NULL, &size); 42 result.resize(size); 43 if (result.empty()) 44 return result; 45 if (!::GetUserNameEx(::NameSamCompatible, &result[0], &size)) 46 return base::string16(); 47 result.resize(size); 48 return result; 49 } 50 51 void CopyChromeSwitchesFromCurrentProcess(CommandLine* destination) { 52 static const char* const kSwitchesToCopy[] = { 53 switches::kCloudPrintURL, 54 switches::kCloudPrintXmppEndpoint, 55 switches::kEnableCloudPrintXps, 56 switches::kEnableLogging, 57 switches::kIgnoreUrlFetcherCertRequests, 58 switches::kLsoUrl, 59 switches::kV, 60 }; 61 destination->CopySwitchesFrom(*CommandLine::ForCurrentProcess(), 62 kSwitchesToCopy, 63 arraysize(kSwitchesToCopy)); 64 } 65 66