srpcgen: Use 'const char*' for string parameters
[chromium-blink-merge.git] / chrome_frame / chrome_launcher_utils.cc
blobc77b9a8d763385139b71f13eeedbaec511caab50
1 // Copyright (c) 2011 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 "chrome_frame/chrome_launcher_utils.h"
7 #include "base/base_switches.h"
8 #include "base/command_line.h"
9 #include "base/file_util.h"
10 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/path_service.h"
13 #include "base/string_util.h"
14 #include "base/win/windows_version.h"
15 #include "chrome/common/chrome_constants.h"
16 #include "chrome/common/chrome_switches.h"
17 #include "chrome_frame/chrome_frame_automation.h"
19 namespace {
21 const char kUpdateCommandFlag[] = "--update-cmd";
23 // Searches for the path to chrome_launcher.exe. Will return false if this
24 // executable cannot be found, otherwise the command line will be placed in
25 // |command_line|.
26 bool CreateChromeLauncherCommandLine(scoped_ptr<CommandLine>* command_line) {
27 DCHECK(command_line);
28 bool success = false;
29 // The launcher EXE will be in the same directory as the Chrome Frame DLL,
30 // so create a full path to it based on this assumption.
31 FilePath module_path;
32 if (PathService::Get(base::FILE_MODULE, &module_path)) {
33 FilePath current_dir = module_path.DirName();
34 FilePath chrome_launcher = current_dir.Append(
35 chrome_launcher::kLauncherExeBaseName);
36 if (file_util::PathExists(chrome_launcher)) {
37 command_line->reset(new CommandLine(chrome_launcher));
38 success = true;
42 if (!success) {
43 NOTREACHED() << "Could not find " << chrome_launcher::kLauncherExeBaseName
44 << " in output dir.";
47 return success;
50 } // namespace
52 namespace chrome_launcher {
54 const wchar_t kLauncherExeBaseName[] = L"chrome_launcher.exe";
56 bool CreateUpdateCommandLine(const std::wstring& update_command,
57 scoped_ptr<CommandLine>* command_line) {
58 DCHECK(command_line);
59 bool success = false;
61 if (CreateChromeLauncherCommandLine(command_line)) {
62 (*command_line)->AppendArg(kUpdateCommandFlag);
63 (*command_line)->AppendArg(WideToASCII(update_command));
64 success = true;
67 return success;
70 bool CreateLaunchCommandLine(scoped_ptr<CommandLine>* command_line) {
71 DCHECK(command_line);
73 // Shortcut for OS versions that don't need the integrity broker.
74 if (base::win::GetVersion() < base::win::VERSION_VISTA) {
75 command_line->reset(new CommandLine(GetChromeExecutablePath()));
76 return true;
79 return CreateChromeLauncherCommandLine(command_line);
82 FilePath GetChromeExecutablePath() {
83 FilePath cur_path;
84 PathService::Get(base::DIR_MODULE, &cur_path);
85 cur_path = cur_path.Append(chrome::kBrowserProcessExecutableName);
87 // The installation model for Chrome places the DLLs in a versioned
88 // sub-folder one down from the Chrome executable. If we fail to find
89 // chrome.exe in the current path, try looking one up and launching that
90 // instead.
91 if (!file_util::PathExists(cur_path)) {
92 PathService::Get(base::DIR_MODULE, &cur_path);
93 cur_path = cur_path.DirName().Append(chrome::kBrowserProcessExecutableName);
96 return cur_path;
99 } // namespace chrome_launcher