| 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 <set> | 10 #include <set> |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 NOTREACHED(); | 159 NOTREACHED(); |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 | 162 |
| 163 bool HasBeenLaunched(const Profile* profile) const { | 163 bool HasBeenLaunched(const Profile* profile) const { |
| 164 return launched_profiles_.find(profile) != launched_profiles_.end(); | 164 return launched_profiles_.find(profile) != launched_profiles_.end(); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void AddLaunched(Profile* profile) { | 167 void AddLaunched(Profile* profile) { |
| 168 launched_profiles_.insert(profile); | 168 launched_profiles_.insert(profile); |
| 169 // Since the startup code only executes for browsers launched in | 169 if (chrome::FindBrowserWithProfile(profile)) { |
| 170 // desktop mode, i.e., HOST_DESKTOP_TYPE_NATIVE. Ash should never get here. | |
| 171 if (chrome::FindBrowserWithProfile(profile, | |
| 172 chrome::HOST_DESKTOP_TYPE_NATIVE)) { | |
| 173 // A browser may get opened before we get initialized (e.g., in tests), | 170 // A browser may get opened before we get initialized (e.g., in tests), |
| 174 // so we never see the NOTIFICATION_BROWSER_WINDOW_READY for it. | 171 // so we never see the NOTIFICATION_BROWSER_WINDOW_READY for it. |
| 175 opened_profiles_.insert(profile); | 172 opened_profiles_.insert(profile); |
| 176 } | 173 } |
| 177 } | 174 } |
| 178 | 175 |
| 179 void Clear() { | 176 void Clear() { |
| 180 launched_profiles_.clear(); | 177 launched_profiles_.clear(); |
| 181 opened_profiles_.clear(); | 178 opened_profiles_.clear(); |
| 182 } | 179 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 209 // Avoid posting more than once before ActivateProfile gets called. | 206 // Avoid posting more than once before ActivateProfile gets called. |
| 210 registrar_.Remove(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 207 registrar_.Remove(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
| 211 content::NotificationService::AllSources()); | 208 content::NotificationService::AllSources()); |
| 212 registrar_.Remove(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 209 registrar_.Remove(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 213 content::NotificationService::AllSources()); | 210 content::NotificationService::AllSources()); |
| 214 } | 211 } |
| 215 | 212 |
| 216 void ActivateProfile() { | 213 void ActivateProfile() { |
| 217 // We need to test again, in case the profile got deleted in the mean time. | 214 // We need to test again, in case the profile got deleted in the mean time. |
| 218 if (profile_to_activate_) { | 215 if (profile_to_activate_) { |
| 219 Browser* browser = chrome::FindBrowserWithProfile( | 216 Browser* browser = chrome::FindBrowserWithProfile(profile_to_activate_); |
| 220 profile_to_activate_, chrome::HOST_DESKTOP_TYPE_NATIVE); | |
| 221 // |profile| may never get launched, e.g., if it only had | 217 // |profile| may never get launched, e.g., if it only had |
| 222 // incognito Windows and one of them was used to exit Chrome. | 218 // incognito Windows and one of them was used to exit Chrome. |
| 223 // So it won't have a browser in that case. | 219 // So it won't have a browser in that case. |
| 224 if (browser) | 220 if (browser) |
| 225 browser->window()->Activate(); | 221 browser->window()->Activate(); |
| 226 // No need try to activate this profile again. | 222 // No need try to activate this profile again. |
| 227 profile_to_activate_ = NULL; | 223 profile_to_activate_ = NULL; |
| 228 } | 224 } |
| 229 // Assign true here, even if no browser was actually activated, so that | 225 // Assign true here, even if no browser was actually activated, so that |
| 230 // the test can stop waiting, and fail gracefully when needed. | 226 // the test can stop waiting, and fail gracefully when needed. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 last_used_profile->GetPath()); | 275 last_used_profile->GetPath()); |
| 280 | 276 |
| 281 if (profile_index == std::string::npos || | 277 if (profile_index == std::string::npos || |
| 282 !profile_info.ProfileIsSigninRequiredAtIndex(profile_index)) { | 278 !profile_info.ProfileIsSigninRequiredAtIndex(profile_index)) { |
| 283 // Signin is not required. However, guest, system or locked profiles cannot | 279 // Signin is not required. However, guest, system or locked profiles cannot |
| 284 // be re-opened on startup. The only exception is if there's already a Guest | 280 // be re-opened on startup. The only exception is if there's already a Guest |
| 285 // window open in a separate process (for example, launching a new browser | 281 // window open in a separate process (for example, launching a new browser |
| 286 // after clicking on a downloaded file in Guest mode). | 282 // after clicking on a downloaded file in Guest mode). |
| 287 if ((!last_used_profile->IsGuestSession() && | 283 if ((!last_used_profile->IsGuestSession() && |
| 288 !last_used_profile->IsSystemProfile()) || | 284 !last_used_profile->IsSystemProfile()) || |
| 289 (chrome::GetTotalBrowserCountForProfile( | 285 (chrome::GetBrowserCount(last_used_profile->GetOffTheRecordProfile()) > |
| 290 last_used_profile->GetOffTheRecordProfile()) > 0)) { | 286 0)) { |
| 291 return false; | 287 return false; |
| 292 } | 288 } |
| 293 } | 289 } |
| 294 | 290 |
| 295 // Show the User Manager. | 291 // Show the User Manager. |
| 296 profiles::UserManagerProfileSelected action = | 292 profiles::UserManagerProfileSelected action = |
| 297 command_line.HasSwitch(switches::kShowAppList) ? | 293 command_line.HasSwitch(switches::kShowAppList) ? |
| 298 profiles::USER_MANAGER_SELECT_PROFILE_APP_LAUNCHER : | 294 profiles::USER_MANAGER_SELECT_PROFILE_APP_LAUNCHER : |
| 299 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION; | 295 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION; |
| 300 UserManager::Show( | 296 UserManager::Show( |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 !IncognitoModePrefs::ShouldLaunchIncognito( | 716 !IncognitoModePrefs::ShouldLaunchIncognito( |
| 721 command_line, last_used_profile->GetPrefs())) { | 717 command_line, last_used_profile->GetPrefs())) { |
| 722 if (!ProcessLoadApps(command_line, cur_dir, last_used_profile)) | 718 if (!ProcessLoadApps(command_line, cur_dir, last_used_profile)) |
| 723 return false; | 719 return false; |
| 724 | 720 |
| 725 // Return early here to avoid opening a browser window. | 721 // Return early here to avoid opening a browser window. |
| 726 // The exception is when there are no browser windows, since we don't want | 722 // The exception is when there are no browser windows, since we don't want |
| 727 // chrome to shut down. | 723 // chrome to shut down. |
| 728 // TODO(jackhou): Do this properly once keep-alive is handled by the | 724 // TODO(jackhou): Do this properly once keep-alive is handled by the |
| 729 // background page of apps. Tracked at http://crbug.com/175381 | 725 // background page of apps. Tracked at http://crbug.com/175381 |
| 730 if (chrome::GetTotalBrowserCountForProfile(last_used_profile) != 0) | 726 if (chrome::GetBrowserCount(last_used_profile) != 0) |
| 731 return true; | 727 return true; |
| 732 } | 728 } |
| 733 | 729 |
| 734 // Check for --load-and-launch-app. | 730 // Check for --load-and-launch-app. |
| 735 if (command_line.HasSwitch(apps::kLoadAndLaunchApp) && | 731 if (command_line.HasSwitch(apps::kLoadAndLaunchApp) && |
| 736 !IncognitoModePrefs::ShouldLaunchIncognito( | 732 !IncognitoModePrefs::ShouldLaunchIncognito( |
| 737 command_line, last_used_profile->GetPrefs())) { | 733 command_line, last_used_profile->GetPrefs())) { |
| 738 base::CommandLine::StringType path = | 734 base::CommandLine::StringType path = |
| 739 command_line.GetSwitchValueNative(apps::kLoadAndLaunchApp); | 735 command_line.GetSwitchValueNative(apps::kLoadAndLaunchApp); |
| 740 | 736 |
| 741 if (!apps::AppLoadService::Get(last_used_profile)->LoadAndLaunch( | 737 if (!apps::AppLoadService::Get(last_used_profile)->LoadAndLaunch( |
| 742 base::FilePath(path), command_line, cur_dir)) { | 738 base::FilePath(path), command_line, cur_dir)) { |
| 743 return false; | 739 return false; |
| 744 } | 740 } |
| 745 | 741 |
| 746 // Return early here since we don't want to open a browser window. | 742 // Return early here since we don't want to open a browser window. |
| 747 // The exception is when there are no browser windows, since we don't want | 743 // The exception is when there are no browser windows, since we don't want |
| 748 // chrome to shut down. | 744 // chrome to shut down. |
| 749 // TODO(jackhou): Do this properly once keep-alive is handled by the | 745 // TODO(jackhou): Do this properly once keep-alive is handled by the |
| 750 // background page of apps. Tracked at http://crbug.com/175381 | 746 // background page of apps. Tracked at http://crbug.com/175381 |
| 751 if (chrome::GetTotalBrowserCountForProfile(last_used_profile) != 0) | 747 if (chrome::GetBrowserCount(last_used_profile) != 0) |
| 752 return true; | 748 return true; |
| 753 } | 749 } |
| 754 | 750 |
| 755 #if defined(OS_WIN) | 751 #if defined(OS_WIN) |
| 756 // Intercept a specific url when setting the default browser asynchronously. | 752 // Intercept a specific url when setting the default browser asynchronously. |
| 757 // This only happens on Windows 10+. | 753 // This only happens on Windows 10+. |
| 758 if (g_default_browser_callback) { | 754 if (g_default_browser_callback) { |
| 759 base::CommandLine::StringType default_browser_url_( | 755 base::CommandLine::StringType default_browser_url_( |
| 760 kSetDefaultBrowserHelpUrl); | 756 kSetDefaultBrowserHelpUrl); |
| 761 for (const auto& arg : command_line.GetArgs()) { | 757 for (const auto& arg : command_line.GetArgs()) { |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 // If we are showing the app list then chrome isn't shown so load the app | 932 // If we are showing the app list then chrome isn't shown so load the app |
| 937 // list's profile rather than chrome's. | 933 // list's profile rather than chrome's. |
| 938 if (command_line.HasSwitch(switches::kShowAppList)) { | 934 if (command_line.HasSwitch(switches::kShowAppList)) { |
| 939 return AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)-> | 935 return AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)-> |
| 940 GetProfilePath(user_data_dir); | 936 GetProfilePath(user_data_dir); |
| 941 } | 937 } |
| 942 | 938 |
| 943 return g_browser_process->profile_manager()->GetLastUsedProfileDir( | 939 return g_browser_process->profile_manager()->GetLastUsedProfileDir( |
| 944 user_data_dir); | 940 user_data_dir); |
| 945 } | 941 } |
| OLD | NEW |