webapps: utilize theme color specified in manifest
[chromium-blink-merge.git] / cloud_print / service / win / service_utils.cc
blobe64b5cb3b2d8ad17b2438e710de95a8d6dd0fe19
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"
8 #include <windows.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() {
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;
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);
36 return user_name;
39 base::string16 GetCurrentUserName() {
40 ULONG size = 0;
41 base::string16 result;
42 ::GetUserNameEx(::NameSamCompatible, NULL, &size);
43 result.resize(size);
44 if (result.empty())
45 return result;
46 if (!::GetUserNameEx(::NameSamCompatible, &result[0], &size))
47 return base::string16();
48 result.resize(size);
49 return result;
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,
59 switches::kLsoUrl,
60 switches::kV,
62 destination->CopySwitchesFrom(*base::CommandLine::ForCurrentProcess(),
63 kSwitchesToCopy,
64 arraysize(kSwitchesToCopy));