summaryrefslogtreecommitdiffstats
path: root/win8/delegate_execute/delegate_execute_util.cc
blob: 87a5fb66b8971e79573abd6234a43f1ea650b6ec (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 {

base::CommandLine CommandLineFromParameters(const wchar_t* params) {
  base::CommandLine command_line(base::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;
}

base::CommandLine MakeChromeCommandLine(const base::FilePath& chrome_exe,
                                        const base::CommandLine& params,
                                        const base::string16& argument) {
  base::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();

  base::CommandLine cmd_line(base::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