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 // Returns true if we should show the user manager on startup. |
|
Peter Kasting
2016/12/22 00:26:33
This comment is inaccurate. How about:
// Return
zmin
2016/12/22 18:49:45
Done.
| |
| 266 // if the last used profile was the guest or system profile. | 266 bool IsProfileAvailable(Profile* profile, |
| 267 // Returns true if the User Manager was shown, false otherwise. | 267 bool allow_incognito, |
| 268 bool ShowUserManagerOnStartupIfNeeded( | 268 const base::CommandLine& command_line) { |
| 269 Profile* last_used_profile, const base::CommandLine& command_line) { | 269 // Profiles are not available if browser needs to be launched with incognito |
| 270 // mode with command line options that do not compatible with incognito mode. | |
|
Peter Kasting
2016/12/22 00:26:33
Nit: do -> are
zmin
2016/12/22 18:49:45
Done.
| |
| 271 if (!allow_incognito && IncognitoModePrefs::ShouldLaunchIncognito( | |
| 272 command_line, profile->GetPrefs())) { | |
| 273 return false; | |
| 274 } | |
|
Peter Kasting
2016/12/22 00:26:33
Nit: I don't think you should put this conditional
zmin
2016/12/22 18:49:45
Done.
| |
| 270 #if defined(OS_CHROMEOS) | 275 #if defined(OS_CHROMEOS) |
| 271 // ChromeOS never shows the User Manager on startup. | 276 // User will always choose and login profile before using Chrome on ChromeOS. |
|
Peter Kasting
2016/12/22 00:26:33
Nit: Grammar; how about: "On ChromeOS, the user ha
zmin
2016/12/22 18:49:45
Done.
| |
| 272 return false; | 277 return true; |
| 273 #else | 278 #else |
| 279 // Profiles that require signin are not available. | |
| 274 ProfileAttributesEntry* entry = nullptr; | 280 ProfileAttributesEntry* entry = nullptr; |
| 275 bool has_entry = | 281 if (g_browser_process->profile_manager() |
| 276 g_browser_process->profile_manager() | |
| 277 ->GetProfileAttributesStorage() | 282 ->GetProfileAttributesStorage() |
| 278 .GetProfileAttributesWithPath(last_used_profile->GetPath(), &entry); | 283 .GetProfileAttributesWithPath(profile->GetPath(), &entry) && |
| 284 entry->IsSigninRequired()) { | |
| 285 return false; | |
| 286 } | |
| 279 | 287 |
| 280 if (!has_entry || !entry->IsSigninRequired()) { | 288 // Guest or system profiles are not available unless a separate process |
| 281 // Signin is not required. However, guest, system or locked profiles cannot | 289 // already has a window open for the profile, |
|
Peter Kasting
2016/12/22 00:26:33
Nit: , -> .
zmin
2016/12/22 18:49:45
Done.
| |
| 282 // be re-opened on startup. The only exception is if there's already a Guest | 290 return (!profile->IsGuestSession() && !profile->IsSystemProfile()) || |
| 283 // window open in a separate process (for example, launching a new browser | 291 (chrome::GetBrowserCount(profile->GetOffTheRecordProfile()) > 0); |
| 284 // after clicking on a downloaded file in Guest mode). | 292 #endif |
| 285 if ((!last_used_profile->IsGuestSession() && | 293 } |
| 286 !last_used_profile->IsSystemProfile()) || | 294 |
| 287 (chrome::GetBrowserCount(last_used_profile->GetOffTheRecordProfile()) > | 295 // Returns whether the User Manager was shown. |
| 288 0)) { | 296 bool ShowUserManagerOnStartupIfNeeded(Profile* last_used_profile, |
| 289 return false; | 297 const base::CommandLine& command_line) { |
| 290 } | 298 if (IsProfileAvailable(last_used_profile, false, command_line)) |
| 291 } | 299 return false; |
| 292 | 300 |
| 293 // Show the User Manager. | 301 // Show the User Manager. |
| 294 profiles::UserManagerAction action = | 302 profiles::UserManagerAction action = |
| 295 command_line.HasSwitch(switches::kShowAppList) ? | 303 command_line.HasSwitch(switches::kShowAppList) ? |
| 296 profiles::USER_MANAGER_SELECT_PROFILE_APP_LAUNCHER : | 304 profiles::USER_MANAGER_SELECT_PROFILE_APP_LAUNCHER : |
| 297 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION; | 305 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION; |
| 298 UserManager::Show( | 306 UserManager::Show( |
| 299 base::FilePath(), profiles::USER_MANAGER_NO_TUTORIAL, action); | 307 base::FilePath(), profiles::USER_MANAGER_NO_TUTORIAL, action); |
| 300 return true; | 308 return true; |
| 301 #endif | |
| 302 } | 309 } |
| 303 | 310 |
| 304 } // namespace | 311 } // namespace |
| 305 | 312 |
| 306 StartupBrowserCreator::StartupBrowserCreator() | 313 StartupBrowserCreator::StartupBrowserCreator() |
| 307 : is_default_browser_dialog_suppressed_(false), | 314 : is_default_browser_dialog_suppressed_(false), |
| 308 show_main_browser_window_(true) {} | 315 show_main_browser_window_(true) {} |
| 309 | 316 |
| 310 StartupBrowserCreator::~StartupBrowserCreator() {} | 317 StartupBrowserCreator::~StartupBrowserCreator() {} |
| 311 | 318 |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 580 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 587 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 581 TRACE_EVENT0("startup", "StartupBrowserCreator::ProcessCmdLineImpl"); | 588 TRACE_EVENT0("startup", "StartupBrowserCreator::ProcessCmdLineImpl"); |
| 582 | 589 |
| 583 DCHECK(last_used_profile); | 590 DCHECK(last_used_profile); |
| 584 if (process_startup) { | 591 if (process_startup) { |
| 585 if (command_line.HasSwitch(switches::kDisablePromptOnRepost)) | 592 if (command_line.HasSwitch(switches::kDisablePromptOnRepost)) |
| 586 content::NavigationController::DisablePromptOnRepost(); | 593 content::NavigationController::DisablePromptOnRepost(); |
| 587 } | 594 } |
| 588 | 595 |
| 589 bool silent_launch = false; | 596 bool silent_launch = false; |
| 597 bool is_profile_available = | |
|
Peter Kasting
2016/12/22 00:26:33
Nit: Maybe call this |can_use_last_profile|, which
zmin
2016/12/22 18:49:45
Done.
| |
| 598 IsProfileAvailable(last_used_profile, true, command_line); | |
| 590 | 599 |
| 591 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) | 600 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 592 // If we are just displaying a print dialog we shouldn't open browser | 601 // If we are just displaying a print dialog we shouldn't open browser |
| 593 // windows. | 602 // windows. |
| 594 if (command_line.HasSwitch(switches::kCloudPrintFile) && | 603 if (command_line.HasSwitch(switches::kCloudPrintFile) && |
| 604 is_profile_available && | |
| 595 print_dialog_cloud::CreatePrintDialogFromCommandLine(last_used_profile, | 605 print_dialog_cloud::CreatePrintDialogFromCommandLine(last_used_profile, |
| 596 command_line)) { | 606 command_line)) { |
| 597 silent_launch = true; | 607 silent_launch = true; |
| 598 } | 608 } |
| 599 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) | 609 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 600 | 610 |
| 601 if (command_line.HasSwitch(switches::kExplicitlyAllowedPorts)) { | 611 if (command_line.HasSwitch(switches::kExplicitlyAllowedPorts)) { |
| 602 std::string allowed_ports = | 612 std::string allowed_ports = |
| 603 command_line.GetSwitchValueASCII(switches::kExplicitlyAllowedPorts); | 613 command_line.GetSwitchValueASCII(switches::kExplicitlyAllowedPorts); |
| 604 net::SetExplicitlyAllowedPorts(allowed_ports); | 614 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 | 686 // If --no-startup-window is specified and Chrome is already running then do |
| 677 // not open a new window. | 687 // not open a new window. |
| 678 if (!process_startup && command_line.HasSwitch(switches::kNoStartupWindow)) | 688 if (!process_startup && command_line.HasSwitch(switches::kNoStartupWindow)) |
| 679 silent_launch = true; | 689 silent_launch = true; |
| 680 | 690 |
| 681 // If we don't want to launch a new browser window or tab we are done here. | 691 // If we don't want to launch a new browser window or tab we are done here. |
| 682 if (silent_launch) | 692 if (silent_launch) |
| 683 return true; | 693 return true; |
| 684 | 694 |
| 685 if (command_line.HasSwitch(extensions::switches::kLoadApps) && | 695 if (command_line.HasSwitch(extensions::switches::kLoadApps) && |
| 686 !IncognitoModePrefs::ShouldLaunchIncognito( | 696 is_profile_available) { |
| 687 command_line, last_used_profile->GetPrefs())) { | |
| 688 if (!ProcessLoadApps(command_line, cur_dir, last_used_profile)) | 697 if (!ProcessLoadApps(command_line, cur_dir, last_used_profile)) |
| 689 return false; | 698 return false; |
| 690 | 699 |
| 691 // Return early here to avoid opening a browser window. | 700 // Return early here to avoid opening a browser window. |
| 692 // The exception is when there are no browser windows, since we don't want | 701 // The exception is when there are no browser windows, since we don't want |
| 693 // chrome to shut down. | 702 // chrome to shut down. |
| 694 // TODO(jackhou): Do this properly once keep-alive is handled by the | 703 // TODO(jackhou): Do this properly once keep-alive is handled by the |
| 695 // background page of apps. Tracked at http://crbug.com/175381 | 704 // background page of apps. Tracked at http://crbug.com/175381 |
| 696 if (chrome::GetBrowserCount(last_used_profile) != 0) | 705 if (chrome::GetBrowserCount(last_used_profile) != 0) |
| 697 return true; | 706 return true; |
| 698 } | 707 } |
| 699 | 708 |
| 700 // Check for --load-and-launch-app. | 709 // Check for --load-and-launch-app. |
| 701 if (command_line.HasSwitch(apps::kLoadAndLaunchApp) && | 710 if (command_line.HasSwitch(apps::kLoadAndLaunchApp) && is_profile_available) { |
| 702 !IncognitoModePrefs::ShouldLaunchIncognito( | |
| 703 command_line, last_used_profile->GetPrefs())) { | |
| 704 base::CommandLine::StringType path = | 711 base::CommandLine::StringType path = |
| 705 command_line.GetSwitchValueNative(apps::kLoadAndLaunchApp); | 712 command_line.GetSwitchValueNative(apps::kLoadAndLaunchApp); |
| 706 | 713 |
| 707 if (!apps::AppLoadService::Get(last_used_profile)->LoadAndLaunch( | 714 if (!apps::AppLoadService::Get(last_used_profile)->LoadAndLaunch( |
| 708 base::FilePath(path), command_line, cur_dir)) { | 715 base::FilePath(path), command_line, cur_dir)) { |
| 709 return false; | 716 return false; |
| 710 } | 717 } |
| 711 | 718 |
| 712 // Return early here since we don't want to open a browser window. | 719 // 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 | 720 // 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 Loading... | |
| 988 if (!entry->IsSigninRequired()) { | 995 if (!entry->IsSigninRequired()) { |
| 989 Profile* profile = profile_manager->GetProfile(entry->GetPath()); | 996 Profile* profile = profile_manager->GetProfile(entry->GetPath()); |
| 990 if (profile) | 997 if (profile) |
| 991 return profile; | 998 return profile; |
| 992 } | 999 } |
| 993 } | 1000 } |
| 994 | 1001 |
| 995 return nullptr; | 1002 return nullptr; |
| 996 } | 1003 } |
| 997 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 1004 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| OLD | NEW |