| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/profiles/profile_window.h" | 5 #include "chrome/browser/profiles/profile_window.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 | 100 |
| 101 // Profile for which the browser should be opened. | 101 // Profile for which the browser should be opened. |
| 102 Profile* profile_; | 102 Profile* profile_; |
| 103 ProfileManager::CreateCallback callback_; | 103 ProfileManager::CreateCallback callback_; |
| 104 | 104 |
| 105 DISALLOW_COPY_AND_ASSIGN(BrowserAddedForProfileObserver); | 105 DISALLOW_COPY_AND_ASSIGN(BrowserAddedForProfileObserver); |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 void OpenBrowserWindowForProfile( | 108 void OpenBrowserWindowForProfile(ProfileManager::CreateCallback callback, |
| 109 ProfileManager::CreateCallback callback, | 109 bool always_create, |
| 110 bool always_create, | 110 bool is_new_profile, |
| 111 bool is_new_profile, | 111 ui::HostDesktopType desktop_type, |
| 112 chrome::HostDesktopType desktop_type, | 112 Profile* profile, |
| 113 Profile* profile, | 113 Profile::CreateStatus status) { |
| 114 Profile::CreateStatus status) { | |
| 115 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 114 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 116 | 115 |
| 117 if (status != Profile::CREATE_STATUS_INITIALIZED) | 116 if (status != Profile::CREATE_STATUS_INITIALIZED) |
| 118 return; | 117 return; |
| 119 | 118 |
| 120 chrome::startup::IsProcessStartup is_process_startup = | 119 chrome::startup::IsProcessStartup is_process_startup = |
| 121 chrome::startup::IS_NOT_PROCESS_STARTUP; | 120 chrome::startup::IS_NOT_PROCESS_STARTUP; |
| 122 chrome::startup::IsFirstRun is_first_run = chrome::startup::IS_NOT_FIRST_RUN; | 121 chrome::startup::IsFirstRun is_first_run = chrome::startup::IS_NOT_FIRST_RUN; |
| 123 | 122 |
| 124 // If this is a brand new profile, then start a first run window. | 123 // If this is a brand new profile, then start a first run window. |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 if (entry->GetUserName() == profile_email) | 252 if (entry->GetUserName() == profile_email) |
| 254 return entry->GetPath(); | 253 return entry->GetPath(); |
| 255 } | 254 } |
| 256 return base::FilePath(); | 255 return base::FilePath(); |
| 257 } | 256 } |
| 258 | 257 |
| 259 void FindOrCreateNewWindowForProfile( | 258 void FindOrCreateNewWindowForProfile( |
| 260 Profile* profile, | 259 Profile* profile, |
| 261 chrome::startup::IsProcessStartup process_startup, | 260 chrome::startup::IsProcessStartup process_startup, |
| 262 chrome::startup::IsFirstRun is_first_run, | 261 chrome::startup::IsFirstRun is_first_run, |
| 263 chrome::HostDesktopType desktop_type, | 262 ui::HostDesktopType desktop_type, |
| 264 bool always_create) { | 263 bool always_create) { |
| 265 #if defined(OS_IOS) | 264 #if defined(OS_IOS) |
| 266 NOTREACHED(); | 265 NOTREACHED(); |
| 267 #else | 266 #else |
| 268 DCHECK(profile); | 267 DCHECK(profile); |
| 269 | 268 |
| 270 if (!always_create) { | 269 if (!always_create) { |
| 271 Browser* browser = chrome::FindTabbedBrowser(profile, false, desktop_type); | 270 Browser* browser = chrome::FindTabbedBrowser(profile, false, desktop_type); |
| 272 if (browser) { | 271 if (browser) { |
| 273 browser->window()->Activate(); | 272 browser->window()->Activate(); |
| 274 return; | 273 return; |
| 275 } | 274 } |
| 276 } | 275 } |
| 277 | 276 |
| 278 content::RecordAction(UserMetricsAction("NewWindow")); | 277 content::RecordAction(UserMetricsAction("NewWindow")); |
| 279 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 278 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 280 StartupBrowserCreator browser_creator; | 279 StartupBrowserCreator browser_creator; |
| 281 browser_creator.LaunchBrowser( | 280 browser_creator.LaunchBrowser( |
| 282 command_line, profile, base::FilePath(), process_startup, is_first_run); | 281 command_line, profile, base::FilePath(), process_startup, is_first_run); |
| 283 #endif // defined(OS_IOS) | 282 #endif // defined(OS_IOS) |
| 284 } | 283 } |
| 285 | 284 |
| 286 void SwitchToProfile(const base::FilePath& path, | 285 void SwitchToProfile(const base::FilePath& path, |
| 287 chrome::HostDesktopType desktop_type, | 286 ui::HostDesktopType desktop_type, |
| 288 bool always_create, | 287 bool always_create, |
| 289 ProfileManager::CreateCallback callback, | 288 ProfileManager::CreateCallback callback, |
| 290 ProfileMetrics::ProfileOpen metric) { | 289 ProfileMetrics::ProfileOpen metric) { |
| 291 ProfileMetrics::LogProfileSwitch(metric, | 290 ProfileMetrics::LogProfileSwitch(metric, |
| 292 g_browser_process->profile_manager(), | 291 g_browser_process->profile_manager(), |
| 293 path); | 292 path); |
| 294 g_browser_process->profile_manager()->CreateProfileAsync( | 293 g_browser_process->profile_manager()->CreateProfileAsync( |
| 295 path, | 294 path, |
| 296 base::Bind(&OpenBrowserWindowForProfile, | 295 base::Bind(&OpenBrowserWindowForProfile, |
| 297 callback, | 296 callback, |
| 298 always_create, | 297 always_create, |
| 299 false, | 298 false, |
| 300 desktop_type), | 299 desktop_type), |
| 301 base::string16(), | 300 base::string16(), |
| 302 base::string16(), | 301 base::string16(), |
| 303 std::string()); | 302 std::string()); |
| 304 } | 303 } |
| 305 | 304 |
| 306 void SwitchToGuestProfile(chrome::HostDesktopType desktop_type, | 305 void SwitchToGuestProfile(ui::HostDesktopType desktop_type, |
| 307 ProfileManager::CreateCallback callback) { | 306 ProfileManager::CreateCallback callback) { |
| 308 const base::FilePath& path = ProfileManager::GetGuestProfilePath(); | 307 const base::FilePath& path = ProfileManager::GetGuestProfilePath(); |
| 309 ProfileMetrics::LogProfileSwitch(ProfileMetrics::SWITCH_PROFILE_GUEST, | 308 ProfileMetrics::LogProfileSwitch(ProfileMetrics::SWITCH_PROFILE_GUEST, |
| 310 g_browser_process->profile_manager(), | 309 g_browser_process->profile_manager(), |
| 311 path); | 310 path); |
| 312 g_browser_process->profile_manager()->CreateProfileAsync( | 311 g_browser_process->profile_manager()->CreateProfileAsync( |
| 313 path, | 312 path, |
| 314 base::Bind(&OpenBrowserWindowForProfile, | 313 base::Bind(&OpenBrowserWindowForProfile, |
| 315 callback, | 314 callback, |
| 316 false, | 315 false, |
| 317 false, | 316 false, |
| 318 desktop_type), | 317 desktop_type), |
| 319 base::string16(), | 318 base::string16(), |
| 320 base::string16(), | 319 base::string16(), |
| 321 std::string()); | 320 std::string()); |
| 322 } | 321 } |
| 323 | 322 |
| 324 bool HasProfileSwitchTargets(Profile* profile) { | 323 bool HasProfileSwitchTargets(Profile* profile) { |
| 325 size_t min_profiles = profile->IsGuestSession() ? 1 : 2; | 324 size_t min_profiles = profile->IsGuestSession() ? 1 : 2; |
| 326 size_t number_of_profiles = | 325 size_t number_of_profiles = |
| 327 g_browser_process->profile_manager()->GetNumberOfProfiles(); | 326 g_browser_process->profile_manager()->GetNumberOfProfiles(); |
| 328 return number_of_profiles >= min_profiles; | 327 return number_of_profiles >= min_profiles; |
| 329 } | 328 } |
| 330 | 329 |
| 331 void CreateAndSwitchToNewProfile(chrome::HostDesktopType desktop_type, | 330 void CreateAndSwitchToNewProfile(ui::HostDesktopType desktop_type, |
| 332 ProfileManager::CreateCallback callback, | 331 ProfileManager::CreateCallback callback, |
| 333 ProfileMetrics::ProfileAdd metric) { | 332 ProfileMetrics::ProfileAdd metric) { |
| 334 ProfileInfoCache& cache = | 333 ProfileInfoCache& cache = |
| 335 g_browser_process->profile_manager()->GetProfileInfoCache(); | 334 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 336 | 335 |
| 337 int placeholder_avatar_index = profiles::GetPlaceholderAvatarIndex(); | 336 int placeholder_avatar_index = profiles::GetPlaceholderAvatarIndex(); |
| 338 ProfileManager::CreateMultiProfileAsync( | 337 ProfileManager::CreateMultiProfileAsync( |
| 339 cache.ChooseNameForNewProfile(placeholder_avatar_index), | 338 cache.ChooseNameForNewProfile(placeholder_avatar_index), |
| 340 base::UTF8ToUTF16(profiles::GetDefaultAvatarIconUrl( | 339 base::UTF8ToUTF16(profiles::GetDefaultAvatarIconUrl( |
| 341 placeholder_avatar_index)), | 340 placeholder_avatar_index)), |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 PrefService* local_state = g_browser_process->local_state(); | 553 PrefService* local_state = g_browser_process->local_state(); |
| 555 const bool dismissed = local_state->GetBoolean( | 554 const bool dismissed = local_state->GetBoolean( |
| 556 prefs::kProfileAvatarRightClickTutorialDismissed); | 555 prefs::kProfileAvatarRightClickTutorialDismissed); |
| 557 | 556 |
| 558 // Don't show the tutorial if it's already been dismissed or if right-clicking | 557 // Don't show the tutorial if it's already been dismissed or if right-clicking |
| 559 // wouldn't show any targets. | 558 // wouldn't show any targets. |
| 560 return !dismissed && HasProfileSwitchTargets(profile); | 559 return !dismissed && HasProfileSwitchTargets(profile); |
| 561 } | 560 } |
| 562 | 561 |
| 563 } // namespace profiles | 562 } // namespace profiles |
| OLD | NEW |