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

Side by Side Diff: chrome/browser/ui/startup/startup_browser_creator.cc

Issue 2582123002: Disable --load-and-launch-app, --load-apps and --cloud-print-file if last_used_profile is not avail… (Closed)
Patch Set: refactor and nit Created 4 years 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 | « no previous file | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/startup/startup_browser_creator.h" 5 #include "chrome/browser/ui/startup/startup_browser_creator.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> // For max(). 9 #include <algorithm> // For max().
10 #include <limits> 10 #include <limits>
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 // The file is overwritten if it exists. This function should only be called in 255 // The file is overwritten if it exists. This function should only be called in
256 // the blocking pool. 256 // the blocking pool.
257 void DumpBrowserHistograms(const base::FilePath& output_file) { 257 void DumpBrowserHistograms(const base::FilePath& output_file) {
258 base::ThreadRestrictions::AssertIOAllowed(); 258 base::ThreadRestrictions::AssertIOAllowed();
259 259
260 std::string output_string(base::StatisticsRecorder::ToJSON(std::string())); 260 std::string output_string(base::StatisticsRecorder::ToJSON(std::string()));
261 base::WriteFile(output_file, output_string.data(), 261 base::WriteFile(output_file, output_string.data(),
262 static_cast<int>(output_string.size())); 262 static_cast<int>(output_string.size()));
263 } 263 }
264 264
265 // Shows the User Manager on startup if the last used profile must sign in or 265 // Returns whether |profile| can be opened during Chrome startup without
266 // if the last used profile was the guest or system profile. 266 // explicit user action.
267 // Returns true if the User Manager was shown, false otherwise. 267 bool ProfileCanBeAutoOpened(Profile* profile) {
268 bool ShowUserManagerOnStartupIfNeeded(
269 Profile* last_used_profile, const base::CommandLine& command_line) {
270 #if defined(OS_CHROMEOS) 268 #if defined(OS_CHROMEOS)
271 // ChromeOS never shows the User Manager on startup. 269 // On ChromeOS, ther user has alrady chosen and logged into the profile
272 return false; 270 // before Chrome starts up.
271 return true;
273 #else 272 #else
273 // Profiles that require signin are not available.
274 ProfileAttributesEntry* entry = nullptr; 274 ProfileAttributesEntry* entry = nullptr;
275 bool has_entry = 275 if (g_browser_process->profile_manager()
276 g_browser_process->profile_manager()
277 ->GetProfileAttributesStorage() 276 ->GetProfileAttributesStorage()
278 .GetProfileAttributesWithPath(last_used_profile->GetPath(), &entry); 277 .GetProfileAttributesWithPath(profile->GetPath(), &entry) &&
278 entry->IsSigninRequired()) {
279 return false;
280 }
279 281
280 if (!has_entry || !entry->IsSigninRequired()) { 282 // Guest or system profiles are not available unless a separate process
281 // Signin is not required. However, guest, system or locked profiles cannot 283 // already has a window open for the profile.
282 // be re-opened on startup. The only exception is if there's already a Guest 284 return (!profile->IsGuestSession() && !profile->IsSystemProfile()) ||
283 // window open in a separate process (for example, launching a new browser 285 (chrome::GetBrowserCount(profile->GetOffTheRecordProfile()) > 0);
284 // after clicking on a downloaded file in Guest mode). 286 #endif
285 if ((!last_used_profile->IsGuestSession() && 287 }
286 !last_used_profile->IsSystemProfile()) || 288
287 (chrome::GetBrowserCount(last_used_profile->GetOffTheRecordProfile()) > 289 // Returns whether the User Manager was shown.
288 0)) { 290 bool ShowUserManagerOnStartupIfNeeded(Profile* last_used_profile,
289 return false; 291 const base::CommandLine& command_line) {
290 } 292 if (ProfileCanBeAutoOpened(last_used_profile))
291 } 293 return false;
292 294
293 // Show the User Manager. 295 // Show the User Manager.
294 profiles::UserManagerAction action = 296 profiles::UserManagerAction action =
295 command_line.HasSwitch(switches::kShowAppList) ? 297 command_line.HasSwitch(switches::kShowAppList) ?
296 profiles::USER_MANAGER_SELECT_PROFILE_APP_LAUNCHER : 298 profiles::USER_MANAGER_SELECT_PROFILE_APP_LAUNCHER :
297 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION; 299 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION;
298 UserManager::Show( 300 UserManager::Show(
299 base::FilePath(), profiles::USER_MANAGER_NO_TUTORIAL, action); 301 base::FilePath(), profiles::USER_MANAGER_NO_TUTORIAL, action);
300 return true; 302 return true;
301 #endif
302 } 303 }
303 304
304 } // namespace 305 } // namespace
305 306
306 StartupBrowserCreator::StartupBrowserCreator() 307 StartupBrowserCreator::StartupBrowserCreator()
307 : is_default_browser_dialog_suppressed_(false), 308 : is_default_browser_dialog_suppressed_(false),
308 show_main_browser_window_(true) {} 309 show_main_browser_window_(true) {}
309 310
310 StartupBrowserCreator::~StartupBrowserCreator() {} 311 StartupBrowserCreator::~StartupBrowserCreator() {}
311 312
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 DCHECK_CURRENTLY_ON(BrowserThread::UI); 581 DCHECK_CURRENTLY_ON(BrowserThread::UI);
581 TRACE_EVENT0("startup", "StartupBrowserCreator::ProcessCmdLineImpl"); 582 TRACE_EVENT0("startup", "StartupBrowserCreator::ProcessCmdLineImpl");
582 583
583 DCHECK(last_used_profile); 584 DCHECK(last_used_profile);
584 if (process_startup) { 585 if (process_startup) {
585 if (command_line.HasSwitch(switches::kDisablePromptOnRepost)) 586 if (command_line.HasSwitch(switches::kDisablePromptOnRepost))
586 content::NavigationController::DisablePromptOnRepost(); 587 content::NavigationController::DisablePromptOnRepost();
587 } 588 }
588 589
589 bool silent_launch = false; 590 bool silent_launch = false;
591 bool can_use_last_profile =
592 (ProfileCanBeAutoOpened(last_used_profile) &&
593 !IncognitoModePrefs::ShouldLaunchIncognito(
594 command_line, last_used_profile->GetPrefs()));
590 595
591 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) 596 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
592 // If we are just displaying a print dialog we shouldn't open browser 597 // If we are just displaying a print dialog we shouldn't open browser
593 // windows. 598 // windows.
594 if (command_line.HasSwitch(switches::kCloudPrintFile) && 599 if (command_line.HasSwitch(switches::kCloudPrintFile) &&
600 can_use_last_profile &&
595 print_dialog_cloud::CreatePrintDialogFromCommandLine(last_used_profile, 601 print_dialog_cloud::CreatePrintDialogFromCommandLine(last_used_profile,
596 command_line)) { 602 command_line)) {
597 silent_launch = true; 603 silent_launch = true;
598 } 604 }
599 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) 605 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
600 606
601 if (command_line.HasSwitch(switches::kExplicitlyAllowedPorts)) { 607 if (command_line.HasSwitch(switches::kExplicitlyAllowedPorts)) {
602 std::string allowed_ports = 608 std::string allowed_ports =
603 command_line.GetSwitchValueASCII(switches::kExplicitlyAllowedPorts); 609 command_line.GetSwitchValueASCII(switches::kExplicitlyAllowedPorts);
604 net::SetExplicitlyAllowedPorts(allowed_ports); 610 net::SetExplicitlyAllowedPorts(allowed_ports);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 // If --no-startup-window is specified and Chrome is already running then do 682 // If --no-startup-window is specified and Chrome is already running then do
677 // not open a new window. 683 // not open a new window.
678 if (!process_startup && command_line.HasSwitch(switches::kNoStartupWindow)) 684 if (!process_startup && command_line.HasSwitch(switches::kNoStartupWindow))
679 silent_launch = true; 685 silent_launch = true;
680 686
681 // If we don't want to launch a new browser window or tab we are done here. 687 // If we don't want to launch a new browser window or tab we are done here.
682 if (silent_launch) 688 if (silent_launch)
683 return true; 689 return true;
684 690
685 if (command_line.HasSwitch(extensions::switches::kLoadApps) && 691 if (command_line.HasSwitch(extensions::switches::kLoadApps) &&
686 !IncognitoModePrefs::ShouldLaunchIncognito( 692 can_use_last_profile) {
687 command_line, last_used_profile->GetPrefs())) {
688 if (!ProcessLoadApps(command_line, cur_dir, last_used_profile)) 693 if (!ProcessLoadApps(command_line, cur_dir, last_used_profile))
689 return false; 694 return false;
690 695
691 // Return early here to avoid opening a browser window. 696 // Return early here to avoid opening a browser window.
692 // The exception is when there are no browser windows, since we don't want 697 // The exception is when there are no browser windows, since we don't want
693 // chrome to shut down. 698 // chrome to shut down.
694 // TODO(jackhou): Do this properly once keep-alive is handled by the 699 // TODO(jackhou): Do this properly once keep-alive is handled by the
695 // background page of apps. Tracked at http://crbug.com/175381 700 // background page of apps. Tracked at http://crbug.com/175381
696 if (chrome::GetBrowserCount(last_used_profile) != 0) 701 if (chrome::GetBrowserCount(last_used_profile) != 0)
697 return true; 702 return true;
698 } 703 }
699 704
700 // Check for --load-and-launch-app. 705 // Check for --load-and-launch-app.
701 if (command_line.HasSwitch(apps::kLoadAndLaunchApp) && 706 if (command_line.HasSwitch(apps::kLoadAndLaunchApp) && can_use_last_profile) {
702 !IncognitoModePrefs::ShouldLaunchIncognito(
703 command_line, last_used_profile->GetPrefs())) {
704 base::CommandLine::StringType path = 707 base::CommandLine::StringType path =
705 command_line.GetSwitchValueNative(apps::kLoadAndLaunchApp); 708 command_line.GetSwitchValueNative(apps::kLoadAndLaunchApp);
706 709
707 if (!apps::AppLoadService::Get(last_used_profile)->LoadAndLaunch( 710 if (!apps::AppLoadService::Get(last_used_profile)->LoadAndLaunch(
708 base::FilePath(path), command_line, cur_dir)) { 711 base::FilePath(path), command_line, cur_dir)) {
709 return false; 712 return false;
710 } 713 }
711 714
712 // Return early here since we don't want to open a browser window. 715 // Return early here since we don't want to open a browser window.
713 // The exception is when there are no browser windows, since we don't want 716 // The exception is when there are no browser windows, since we don't want
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 if (!entry->IsSigninRequired()) { 991 if (!entry->IsSigninRequired()) {
989 Profile* profile = profile_manager->GetProfile(entry->GetPath()); 992 Profile* profile = profile_manager->GetProfile(entry->GetPath());
990 if (profile) 993 if (profile)
991 return profile; 994 return profile;
992 } 995 }
993 } 996 }
994 997
995 return nullptr; 998 return nullptr;
996 } 999 }
997 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) 1000 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698