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/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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 #include "chrome/browser/ui/browser_window.h" | 60 #include "chrome/browser/ui/browser_window.h" |
61 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 61 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
62 #endif // !defined (OS_IOS) | 62 #endif // !defined (OS_IOS) |
63 | 63 |
64 #if defined(OS_WIN) | 64 #if defined(OS_WIN) |
65 #include "base/win/metro.h" | 65 #include "base/win/metro.h" |
66 #include "chrome/installer/util/browser_distribution.h" | 66 #include "chrome/installer/util/browser_distribution.h" |
67 #endif | 67 #endif |
68 | 68 |
69 #if defined(OS_CHROMEOS) | 69 #if defined(OS_CHROMEOS) |
70 #include "base/chromeos/chromeos_version.h" | |
71 #include "chrome/browser/chromeos/login/user.h" | |
70 #include "chrome/browser/chromeos/login/user_manager.h" | 72 #include "chrome/browser/chromeos/login/user_manager.h" |
71 #include "chromeos/chromeos_switches.h" | 73 #include "chromeos/chromeos_switches.h" |
72 #include "chromeos/dbus/cryptohome_client.h" | 74 #include "chromeos/dbus/cryptohome_client.h" |
73 #include "chromeos/dbus/dbus_thread_manager.h" | 75 #include "chromeos/dbus/dbus_thread_manager.h" |
74 #endif | 76 #endif |
75 | 77 |
76 using content::BrowserThread; | 78 using content::BrowserThread; |
77 using content::UserMetricsAction; | 79 using content::UserMetricsAction; |
78 | 80 |
79 namespace { | 81 namespace { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 #if defined(OS_CHROMEOS) | 185 #if defined(OS_CHROMEOS) |
184 void CheckCryptohomeIsMounted(chromeos::DBusMethodCallStatus call_status, | 186 void CheckCryptohomeIsMounted(chromeos::DBusMethodCallStatus call_status, |
185 bool is_mounted) { | 187 bool is_mounted) { |
186 if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS) { | 188 if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS) { |
187 LOG(ERROR) << "IsMounted call failed."; | 189 LOG(ERROR) << "IsMounted call failed."; |
188 return; | 190 return; |
189 } | 191 } |
190 if (!is_mounted) | 192 if (!is_mounted) |
191 LOG(ERROR) << "Cryptohome is not mounted."; | 193 LOG(ERROR) << "Cryptohome is not mounted."; |
192 } | 194 } |
195 | |
196 // TODO(nkostylev): Remove this hack when http://crbug.com/224291 is fixed. | |
197 // Now user homedirs are mounted to /home/user which is different from | |
198 // user data dir (/home/chronos). | |
199 base::FilePath GetChromeOSProfileDir(const base::FilePath& path) { | |
200 base::FilePath profile_dir(FILE_PATH_LITERAL("/home/user/")); | |
201 profile_dir = profile_dir.Append(path); | |
202 return profile_dir; | |
203 } | |
193 #endif | 204 #endif |
194 | 205 |
195 } // namespace | 206 } // namespace |
196 | 207 |
197 #if defined(ENABLE_SESSION_SERVICE) | 208 #if defined(ENABLE_SESSION_SERVICE) |
198 // static | 209 // static |
199 void ProfileManager::ShutdownSessionServices() { | 210 void ProfileManager::ShutdownSessionServices() { |
200 ProfileManager* pm = g_browser_process->profile_manager(); | 211 ProfileManager* pm = g_browser_process->profile_manager(); |
201 if (!pm) // Is NULL when running unit tests. | 212 if (!pm) // Is NULL when running unit tests. |
202 return; | 213 return; |
(...skipping 12 matching lines...) Expand all Loading... | |
215 // Delete both the profile directory and its corresponding cache. | 226 // Delete both the profile directory and its corresponding cache. |
216 base::FilePath cache_path; | 227 base::FilePath cache_path; |
217 chrome::GetUserCacheDirectory(*it, &cache_path); | 228 chrome::GetUserCacheDirectory(*it, &cache_path); |
218 file_util::Delete(*it, true); | 229 file_util::Delete(*it, true); |
219 file_util::Delete(cache_path, true); | 230 file_util::Delete(cache_path, true); |
220 } | 231 } |
221 ProfilesToDelete().clear(); | 232 ProfilesToDelete().clear(); |
222 } | 233 } |
223 | 234 |
224 // static | 235 // static |
236 // TODO(nkostylev): Remove this method once all clients are migrated. | |
225 Profile* ProfileManager::GetDefaultProfile() { | 237 Profile* ProfileManager::GetDefaultProfile() { |
226 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 238 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
227 return profile_manager->GetDefaultProfile(profile_manager->user_data_dir_); | 239 return profile_manager->GetDefaultProfile(profile_manager->user_data_dir_); |
228 } | 240 } |
229 | 241 |
230 // static | 242 // static |
243 // TODO(nkostylev): Remove this method once all clients are migrated. | |
231 Profile* ProfileManager::GetDefaultProfileOrOffTheRecord() { | 244 Profile* ProfileManager::GetDefaultProfileOrOffTheRecord() { |
232 // TODO (mukai,nkostylev): In the long term we should fix those cases that | 245 // TODO (mukai,nkostylev): In the long term we should fix those cases that |
233 // crash on Guest mode and have only one GetDefaultProfile() method. | 246 // crash on Guest mode and have only one GetDefaultProfile() method. |
234 Profile* profile = GetDefaultProfile(); | 247 Profile* profile = GetDefaultProfile(); |
235 #if defined(OS_CHROMEOS) | 248 #if defined(OS_CHROMEOS) |
236 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) | 249 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) |
237 profile = profile->GetOffTheRecordProfile(); | 250 profile = profile->GetOffTheRecordProfile(); |
238 #endif | 251 #endif |
239 return profile; | 252 return profile; |
240 } | 253 } |
(...skipping 19 matching lines...) Expand all Loading... | |
260 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 273 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
261 ALLOW_THIS_IN_INITIALIZER_LIST( | 274 ALLOW_THIS_IN_INITIALIZER_LIST( |
262 browser_list_observer_(this)), | 275 browser_list_observer_(this)), |
263 #endif | 276 #endif |
264 closing_all_browsers_(false) { | 277 closing_all_browsers_(false) { |
265 #if defined(OS_CHROMEOS) | 278 #if defined(OS_CHROMEOS) |
266 registrar_.Add( | 279 registrar_.Add( |
267 this, | 280 this, |
268 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 281 chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
269 content::NotificationService::AllSources()); | 282 content::NotificationService::AllSources()); |
283 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kMultiProfiles)) { | |
284 registrar_.Add( | |
285 this, | |
286 chrome::NOTIFICATION_ACTIVE_USER_CHANGED, | |
287 content::NotificationService::AllSources()); | |
288 } | |
270 #endif | 289 #endif |
271 registrar_.Add( | 290 registrar_.Add( |
272 this, | 291 this, |
273 chrome::NOTIFICATION_BROWSER_OPENED, | 292 chrome::NOTIFICATION_BROWSER_OPENED, |
274 content::NotificationService::AllSources()); | 293 content::NotificationService::AllSources()); |
275 registrar_.Add( | 294 registrar_.Add( |
276 this, | 295 this, |
277 chrome::NOTIFICATION_BROWSER_CLOSED, | 296 chrome::NOTIFICATION_BROWSER_CLOSED, |
278 content::NotificationService::AllSources()); | 297 content::NotificationService::AllSources()); |
279 registrar_.Add( | 298 registrar_.Add( |
280 this, | 299 this, |
281 chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, | 300 chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, |
282 content::NotificationService::AllSources()); | 301 content::NotificationService::AllSources()); |
283 registrar_.Add( | 302 registrar_.Add( |
284 this, | 303 this, |
285 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, | 304 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, |
286 content::NotificationService::AllSources()); | 305 content::NotificationService::AllSources()); |
287 | 306 |
288 if (ProfileShortcutManager::IsFeatureEnabled() && !user_data_dir.empty()) | 307 if (ProfileShortcutManager::IsFeatureEnabled() && !user_data_dir_.empty()) |
289 profile_shortcut_manager_.reset(ProfileShortcutManager::Create( | 308 profile_shortcut_manager_.reset(ProfileShortcutManager::Create( |
290 this)); | 309 this)); |
291 } | 310 } |
292 | 311 |
293 ProfileManager::~ProfileManager() { | 312 ProfileManager::~ProfileManager() { |
294 } | 313 } |
295 | 314 |
296 base::FilePath ProfileManager::GetDefaultProfileDir( | 315 base::FilePath ProfileManager::GetDefaultProfileDir( |
297 const base::FilePath& user_data_dir) { | 316 const base::FilePath& user_data_dir) { |
298 base::FilePath default_profile_dir(user_data_dir); | 317 base::FilePath default_profile_dir(user_data_dir); |
(...skipping 17 matching lines...) Expand all Loading... | |
316 base::FilePath profile_dir; | 335 base::FilePath profile_dir; |
317 // If the user has logged in, pick up the new profile. | 336 // If the user has logged in, pick up the new profile. |
318 if (command_line.HasSwitch(chromeos::switches::kLoginProfile)) { | 337 if (command_line.HasSwitch(chromeos::switches::kLoginProfile)) { |
319 profile_dir = command_line.GetSwitchValuePath( | 338 profile_dir = command_line.GetSwitchValuePath( |
320 chromeos::switches::kLoginProfile); | 339 chromeos::switches::kLoginProfile); |
321 } else { | 340 } else { |
322 // We should never be logged in with no profile dir. | 341 // We should never be logged in with no profile dir. |
323 NOTREACHED(); | 342 NOTREACHED(); |
324 return base::FilePath(""); | 343 return base::FilePath(""); |
325 } | 344 } |
345 // In case of multi-profiles ignore --login-profile switch. | |
346 // TODO(nkostylev): Some cases like Guest mode will have empty username_hash | |
347 // so default kLoginProfile dir will be used. | |
348 if (command_line.HasSwitch(switches::kMultiProfiles) && | |
349 !active_profile_username_hash_.empty()) { | |
350 profile_dir = base::FilePath(active_profile_username_hash_); | |
351 } | |
326 relative_profile_dir = relative_profile_dir.Append(profile_dir); | 352 relative_profile_dir = relative_profile_dir.Append(profile_dir); |
327 return relative_profile_dir; | 353 return relative_profile_dir; |
328 } | 354 } |
329 #endif | 355 #endif |
330 // TODO(mirandac): should not automatically be default profile. | 356 // TODO(mirandac): should not automatically be default profile. |
331 relative_profile_dir = | 357 relative_profile_dir = |
332 relative_profile_dir.AppendASCII(chrome::kInitialProfile); | 358 relative_profile_dir.AppendASCII(chrome::kInitialProfile); |
333 return relative_profile_dir; | 359 return relative_profile_dir; |
334 } | 360 } |
335 | 361 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
378 } | 404 } |
379 to_return.push_back(GetProfile(user_data_dir.AppendASCII(profile))); | 405 to_return.push_back(GetProfile(user_data_dir.AppendASCII(profile))); |
380 } | 406 } |
381 } | 407 } |
382 } | 408 } |
383 return to_return; | 409 return to_return; |
384 } | 410 } |
385 | 411 |
386 Profile* ProfileManager::GetDefaultProfile( | 412 Profile* ProfileManager::GetDefaultProfile( |
387 const base::FilePath& user_data_dir) { | 413 const base::FilePath& user_data_dir) { |
414 #if defined(OS_CHROMEOS) | |
415 base::FilePath default_profile_dir(user_data_dir); | |
416 if (logged_in_) { | |
417 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kMultiProfiles) && | |
418 base::chromeos::IsRunningOnChromeOS()) { | |
419 // TODO(nkostylev): Change to [user_data_dir]/profile-[hash] | |
420 default_profile_dir = GetChromeOSProfileDir(GetInitialProfileDir()); | |
421 } else { | |
422 default_profile_dir = default_profile_dir.Append(GetInitialProfileDir()); | |
423 } | |
424 } else { | |
425 default_profile_dir = GetDefaultProfileDir(user_data_dir); | |
426 } | |
427 #else | |
388 base::FilePath default_profile_dir(user_data_dir); | 428 base::FilePath default_profile_dir(user_data_dir); |
389 default_profile_dir = default_profile_dir.Append(GetInitialProfileDir()); | 429 default_profile_dir = default_profile_dir.Append(GetInitialProfileDir()); |
430 #endif | |
390 #if defined(OS_CHROMEOS) | 431 #if defined(OS_CHROMEOS) |
391 if (!logged_in_) { | 432 if (!logged_in_) { |
392 Profile* profile = GetProfile(default_profile_dir); | 433 Profile* profile = GetProfile(default_profile_dir); |
393 // For cros, return the OTR profile so we never accidentally keep | 434 // For cros, return the OTR profile so we never accidentally keep |
394 // user data in an unencrypted profile. But doing this makes | 435 // user data in an unencrypted profile. But doing this makes |
395 // many of the browser and ui tests fail. We do return the OTR profile | 436 // many of the browser and ui tests fail. We do return the OTR profile |
396 // if the login-profile switch is passed so that we can test this. | 437 // if the login-profile switch is passed so that we can test this. |
397 // TODO(davemoore) Fix the tests so they allow OTR profiles. | 438 // TODO(davemoore) Fix the tests so they allow OTR profiles. |
398 if (ShouldGoOffTheRecord()) | 439 if (ShouldGoOffTheRecord()) |
399 return profile->GetOffTheRecordProfile(); | 440 return profile->GetOffTheRecordProfile(); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
500 // static | 541 // static |
501 void ProfileManager::CreateDefaultProfileAsync(const CreateCallback& callback) { | 542 void ProfileManager::CreateDefaultProfileAsync(const CreateCallback& callback) { |
502 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 543 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
503 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 544 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
504 | 545 |
505 base::FilePath default_profile_dir = profile_manager->user_data_dir_; | 546 base::FilePath default_profile_dir = profile_manager->user_data_dir_; |
506 // TODO(mirandac): current directory will not always be default in the future | 547 // TODO(mirandac): current directory will not always be default in the future |
507 default_profile_dir = default_profile_dir.Append( | 548 default_profile_dir = default_profile_dir.Append( |
508 profile_manager->GetInitialProfileDir()); | 549 profile_manager->GetInitialProfileDir()); |
509 | 550 |
551 #if defined(OS_CHROMEOS) | |
552 // TODO(nkostylev): Change to [user_data_dir]/profile-[hash] | |
553 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kMultiProfiles) && | |
554 base::chromeos::IsRunningOnChromeOS()) { | |
555 default_profile_dir = GetChromeOSProfileDir( | |
556 profile_manager->GetInitialProfileDir()); | |
557 } | |
558 #endif | |
559 | |
510 // Chrome OS specific note: since we pass string16() here as the icon_url, | 560 // Chrome OS specific note: since we pass string16() here as the icon_url, |
511 // profile cache information will not get updated with the is_managed value | 561 // profile cache information will not get updated with the is_managed value |
512 // so we're fine with passing all default values here. | 562 // so we're fine with passing all default values here. |
513 // On Chrome OS |is_managed| preference will get initialized in | 563 // On Chrome OS |is_managed| preference will get initialized in |
514 // Profile::CREATE_STATUS_CREATED callback. | 564 // Profile::CREATE_STATUS_CREATED callback. |
515 profile_manager->CreateProfileAsync( | 565 profile_manager->CreateProfileAsync( |
516 default_profile_dir, callback, string16(), string16(), false); | 566 default_profile_dir, callback, string16(), string16(), false); |
517 } | 567 } |
518 | 568 |
519 bool ProfileManager::AddProfile(Profile* profile) { | 569 bool ProfileManager::AddProfile(Profile* profile) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
583 } | 633 } |
584 | 634 |
585 void ProfileManager::Observe( | 635 void ProfileManager::Observe( |
586 int type, | 636 int type, |
587 const content::NotificationSource& source, | 637 const content::NotificationSource& source, |
588 const content::NotificationDetails& details) { | 638 const content::NotificationDetails& details) { |
589 #if defined(OS_CHROMEOS) | 639 #if defined(OS_CHROMEOS) |
590 if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { | 640 if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { |
591 logged_in_ = true; | 641 logged_in_ = true; |
592 | 642 |
643 chromeos::User* user = content::Details<chromeos::User>(details).ptr(); | |
644 DCHECK(user); | |
645 | |
593 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 646 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
594 if (!command_line.HasSwitch(switches::kTestType)) { | 647 if (!command_line.HasSwitch(switches::kTestType)) { |
595 // If we don't have a mounted profile directory we're in trouble. | 648 // If we don't have a mounted profile directory we're in trouble. |
596 // TODO(davemoore) Once we have better api this check should ensure that | 649 // TODO(davemoore) Once we have better api this check should ensure that |
597 // our profile directory is the one that's mounted, and that it's mounted | 650 // our profile directory is the one that's mounted, and that it's mounted |
598 // as the current user. | 651 // as the current user. |
599 chromeos::DBusThreadManager::Get()->GetCryptohomeClient()->IsMounted( | 652 chromeos::DBusThreadManager::Get()->GetCryptohomeClient()->IsMounted( |
600 base::Bind(&CheckCryptohomeIsMounted)); | 653 base::Bind(&CheckCryptohomeIsMounted)); |
601 | 654 |
602 // Confirm that we hadn't loaded the new profile previously. | 655 // Confirm that we hadn't loaded the new profile previously. |
603 base::FilePath default_profile_dir = | 656 if (command_line.HasSwitch(switches::kMultiProfiles)) { |
604 user_data_dir_.Append(GetInitialProfileDir()); | 657 // TODO(nkostylev): We could not enforce username_hash not being |
658 // empty here till all cases like Guest mode are migrated. | |
659 active_profile_username_hash_ = user->username_hash(); | |
660 LOG(INFO) << "Switching to custom profile_dir: " | |
661 << active_profile_username_hash_; | |
662 } | |
663 base::FilePath default_profile_dir = user_data_dir_.Append( | |
664 GetInitialProfileDir(/*active_profile_username_hash_*/)); | |
sail
2013/04/12 17:28:34
what's active_profile_username_hash_ here for?
| |
605 CHECK(!GetProfileByPath(default_profile_dir)) | 665 CHECK(!GetProfileByPath(default_profile_dir)) |
606 << "The default profile was loaded before we mounted the cryptohome."; | 666 << "The default profile was loaded before we mounted the cryptohome."; |
607 } | 667 } |
608 return; | 668 return; |
669 } else if (type == chrome::NOTIFICATION_ACTIVE_USER_CHANGED) { | |
670 chromeos::User* user = content::Details<chromeos::User>(details).ptr(); | |
671 active_profile_username_hash_ = user->username_hash(); | |
672 LOG(INFO) << "Switching to custom profile_dir: " | |
673 << active_profile_username_hash_; | |
674 return; | |
609 } | 675 } |
610 #endif | 676 #endif |
611 bool save_active_profiles = false; | 677 bool save_active_profiles = false; |
612 switch (type) { | 678 switch (type) { |
613 case chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST: { | 679 case chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST: { |
614 // Ignore any browsers closing from now on. | 680 // Ignore any browsers closing from now on. |
615 closing_all_browsers_ = true; | 681 closing_all_browsers_ = true; |
616 break; | 682 break; |
617 } | 683 } |
618 case chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED: { | 684 case chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED: { |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1125 ProfileManager::ProfileInfo::ProfileInfo( | 1191 ProfileManager::ProfileInfo::ProfileInfo( |
1126 Profile* profile, | 1192 Profile* profile, |
1127 bool created) | 1193 bool created) |
1128 : profile(profile), | 1194 : profile(profile), |
1129 created(created) { | 1195 created(created) { |
1130 } | 1196 } |
1131 | 1197 |
1132 ProfileManager::ProfileInfo::~ProfileInfo() { | 1198 ProfileManager::ProfileInfo::~ProfileInfo() { |
1133 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); | 1199 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); |
1134 } | 1200 } |
OLD | NEW |