Skip to content

Commit

Permalink
Prefix CommandLine usage with base namespace (Part 9: components)
Browse files Browse the repository at this point in the history
Prefix all CommandLine usage in the components/ directory's following subdirectories:
feedback, gcm_driver, google, infobars, invalidation, keyed_service, metrics, nacl,
omnibox and os_crypt with the base:: namespace

BUG=422426

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

Cr-Commit-Position: refs/heads/master@{#306790}
  • Loading branch information
kkristof authored and Commit bot committed Dec 4, 2014
1 parent e69fcbd commit b33617c
Show file tree
Hide file tree
Showing 28 changed files with 76 additions and 65 deletions.
7 changes: 4 additions & 3 deletions components/feedback/feedback_uploader_chrome.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ FeedbackUploaderChrome::FeedbackUploaderChrome(
BrowserThread::GetBlockingPool()),
context_(context) {
CHECK(context_);
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kFeedbackServer))
url_ = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kFeedbackServer);
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kFeedbackServer))
url_ = command_line.GetSwitchValueASCII(switches::kFeedbackServer);
}

void FeedbackUploaderChrome::DispatchReport(const std::string& data) {
Expand Down
7 changes: 4 additions & 3 deletions components/gcm_driver/gcm_channel_status_syncer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ GCMChannelStatusSyncer::GCMChannelStatusSyncer(
poll_interval_seconds_ =
GCMChannelStatusRequest::min_poll_interval_seconds();
}
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kCustomPollIntervalMinutes)) {
std::string value(CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kCustomPollIntervalMinutes)) {
std::string value(command_line.GetSwitchValueASCII(
switches::kCustomPollIntervalMinutes));
int minutes = 0;
if (base::StringToInt(value, &minutes)) {
Expand Down
3 changes: 2 additions & 1 deletion components/google/core/browser/google_url_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ void GoogleURLTracker::StartFetchIfDesirable() {
// specified a Google base URL manually, we shouldn't bother to look up any
// alternatives or offer to switch to them.
if (!client_->IsBackgroundNetworkingEnabled() ||
CommandLine::ForCurrentProcess()->HasSwitch(switches::kGoogleBaseURL))
base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kGoogleBaseURL))
return;

already_fetched_ = true;
Expand Down
2 changes: 1 addition & 1 deletion components/google/core/browser/google_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ GURL CommandLineGoogleBaseURL() {
CR_DEFINE_STATIC_LOCAL(std::string, switch_value, ());
CR_DEFINE_STATIC_LOCAL(GURL, base_url, ());
std::string current_switch_value(
CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kGoogleBaseURL));
if (current_switch_value != switch_value) {
switch_value = current_switch_value;
Expand Down
16 changes: 8 additions & 8 deletions components/google/core/browser/google_util_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ TEST(GoogleUtilTest, GoogleBaseURLNotSpecified) {
EXPECT_FALSE(IsSearch("http://www.foo.com/search?q=a"));

// Override the Google base URL on the command line.
CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL,
"http://www.foo.com/");
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kGoogleBaseURL, "http://www.foo.com/");

// Only URLs which start with exactly the string on the command line should
// cause StartsWithCommandLineGoogleBaseURL() to return true.
Expand All @@ -336,20 +336,20 @@ TEST(GoogleUtilTest, GoogleBaseURLNotSpecified) {
}

TEST(GoogleUtilTest, GoogleBaseURLDisallowQuery) {
CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL,
"http://www.foo.com/?q=");
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kGoogleBaseURL, "http://www.foo.com/?q=");
EXPECT_FALSE(google_util::CommandLineGoogleBaseURL().is_valid());
}

TEST(GoogleUtilTest, GoogleBaseURLDisallowRef) {
CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL,
"http://www.foo.com/#q=");
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kGoogleBaseURL, "http://www.foo.com/#q=");
EXPECT_FALSE(google_util::CommandLineGoogleBaseURL().is_valid());
}

TEST(GoogleUtilTest, GoogleBaseURLFixup) {
CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL,
"www.foo.com");
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kGoogleBaseURL, "www.foo.com");
ASSERT_TRUE(google_util::CommandLineGoogleBaseURL().is_valid());
EXPECT_EQ("http://www.foo.com/",
google_util::CommandLineGoogleBaseURL().spec());
Expand Down
3 changes: 2 additions & 1 deletion components/infobars/core/infobar_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ void InfoBarManager::RemoveObserver(Observer* obs) {

InfoBarManager::InfoBarManager()
: infobars_enabled_(true) {
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableInfoBars))
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableInfoBars))
infobars_enabled_ = false;
}

