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

Side by Side Diff: chrome/browser/profiles/profile_manager.cc

Issue 271533004: Turning on MultiProfile by default for ChromeOS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months 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 | Annotate | Revision Log
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/profiles/profile_manager.h" 5 #include "chrome/browser/profiles/profile_manager.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 #if defined(OS_WIN) 76 #if defined(OS_WIN)
77 #include "base/win/metro.h" 77 #include "base/win/metro.h"
78 #include "chrome/installer/util/browser_distribution.h" 78 #include "chrome/installer/util/browser_distribution.h"
79 #endif 79 #endif
80 80
81 #if defined(OS_CHROMEOS) 81 #if defined(OS_CHROMEOS)
82 #include "chrome/browser/browser_process_platform_part_chromeos.h" 82 #include "chrome/browser/browser_process_platform_part_chromeos.h"
83 #include "chrome/browser/chromeos/login/user.h" 83 #include "chrome/browser/chromeos/login/user.h"
84 #include "chrome/browser/chromeos/login/user_manager.h" 84 #include "chrome/browser/chromeos/login/user_manager.h"
85 #include "chrome/browser/chromeos/profiles/profile_helper.h" 85 #include "chrome/browser/chromeos/profiles/profile_helper.h"
86 #include "chrome/browser/profiles/profiles_state.h"
86 #include "chromeos/chromeos_switches.h" 87 #include "chromeos/chromeos_switches.h"
87 #include "chromeos/dbus/cryptohome_client.h" 88 #include "chromeos/dbus/cryptohome_client.h"
88 #include "chromeos/dbus/dbus_thread_manager.h" 89 #include "chromeos/dbus/dbus_thread_manager.h"
89 #endif 90 #endif
90 91
91 using base::UserMetricsAction; 92 using base::UserMetricsAction;
92 using content::BrowserThread; 93 using content::BrowserThread;
93 94
94 namespace { 95 namespace {
95 96
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 #else 320 #else
320 return profile_manager->GetActiveUserOrOffTheRecordProfileFromPath( 321 return profile_manager->GetActiveUserOrOffTheRecordProfileFromPath(
321 profile_manager->user_data_dir()); 322 profile_manager->user_data_dir());
322 #endif 323 #endif
323 } 324 }
324 325
325 // static 326 // static
326 Profile* ProfileManager::GetActiveUserProfile() { 327 Profile* ProfileManager::GetActiveUserProfile() {
327 ProfileManager* profile_manager = g_browser_process->profile_manager(); 328 ProfileManager* profile_manager = g_browser_process->profile_manager();
328 #if defined(OS_CHROMEOS) 329 #if defined(OS_CHROMEOS)
329 if (!chromeos::UserManager::IsMultipleProfilesAllowed() || 330 if (!profile_manager->IsLoggedIn() ||
330 !profile_manager->IsLoggedIn() || 331 !chromeos::UserManager::IsInitialized()) {
331 !chromeos::UserManager::IsInitialized())
332 return profile_manager->GetActiveUserOrOffTheRecordProfileFromPath( 332 return profile_manager->GetActiveUserOrOffTheRecordProfileFromPath(
333 profile_manager->user_data_dir()); 333 profile_manager->user_data_dir());
334 }
335
334 chromeos::UserManager* manager = chromeos::UserManager::Get(); 336 chromeos::UserManager* manager = chromeos::UserManager::Get();
335 const chromeos::User* user = manager->GetActiveUser(); 337 const chromeos::User* user = manager->GetActiveUser();
336 // To avoid an endless loop (crbug.com/334098) we have to additionally check 338 // To avoid an endless loop (crbug.com/334098) we have to additionally check
337 // if the profile of the user was already created. If the profile was not yet 339 // if the profile of the user was already created. If the profile was not yet
338 // created we load the profile using the profile directly. 340 // created we load the profile using the profile directly.
339 // TODO: This should be cleaned up with the new profile manager. 341 // TODO: This should be cleaned up with the new profile manager.
340 if (user && user->is_profile_created()) 342 if (user && user->is_profile_created())
341 return manager->GetProfileByUser(user); 343 return manager->GetProfileByUser(user);
342 #endif 344 #endif
343 return profile_manager->GetActiveUserOrOffTheRecordProfileFromPath( 345 return profile_manager->GetActiveUserOrOffTheRecordProfileFromPath(
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 449 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
448 if (logged_in_) { 450 if (logged_in_) {
449 base::FilePath profile_dir; 451 base::FilePath profile_dir;
450 // If the user has logged in, pick up the new profile. 452 // If the user has logged in, pick up the new profile.
451 if (command_line.HasSwitch(chromeos::switches::kLoginProfile)) { 453 if (command_line.HasSwitch(chromeos::switches::kLoginProfile)) {
452 // TODO(nkostylev): Remove this code completely once we eliminate 454 // TODO(nkostylev): Remove this code completely once we eliminate
453 // legacy --login-profile=user switch and enable multi-profiles on CrOS 455 // legacy --login-profile=user switch and enable multi-profiles on CrOS
454 // by default. http://crbug.com/294628 456 // by default. http://crbug.com/294628
455 profile_dir = chromeos::ProfileHelper:: 457 profile_dir = chromeos::ProfileHelper::
456 GetProfileDirByLegacyLoginProfileSwitch(); 458 GetProfileDirByLegacyLoginProfileSwitch();
457 } else if (!command_line.HasSwitch(switches::kMultiProfiles)) {
458 // We should never be logged in with no profile dir unless
459 // multi-profiles are enabled.
460 // In that case profile dir will be defined by user_id hash.
461 NOTREACHED();
462 return base::FilePath("");
463 } 459 }
464 // In case of multi-profiles ignore --login-profile switch. 460 // In case of multi-profiles ignore --login-profile switch.
465 // TODO(nkostylev): Some cases like Guest mode will have empty username_hash 461 // TODO(nkostylev): Some cases like Guest mode will have empty username_hash
466 // so default kLoginProfile dir will be used. 462 // so default kLoginProfile dir will be used.
467 std::string user_id_hash = g_browser_process->platform_part()-> 463 std::string user_id_hash = g_browser_process->platform_part()->
468 profile_helper()->active_user_id_hash(); 464 profile_helper()->active_user_id_hash();
469 if (command_line.HasSwitch(switches::kMultiProfiles) && 465 if (!user_id_hash.empty()) {
470 !user_id_hash.empty()) {
471 profile_dir = g_browser_process->platform_part()-> 466 profile_dir = g_browser_process->platform_part()->
472 profile_helper()->GetActiveUserProfileDir(); 467 profile_helper()->GetActiveUserProfileDir();
473 } 468 }
474 relative_profile_dir = relative_profile_dir.Append(profile_dir); 469 relative_profile_dir = relative_profile_dir.Append(profile_dir);
475 return relative_profile_dir; 470 return relative_profile_dir;
476 } 471 }
477 #endif 472 #endif
478 // TODO(mirandac): should not automatically be default profile. 473 // TODO(mirandac): should not automatically be default profile.
479 relative_profile_dir = 474 relative_profile_dir =
480 relative_profile_dir.AppendASCII(chrome::kInitialProfile); 475 relative_profile_dir.AppendASCII(chrome::kInitialProfile);
481 return relative_profile_dir; 476 return relative_profile_dir;
482 } 477 }
483 478
484 Profile* ProfileManager::GetLastUsedProfile( 479 Profile* ProfileManager::GetLastUsedProfile(
485 const base::FilePath& user_data_dir) { 480 const base::FilePath& user_data_dir) {
486 #if defined(OS_CHROMEOS) 481 #if defined(OS_CHROMEOS)
487 // Use default login profile if user has not logged in yet. 482 // Use default login profile if user has not logged in yet.
488 if (!logged_in_) { 483 if (!logged_in_) {
489 return GetActiveUserOrOffTheRecordProfileFromPath(user_data_dir); 484 return GetActiveUserOrOffTheRecordProfileFromPath(user_data_dir);
490 } else { 485 } else {
491 // CrOS multi-profiles implementation is different so GetLastUsedProfile 486 // CrOS multi-profiles implementation is different so GetLastUsedProfile
492 // has custom implementation too. 487 // has custom implementation too.
493 base::FilePath profile_dir; 488 base::FilePath profile_dir;
494 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 489 // In case of multi-profiles we ignore "last used profile" preference
495 if (command_line.HasSwitch(switches::kMultiProfiles)) { 490 // since it may refer to profile that has been in use in previous session.
496 // In case of multi-profiles we ignore "last used profile" preference 491 // That profile dir may not be mounted in this session so instead return
497 // since it may refer to profile that has been in use in previous session. 492 // active profile from current session.
498 // That profile dir may not be mounted in this session so instead return 493 profile_dir = g_browser_process->platform_part()->
499 // active profile from current session. 494 profile_helper()->GetActiveUserProfileDir();
500 profile_dir = g_browser_process->platform_part()->
501 profile_helper()->GetActiveUserProfileDir();
502 } else {
503 // For legacy (not multi-profiles) implementation always default to
504 // --login-profile value.
505 profile_dir =
506 chromeos::ProfileHelper::GetProfileDirByLegacyLoginProfileSwitch();
507 }
508 495
509 base::FilePath profile_path(user_data_dir); 496 base::FilePath profile_path(user_data_dir);
510 Profile* profile = GetProfile(profile_path.Append(profile_dir)); 497 Profile* profile = GetProfile(profile_path.Append(profile_dir));
511 return profile->IsGuestSession() ? profile->GetOffTheRecordProfile() : 498 return profile->IsGuestSession() ? profile->GetOffTheRecordProfile() :
512 profile; 499 profile;
513 } 500 }
514 #endif 501 #endif
515 502
516 return GetProfile(GetLastUsedProfileDir(user_data_dir)); 503 return GetProfile(GetLastUsedProfileDir(user_data_dir));
517 } 504 }
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 last_non_managed_profile_path.BaseName().MaybeAsASCII()); 1273 last_non_managed_profile_path.BaseName().MaybeAsASCII());
1287 FinishDeletingProfile(profile_to_delete_path); 1274 FinishDeletingProfile(profile_to_delete_path);
1288 } 1275 }
1289 } 1276 }
1290 } 1277 }
1291 #endif 1278 #endif
1292 1279
1293 ProfileManagerWithoutInit::ProfileManagerWithoutInit( 1280 ProfileManagerWithoutInit::ProfileManagerWithoutInit(
1294 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { 1281 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) {
1295 } 1282 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_io_data.cc ('k') | chrome/browser/profiles/profile_manager_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698