Home | History | Annotate | Download | only in win
      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 
     15 base::string16 GetLocalComputerName() {
     16   DWORD size = 0;
     17   base::string16 result;
     18   ::GetComputerName(NULL, &size);
     19   result.resize(size);
     20   if (result.empty())
     21     return result;
     22   if (!::GetComputerName(&result[0], &size))
     23     return base::string16();
     24   result.resize(size);
     25   return result;
     26 }
     27 
     28 base::string16 ReplaceLocalHostInName(const base::string16& user_name) {
     29   static const wchar_t kLocalDomain[] = L".\\";
     30   if (StartsWith(user_name, kLocalDomain, true)) {
     31     return GetLocalComputerName() +
     32            user_name.substr(arraysize(kLocalDomain) - 2);
     33   }
     34   return user_name;
     35 }
     36 
     37 base::string16 GetCurrentUserName() {
     38   ULONG size = 0;
     39   base::string16 result;
     40   ::GetUserNameEx(::NameSamCompatible, NULL, &size);
     41   result.resize(size);
     42   if (result.empty())
     43     return result;
     44   if (!::GetUserNameEx(::NameSamCompatible, &result[0], &size))
     45     return base::string16();
     46   result.resize(size);
     47   return result;
     48 }
     49 
     50 void CopyChromeSwitchesFromCurrentProcess(CommandLine* destination) {
     51   static const char* const kSwitchesToCopy[] = {
     52     switches::kCloudPrintServiceURL,
     53     switches::kEnableLogging,
     54     switches::kIgnoreUrlFetcherCertRequests,
     55     switches::kLsoUrl,
     56     switches::kV,
     57   };
     58   destination->CopySwitchesFrom(*CommandLine::ForCurrentProcess(),
     59                                 kSwitchesToCopy,
     60                                 arraysize(kSwitchesToCopy));
     61 }
     62 
     63