OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome_frame/chrome_launcher_utils.h" | 5 #include "chrome_frame/chrome_launcher_utils.h" |
6 | 6 |
7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/win/windows_version.h" | 12 #include "base/win/windows_version.h" |
13 #include "chrome/common/chrome_constants.h" | 13 #include "chrome/common/chrome_constants.h" |
14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
15 #include "chrome_frame/chrome_frame_automation.h" | 15 #include "chrome_frame/chrome_frame_automation.h" |
16 | 16 |
17 namespace chrome_launcher { | 17 namespace { |
18 | 18 |
19 const wchar_t kLauncherExeBaseName[] = L"chrome_launcher.exe"; | 19 const char kUpdateCommandFlag[] = "--update-cmd"; |
20 | 20 |
21 CommandLine* CreateLaunchCommandLine() { | 21 CommandLine* CreateChromeLauncherCommandLine() { |
22 // Shortcut for OS versions that don't need the integrity broker. | |
23 if (base::win::GetVersion() < base::win::VERSION_VISTA) { | |
24 return new CommandLine(GetChromeExecutablePath()); | |
25 } | |
26 | |
27 // The launcher EXE will be in the same directory as the Chrome Frame DLL, | 22 // The launcher EXE will be in the same directory as the Chrome Frame DLL, |
28 // so create a full path to it based on this assumption. Since our unit | 23 // so create a full path to it based on this assumption. Since our unit |
29 // tests also use this function, and live in the directory above, we test | 24 // tests also use this function, and live in the directory above, we test |
30 // existence of the file and try the path that includes the /servers/ | 25 // existence of the file and try the path that includes the /servers/ |
31 // directory if needed. | 26 // directory if needed. |
32 FilePath module_path; | 27 FilePath module_path; |
33 if (PathService::Get(base::FILE_MODULE, &module_path)) { | 28 if (PathService::Get(base::FILE_MODULE, &module_path)) { |
34 FilePath current_dir = module_path.DirName(); | 29 FilePath current_dir = module_path.DirName(); |
35 FilePath same_dir_path = current_dir.Append(kLauncherExeBaseName); | 30 FilePath same_dir_path = current_dir.Append( |
| 31 chrome_launcher::kLauncherExeBaseName); |
36 if (file_util::PathExists(same_dir_path)) { | 32 if (file_util::PathExists(same_dir_path)) { |
37 return new CommandLine(same_dir_path); | 33 return new CommandLine(same_dir_path); |
38 } else { | 34 } else { |
39 FilePath servers_path = | 35 FilePath servers_path = current_dir.Append(L"servers").Append( |
40 current_dir.Append(L"servers").Append(kLauncherExeBaseName); | 36 chrome_launcher::kLauncherExeBaseName); |
41 DCHECK(file_util::PathExists(servers_path)) << | 37 DCHECK(file_util::PathExists(servers_path)) << |
42 "What module is this? It's not in 'servers' or main output dir."; | 38 "What module is this? It's not in 'servers' or main output dir."; |
43 return new CommandLine(servers_path); | 39 return new CommandLine(servers_path); |
44 } | 40 } |
45 } else { | 41 } else { |
46 NOTREACHED(); | 42 NOTREACHED(); |
47 return NULL; | 43 return NULL; |
48 } | 44 } |
49 } | 45 } |
50 | 46 |
| 47 } // namespace |
| 48 |
| 49 namespace chrome_launcher { |
| 50 |
| 51 const wchar_t kLauncherExeBaseName[] = L"chrome_launcher.exe"; |
| 52 |
| 53 CommandLine* CreateUpdateCommandLine(const std::wstring& update_command) { |
| 54 CommandLine* command_line = CreateChromeLauncherCommandLine(); |
| 55 |
| 56 if (command_line) { |
| 57 command_line->AppendArg(kUpdateCommandFlag); |
| 58 command_line->AppendArg(WideToASCII(update_command)); |
| 59 } |
| 60 |
| 61 return command_line; |
| 62 } |
| 63 |
| 64 CommandLine* CreateLaunchCommandLine() { |
| 65 // Shortcut for OS versions that don't need the integrity broker. |
| 66 if (base::win::GetVersion() < base::win::VERSION_VISTA) { |
| 67 return new CommandLine(GetChromeExecutablePath()); |
| 68 } |
| 69 |
| 70 return CreateChromeLauncherCommandLine(); |
| 71 } |
| 72 |
51 FilePath GetChromeExecutablePath() { | 73 FilePath GetChromeExecutablePath() { |
52 FilePath cur_path; | 74 FilePath cur_path; |
53 PathService::Get(base::DIR_MODULE, &cur_path); | 75 PathService::Get(base::DIR_MODULE, &cur_path); |
54 cur_path = cur_path.Append(chrome::kBrowserProcessExecutableName); | 76 cur_path = cur_path.Append(chrome::kBrowserProcessExecutableName); |
55 | 77 |
56 // The installation model for Chrome places the DLLs in a versioned | 78 // The installation model for Chrome places the DLLs in a versioned |
57 // sub-folder one down from the Chrome executable. If we fail to find | 79 // sub-folder one down from the Chrome executable. If we fail to find |
58 // chrome.exe in the current path, try looking one up and launching that | 80 // chrome.exe in the current path, try looking one up and launching that |
59 // instead. | 81 // instead. |
60 if (!file_util::PathExists(cur_path)) { | 82 if (!file_util::PathExists(cur_path)) { |
61 PathService::Get(base::DIR_MODULE, &cur_path); | 83 PathService::Get(base::DIR_MODULE, &cur_path); |
62 cur_path = cur_path.DirName().Append(chrome::kBrowserProcessExecutableName); | 84 cur_path = cur_path.DirName().Append(chrome::kBrowserProcessExecutableName); |
63 } | 85 } |
64 | 86 |
65 return cur_path; | 87 return cur_path; |
66 } | 88 } |
67 | 89 |
68 } // namespace chrome_launcher | 90 } // namespace chrome_launcher |
OLD | NEW |