Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: chrome/app_shim/win/app_shim_main.cc

Issue 685103004: Refactor chrome_launcher_support::GetAnyChromePath. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix app_installer compile. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/app_installer/win/app_installer_util.cc ('k') | chrome/installer/gcapi/gcapi.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <windows.h> 5 #include <windows.h>
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/process/launch.h" 12 #include "base/process/launch.h"
13 #include "chrome/installer/launcher_support/chrome_launcher_support.h" 13 #include "chrome/installer/launcher_support/chrome_launcher_support.h"
14 14
15 namespace { 15 namespace {
16 16
17 // Return codes. 17 // Return codes.
18 const int kOK = 0; 18 const int kOK = 0;
19 const int kNoProgram = 1; 19 const int kNoProgram = 1;
20 const int kLaunchFailure = 2; 20 const int kLaunchFailure = 2;
21 21
22 // Command-line switches. 22 // Command-line switches.
23 const char kChromeSxS[] = "chrome-sxs"; 23 const char kChromeSxS[] = "chrome-sxs";
24 24
25 base::FilePath GetChromeExePath(bool is_canary) {
26 return is_canary ? chrome_launcher_support::GetAnyChromeSxSPath()
27 : chrome_launcher_support::GetAnyChromePath();
28 }
29
30 } // namespace 25 } // namespace
31 26
32 // This program runs chrome.exe, passing its arguments on to the Chrome binary. 27 // This program runs chrome.exe, passing its arguments on to the Chrome binary.
33 // It uses the Windows registry to find chrome.exe (and hence it only works if 28 // It uses the Windows registry to find chrome.exe (and hence it only works if
34 // Chrome/Chromium has been properly installed). It terminates as soon as the 29 // Chrome/Chromium has been properly installed). It terminates as soon as the
35 // program is launched. It is intended to allow file types to be associated with 30 // program is launched. It is intended to allow file types to be associated with
36 // Chrome apps, with a custom name (and in some cases, icon) rather than simply 31 // Chrome apps, with a custom name (and in some cases, icon) rather than simply
37 // the name of the Chrome binary. 32 // the name of the Chrome binary.
38 // 33 //
39 // Usage: app_shim_win [--chrome-sxs] -- [CHROME_ARGS...] 34 // Usage: app_shim_win [--chrome-sxs] -- [CHROME_ARGS...]
40 // 35 //
41 // The -- is required if switches are to be passed to Chrome; any switches 36 // The -- is required if switches are to be passed to Chrome; any switches
42 // before the -- will be interpreted by app_shim_win, and not passed to Chrome. 37 // before the -- will be interpreted by app_shim_win, and not passed to Chrome.
43 // 38 //
44 // If --chrome-sxs is specified, looks for the SxS (Canary) build of Chrome. 39 // If --chrome-sxs is specified, looks for the SxS (Canary) build of Chrome.
45 // This will always fail for Chromium. 40 // This will always fail for Chromium.
46 int WINAPI wWinMain(HINSTANCE instance, 41 int WINAPI wWinMain(HINSTANCE instance,
47 HINSTANCE prev_instance, 42 HINSTANCE prev_instance,
48 wchar_t* /*command_line*/, 43 wchar_t* /*command_line*/,
49 int show_command) { 44 int show_command) {
50 base::CommandLine::Init(0, nullptr); 45 base::CommandLine::Init(0, nullptr);
51 46
52 // Log to stderr. Otherwise it will log to a file by default. 47 // Log to stderr. Otherwise it will log to a file by default.
53 logging::LoggingSettings logging_settings; 48 logging::LoggingSettings logging_settings;
54 logging_settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; 49 logging_settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
55 logging::InitLogging(logging_settings); 50 logging::InitLogging(logging_settings);
56 51
57 // Get the command-line for the Chrome binary. 52 // Get the command-line for the Chrome binary.
58 // --chrome-sxs on the command line means we should run the canary binary. 53 // --chrome-sxs on the command line means we should run the SxS binary.
59 bool is_canary = 54 bool is_sxs = base::CommandLine::ForCurrentProcess()->HasSwitch(kChromeSxS);
60 base::CommandLine::ForCurrentProcess()->HasSwitch(kChromeSxS); 55 base::FilePath chrome_path =
61 base::FilePath chrome_path = GetChromeExePath(is_canary); 56 chrome_launcher_support::GetAnyChromePath(is_sxs);
62 if (chrome_path.empty()) { 57 if (chrome_path.empty()) {
63 LOG(ERROR) << "Could not find chrome.exe path in the registry."; 58 LOG(ERROR) << "Could not find chrome.exe path in the registry.";
64 return kNoProgram; 59 return kNoProgram;
65 } 60 }
66 base::CommandLine command_line(chrome_path); 61 base::CommandLine command_line(chrome_path);
67 62
68 // Get the command-line arguments for the subprocess, consisting of the 63 // Get the command-line arguments for the subprocess, consisting of the
69 // arguments (but not switches) to this binary. This gets everything after the 64 // arguments (but not switches) to this binary. This gets everything after the
70 // "--". 65 // "--".
71 for (const auto& arg : base::CommandLine::ForCurrentProcess()->GetArgs()) 66 for (const auto& arg : base::CommandLine::ForCurrentProcess()->GetArgs())
72 command_line.AppendArgNative(arg); 67 command_line.AppendArgNative(arg);
73 68
74 if (!base::LaunchProcess(command_line, base::LaunchOptions()).IsValid()) { 69 if (!base::LaunchProcess(command_line, base::LaunchOptions()).IsValid()) {
75 LOG(ERROR) << "Could not run chrome.exe."; 70 LOG(ERROR) << "Could not run chrome.exe.";
76 return kLaunchFailure; 71 return kLaunchFailure;
77 } 72 }
78 73
79 return kOK; 74 return kOK;
80 } 75 }
OLDNEW
« no previous file with comments | « chrome/app_installer/win/app_installer_util.cc ('k') | chrome/installer/gcapi/gcapi.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698