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

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

Issue 160331: Ensure we have a valid profile when using BrowserInit::LaunchWithProfile::Ope... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 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 | Annotate | Revision Log
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 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include "app/win_util.h" 8 #include "app/win_util.h"
9 #endif 9 #endif
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 return in_startup; 370 return in_startup;
371 } 371 }
372 372
373 // LaunchWithProfile ---------------------------------------------------------- 373 // LaunchWithProfile ----------------------------------------------------------
374 374
375 BrowserInit::LaunchWithProfile::LaunchWithProfile( 375 BrowserInit::LaunchWithProfile::LaunchWithProfile(
376 const std::wstring& cur_dir, 376 const std::wstring& cur_dir,
377 const CommandLine& command_line) 377 const CommandLine& command_line)
378 : cur_dir_(cur_dir), 378 : cur_dir_(cur_dir),
379 command_line_(command_line), 379 command_line_(command_line),
380 profile_(NULL),
380 browser_init_(NULL) { 381 browser_init_(NULL) {
381 } 382 }
382 383
383 BrowserInit::LaunchWithProfile::LaunchWithProfile( 384 BrowserInit::LaunchWithProfile::LaunchWithProfile(
384 const std::wstring& cur_dir, 385 const std::wstring& cur_dir,
385 const CommandLine& command_line, 386 const CommandLine& command_line,
386 BrowserInit* browser_init) 387 BrowserInit* browser_init)
387 : cur_dir_(cur_dir), 388 : cur_dir_(cur_dir),
388 command_line_(command_line), 389 command_line_(command_line),
390 profile_(NULL),
389 browser_init_(browser_init) { 391 browser_init_(browser_init) {
390 } 392 }
391 393
392 bool BrowserInit::LaunchWithProfile::Launch(Profile* profile, 394 bool BrowserInit::LaunchWithProfile::Launch(Profile* profile,
393 bool process_startup) { 395 bool process_startup) {
394 DCHECK(profile); 396 DCHECK(profile);
395 profile_ = profile; 397 profile_ = profile;
396 398
397 if (command_line_.HasSwitch(switches::kDnsLogDetails)) 399 if (command_line_.HasSwitch(switches::kDnsLogDetails))
398 chrome_browser_net::EnableDnsDetailedLog(true); 400 chrome_browser_net::EnableDnsDetailedLog(true);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 default: 549 default:
548 return false; 550 return false;
549 } 551 }
550 } 552 }
551 553
552 Browser* BrowserInit::LaunchWithProfile::OpenURLsInBrowser( 554 Browser* BrowserInit::LaunchWithProfile::OpenURLsInBrowser(
553 Browser* browser, 555 Browser* browser,
554 bool process_startup, 556 bool process_startup,
555 const std::vector<GURL>& urls) { 557 const std::vector<GURL>& urls) {
556 DCHECK(!urls.empty()); 558 DCHECK(!urls.empty());
559 // If we don't yet have a profile, try to use the one we're given from
560 // |browser|. While we may not end up actually using |browser| (since it
561 // could be a popup window), we can at least use the profile.
562 if (!profile_ && browser)
563 profile_ = browser->profile();
564
557 int pin_count = 0; 565 int pin_count = 0;
558 if (!browser) { 566 if (!browser) {
559 std::wstring pin_count_string = 567 std::wstring pin_count_string =
560 command_line_.GetSwitchValue(switches::kPinnedTabCount); 568 command_line_.GetSwitchValue(switches::kPinnedTabCount);
561 if (!pin_count_string.empty()) 569 if (!pin_count_string.empty())
562 pin_count = StringToInt(WideToUTF16Hack(pin_count_string)); 570 pin_count = StringToInt(WideToUTF16Hack(pin_count_string));
563 } 571 }
564 if (!browser || browser->type() != Browser::TYPE_NORMAL) 572 if (!browser || browser->type() != Browser::TYPE_NORMAL) {
565 browser = Browser::Create(profile_); 573 // Try to find an existing "normal" browser. If one does not exist, create
566 574 // one.
575 browser = BrowserList::FindBrowserWithType(profile_, Browser::TYPE_NORMAL);
576 if (!browser || !browser->GetSelectedTabContents())
577 browser = Browser::Create(profile_);
578 }
567 for (size_t i = 0; i < urls.size(); ++i) { 579 for (size_t i = 0; i < urls.size(); ++i) {
568 TabContents* tab = browser->AddTabWithURL( 580 TabContents* tab = browser->AddTabWithURL(
569 urls[i], GURL(), PageTransition::START_PAGE, (i == 0), -1, false, NULL); 581 urls[i], GURL(), PageTransition::START_PAGE, (i == 0), -1, false, NULL);
570 if (i < static_cast<size_t>(pin_count)) 582 if (i < static_cast<size_t>(pin_count))
571 browser->tabstrip_model()->SetTabPinned(browser->tab_count() - 1, true); 583 browser->tabstrip_model()->SetTabPinned(browser->tab_count() - 1, true);
572 if (i == 0 && process_startup && !browser_defaults::kSuppressCrashInfoBar) 584 if (i == 0 && process_startup && !browser_defaults::kSuppressCrashInfoBar)
573 AddCrashedInfoBarIfNecessary(tab); 585 AddCrashedInfoBarIfNecessary(tab);
574 } 586 }
575 browser->window()->Show(); 587 browser->window()->Show();
576 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial 588 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 scoped_refptr<AutomationProviderClass> automation = 844 scoped_refptr<AutomationProviderClass> automation =
833 new AutomationProviderClass(profile); 845 new AutomationProviderClass(profile);
834 automation->ConnectToChannel(channel_id); 846 automation->ConnectToChannel(channel_id);
835 automation->SetExpectedTabCount(expected_tabs); 847 automation->SetExpectedTabCount(expected_tabs);
836 848
837 AutomationProviderList* list = 849 AutomationProviderList* list =
838 g_browser_process->InitAutomationProviderList(); 850 g_browser_process->InitAutomationProviderList();
839 DCHECK(list); 851 DCHECK(list);
840 list->AddProvider(automation); 852 list->AddProvider(automation);
841 } 853 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/browser_init_browsertest.cc » ('j') | chrome/browser/browser_init_browsertest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698