Expand Down
2 changes: 1 addition & 1 deletion components/invalidation/invalidation_service_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace invalidation {

notifier::NotifierOptions ParseNotifierOptions(
const CommandLine& command_line) {
const base::CommandLine& command_line) {
notifier::NotifierOptions notifier_options;

if (command_line.HasSwitch(switches::kSyncNotificationHostPort)) {
Expand Down
2 changes: 1 addition & 1 deletion components/invalidation/p2p_invalidation_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ P2PInvalidationService::P2PInvalidationService(
syncer::P2PNotificationTarget notification_target)
: identity_provider_(identity_provider.Pass()) {
notifier::NotifierOptions notifier_options =
ParseNotifierOptions(*CommandLine::ForCurrentProcess());
ParseNotifierOptions(*base::CommandLine::ForCurrentProcess());
notifier_options.request_context_getter = request_context;
invalidator_id_ = GenerateInvalidatorClientId();
invalidator_.reset(new syncer::P2PInvalidator(
Expand Down
2 changes: 1 addition & 1 deletion components/invalidation/ticl_invalidation_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ void TiclInvalidationService::StartInvalidator(
switch (network_channel) {
case PUSH_CLIENT_CHANNEL: {
notifier::NotifierOptions options =
ParseNotifierOptions(*CommandLine::ForCurrentProcess());
ParseNotifierOptions(*base::CommandLine::ForCurrentProcess());
options.request_context_getter = request_context_;
options.auth_mechanism = "X-OAUTH2";
network_channel_options_.SetString("Options.HostPort",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void BrowserContextDependencyManager::DumpContextDependencies(
const base::SupportsUserData* context) const {
// Whenever we try to build a destruction ordering, we should also dump a
// dependency graph to "/path/to/context/context-dependencies.dot".
if (CommandLine::ForCurrentProcess()->HasSwitch(
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
kDumpBrowserContextDependencyGraphFlag)) {
base::FilePath dot_file =
static_cast<const content::BrowserContext*>(context)
Expand Down
2 changes: 1 addition & 1 deletion components/metrics/metrics_state_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ int MetricsStateManager::GetLowEntropySource() {
if (low_entropy_source_ != kLowEntropySourceNotSet)
return low_entropy_source_;

const CommandLine* command_line(CommandLine::ForCurrentProcess());
const base::CommandLine* command_line(base::CommandLine::ForCurrentProcess());
// Only try to load the value from prefs if the user did not request a
// reset.
// Otherwise, skip to generating a new value.
Expand Down
2 changes: 1 addition & 1 deletion components/metrics/metrics_state_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ TEST_F(MetricsStateManagerTest,

// Verify that the cache does get reset if --reset-variations-state is passed.
{
CommandLine::ForCurrentProcess()->AppendSwitch(
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kResetVariationState);

scoped_ptr<MetricsStateManager> state_manager(CreateStateManager());
Expand Down
4 changes: 2 additions & 2 deletions components/nacl/broker/nacl_broker_listener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ NaClBrokerListener::~NaClBrokerListener() {

void NaClBrokerListener::Listen() {
std::string channel_name =
CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kProcessChannelID);
channel_ = IPC::Channel::CreateClient(channel_name, this);
CHECK(channel_->Connect());
Expand Down Expand Up @@ -94,7 +94,7 @@ void NaClBrokerListener::OnLaunchLoaderThroughBroker(
base::FilePath exe_path;
PathService::Get(base::FILE_EXE, &exe_path);
if (!exe_path.empty()) {
CommandLine* cmd_line = new CommandLine(exe_path);
base::CommandLine* cmd_line = new base::CommandLine(exe_path);
nacl::CopyNaClCommandLineArguments(cmd_line);

cmd_line->AppendSwitchASCII(switches::kProcessType,
Expand Down
2 changes: 1 addition & 1 deletion components/nacl/browser/nacl_broker_host_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ bool NaClBrokerHost::Init() {
if (!NaClBrowser::GetInstance()->GetNaCl64ExePath(&nacl_path))
return false;

CommandLine* cmd_line = new CommandLine(nacl_path);
base::CommandLine* cmd_line = new base::CommandLine(nacl_path);
CopyNaClCommandLineArguments(cmd_line);

cmd_line->AppendSwitchASCII(switches::kProcessType,
Expand Down
38 changes: 20 additions & 18 deletions components/nacl/browser/nacl_process_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ NaClProcessHost::NaClProcessHost(const GURL& manifest_url,
// for this use case.
process_->SetName(net::FormatUrl(manifest_url_, std::string()));

enable_debug_stub_ = CommandLine::ForCurrentProcess()->HasSwitch(
enable_debug_stub_ = base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableNaClDebug);
DCHECK(process_type_ != kUnknownNaClProcessType);
enable_crash_throttling_ = process_type_ != kNativeNaClProcessType;
Expand Down Expand Up @@ -310,7 +310,7 @@ NaClProcessHost::~NaClProcessHost() {

void NaClProcessHost::OnProcessCrashed(int exit_status) {
if (enable_crash_throttling_ &&
!CommandLine::ForCurrentProcess()->HasSwitch(
!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisablePnaclCrashThrottling)) {
NaClBrowser::GetInstance()->OnProcessCrashed();
}
Expand All @@ -326,7 +326,7 @@ void NaClProcessHost::EarlyStartup() {
// under us by autoupdate.
NaClBrowser::GetInstance()->EnsureIrtAvailable();
#endif
CommandLine* cmd = CommandLine::ForCurrentProcess();
base::CommandLine* cmd = base::CommandLine::ForCurrentProcess();
UMA_HISTOGRAM_BOOLEAN(
"NaCl.nacl-gdb",
!cmd->GetSwitchValuePath(switches::kNaClGdb).empty());
Expand Down Expand Up @@ -364,7 +364,7 @@ void NaClProcessHost::Launch(
// Do not launch the requested NaCl module if NaCl is marked "unstable" due
// to too many crashes within a given time period.
if (enable_crash_throttling_ &&
!CommandLine::ForCurrentProcess()->HasSwitch(
!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisablePnaclCrashThrottling) &&
NaClBrowser::GetInstance()->IsThrottled()) {
SendErrorToRenderer("Process creation was throttled due to excessive"
Expand All @@ -373,7 +373,7 @@ void NaClProcessHost::Launch(
return;
}

const CommandLine* cmd = CommandLine::ForCurrentProcess();
const base::CommandLine* cmd = base::CommandLine::ForCurrentProcess();
#if defined(OS_WIN)
if (cmd->HasSwitch(switches::kEnableNaClDebug) &&
!cmd->HasSwitch(switches::kNoSandbox)) {
Expand Down Expand Up @@ -455,7 +455,7 @@ void NaClProcessHost::Launch(
}

void NaClProcessHost::OnChannelConnected(int32 peer_pid) {
if (!CommandLine::ForCurrentProcess()->GetSwitchValuePath(
if (!base::CommandLine::ForCurrentProcess()->GetSwitchValuePath(
switches::kNaClGdb).empty()) {
LaunchNaClGdb();
}
Expand Down Expand Up @@ -483,18 +483,20 @@ bool NaClProcessHost::Send(IPC::Message* msg) {
}

bool NaClProcessHost::LaunchNaClGdb() {
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
#if defined(OS_WIN)
base::FilePath nacl_gdb =
CommandLine::ForCurrentProcess()->GetSwitchValuePath(switches::kNaClGdb);
CommandLine cmd_line(nacl_gdb);
command_line.GetSwitchValuePath(switches::kNaClGdb);
base::CommandLine cmd_line(nacl_gdb);
#else
CommandLine::StringType nacl_gdb =
CommandLine::ForCurrentProcess()->GetSwitchValueNative(
switches::kNaClGdb);
CommandLine::StringVector argv;
base::CommandLine::StringType nacl_gdb =
command_line.GetSwitchValueNative(switches::kNaClGdb);
base::CommandLine::StringVector argv;
// We don't support spaces inside arguments in --nacl-gdb switch.
base::SplitString(nacl_gdb, static_cast<CommandLine::CharType>(' '), &argv);
CommandLine cmd_line(argv);
base::SplitString(nacl_gdb, static_cast<base::CommandLine::CharType>(' '),
&argv);
base::CommandLine cmd_line(argv);
#endif
cmd_line.AppendArg("--eval-command");
base::FilePath::StringType irt_path(
Expand All @@ -514,8 +516,8 @@ bool NaClProcessHost::LaunchNaClGdb() {
}
cmd_line.AppendArg("--eval-command");
cmd_line.AppendArg("target remote :4014");
base::FilePath script = CommandLine::ForCurrentProcess()->GetSwitchValuePath(
switches::kNaClGdbScript);
base::FilePath script =
command_line.GetSwitchValuePath(switches::kNaClGdbScript);
if (!script.empty()) {
cmd_line.AppendArg("--command");
cmd_line.AppendArgNative(script.value());
Expand Down Expand Up @@ -587,7 +589,7 @@ bool NaClProcessHost::LaunchSelLdr() {
}
#endif

scoped_ptr<CommandLine> cmd_line(new CommandLine(exe_path));
scoped_ptr<base::CommandLine> cmd_line(new base::CommandLine(exe_path));
CopyNaClCommandLineArguments(cmd_line.get());

cmd_line->AppendSwitchASCII(switches::kProcessType,
Expand Down Expand Up @@ -967,7 +969,7 @@ void NaClProcessHost::OnPpapiChannelsCreated(
args.permissions = permissions_;
args.keepalive_throttle_interval_milliseconds =
keepalive_throttle_interval_milliseconds_;
CommandLine* cmdline = CommandLine::ForCurrentProcess();
base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
DCHECK(cmdline);
std::string flag_whitelist[] = {
switches::kV,
Expand Down
5 changes: 3 additions & 2 deletions components/nacl/common/nacl_cmd_line.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

namespace nacl {

void CopyNaClCommandLineArguments(CommandLine* cmd_line) {
const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
void CopyNaClCommandLineArguments(base::CommandLine* cmd_line) {
const base::CommandLine& browser_command_line =
*base::CommandLine::ForCurrentProcess();

// Propagate the following switches to the NaCl loader command line (along
// with any associated values) if present in the browser command line.
Expand Down
2 changes: 1 addition & 1 deletion components/nacl/common/nacl_nonsfi_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bool IsNonSFIModeEnabled() {
#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
return true;
#elif defined(OS_LINUX)
return CommandLine::ForCurrentProcess()->HasSwitch(
return base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableNaClNonSfiMode);
#else
return false;
Expand Down
9 changes: 5 additions & 4 deletions components/nacl/loader/nacl_helper_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void ChildNaClLoaderInit(ScopedVector<base::ScopedFD> child_fds,
CHECK(content::SendZygoteChildPing(
child_fds[content::ZygoteForkDelegate::kPIDOracleFDIndex]->get()));

CommandLine::ForCurrentProcess()->AppendSwitchASCII(
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kProcessChannelID, channel_id);

// Save the browser socket and close the rest.
Expand Down Expand Up @@ -362,7 +362,8 @@ static const char kNaClHelperRDebug[] = "r_debug";
// process the --r_debug option.
static void CheckRDebug(char* argv0) {
std::string r_debug_switch_value =
CommandLine::ForCurrentProcess()->GetSwitchValueASCII(kNaClHelperRDebug);
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
kNaClHelperRDebug);
if (!r_debug_switch_value.empty()) {
char* endp;
uintptr_t r_debug_addr = strtoul(r_debug_switch_value.c_str(), &endp, 0);
Expand Down Expand Up @@ -394,7 +395,7 @@ static void CheckRDebug(char* argv0) {
static size_t CheckReservedAtZero() {
size_t prereserved_sandbox_size = 0;
std::string reserved_at_zero_switch_value =
CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
kNaClHelperReservedAtZero);
if (!reserved_at_zero_switch_value.empty()) {
char* endp;
Expand Down Expand Up @@ -430,7 +431,7 @@ const char* __asan_default_options() {
#endif

int main(int argc, char* argv[]) {
CommandLine::Init(argc, argv);
base::CommandLine::Init(argc, argv);
base::AtExitManager exit_manager;
base::RandUint64(); // acquire /dev/urandom fd before sandbox is raised

Expand Down
3 changes: 2 additions & 1 deletion components/nacl/loader/nacl_helper_win_64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ int NaClWin64Main() {
sandbox::SandboxInterfaceInfo sandbox_info = {0};
content::InitializeSandboxInfo(&sandbox_info);

const CommandLine& command_line = *CommandLine::ForCurrentProcess();
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
std::string process_type =
command_line.GetSwitchValueASCII(switches::kProcessType);

Expand Down
2 changes: 1 addition & 1 deletion components/nacl/loader/nacl_listener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class FileTokenMessageFilter : public IPC::MessageFilter {

void NaClListener::Listen() {
std::string channel_name =
CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kProcessChannelID);
channel_ = IPC::SyncChannel::Create(
this, io_thread_.message_loop_proxy().get(), &shutdown_event_);
Expand Down
2 changes: 1 addition & 1 deletion components/nacl/loader/nacl_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

// main() routine for the NaCl loader process.
int NaClMain(const content::MainFunctionParams& parameters) {
const CommandLine& parsed_command_line = parameters.command_line;
const base::CommandLine& parsed_command_line = parameters.command_line;

// The main thread of the plugin services IO.
base::MessageLoopForIO main_message_loop;
Expand Down
2 changes: 1 addition & 1 deletion components/nacl/loader/nonsfi/nonsfi_listener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ NonSfiListener::~NonSfiListener() {

void NonSfiListener::Listen() {
channel_ = IPC::SyncChannel::Create(
CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kProcessChannelID),
IPC::Channel::MODE_CLIENT,
this, // As a Listener.
Expand Down
2 changes: 1 addition & 1 deletion components/nacl/loader/sandbox_linux/nacl_sandbox_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void NaClSandbox::CheckSandboxingStateWithPolicy() {
" this is not allowed in this configuration.";

const bool no_sandbox_for_nonsfi_ok =
CommandLine::ForCurrentProcess()->HasSwitch(
base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kNaClDangerousNoSandboxNonSfi);
const bool can_be_no_sandbox =
!layer_two_is_nonsfi_ || no_sandbox_for_nonsfi_ok;
Expand Down
Loading

0 comments on commit b33617c

Please sign in to comment.