summaryrefslogtreecommitdiffstats
path: root/win8/delegate_execute/delegate_execute_util.cc
blob: 78203ed4ec8da297b1405ae049a7c3a895a02f2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "win8/delegate_execute/delegate_execute_util.h"

#include "base/files/file_path.h"
#include "base/strings/string_util.h"

namespace delegate_execute {

CommandLine CommandLineFromParameters(const wchar_t* params) {
  CommandLine command_line(CommandLine::NO_PROGRAM);

  if (params) {
    base::string16 command_string(L"noprogram.exe ");
    command_string.append(params);
    command_line.ParseFromString(command_string);
    command_line.SetProgram(base::FilePath());
  }

  return command_line;
}

CommandLine MakeChromeCommandLine(const base::FilePath& chrome_exe,
                                  const CommandLine& params,
                                  const base::string16& argument) {
  CommandLine chrome_cmd(params);
  chrome_cmd.SetProgram(chrome_exe);

  if (!argument.empty())
    chrome_cmd.AppendArgNative(argument);

  return chrome_cmd;
}

base::string16 ParametersFromSwitch(const char* a_switch) {
  if (!a_switch)
    return base::string16();

  CommandLine cmd_line(CommandLine::NO_PROGRAM);

  cmd_line.AppendSwitch(a_switch);

  base::string16 command_string(cmd_line.GetCommandLineString());
  base::TrimWhitespace(command_string, base::TRIM_ALL, &command_string);
  return command_string;
}

}  // namespace delegate_execute