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

Side by Side Diff: chrome/browser/browser_init.cc

Issue 18248: CommandLine API rework (Closed)
Patch Set: fixes Created 11 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/browser/browser.cc ('k') | chrome/browser/browser_main.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 (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/browser/browser_init.h" 5 #include "chrome/browser/browser_init.h"
6 6
7 #include <shellapi.h> 7 #include <shellapi.h>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 const std::wstring& cmd_line) 396 const std::wstring& cmd_line)
397 : command_line_(cmd_line), 397 : command_line_(cmd_line),
398 cur_dir_(cur_dir) { 398 cur_dir_(cur_dir) {
399 } 399 }
400 400
401 bool BrowserInit::LaunchWithProfile::Launch(Profile* profile, 401 bool BrowserInit::LaunchWithProfile::Launch(Profile* profile,
402 bool process_startup) { 402 bool process_startup) {
403 DCHECK(profile); 403 DCHECK(profile);
404 profile_ = profile; 404 profile_ = profile;
405 405
406 CommandLine parsed_command_line(command_line_); 406 CommandLine parsed_command_line(L"");
407 parsed_command_line.ParseFromString(command_line_);
407 if (parsed_command_line.HasSwitch(switches::kDnsLogDetails)) 408 if (parsed_command_line.HasSwitch(switches::kDnsLogDetails))
408 chrome_browser_net::EnableDnsDetailedLog(true); 409 chrome_browser_net::EnableDnsDetailedLog(true);
409 if (parsed_command_line.HasSwitch(switches::kDnsPrefetchDisable)) 410 if (parsed_command_line.HasSwitch(switches::kDnsPrefetchDisable))
410 chrome_browser_net::EnableDnsPrefetch(false); 411 chrome_browser_net::EnableDnsPrefetch(false);
411 412
412 if (parsed_command_line.HasSwitch(switches::kDumpHistogramsOnExit)) { 413 if (parsed_command_line.HasSwitch(switches::kDumpHistogramsOnExit)) {
413 StatisticsRecorder::set_dump_on_exit(true); 414 StatisticsRecorder::set_dump_on_exit(true);
414 } 415 }
415 416
416 if (parsed_command_line.HasSwitch(switches::kRemoteShellPort)) { 417 if (parsed_command_line.HasSwitch(switches::kRemoteShellPort)) {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 // The last session didn't exit cleanly. Show an infobar to the user 563 // The last session didn't exit cleanly. Show an infobar to the user
563 // so that they can restore if they want. The delegate deletes itself when 564 // so that they can restore if they want. The delegate deletes itself when
564 // it is closed. 565 // it is closed.
565 tab->AddInfoBar(new SessionCrashedInfoBarDelegate(tab)); 566 tab->AddInfoBar(new SessionCrashedInfoBarDelegate(tab));
566 } 567 }
567 } 568 }
568 569
569 std::vector<GURL> BrowserInit::LaunchWithProfile::GetURLsFromCommandLine( 570 std::vector<GURL> BrowserInit::LaunchWithProfile::GetURLsFromCommandLine(
570 const CommandLine& command_line, Profile* profile) { 571 const CommandLine& command_line, Profile* profile) {
571 std::vector<GURL> urls; 572 std::vector<GURL> urls;
572 if (command_line.GetLooseValueCount() > 0) { 573 std::vector<std::wstring> params = command_line.GetLooseValues();
573 for (CommandLine::LooseValueIterator iter = 574 for (size_t i = 0; i < params.size(); ++i) {
574 command_line.GetLooseValuesBegin(); 575 const std::wstring& value = params[i];
575 iter != command_line.GetLooseValuesEnd(); ++iter) { 576 // Handle Vista way of searching - "? <search-term>"
576 std::wstring value = *iter; 577 if (value.find(L"? ") == 0) {
577 // Handle Vista way of searching - "? <search-term>" 578 const TemplateURL* const default_provider =
578 if (value.find(L"? ") == 0) { 579 profile->GetTemplateURLModel()->GetDefaultSearchProvider();
579 const TemplateURL* const default_provider = 580 if (!default_provider || !default_provider->url()) {
580 profile->GetTemplateURLModel()->GetDefaultSearchProvider(); 581 // No search provider available. Just treat this as regular URL.
581 if (!default_provider || !default_provider->url()) { 582 urls.push_back(GURL(URLFixerUpper::FixupRelativeFile(cur_dir_,
582 // No search provider available. Just treat this as regular URL. 583 value)));
583 urls.push_back(GURL(URLFixerUpper::FixupRelativeFile(cur_dir_, 584 continue;
584 value)));
585 continue;
586 }
587 const TemplateURLRef* const search_url = default_provider->url();
588 DCHECK(search_url->SupportsReplacement());
589 urls.push_back(GURL(search_url->ReplaceSearchTerms(*default_provider,
590 value.substr(2), TemplateURLRef::NO_SUGGESTIONS_AVAILABLE,
591 std::wstring())));
592 } else {
593 // This will create a file URL or a regular URL.
594 urls.push_back(GURL(URLFixerUpper::FixupRelativeFile(cur_dir_, value)));
595 } 585 }
586 const TemplateURLRef* const search_url = default_provider->url();
587 DCHECK(search_url->SupportsReplacement());
588 urls.push_back(GURL(search_url->ReplaceSearchTerms(*default_provider,
589 value.substr(2), TemplateURLRef::NO_SUGGESTIONS_AVAILABLE,
590 std::wstring())));
591 } else {
592 // This will create a file URL or a regular URL.
593 urls.push_back(GURL(URLFixerUpper::FixupRelativeFile(cur_dir_, value)));
596 } 594 }
597 } 595 }
598 return urls; 596 return urls;
599 } 597 }
600 598
601 bool BrowserInit::ProcessCommandLine(const CommandLine& parsed_command_line, 599 bool BrowserInit::ProcessCommandLine(const CommandLine& parsed_command_line,
602 const std::wstring& cur_dir, PrefService* prefs, bool process_startup, 600 const std::wstring& cur_dir, PrefService* prefs, bool process_startup,
603 Profile* profile, int* return_code) { 601 Profile* profile, int* return_code) {
604 DCHECK(profile); 602 DCHECK(profile);
605 if (process_startup) { 603 if (process_startup) {
(...skipping 20 matching lines...) Expand all
626 if (parsed_command_line.HasSwitch(switches::kTestingChannelID)) { 624 if (parsed_command_line.HasSwitch(switches::kTestingChannelID)) {
627 std::wstring testing_channel_id = 625 std::wstring testing_channel_id =
628 parsed_command_line.GetSwitchValue(switches::kTestingChannelID); 626 parsed_command_line.GetSwitchValue(switches::kTestingChannelID);
629 // TODO(sanjeevr) Check if we need to make this a singleton for 627 // TODO(sanjeevr) Check if we need to make this a singleton for
630 // compatibility with the old testing code 628 // compatibility with the old testing code
631 // If there are any loose parameters, we expect each one to generate a 629 // If there are any loose parameters, we expect each one to generate a
632 // new tab; if there are none then we get one homepage tab. 630 // new tab; if there are none then we get one homepage tab.
633 CreateAutomationProvider<TestingAutomationProvider>( 631 CreateAutomationProvider<TestingAutomationProvider>(
634 testing_channel_id, 632 testing_channel_id,
635 profile, 633 profile,
636 std::max(static_cast<int>(parsed_command_line.GetLooseValueCount()), 634 std::max(static_cast<int>(parsed_command_line.GetLooseValues().size()) ,
637 1)); 635 1));
638 } 636 }
639 } 637 }
640 638
641 // Allow the command line to override the persisted setting of home page. 639 // Allow the command line to override the persisted setting of home page.
642 SetOverrideHomePage(parsed_command_line, profile->GetPrefs()); 640 SetOverrideHomePage(parsed_command_line, profile->GetPrefs());
643 641
644 if (parsed_command_line.HasSwitch(switches::kBrowserStartRenderersManually)) 642 if (parsed_command_line.HasSwitch(switches::kBrowserStartRenderersManually))
645 prefs->transient()->SetBoolean(prefs::kStartRenderersManually, true); 643 prefs->transient()->SetBoolean(prefs::kStartRenderersManually, true);
646 644
647 bool silent_launch = false; 645 bool silent_launch = false;
648 if (parsed_command_line.HasSwitch(switches::kAutomationClientChannelID)) { 646 if (parsed_command_line.HasSwitch(switches::kAutomationClientChannelID)) {
649 std::wstring automation_channel_id = 647 std::wstring automation_channel_id =
650 parsed_command_line.GetSwitchValue(switches::kAutomationClientChannelID); 648 parsed_command_line.GetSwitchValue(switches::kAutomationClientChannelID);
651 // If there are any loose parameters, we expect each one to generate a 649 // If there are any loose parameters, we expect each one to generate a
652 // new tab; if there are none then we have no tabs 650 // new tab; if there are none then we have no tabs
653 size_t expected_tabs = 651 size_t expected_tabs =
654 std::max(static_cast<int>(parsed_command_line.GetLooseValueCount()), 652 std::max(static_cast<int>(parsed_command_line.GetLooseValues().size()),
655 0); 653 0);
656 if (expected_tabs == 0) { 654 if (expected_tabs == 0) {
657 silent_launch = true; 655 silent_launch = true;
658 } 656 }
659 CreateAutomationProvider<AutomationProvider>(automation_channel_id, 657 CreateAutomationProvider<AutomationProvider>(automation_channel_id,
660 profile, expected_tabs); 658 profile, expected_tabs);
661 } 659 }
662 // If we don't want to launch a new browser window or tab (in the case 660 // If we don't want to launch a new browser window or tab (in the case
663 // of an automation request), we are done here. 661 // of an automation request), we are done here.
664 if (!silent_launch) { 662 if (!silent_launch) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 if (!launched) { 722 if (!launched) {
725 LOG(ERROR) << "launch error"; 723 LOG(ERROR) << "launch error";
726 if (return_code != NULL) { 724 if (return_code != NULL) {
727 *return_code = ResultCodes::INVALID_CMDLINE_URL; 725 *return_code = ResultCodes::INVALID_CMDLINE_URL;
728 } 726 }
729 return false; 727 return false;
730 } 728 }
731 729
732 return true; 730 return true;
733 } 731 }
OLDNEW
« no previous file with comments | « chrome/browser/browser.cc ('k') | chrome/browser/browser_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698