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

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: pkasting's comments 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 true if we should show the user manager on startup.
266 // if the last used profile was the guest or system profile. 266 bool ShouldShowUserManagerOnStartup(Profile* last_profile) {
267 // Returns true if the User Manager was shown, false otherwise.
268 bool ShowUserManagerOnStartupIfNeeded(
269 Profile* last_used_profile, const base::CommandLine& command_line) {
270 #if defined(OS_CHROMEOS) 267 #if defined(OS_CHROMEOS)
271 // ChromeOS never shows the User Manager on startup. 268 // ChromeOS never shows the User Manager on startup.
272 return false; 269 return false;
273 #else 270 #else
271 // Avoid reopen profile that requires sign in.
Peter Kasting 2016/12/20 23:21:09 Nit: You changed my suggested comments, which is f
zmin 2016/12/21 00:09:50 Done.
274 ProfileAttributesEntry* entry = nullptr; 272 ProfileAttributesEntry* entry = nullptr;
275 bool has_entry = 273 if (g_browser_process->profile_manager()
276 g_browser_process->profile_manager()
277 ->GetProfileAttributesStorage() 274 ->GetProfileAttributesStorage()
278 .GetProfileAttributesWithPath(last_used_profile->GetPath(), &entry); 275 .GetProfileAttributesWithPath(last_profile->GetPath(), &entry) &&
276 entry->IsSigninRequired()) {
277 return true;
278 }
279 279
280 if (!has_entry || !entry->IsSigninRequired()) { 280 // Avoid reopen guest or sysmte profile, unless a separate process already has
281 // Signin is not required. However, guest, system or locked profiles cannot 281 // a window open for the profile,
282 // be re-opened on startup. The only exception is if there's already a Guest 282 return (last_profile->IsGuestSession() || last_profile->IsSystemProfile()) &&
283 // window open in a separate process (for example, launching a new browser 283 (chrome::GetBrowserCount(last_profile->GetOffTheRecordProfile()) == 0);
284 // after clicking on a downloaded file in Guest mode). 284 #endif
285 if ((!last_used_profile->IsGuestSession() && 285 }
286 !last_used_profile->IsSystemProfile()) || 286
287 (chrome::GetBrowserCount(last_used_profile->GetOffTheRecordProfile()) > 287 // Returns whether the User Manager was shown.
288 0)) { 288 bool ShowUserManagerOnStartupIfNeeded(Profile* last_used_profile,
289 return false; 289 const base::CommandLine& command_line) {
290 } 290 if (!ShouldShowUserManagerOnStartup(last_used_profile))
291 } 291 return false;
292 292
293 // Show the User Manager. 293 // Show the User Manager.
294 profiles::UserManagerAction action = 294 profiles::UserManagerAction action =
295 command_line.HasSwitch(switches::kShowAppList) ? 295 command_line.HasSwitch(switches::kShowAppList) ?
296 profiles::USER_MANAGER_SELECT_PROFILE_APP_LAUNCHER : 296 profiles::USER_MANAGER_SELECT_PROFILE_APP_LAUNCHER :
297 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION; 297 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION;
298 UserManager::Show( 298 UserManager::Show(
299 base::FilePath(), profiles::USER_MANAGER_NO_TUTORIAL, action); 299 base::FilePath(), profiles::USER_MANAGER_NO_TUTORIAL, action);
300 return true; 300 return true;
301 #endif
302 } 301 }
303 302
304 } // namespace 303 } // namespace
305 304
306 StartupBrowserCreator::StartupBrowserCreator() 305 StartupBrowserCreator::StartupBrowserCreator()
307 : is_default_browser_dialog_suppressed_(false), 306 : is_default_browser_dialog_suppressed_(false),
308 show_main_browser_window_(true) {} 307 show_main_browser_window_(true) {}
309 308
310 StartupBrowserCreator::~StartupBrowserCreator() {} 309 StartupBrowserCreator::~StartupBrowserCreator() {}
311 310
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 DCHECK_CURRENTLY_ON(BrowserThread::UI); 579 DCHECK_CURRENTLY_ON(BrowserThread::UI);
581 TRACE_EVENT0("startup", "StartupBrowserCreator::ProcessCmdLineImpl"); 580 TRACE_EVENT0("startup", "StartupBrowserCreator::ProcessCmdLineImpl");
582 581
583 DCHECK(last_used_profile); 582 DCHECK(last_used_profile);
584 if (process_startup) { 583 if (process_startup) {
585 if (command_line.HasSwitch(switches::kDisablePromptOnRepost)) 584 if (command_line.HasSwitch(switches::kDisablePromptOnRepost))
586 content::NavigationController::DisablePromptOnRepost(); 585 content::NavigationController::DisablePromptOnRepost();
587 } 586 }
588 587
589 bool silent_launch = false; 588 bool silent_launch = false;
589 bool should_show_user_manager =
590 ShouldShowUserManagerOnStartup(last_used_profile);
590 591
591 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) 592 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
592 // If we are just displaying a print dialog we shouldn't open browser 593 // If we are just displaying a print dialog we shouldn't open browser
593 // windows. 594 // windows.
594 if (command_line.HasSwitch(switches::kCloudPrintFile) && 595 if (command_line.HasSwitch(switches::kCloudPrintFile) &&
596 !should_show_user_manager &&
Peter Kasting 2016/12/20 23:21:09 Should this code have previously been checking !Sh
zmin 2016/12/21 00:09:50 I just did a quick test,--cloud-print-file will ig
Peter Kasting 2016/12/21 00:21:25 At first glance, that sounds more consistent with
595 print_dialog_cloud::CreatePrintDialogFromCommandLine(last_used_profile, 597 print_dialog_cloud::CreatePrintDialogFromCommandLine(last_used_profile,
596 command_line)) { 598 command_line)) {
597 silent_launch = true; 599 silent_launch = true;
598 } 600 }
599 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) 601 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
600 602
601 if (command_line.HasSwitch(switches::kExplicitlyAllowedPorts)) { 603 if (command_line.HasSwitch(switches::kExplicitlyAllowedPorts)) {
602 std::string allowed_ports = 604 std::string allowed_ports =
603 command_line.GetSwitchValueASCII(switches::kExplicitlyAllowedPorts); 605 command_line.GetSwitchValueASCII(switches::kExplicitlyAllowedPorts);
604 net::SetExplicitlyAllowedPorts(allowed_ports); 606 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 678 // If --no-startup-window is specified and Chrome is already running then do
677 // not open a new window. 679 // not open a new window.
678 if (!process_startup && command_line.HasSwitch(switches::kNoStartupWindow)) 680 if (!process_startup && command_line.HasSwitch(switches::kNoStartupWindow))
679 silent_launch = true; 681 silent_launch = true;
680 682
681 // If we don't want to launch a new browser window or tab we are done here. 683 // If we don't want to launch a new browser window or tab we are done here.
682 if (silent_launch) 684 if (silent_launch)
683 return true; 685 return true;
684 686
685 if (command_line.HasSwitch(extensions::switches::kLoadApps) && 687 if (command_line.HasSwitch(extensions::switches::kLoadApps) &&
688 !should_show_user_manager &&
686 !IncognitoModePrefs::ShouldLaunchIncognito( 689 !IncognitoModePrefs::ShouldLaunchIncognito(
687 command_line, last_used_profile->GetPrefs())) { 690 command_line, last_used_profile->GetPrefs())) {
688 if (!ProcessLoadApps(command_line, cur_dir, last_used_profile)) 691 if (!ProcessLoadApps(command_line, cur_dir, last_used_profile))
689 return false; 692 return false;
690 693
691 // Return early here to avoid opening a browser window. 694 // Return early here to avoid opening a browser window.
692 // The exception is when there are no browser windows, since we don't want 695 // The exception is when there are no browser windows, since we don't want
693 // chrome to shut down. 696 // chrome to shut down.
694 // TODO(jackhou): Do this properly once keep-alive is handled by the 697 // TODO(jackhou): Do this properly once keep-alive is handled by the
695 // background page of apps. Tracked at http://crbug.com/175381 698 // background page of apps. Tracked at http://crbug.com/175381
696 if (chrome::GetBrowserCount(last_used_profile) != 0) 699 if (chrome::GetBrowserCount(last_used_profile) != 0)
697 return true; 700 return true;
698 } 701 }
699 702
700 // Check for --load-and-launch-app. 703 // Check for --load-and-launch-app.
701 if (command_line.HasSwitch(apps::kLoadAndLaunchApp) && 704 if (command_line.HasSwitch(apps::kLoadAndLaunchApp) &&
705 !should_show_user_manager &&
702 !IncognitoModePrefs::ShouldLaunchIncognito( 706 !IncognitoModePrefs::ShouldLaunchIncognito(
703 command_line, last_used_profile->GetPrefs())) { 707 command_line, last_used_profile->GetPrefs())) {
704 base::CommandLine::StringType path = 708 base::CommandLine::StringType path =
705 command_line.GetSwitchValueNative(apps::kLoadAndLaunchApp); 709 command_line.GetSwitchValueNative(apps::kLoadAndLaunchApp);
706 710
707 if (!apps::AppLoadService::Get(last_used_profile)->LoadAndLaunch( 711 if (!apps::AppLoadService::Get(last_used_profile)->LoadAndLaunch(
708 base::FilePath(path), command_line, cur_dir)) { 712 base::FilePath(path), command_line, cur_dir)) {
709 return false; 713 return false;
710 } 714 }
711 715
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 if (!entry->IsSigninRequired()) { 992 if (!entry->IsSigninRequired()) {
989 Profile* profile = profile_manager->GetProfile(entry->GetPath()); 993 Profile* profile = profile_manager->GetProfile(entry->GetPath());
990 if (profile) 994 if (profile)
991 return profile; 995 return profile;
992 } 996 }
993 } 997 }
994 998
995 return nullptr; 999 return nullptr;
996 } 1000 }
997 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) 1001 #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