0
Commit Graph

68 Commits

Author SHA1 Message Date
Lei Zhang
21c390b68b Remove some unneeded base/stl_util.h includes in base/ and mojo/.
Repeatedly use grep to find some files in base/ and mojo/ that includes
base/stl_util.h but do not use any functions provided by
base/stl_util.h and base/cxx*_backports.h, and then remove the
base/stl_util.h include from them. Files that include base/stl_util.h,
but actually needs base/cxx*_backports.h, will be dealt with separately.

Fix the build by adding a missing include to base/process/memory_win.cc.

Bug: 1194078
Change-Id: I2f74ac6a64751ca9264f3a20f79b06b71e181cec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2912135
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Auto-Submit: Lei Zhang <thestig@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#886625}
2021-05-26 06:48:35 +00:00
Jesse McKenna
185ceda258 Skip GetCommandLineString DCHECK in installer
This change allows the installer to bypass a DCHECK in CommandLine.
The DCHECK enforces that no arguments are parsed by
QuoteForCommandLineToArgvW with syntax "%*", e.g., %1, %2, etc. These
argument placeholders are called "insert sequences" and are used by
the Windows shell.

The DCHECK is intended to prevent new code from generating a command
line for the Windows shell by parsing a string like "chrome.exe %1"
instead of using the purpose-built GetCommandLineStringForShell().

However, setup.exe does generate a command line from string for itself
that contains placeholders, and has no need for the special syntax
created by GetCommandLineStringForShell(). Its use case is known to be
safe because the insert sequence %1 is substituted by Google Update in
a safe way. In order to support this call site, this change adds
GetCommandLineStringWithUnsafeInsertSequences(), which skips the
DCHECK, and invokes it in the setup code in question.

