Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 // Return true if the last used profile must sign in or the last used profile |
|
Peter Kasting
2016/12/20 01:43:49
Nit: Return -> returns
zmin
2016/12/20 20:32:13
Done.
| |
| 266 // if the last used profile was the guest or system profile. | 266 // was the guest or system profile. Otherwise, return false. |
|
Peter Kasting
2016/12/20 01:43:49
Nit: Remove last sentence, it's implied.
This com
zmin
2016/12/20 20:32:13
Done.
| |
| 267 // Returns true if the User Manager was shown, false otherwise. | 267 bool ShouldShowUserManagerOnStartup(Profile* last_used_profile) { |
| 268 bool ShowUserManagerOnStartupIfNeeded( | |
| 269 Profile* last_used_profile, const base::CommandLine& command_line) { | |
| 270 #if defined(OS_CHROMEOS) | |
| 271 // ChromeOS never shows the User Manager on startup. | |
| 272 return false; | |
| 273 #else | |
|
Peter Kasting
2016/12/20 01:43:49
It's not obvious to me from the new callers whethe
zmin
2016/12/20 20:32:14
I have moved the #ifdef to ShouldShowUserManagerOn
| |
| 274 ProfileAttributesEntry* entry = nullptr; | 268 ProfileAttributesEntry* entry = nullptr; |
| 275 bool has_entry = | 269 bool has_entry = |
| 276 g_browser_process->profile_manager() | 270 g_browser_process->profile_manager() |
| 277 ->GetProfileAttributesStorage() | 271 ->GetProfileAttributesStorage() |
| 278 .GetProfileAttributesWithPath(last_used_profile->GetPath(), &entry); | 272 .GetProfileAttributesWithPath(last_used_profile->GetPath(), &entry); |
| 279 | 273 |
| 280 if (!has_entry || !entry->IsSigninRequired()) { | 274 if (!has_entry || !entry->IsSigninRequired()) { |
|
Peter Kasting
2016/12/20 01:43:49
Nit: This equivalent implementation is shorter and
zmin
2016/12/20 20:32:14
Done. But I have changed it little bit:
* Put "g_b
| |
| 281 // Signin is not required. However, guest, system or locked profiles cannot | 275 // Signin is not required. However, guest, system or locked profiles cannot |
| 282 // be re-opened on startup. The only exception is if there's already a Guest | 276 // be re-opened on startup. The only exception is if there's already a Guest |
| 283 // window open in a separate process (for example, launching a new browser | 277 // window open in a separate process (for example, launching a new browser |
| 284 // after clicking on a downloaded file in Guest mode). | 278 // after clicking on a downloaded file in Guest mode). |
| 285 if ((!last_used_profile->IsGuestSession() && | 279 if ((!last_used_profile->IsGuestSession() && |
| 286 !last_used_profile->IsSystemProfile()) || | 280 !last_used_profile->IsSystemProfile()) || |
| 287 (chrome::GetBrowserCount(last_used_profile->GetOffTheRecordProfile()) > | 281 (chrome::GetBrowserCount(last_used_profile->GetOffTheRecordProfile()) > |
| 288 0)) { | 282 0)) { |
| 289 return false; | 283 return false; |
| 290 } | 284 } |
| 291 } | 285 } |
| 286 return true; | |
| 287 } | |
| 288 | |
| 289 // Shows the User Manager on startup if the last used profile must sign in or | |
| 290 // if the last used profile was the guest or system profile. | |
| 291 // Returns true if the User Manager was shown, false otherwise. | |
|
Peter Kasting
2016/12/20 01:43:49
Nit: Or just "Returns whether the User Manager was
zmin
2016/12/20 20:32:14
Done.
| |
| 292 bool ShowUserManagerOnStartupIfNeeded(Profile* last_used_profile, | |
| 293 const base::CommandLine& command_line) { | |
| 294 #if defined(OS_CHROMEOS) | |
| 295 // ChromeOS never shows the User Manager on startup. | |
| 296 return false; | |
| 297 #else | |
| 298 | |
| 299 if (!ShouldShowUserManagerOnStartup(last_used_profile)) { | |
|
Peter Kasting
2016/12/20 01:43:49
Nit: {} unnecessary (and inconsistent with other p
zmin
2016/12/20 20:32:13
Done.
| |
| 300 return false; | |
| 301 } | |
| 292 | 302 |
| 293 // Show the User Manager. | 303 // Show the User Manager. |
| 294 profiles::UserManagerAction action = | 304 profiles::UserManagerAction action = |
| 295 command_line.HasSwitch(switches::kShowAppList) ? | 305 command_line.HasSwitch(switches::kShowAppList) ? |
| 296 profiles::USER_MANAGER_SELECT_PROFILE_APP_LAUNCHER : | 306 profiles::USER_MANAGER_SELECT_PROFILE_APP_LAUNCHER : |
| 297 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION; | 307 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION; |
| 298 UserManager::Show( | 308 UserManager::Show( |
| 299 base::FilePath(), profiles::USER_MANAGER_NO_TUTORIAL, action); | 309 base::FilePath(), profiles::USER_MANAGER_NO_TUTORIAL, action); |
| 300 return true; | 310 return true; |
| 301 #endif | 311 #endif |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 580 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 590 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 581 TRACE_EVENT0("startup", "StartupBrowserCreator::ProcessCmdLineImpl"); | 591 TRACE_EVENT0("startup", "StartupBrowserCreator::ProcessCmdLineImpl"); |
| 582 | 592 |
| 583 DCHECK(last_used_profile); | 593 DCHECK(last_used_profile); |
| 584 if (process_startup) { | 594 if (process_startup) { |
| 585 if (command_line.HasSwitch(switches::kDisablePromptOnRepost)) | 595 if (command_line.HasSwitch(switches::kDisablePromptOnRepost)) |
| 586 content::NavigationController::DisablePromptOnRepost(); | 596 content::NavigationController::DisablePromptOnRepost(); |
| 587 } | 597 } |
| 588 | 598 |
| 589 bool silent_launch = false; | 599 bool silent_launch = false; |
| 600 bool should_show_user_manager = | |
| 601 ShouldShowUserManagerOnStartup(last_used_profile); | |
| 590 | 602 |
| 591 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) | 603 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 592 // If we are just displaying a print dialog we shouldn't open browser | 604 // If we are just displaying a print dialog we shouldn't open browser |
| 593 // windows. | 605 // windows. |
| 594 if (command_line.HasSwitch(switches::kCloudPrintFile) && | 606 if (command_line.HasSwitch(switches::kCloudPrintFile) && |
| 607 !should_show_user_manager && | |
| 595 print_dialog_cloud::CreatePrintDialogFromCommandLine(last_used_profile, | 608 print_dialog_cloud::CreatePrintDialogFromCommandLine(last_used_profile, |
| 596 command_line)) { | 609 command_line)) { |
| 597 silent_launch = true; | 610 silent_launch = true; |
| 598 } | 611 } |
| 599 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) | 612 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 600 | 613 |
| 601 if (command_line.HasSwitch(switches::kExplicitlyAllowedPorts)) { | 614 if (command_line.HasSwitch(switches::kExplicitlyAllowedPorts)) { |
| 602 std::string allowed_ports = | 615 std::string allowed_ports = |
| 603 command_line.GetSwitchValueASCII(switches::kExplicitlyAllowedPorts); | 616 command_line.GetSwitchValueASCII(switches::kExplicitlyAllowedPorts); |
| 604 net::SetExplicitlyAllowedPorts(allowed_ports); | 617 net::SetExplicitlyAllowedPorts(allowed_ports); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 676 // If --no-startup-window is specified and Chrome is already running then do | 689 // If --no-startup-window is specified and Chrome is already running then do |
| 677 // not open a new window. | 690 // not open a new window. |
| 678 if (!process_startup && command_line.HasSwitch(switches::kNoStartupWindow)) | 691 if (!process_startup && command_line.HasSwitch(switches::kNoStartupWindow)) |
| 679 silent_launch = true; | 692 silent_launch = true; |
| 680 | 693 |
| 681 // If we don't want to launch a new browser window or tab we are done here. | 694 // If we don't want to launch a new browser window or tab we are done here. |
| 682 if (silent_launch) | 695 if (silent_launch) |
| 683 return true; | 696 return true; |
| 684 | 697 |
| 685 if (command_line.HasSwitch(extensions::switches::kLoadApps) && | 698 if (command_line.HasSwitch(extensions::switches::kLoadApps) && |
| 699 !should_show_user_manager && | |
| 686 !IncognitoModePrefs::ShouldLaunchIncognito( | 700 !IncognitoModePrefs::ShouldLaunchIncognito( |
| 687 command_line, last_used_profile->GetPrefs())) { | 701 command_line, last_used_profile->GetPrefs())) { |
| 688 if (!ProcessLoadApps(command_line, cur_dir, last_used_profile)) | 702 if (!ProcessLoadApps(command_line, cur_dir, last_used_profile)) |
| 689 return false; | 703 return false; |
| 690 | 704 |
| 691 // Return early here to avoid opening a browser window. | 705 // Return early here to avoid opening a browser window. |
| 692 // The exception is when there are no browser windows, since we don't want | 706 // The exception is when there are no browser windows, since we don't want |
| 693 // chrome to shut down. | 707 // chrome to shut down. |
| 694 // TODO(jackhou): Do this properly once keep-alive is handled by the | 708 // TODO(jackhou): Do this properly once keep-alive is handled by the |
| 695 // background page of apps. Tracked at http://crbug.com/175381 | 709 // background page of apps. Tracked at http://crbug.com/175381 |
| 696 if (chrome::GetBrowserCount(last_used_profile) != 0) | 710 if (chrome::GetBrowserCount(last_used_profile) != 0) |
| 697 return true; | 711 return true; |
| 698 } | 712 } |
| 699 | 713 |
| 700 // Check for --load-and-launch-app. | 714 // Check for --load-and-launch-app. |
| 701 if (command_line.HasSwitch(apps::kLoadAndLaunchApp) && | 715 if (command_line.HasSwitch(apps::kLoadAndLaunchApp) && |
| 716 !should_show_user_manager && | |
| 702 !IncognitoModePrefs::ShouldLaunchIncognito( | 717 !IncognitoModePrefs::ShouldLaunchIncognito( |
| 703 command_line, last_used_profile->GetPrefs())) { | 718 command_line, last_used_profile->GetPrefs())) { |
| 704 base::CommandLine::StringType path = | 719 base::CommandLine::StringType path = |
| 705 command_line.GetSwitchValueNative(apps::kLoadAndLaunchApp); | 720 command_line.GetSwitchValueNative(apps::kLoadAndLaunchApp); |
| 706 | 721 |
| 707 if (!apps::AppLoadService::Get(last_used_profile)->LoadAndLaunch( | 722 if (!apps::AppLoadService::Get(last_used_profile)->LoadAndLaunch( |
| 708 base::FilePath(path), command_line, cur_dir)) { | 723 base::FilePath(path), command_line, cur_dir)) { |
| 709 return false; | 724 return false; |
| 710 } | 725 } |
| 711 | 726 |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 988 if (!entry->IsSigninRequired()) { | 1003 if (!entry->IsSigninRequired()) { |
| 989 Profile* profile = profile_manager->GetProfile(entry->GetPath()); | 1004 Profile* profile = profile_manager->GetProfile(entry->GetPath()); |
| 990 if (profile) | 1005 if (profile) |
| 991 return profile; | 1006 return profile; |
| 992 } | 1007 } |
| 993 } | 1008 } |
| 994 | 1009 |
| 995 return nullptr; | 1010 return nullptr; |
| 996 } | 1011 } |
| 997 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 1012 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| OLD | NEW |