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

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: Respond to comments. 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
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...]
(...skipping 11 matching lines...) Expand all
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 canary binary.
59 bool is_canary = 54 bool is_canary =
60 base::CommandLine::ForCurrentProcess()->HasSwitch(kChromeSxS); 55 base::CommandLine::ForCurrentProcess()->HasSwitch(kChromeSxS);
61 base::FilePath chrome_path = GetChromeExePath(is_canary); 56 base::FilePath chrome_path =
57 chrome_launcher_support::GetAnyChromePath(is_canary);
62 if (chrome_path.empty()) { 58 if (chrome_path.empty()) {
63 LOG(ERROR) << "Could not find chrome.exe path in the registry."; 59 LOG(ERROR) << "Could not find chrome.exe path in the registry.";
64 return kNoProgram; 60 return kNoProgram;
65 } 61 }
66 base::CommandLine command_line(chrome_path); 62 base::CommandLine command_line(chrome_path);
67 63
68 // Get the command-line arguments for the subprocess, consisting of the 64 // Get the command-line arguments for the subprocess, consisting of the
69 // arguments (but not switches) to this binary. This gets everything after the 65 // arguments (but not switches) to this binary. This gets everything after the
70 // "--". 66 // "--".
71 for (const auto& arg : base::CommandLine::ForCurrentProcess()->GetArgs()) 67 for (const auto& arg : base::CommandLine::ForCurrentProcess()->GetArgs())
72 command_line.AppendArgNative(arg); 68 command_line.AppendArgNative(arg);
73 69
74 if (!base::LaunchProcess(command_line, base::LaunchOptions()).IsValid()) { 70 if (!base::LaunchProcess(command_line, base::LaunchOptions()).IsValid()) {
75 LOG(ERROR) << "Could not run chrome.exe."; 71 LOG(ERROR) << "Could not run chrome.exe.";
76 return kLaunchFailure; 72 return kLaunchFailure;
77 } 73 }
78 74
79 return kOK; 75 return kOK;
80 } 76 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698