Bug: 1181955
Change-Id: I4b7e64a7a83b887b32c57207ce4ac3850d40f874
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2727878
Reviewed-by: Greg Thompson <grt@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Commit-Queue: Jesse McKenna <jessemckenna@google.com>
Cr-Commit-Position: refs/heads/master@{#861452}
2021-03-10 06:47:55 +00:00
Jesse McKenna
036150cfca Reland "Limit Windows-shell-based launches to one argument" and "Replace --single-argument= with --single-argument"
This reverts commit 2538167d39.

Reason for revert: This relands the two reverted CLs.

The original change to the command-line syntax (landed in two separate
CLs) caused the following issues:
* Temporary breakage after background update from `chrome.exe %1`
  syntax to `chrome.exe --single-argument=%1` (crbug.com/1092913),
  when a file is opened via the shell:
  * Registry contains `--single-argument=%1`, running browser sees no
    argument (only an unrecognized switch), opens new tab page
* Crashes after attempted fix that replaced `--single-argument=%1`
  with `--single-argument %1` due to a CHECK in the first change
  enforcing the presence of the `=` character:
  * After background update, registry contains `--single-argument %1`,
    running browser CHECKs for `=` and crashes (crbug.com/1096004)
  * Windows 7 Dev channel (expecting `=`) default-browser check parses
    Canary's registry command line (containing ` `) to get the default
    browser path (crbug.com/1096964), triggering CHECK
  * Crash when unregistering PWA file handlers on local Chromium build
    (crbug.com/1096004#c3), presumed to be caused by parsing the
    shell/open command written by file-handler registration on an
    older version (as local Chromium builds don't background update)

What all the above issues have in common is that they are caused by
incompatibility between new and old versions. With this in mind, this
reland assumes that the old and new syntax can and will be mixed in
potentially unexpected ways.

This change replaces `chrome.exe %1` with
`chrome.exe --single-argument %1`, which is flexible enough to handle
the following cases:
* If registry contains old syntax and running browser expects new
  syntax:
  * Due to the absence of the `--single-argument` switch, the command
    line will be parsed normally (potentially as multiple arguments)
* If registry contains new syntax and running browser expects old
  syntax:
  * The browser will ignore the unrecognized `--single-argument`
    switch and parse the command line normally (as the argument still
    appears after a space like in the current syntax)
* If browser parses command line from another channel with different
  syntax:
  * Covered by either the first or second case above

This reland also replaces the single remaining CHECK with a DCHECK.

Original change's description:
> Revert "Limit Windows-shell-based launches to one argument" and "Replace --single-argument= with --single-argument"
>
> This reverts commits 452f831564
> and 74ae85ac6e.
>
> Reason for revert: this CL and crrev.com/c/2238270, which introduced
> the --single-argument flag to the Windows command line, have caused
> issues (crbug.com/1092913, crbug.com/1096004, and crbug.com/1096964)
> related to incompatibility between the Chrome command line in the
> registry and that expected by the running browser. crrev.com/c/2238270
> was an attempt to fix those issues, but outstanding bug
> crbug.com/1096964 is still not well-understood and has made it to the
> Dev channel. This change reverts both CLs to prevent further issues
> and to enable a future reland that incorporates lessons learned.
> Reverting both CLs simultaneously is necessary to prevent trybot
> failures due to the same registry-browser command-line incompatibility
> issues (i.e., browser-test trybots having the current command-line
> syntax "chrome.exe --single-argument %1" in their registry, and
> failing to recognize the argument in the between-changes syntax
> "chrome.exe --single-argument=%1").
>
> Original change's description:
> > Limit Windows-shell-based launches to one argument
> >
> > This change adds "--single-argument" to launches done via the Windows
> > shell, which makes Chrome treat all text after "--single-argument=" as
> > Chrome's one and only argument. This limits shell-based launches to
> > passing only one argument to Chrome.
> >
> > Previously, Chrome's command line as registered with the Windows shell
> > was `chrome.exe "%1"`, %1 being Windows' filename placeholder. The
> > shell replaces this placeholder with the file/URL that Chrome has been
> > invoked on (e.g., if the link "https://www.chromium.org" were clicked,
> > Chrome would be run with command line
> > `chrome.exe "https://www.chromium.org"`.
> >
> > With this change, Chrome's command line is
> > `chrome.exe --single-argument=%1`, and the contents of %1 are treated
> > as a single argument regardless of quotes or spacing.
> >
> > Code that creates the command line string for the Windows shell (e.g.
> > code writing Chrome's command line to the registry) must use the new
> > format by calling GetCommandLineStringForShell(), which appends
> > "--single-argument=%1" to the returned string.
> >
> > Bug: 937179
> > Change-Id: I6c0d6f0abce7a8c9f65ca8b90d15438310db7c92
> > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2116596
> > Commit-Queue: Jesse McKenna <jessemckenna@google.com>
> > Reviewed-by: Lei Zhang <thestig@chromium.org>
> > Reviewed-by: Greg Thompson <grt@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#773398}
>
> TBR=thestig@chromium.org,grt@chromium.org,jessemckenna@google.com
>
> # Not skipping CQ checks because original CL landed > 1 day ago.
>
> Bug: 937179
> Change-Id: I014cd0b1acb5080b16b68268ea8d20eb18f9b431
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2255138
> Commit-Queue: Jesse McKenna <jessemckenna@google.com>
> Reviewed-by: Jesse McKenna <jessemckenna@google.com>
> Cr-Commit-Position: refs/heads/master@{#780559}

TBR=thestig@chromium.org,grt@chromium.org,jessemckenna@google.com

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 937179
Change-Id: I3d83b82bddaf1a40235273bce94541c63322cc7a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2273598
Reviewed-by: Greg Thompson <grt@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Jesse McKenna <jessemckenna@google.com>
Commit-Queue: Jesse McKenna <jessemckenna@google.com>
Cr-Commit-Position: refs/heads/master@{#789641}
2020-07-17 21:11:17 +00:00
Jesse McKenna
2538167d39 Revert "Limit Windows-shell-based launches to one argument" and "Replace --single-argument= with --single-argument"
This reverts commits 452f831564
and 74ae85ac6e.

Reason for revert: this CL and crrev.com/c/2238270, which introduced
the --single-argument flag to the Windows command line, have caused
issues (crbug.com/1092913, crbug.com/1096004, and crbug.com/1096964)
related to incompatibility between the Chrome command line in the
registry and that expected by the running browser. crrev.com/c/2238270
was an attempt to fix those issues, but outstanding bug
crbug.com/1096964 is still not well-understood and has made it to the
Dev channel. This change reverts both CLs to prevent further issues
and to enable a future reland that incorporates lessons learned.
Reverting both CLs simultaneously is necessary to prevent trybot
failures due to the same registry-browser command-line incompatibility
issues (i.e., browser-test trybots having the current command-line
syntax "chrome.exe --single-argument %1" in their registry, and
failing to recognize the argument in the between-changes syntax
"chrome.exe --single-argument=%1").

Original change's description:
> Limit Windows-shell-based launches to one argument
>
> This change adds "--single-argument" to launches done via the Windows
> shell, which makes Chrome treat all text after "--single-argument=" as
> Chrome's one and only argument. This limits shell-based launches to
> passing only one argument to Chrome.
>
> Previously, Chrome's command line as registered with the Windows shell
> was `chrome.exe "%1"`, %1 being Windows' filename placeholder. The
> shell replaces this placeholder with the file/URL that Chrome has been
> invoked on (e.g., if the link "https://www.chromium.org" were clicked,
> Chrome would be run with command line
> `chrome.exe "https://www.chromium.org"`.
>
> With this change, Chrome's command line is
> `chrome.exe --single-argument=%1`, and the contents of %1 are treated
> as a single argument regardless of quotes or spacing.
>
> Code that creates the command line string for the Windows shell (e.g.
> code writing Chrome's command line to the registry) must use the new
> format by calling GetCommandLineStringForShell(), which appends
> "--single-argument=%1" to the returned string.
>
> Bug: 937179
> Change-Id: I6c0d6f0abce7a8c9f65ca8b90d15438310db7c92
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2116596
> Commit-Queue: Jesse McKenna <jessemckenna@google.com>
> Reviewed-by: Lei Zhang <thestig@chromium.org>
> Reviewed-by: Greg Thompson <grt@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#773398}

TBR=thestig@chromium.org,grt@chromium.org,jessemckenna@google.com

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 937179
Change-Id: I014cd0b1acb5080b16b68268ea8d20eb18f9b431
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2255138
Commit-Queue: Jesse McKenna <jessemckenna@google.com>
Reviewed-by: Jesse McKenna <jessemckenna@google.com>
Cr-Commit-Position: refs/heads/master@{#780559}
2020-06-20 04:47:45 +00:00
Jesse McKenna
74ae85ac6e Replace --single-argument= with --single-argument
This change changes the command-line single-argument switch, used for
launches from the Windows shell, from `--single-argument=` to
`--single-argument `. This fixes an issue where users who have updated
but not restarted Chrome are unable to open shell links (due to the
mismatch between the just-updated open command in the registry and the
expectations of the now-obsolete running browser).

crrev.com/c/2116596 changed the command line used by the Windows shell
(and set in the registry) from `"chrome.exe" "%1"` (where %1 is
replaced by the argument to launch by the shell) to
`"chrome.exe" --single-argument=%1` to enforce a limit of one
argument on shell-based launches.

This caused old versions (those which have updated but not restarted
Chrome) to receive `--single-argument=<arg>` when Chrome is invoked
from the shell, but be unable to interpret it. Because this change
replaces the `=` with ` `, it is more backwards-compatible with old
versions. They will simply ignore the `--single-argument` switch and
interpret the space-delimited <arg> as the argument until the user
restarts Chrome to launch the new version.

Bug: 1092913
Change-Id: Iba734fe290944176f7ad38d36e670a1bea04623b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2238270
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Greg Thompson <grt@chromium.org>
Commit-Queue: Jesse McKenna <jessemckenna@google.com>
Cr-Commit-Position: refs/heads/master@{#778584}
2020-06-16 00:53:39 +00:00
Jesse McKenna
452f831564 Limit Windows-shell-based launches to one argument
This change adds "--single-argument" to launches done via the Windows
shell, which makes Chrome treat all text after "--single-argument=" as
Chrome's one and only argument. This limits shell-based launches to
passing only one argument to Chrome.

Previously, Chrome's command line as registered with the Windows shell
was `chrome.exe "%1"`, %1 being Windows' filename placeholder. The
shell replaces this placeholder with the file/URL that Chrome has been
invoked on (e.g., if the link "https://www.chromium.org" were clicked,
Chrome would be run with command line
`chrome.exe "https://www.chromium.org"`.

With this change, Chrome's command line is
`chrome.exe --single-argument=%1`, and the contents of %1 are treated
as a single argument regardless of quotes or spacing.

Code that creates the command line string for the Windows shell (e.g.
code writing Chrome's command line to the registry) must use the new
format by calling GetCommandLineStringForShell(), which appends
"--single-argument=%1" to the returned string.

Bug: 937179
Change-Id: I6c0d6f0abce7a8c9f65ca8b90d15438310db7c92
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2116596
Commit-Queue: Jesse McKenna <jessemckenna@google.com>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Greg Thompson <grt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#773398}
2020-05-29 23:06:56 +00:00
Jan Wilken Dörrie
da77fd4325 [base] Use std::wstring for CommandLine on Windows
This change modifies base::CommandLine::StringType to be std::wstring on
Windows. It relies on changing base::FilePath::StringType to
std::wstring on Windows as well, in order to compile once base::string16
is no longer std::wstring.

Bug: 911896
Change-Id: I07accc7e043fadf2b584799b699881f300e18bb2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1875748
Reviewed-by: Robert Liao <robliao@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709226}
2019-10-24 21:40:34 +00:00
Andrei Polushin
2ec89bc8d3 base: CommandLine::RemoveSwitch should drop multiple same switches from argv
When there are multiple switches having the same key within the argv
array, CommandLine constructor only puts one of them within the
parsed-out switches map.

On the other hand, CommandLine::RemoveSwitch removes a switch from the
switches map.  It should also drop all the switches having the same key
from the argv array.

BUG=957138
TEST=base_unittests --gtest_filter="CommandLineTest.*"

Change-Id: Ia4cf08bc497d4d53e0213879df71f85d945a4fec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1724079
Auto-Submit: Andrei Polushin <anpol@yandex-team.ru>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#682443}
2019-07-30 20:47:17 +00:00
Pavol Marko
bf16b81ece base: CommandLine::RemoveSwitch should also remove from argv
CommandLine::RemoveSwitch should also remove the switch from argv_.

Bug: 964068
Test: base_unittests --gtest_filter=*CommandLine*
Change-Id: If44106642c8089b83eb897e09c98ab8cf88fa24b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1653929
Commit-Queue: Pavol Marko <pmarko@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#669073}
2019-06-14 00:53:12 +00:00
John Rummell
b1d5fcb39d Note that only the last value of a switch is used by CommandLine.
Also adds a test to verify the behavior.

BUG=957138
TEST=new base_unittest passes

Change-Id: Ida1d0801f457e96dbf1d2ed299966a50aec05442
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1586220
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#654698}
2019-04-27 01:13:33 +00:00
jdoerrie
5c4dc4ed4b [base] Prepare //base For String16 Switch
This change prepares //base for the upcoming switch of base::string16 to
std::u16string.

Bug: 911896
Change-Id: I01ca2d0c2634503438f4e9f3b18681d182555b40
Reviewed-on: https://chromium-review.googlesource.com/c/1437195
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#628381}
2019-02-01 18:02:33 +00:00
Avi Drissman
1aa6cb924c Really lock '--disable-web-security' to '--user-data-dir'.
This is a followup to http://crrev.com/366963 . That change made
the '--disable-web-security' flag have no effect unless the
'--user-data-dir' flag was also specified. This was done to encourage
the use of the '--disable-web-security' flag only for development
and not for general purpose use.

However, that change (locking '--disable-web-security' to
'--user-data-dir') was made only in one place in the Chromium code.
There are quite a few other places in Chromium that turn off security
features when '--disable-web-security' is specified, and none of
them lock it to the use of the '--user-data-dir' flag.

Therefore, move the lock to much earlier in Chromium startup, and if
the '--user-data-dir' flag isn't specified, remove the
'--disable-web-security' flag entirely from the CommandLine. That
way, this correctly locks together those two flags for all of
Chromium.

BUG=923523,327804

Change-Id: I9000f1fbd2c236a435d8dae25870dead870ddd55
Reviewed-on: https://chromium-review.googlesource.com/c/1423342
Reviewed-by: Mark Mentovai <mark@chromium.org>
Reviewed-by: Chris Palmer <palmer@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#625210}
2019-01-23 15:58:38 +00:00
Avi Drissman
e3b70bf502 Use base::size rather than arraysize in base/.
This is purely a mechanical change; there is no intended behavior change.

BUG=837308

Change-Id: Id02b2c0bf9efcbdbefe2f8a3278bca90d167a85d
Reviewed-on: https://chromium-review.googlesource.com/c/1390906
Reviewed-by: Robert Sesek <rsesek@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
Reviewed-by: Jungshik Shin <jshin@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#620036}
2019-01-04 19:50:22 +00:00
jdoerrie
1c4b8ffd7d [clang-tidy] Apply modernize-use-auto in /base
This change applies clang-tidy's modernize-use-auto [1] in /base.
This change does not rewrite new and cast expressions.

Reproduction steps:
- run clang-tidy's modernize-use-auto
- run git cl format
- manually remove unused typedefs due to -Wunused-local-typedef error

[1] https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-auto.html

This CL was uploaded by git cl split.

R=dcheng@chromium.org

Bug: 890902
Change-Id: I1e938b7c80ba50b8e8a0d90f4a0b57ac4e3ae5b5
Reviewed-on: https://chromium-review.googlesource.com/c/1257885
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#596060}
2018-10-03 00:10:57 +00:00
Fabrice de Gans-Riberi
306871de3e Fuchsia: Prepare for OS_POSIX removal in base/
This cleans up multi-platform code paths selection and prepares for
the removal of OS_POSIX for the Fuchsia build.

Bug: 836416
Change-Id: I3a8e6393d0a9981aa890fb6d8c302ed8d2bdd69d
Reviewed-on: https://chromium-review.googlesource.com/1031099
Commit-Queue: Fabrice de Gans-Riberi <fdegans@chromium.org>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Reviewed-by: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#559230}
2018-05-16 19:38:39 +00:00
Ivan Kotenkov
a16212a56d Convert NULL and 0 to nullptr in base using clang-tidy.
Steps to replicate:
1. Build clang-tidy and clang-apply-replacements as described here: https://chromium.googlesource.com/chromium/src/+/lkcr/docs/clang_tidy.md
2. Build targets necessary for the change in out/gn.
3. Generate the compilation database:
  tools/clang/scripts/generate_compdb.py -p out/gn > compile_commands.json
4. Run clang-tidy and apply replacements:
  cd out/gn && PATH_TO_RUN_CLANG_TIDY/run-clang-tidy.py -p ../../ -clang-tidy-binary PATH_TO_CLANG_TIDY_BINARY -clang-apply-replacements-binary PATH_TO_CLANG_APPLY_REPLACEMENTS_BINARY -checks=-*,modernize-use-nullptr -fix -j 8 DIR_TO_CONVERT

Bug: 403854, 776257
Change-Id: I920f43d09b9fab758a3b8663fcf0c405d8519ad4
Reviewed-on: https://chromium-review.googlesource.com/732105
Commit-Queue: Ivan Kotenkov <kotenkov@yandex-team.ru>
Reviewed-by: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#514808}
2017-11-08 12:37:33 +00:00
skyostil
d851aa1e52 base: Support command line wrappers with quoted arguments
Command line wrappers (e.g., --renderer-cmd-prefix) were previously
split into individual arguments purely based on whitespace. This fails
if the prefix has arguments with embedded whitespace (e.g., gdb -ex "set
height 0").

This patch fixes the issue by tokenizing the prefix based on whitespace
while using ' and " as quote characters.

BUG=546953

Review-Url: https://codereview.chromium.org/2778173003
Cr-Commit-Position: refs/heads/master@{#460443}
2017-03-29 17:38:35 +00:00
dcheng
093de9b30c Convert //base to use std::unique_ptr
With bonus IWYU fixes that weren't caught by local android gn, cros gn,
linux gn, mac gyp, and win gyp builds.

BUG=554298
TBR=brettw@chromium.org

Review URL: https://codereview.chromium.org/1852433005

Cr-Commit-Position: refs/heads/master@{#385011}
2016-04-04 21:27:51 +00:00
avi
9b6f42934e Switch to standard integer types in base/.
BUG=138542
TBR=mark@chromium.org
NOPRESUBMIT=true

Review URL: https://codereview.chromium.org/1538743002

Cr-Commit-Position: refs/heads/master@{#366910}
2015-12-26 22:16:15 +00:00
arihc
e89963accb Updates to base unittests so they run correctly in libchrome on Android
Parallel change to https://android-review.googlesource.com/#/c/163293/
(does not include changes being made to base/command_line_unittest
that are fixing temporary runner issues, since the runner is fine here)

BUG= 22884411, 22947438

Review URL: https://codereview.chromium.org/1273243002

Cr-Commit-Position: refs/heads/master@{#343126}
2015-08-12 23:46:25 +00:00
jackhou
1bd9da9212 Take a StringPiece when looking up CommandLine switches.
This avoids the string allocation when searching for a char* in a
std::map<std::string>.

CommandLine now maintains a parallel map of StringPieces that reference
the strings in |switches_|. StringPiece is trivial to construct from a
string, and only requires a strlen to construct from a char*.

On a profile with 2 extensions, HasSwitch is called ~12k times during
startup. In an ideal situation (no paging/cache pressure), the
string allocation under Windows takes ~137ns on a Xeon E5-2690 @
2.9Ghz. A strlen on a typical switch takes about 50ns, and 91% of calls
pass a char*, so there's a net saving of at least
(137 - 0.9 * 50)ns * 12k = 1.1ms from a typical startup with this
hardware. For context, Startup.BrowserMessageLoopStartTimeFromMainEntry
is typically 280-300ms on the same hardware, so we should get a ~0.4%
improvement.

BUG=472383

Review URL: https://codereview.chromium.org/1063933002

Cr-Commit-Position: refs/heads/master@{#330902}
2015-05-21 04:49:24 +00:00
jackhou
b20cbb4954 Enforce lowercase switches when calling CommandLine::HasSwitch.
At the moment, all compile-time switches are lowercase. By enforcing
this, we can skip converting it to lowercase on Windows, which saves
one string allocation per call.

On a profile with 2 extensions, HasSwitch is called ~12k times during
startup. In an ideal situation (no paging/cache pressure), the
string allocation under Windows takes ~137ns on an Xeon E5-2690 @
2.9Ghz. So this should shave off at least 1.6ms off a typical startup
with this hardware. For context,
Startup.BrowserMessageLoopStartTimeFromMainEntry is typically
280-300ms on the same hardware, so we should get a ~0.5% improvement.

BUG=472383

Committed: https://crrev.com/f58961749a980032241fe6c3fc829ac2e6652030
Cr-Commit-Position: refs/heads/master@{#325576}

Review URL: https://codereview.chromium.org/1046363002

Cr-Commit-Position: refs/heads/master@{#326219}
2015-04-22 02:22:56 +00:00
yoichio
817cf387db Revert of Enforce lowercase switches when calling CommandLine::HasSwitch(const char*). (patchset id:80001 of https://codereview.chromium.org/1046363002/)
Reason for revert:
This causes test fails on Android:
https://build.chromium.org/p/chromium.linux/builders/Android%20Tests%20%28dbg%29/builds/27294

The test uses upper case with HasSwitch():
https://code.google.com/p/chromium/codesearch#chromium/src/content/public/android/javatests/src/org/chromium/content/browser/ContentCommandLineTest.java&q=testJavaNativeTransition&sq=package:chromium&type=cs&l=96

Original issue's description:
> Enforce lowercase switches when calling CommandLine::HasSwitch.
>
> At the moment, all compile-time switches are lowercase. By enforcing
> this, we can skip converting it to lowercase on Windows, which saves
> one string allocation per call.
>
> On a profile with 2 extensions, HasSwitch is called ~12k times during
> startup. In an ideal situation (no paging/cache pressure), the
> string allocation under Windows takes ~137ns on an Xeon E5-2690 @
> 2.9Ghz. So this should shave off at least 1.6ms off a typical startup
> with this hardware. For context,
> Startup.BrowserMessageLoopStartTimeFromMainEntry is typically
> 280-300ms on the same hardware, so we should get a ~0.5% improvement.
>
> BUG=472383
>
> Committed: https://crrev.com/f58961749a980032241fe6c3fc829ac2e6652030
> Cr-Commit-Position: refs/heads/master@{#325576}

TBR=tapted@chromium.org,brettw@chromium.org,jackhou@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=472383

Review URL: https://codereview.chromium.org/1091993002

Cr-Commit-Position: refs/heads/master@{#325610}
2015-04-17 08:29:07 +00:00
jackhou
f58961749a Enforce lowercase switches when calling CommandLine::HasSwitch.
At the moment, all compile-time switches are lowercase. By enforcing
this, we can skip converting it to lowercase on Windows, which saves
one string allocation per call.

On a profile with 2 extensions, HasSwitch is called ~12k times during
startup. In an ideal situation (no paging/cache pressure), the
string allocation under Windows takes ~137ns on an Xeon E5-2690 @
2.9Ghz. So this should shave off at least 1.6ms off a typical startup
with this hardware. For context,
Startup.BrowserMessageLoopStartTimeFromMainEntry is typically
280-300ms on the same hardware, so we should get a ~0.5% improvement.

BUG=472383

Review URL: https://codereview.chromium.org/1046363002

Cr-Commit-Position: refs/heads/master@{#325576}
2015-04-17 01:56:38 +00:00
pgal.u-szeged
421dddbfb6 Prefix CommandLine usege with base namespace (Part 1: base/)
Prefix all CommandLine usage in the base/ directory with the
base:: namespace.

BUG=422426

Review URL: https://codereview.chromium.org/645133002

Cr-Commit-Position: refs/heads/master@{#305626}
2014-11-25 12:55:16 +00:00
mgiuca
c974d5100e base::CommandLine: Added optional quoting of placeholder arguments.
Added an optional parameter |quote_placeholder| to GetCommandLineString
and GetArgumentsString. If true, placeholder command-line arguments such
as "%1" will also be quoted. These need quoting in case the substituted
argument has a space in it. It was previously not possible to build a
CommandLine that would contain a quoted "%1" when converted to a string.

Only affects Windows.

BUG=416785

Review URL: https://codereview.chromium.org/595803002

Cr-Commit-Position: refs/heads/master@{#297617}
2014-10-01 09:25:00 +00:00
mgiuca
b937b24239 CommandLineTest.ProgramQuotes: Fix crash-prone test.
Previously, this test would crash if the output wasn't quoted properly
(since it assumes that cmd_string.length() >= program_string.length() +
2). Instead, directly compare the string with the expected output. This
also guards against the possibility of mis-constructing the expected
string.

Review URL: https://codereview.chromium.org/589393002

Cr-Commit-Position: refs/heads/master@{#296350}
2014-09-24 04:55:45 +00:00
avi@chromium.org
f729d7a55a Remove UTF string conversion functions from the global namespace.
BUG=330556
TEST=no change
TBR=ben@chromium.org

Review URL: https://codereview.chromium.org/102993018

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@242519 0039d316-1c4b-4281-b951-d872f2087c98
2013-12-26 07:07:56 +00:00
avi@chromium.org
a4ea1f1bb8 Use a direct include of utf_string_conversions.h in android_webview/, apps/, ash/, base/.
BUG=none
TEST=none

Review URL: https://chromiumcodereview.appspot.com/15735027

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204874 0039d316-1c4b-4281-b951-d872f2087c98
2013-06-07 18:37:07 +00:00
brettw@chromium.org
57999817d3 Move file_path.h to base/files.
TBR=sky

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@184344 0039d316-1c4b-4281-b951-d872f2087c98
2013-02-24 05:40:52 +00:00
brettw@chromium.org
023ad6abe4 Replace FilePath with base::FilePath.
This is im preparation for removing the 'using" in file_path.h

Review URL: https://codereview.chromium.org/12286020

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@183021 0039d316-1c4b-4281-b951-d872f2087c98
2013-02-17 05:07:23 +00:00
gab@chromium.org
45f982ef3e Extract arguments reconstruction logic out of GetCommandLineString() into GetArgumentsString().
BUG=To get arguments we had to GetCommandLineString() and piece out the program: http://code.google.com/searchframe#OAMlx_jo-ck/src/chrome/installer/util/install_util.cc&exact_package=chromium&q=GetCommandLineString&type=cs&l=125
TEST=base_unittests.exe --gtest_filter=CommandLineTest*


Review URL: https://chromiumcodereview.appspot.com/11305010

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@164740 0039d316-1c4b-4281-b951-d872f2087c98
2012-10-29 21:31:31 +00:00
jochen@chromium.org
21e342f0bb [content shell] add support for getting tests from the command line.
Related to this, parse a single dash on the command line as argument, instead of a switch with no value and name

BUG=111316
TEST=out/Debug/content_shell --dump-render-tree path/to/test.html works


Review URL: https://chromiumcodereview.appspot.com/11184050

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@162947 0039d316-1c4b-4281-b951-d872f2087c98
2012-10-19 06:19:59 +00:00
erikwright@chromium.org
72e2e24228 Allow callers of CommandLine::Init to know whether they were the first caller.
If there are multiple callers to Init, only one should call Reset. The boolean return value tells the caller whether they are the one responsible for the destruction. As long as the lifetimes of clients are strictly nested (i.e., a client X who uses CommandLine after client Y has initialized it always ceases its use before client Y destroys it) this secures access to this singleton object.

One client in particular is updated to follow this model. I will submit follow-up CLs for remaining clients (at least, those who currently do call Reset).

This is motivated by a crash in the chrome_frame_net_tests. This test executable nests a TestSuite within the lifetime of a ContentMainRunner (i.e., the engine that is typically used to run Chrome). The content layer initializes CommandLine and Resets it, but the TestSuite also resets it, leading to a DCHECK. This is currently the last remaining issue keeping the chrome_frame_net_tests off the waterfall, and I am very eager to get them back there to reduce the likelihood of further issues being introduced.

BUG=114369
TEST=A test has been modified to reflect this change.


Review URL: http://codereview.chromium.org/9477001

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123763 0039d316-1c4b-4281-b951-d872f2087c98
2012-02-27 18:38:12 +00:00
joth@chromium.org
1fa39f057d micro optimize CommandLine.GetSwitchPrefixLength
avoid searching the entire length of each switch for the -- prefix, as we know it can only exist at the start.

BUG=None
TEST=None


Review URL: http://codereview.chromium.org/7866036

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100918 0039d316-1c4b-4281-b951-d872f2087c98
2011-09-13 15:45:34 +00:00
msw@chromium.org
61a4c6f837 Rename CommandLine::GetCommandLineString().
Fix string hackery in net/tools/dump_cache/dump_cache.cc
Fix const casts in chrome/installer/util/product.cc and base/process_util_win.cc.

BUG=73195
TEST=none

Review URL: http://codereview.chromium.org/7386002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93165 0039d316-1c4b-4281-b951-d872f2087c98
2011-07-20 04:54:52 +00:00
msw@chromium.org
75f1c78e25 Rename CommandLine::GetArgs(), update callers.
BUG=73195
TEST=none

Review URL: http://codereview.chromium.org/7352006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92448 0039d316-1c4b-4281-b951-d872f2087c98
2011-07-13 23:41:22 +00:00
rvargas@google.com
f96fe2c494 Base: Don't delete the previous command line when calling
CommandLine::Init()

In the multi-DLL build, we can end up initializing the object
twice at startup (once in chrome.exe and once in chrome.dll).
It should be harmless.

BUG=76996
TEST=base_unittests
Review URL: http://codereview.chromium.org/7273053

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92380 0039d316-1c4b-4281-b951-d872f2087c98
2011-07-13 18:03:34 +00:00
msw@chromium.org
a40ca43033 Consolidate most CommandLine code across platforms.
Significant refactoring with some notable behavior changes:
1. Switches are appended preceding existing arguments (after other swtiches).
2. (Windows) command_line_string() is generated and properly quoted/escaped.
3. Appended switches will retain their (optional) included prefixes (--,-,/).
Notable internal changes (shouldn't affect behavior):
1. (Windows) Generate the cl string, instead of storing&updating the original.
2. Explicitly retain switch prefixes (--,-,/) (was automatic in init*/ctor).
Update (obvious) code expecting switches to be appended antecedent to args.
Add Nico's test from: codereview.chromium.org/6728016/.

An intermediary CL landed between patch set 3 and 4, see:
http://codereview.chromium.org/6596020

BUG=73195,67764
TEST=Commandline usage.

Review URL: http://codereview.chromium.org/6526040

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85360 0039d316-1c4b-4281-b951-d872f2087c98
2011-05-14 01:10:24 +00:00
erg@google.com
6775e40aeb Change other usages of .size() to .empty() when applicable.
BUG=carnitas
TEST=compiles

Review URL: http://codereview.chromium.org/6609008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76962 0039d316-1c4b-4281-b951-d872f2087c98
2011-03-04 21:03:47 +00:00
erg@google.com
f6b8ce31c1 Pure pedantry: Replace all ".size() == 0" with ".empty()".
BUG=carnitas
TEST=compiles; existing unit tests.

Review URL: http://codereview.chromium.org/6602049

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76467 0039d316-1c4b-4281-b951-d872f2087c98
2011-03-02 00:03:18 +00:00
tommi@chromium.org
450b34ecab Add a unit test for CommandLine that makes sure that GetProgram will not return a quoted string and that (on Windows) the program part of a command line string will always be quoted.
BUG=none
TEST=Run the ProgramQuotes test.  Should be no visible changes.

Review URL: http://codereview.chromium.org/4949004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67583 0039d316-1c4b-4281-b951-d872f2087c98
2010-11-29 21:12:22 +00:00
tommi@chromium.org
e6124ad556 Attempt to reland http://codereview.chromium.org/4928002/
For some reason the Win bot failed to compile the sandbox unit test.
Trybots and my machines don't have these build problems, so I'm going to try again, unchanged.

Original description:

Changing the installer switches from wchar_t[] to char[].

Because of this I'm also refactoring some code that before
was using wstring to build command lines by hand instead of
using the CommandLine class. Now we use CommandLine.

To get this to work correctly, I also needed to fix CommandLine::AppendArguments so I added a little test for it.

TEST=There should be no changes in functionality. Run all installer tests.
BUG=61609

TBR=robertshield

Review URL: http://codereview.chromium.org/4989001

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66096 0039d316-1c4b-4281-b951-d872f2087c98
2010-11-15 04:17:52 +00:00
tommi@chromium.org
9d84e1a1e1 Revert 66088 - Changing the installer switches from wchar_t[] to char[].
Because of this I'm also refactoring some code that before
was using wstring to build command lines by hand instead of
using the CommandLine class.  Now we use CommandLine.

To get this to work correctly, I also needed to fix CommandLine::AppendArguments so I added a little test for it.

TEST=There should be no changes in functionality.  Run all installer tests.
BUG=61609

Review URL: http://codereview.chromium.org/4928002

TBR=tommi@chromium.org
Review URL: http://codereview.chromium.org/4988001

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66089 0039d316-1c4b-4281-b951-d872f2087c98
2010-11-15 00:18:30 +00:00
tommi@chromium.org
12c0b1823a Changing the installer switches from wchar_t[] to char[].
Because of this I'm also refactoring some code that before
was using wstring to build command lines by hand instead of
using the CommandLine class.  Now we use CommandLine.

To get this to work correctly, I also needed to fix CommandLine::AppendArguments so I added a little test for it.

TEST=There should be no changes in functionality.  Run all installer tests.
BUG=61609

Review URL: http://codereview.chromium.org/4928002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66088 0039d316-1c4b-4281-b951-d872f2087c98
2010-11-14 23:50:39 +00:00
evan@chromium.org
fc8edf5c2a CommandLine: remove wstring-based program() accessor
This was already removed on non-Windows, so this change modifies
the remaining Windows-specific usage.  In a few places I converted
use of wstring paths into FilePath, but in general for Windows-specific
code I don't think it's too important to use FilePath everywhere,
because it is equivalent on Windows and the current code already works.

BUG=23581

Review URL: http://codereview.chromium.org/3817001

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62637 0039d316-1c4b-4281-b951-d872f2087c98
2010-10-14 20:30:45 +00:00
evan@chromium.org
78c4c4239c CommandLine: deprecate another function on non-Windows
BUG=23581
TEST=CommandLine unit tests

Review URL: http://codereview.chromium.org/3549023

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61889 0039d316-1c4b-4281-b951-d872f2087c98
2010-10-08 00:06:31 +00:00
brettw@chromium.org
f16339329d Header cleanup in base.
This makes uses of StringPrintf and friends use the base namespace and include
stringprintf.h explicitly. This also removes a bunch of unnecessary string_util
includes (which exposed a few other errors like people forgetting to include
<vector>.

TEST=it compiles
BUG=none

Review URL: http://codereview.chromium.org/3119022

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56446 0039d316-1c4b-4281-b951-d872f2087c98
2010-08-17 23:05:28 +00:00
evan@chromium.org
98a1c268c3 Factor out command-line quoting code on Windows.
Our command line code is not very good with respect to getting
quoting right.  Because of this, callers will sometimes themselves
attempt to quote arguments, though some of them get it wrong(!) by
just surrounding with quotes.

The first step is to add a quoting function that we think is correct
and update the unit test to test it.

(Note that most of this is Windows-specific, because on POSIX
we can pass arguments to commands as a vector -- trying to do
quoting on POSIX is usually wrong.)

Review URL: http://codereview.chromium.org/3007038

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55591 0039d316-1c4b-4281-b951-d872f2087c98
2010-08-10 18:14:19 +00:00
evan@chromium.org
05076ba206 Convert a bunch of easy AppendSwitchWithValue to *ASCII.
For this patch, I skipped over any instance where it wasn't a nearly trivial
change.

Review URL: http://codereview.chromium.org/3069014

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54285 0039d316-1c4b-4281-b951-d872f2087c98
2010-07-30 05:59:57 +00:00