| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <set> | 5 #include <set> |
| 6 | 6 |
| 7 #include "chrome/browser/profile_manager.h" | 7 #include "chrome/browser/profile_manager.h" |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "chrome/common/logging_chrome.h" | 24 #include "chrome/common/logging_chrome.h" |
| 25 #include "chrome/common/notification_service.h" | 25 #include "chrome/common/notification_service.h" |
| 26 #include "chrome/common/notification_type.h" | 26 #include "chrome/common/notification_type.h" |
| 27 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 28 #include "grit/generated_resources.h" | 28 #include "grit/generated_resources.h" |
| 29 #include "net/http/http_transaction_factory.h" | 29 #include "net/http/http_transaction_factory.h" |
| 30 #include "net/url_request/url_request_context.h" | 30 #include "net/url_request/url_request_context.h" |
| 31 #include "net/url_request/url_request_job.h" | 31 #include "net/url_request/url_request_job.h" |
| 32 #include "net/url_request/url_request_job_tracker.h" | 32 #include "net/url_request/url_request_job_tracker.h" |
| 33 | 33 |
| 34 #if defined(OS_CHROMEOS) |
| 35 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 36 #include "chrome/browser/chromeos/cros/cryptohome_library.h" |
| 37 #endif |
| 38 |
| 34 // static | 39 // static |
| 35 void ProfileManager::ShutdownSessionServices() { | 40 void ProfileManager::ShutdownSessionServices() { |
| 36 ProfileManager* pm = g_browser_process->profile_manager(); | 41 ProfileManager* pm = g_browser_process->profile_manager(); |
| 37 for (ProfileManager::const_iterator i = pm->begin(); i != pm->end(); ++i) | 42 for (ProfileManager::const_iterator i = pm->begin(); i != pm->end(); ++i) |
| 38 (*i)->ShutdownSessionService(); | 43 (*i)->ShutdownSessionService(); |
| 39 } | 44 } |
| 40 | 45 |
| 41 // static | 46 // static |
| 42 Profile* ProfileManager::GetLoginWizardProfile() { | 47 Profile* ProfileManager::GetDefaultProfile() { |
| 43 FilePath user_data_dir; | 48 FilePath user_data_dir; |
| 44 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 49 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 45 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 50 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 46 return profile_manager->GetDefaultProfile( | 51 return profile_manager->GetDefaultProfile(user_data_dir); |
| 47 user_data_dir)->GetOffTheRecordProfile(); | |
| 48 } | 52 } |
| 49 | 53 |
| 50 ProfileManager::ProfileManager() : logged_in_(false) { | 54 ProfileManager::ProfileManager() : logged_in_(false) { |
| 51 SystemMonitor::Get()->AddObserver(this); | 55 SystemMonitor::Get()->AddObserver(this); |
| 52 #if defined(OS_CHROMEOS) | 56 #if defined(OS_CHROMEOS) |
| 53 registrar_.Add( | 57 registrar_.Add( |
| 54 this, | 58 this, |
| 55 NotificationType::LOGIN_USER_CHANGED, | 59 NotificationType::LOGIN_USER_CHANGED, |
| 56 NotificationService::AllSources()); | 60 NotificationService::AllSources()); |
| 57 #endif | 61 #endif |
| (...skipping 26 matching lines...) Expand all Loading... |
| 84 | 88 |
| 85 FilePath ProfileManager::GetProfilePrefsPath( | 89 FilePath ProfileManager::GetProfilePrefsPath( |
| 86 const FilePath &profile_dir) { | 90 const FilePath &profile_dir) { |
| 87 FilePath default_prefs_path(profile_dir); | 91 FilePath default_prefs_path(profile_dir); |
| 88 default_prefs_path = default_prefs_path.Append(chrome::kPreferencesFilename); | 92 default_prefs_path = default_prefs_path.Append(chrome::kPreferencesFilename); |
| 89 return default_prefs_path; | 93 return default_prefs_path; |
| 90 } | 94 } |
| 91 | 95 |
| 92 Profile* ProfileManager::GetDefaultProfile(const FilePath& user_data_dir) { | 96 Profile* ProfileManager::GetDefaultProfile(const FilePath& user_data_dir) { |
| 93 FilePath default_profile_dir(user_data_dir); | 97 FilePath default_profile_dir(user_data_dir); |
| 94 std::wstring profile = chrome::kNotSignedInProfile; | |
| 95 #if defined(OS_CHROMEOS) | 98 #if defined(OS_CHROMEOS) |
| 96 // If the user has logged in, pick up the new profile. | |
| 97 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 99 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 98 // TODO(davemoore) Delete this once chromium os has started using | 100 if (logged_in_) { |
| 99 // "--login-profile" instead of "--profile". | 101 std::wstring profile_dir; |
| 100 if (logged_in_ && command_line.HasSwitch(switches::kProfile)) { | 102 // If the user has logged in, pick up the new profile. |
| 101 profile = command_line.GetSwitchValue(switches::kProfile); | 103 // TODO(davemoore) Delete this once chromium os has started using |
| 104 // "--login-profile" instead of "--profile". |
| 105 if (command_line.HasSwitch(switches::kLoginProfile)) { |
| 106 profile_dir = command_line.GetSwitchValue(switches::kLoginProfile); |
| 107 } else if (command_line.HasSwitch(switches::kProfile)) { |
| 108 profile_dir = command_line.GetSwitchValue(switches::kProfile); |
| 109 } else { |
| 110 // We should never be logged in with no profile dir. |
| 111 NOTREACHED(); |
| 112 return NULL; |
| 113 } |
| 114 default_profile_dir = default_profile_dir.Append( |
| 115 FilePath::FromWStringHack(profile_dir)); |
| 116 return GetProfile(default_profile_dir); |
| 117 } else { |
| 118 // If not logged in on cros, always return the incognito profile |
| 119 default_profile_dir = default_profile_dir.Append( |
| 120 FilePath::FromWStringHack(chrome::kNotSignedInProfile)); |
| 121 Profile*profile = GetProfile(default_profile_dir); |
| 122 |
| 123 // For cros, return the OTR profile so we never accidentally keep |
| 124 // user data in an unencrypted profile. But doing this makes |
| 125 // many of the browser and ui tests fail. |
| 126 // TODO(davemoore) Fix the tests. |
| 127 if (!command_line.HasSwitch(switches::kTestType)) |
| 128 profile = profile->GetOffTheRecordProfile(); |
| 129 |
| 130 return profile; |
| 102 } | 131 } |
| 103 if (logged_in_ && command_line.HasSwitch(switches::kLoginProfile)) { | 132 #else |
| 104 profile = command_line.GetSwitchValue(switches::kLoginProfile); | 133 default_profile_dir = default_profile_dir.Append( |
| 105 } | 134 FilePath::FromWStringHack(chrome::kNotSignedInProfile)); |
| 135 return GetProfile(default_profile_dir); |
| 106 #endif | 136 #endif |
| 107 default_profile_dir = default_profile_dir.Append( | |
| 108 FilePath::FromWStringHack(profile)); | |
| 109 return GetProfile(default_profile_dir); | |
| 110 } | 137 } |
| 111 | 138 |
| 112 Profile* ProfileManager::GetProfile(const FilePath& profile_dir) { | 139 Profile* ProfileManager::GetProfile(const FilePath& profile_dir) { |
| 113 // If the profile is already loaded (e.g., chrome.exe launched twice), just | 140 // If the profile is already loaded (e.g., chrome.exe launched twice), just |
| 114 // return it. | 141 // return it. |
| 115 Profile* profile = GetProfileByPath(profile_dir); | 142 Profile* profile = GetProfileByPath(profile_dir); |
| 116 if (NULL != profile) | 143 if (NULL != profile) |
| 117 return profile; | 144 return profile; |
| 118 | 145 |
| 119 if (!ProfileManager::IsProfile(profile_dir)) { | 146 if (!ProfileManager::IsProfile(profile_dir)) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 NewRunnableFunction(&ProfileManager::ResumeProfile, *i)); | 220 NewRunnableFunction(&ProfileManager::ResumeProfile, *i)); |
| 194 } | 221 } |
| 195 } | 222 } |
| 196 | 223 |
| 197 void ProfileManager::Observe( | 224 void ProfileManager::Observe( |
| 198 NotificationType type, | 225 NotificationType type, |
| 199 const NotificationSource& source, | 226 const NotificationSource& source, |
| 200 const NotificationDetails& details) { | 227 const NotificationDetails& details) { |
| 201 #if defined(OS_CHROMEOS) | 228 #if defined(OS_CHROMEOS) |
| 202 if (type == NotificationType::LOGIN_USER_CHANGED) { | 229 if (type == NotificationType::LOGIN_USER_CHANGED) { |
| 230 CHECK(chromeos::CrosLibrary::EnsureLoaded()); |
| 231 // If we don't have a mounted profile directory we're in trouble. |
| 232 // TODO(davemoore) Once we have better api this check should ensure that |
| 233 // our profile directory is the one that's mounted, and that it's mounted |
| 234 // as the current user. |
| 235 CHECK(chromeos::CryptohomeLibrary::Get()->IsMounted()); |
| 203 logged_in_ = true; | 236 logged_in_ = true; |
| 204 } | 237 } |
| 205 #endif | 238 #endif |
| 206 } | 239 } |
| 207 | 240 |
| 208 void ProfileManager::SuspendProfile(Profile* profile) { | 241 void ProfileManager::SuspendProfile(Profile* profile) { |
| 209 DCHECK(profile); | 242 DCHECK(profile); |
| 210 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 243 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| 211 | 244 |
| 212 for (URLRequestJobTracker::JobIterator i = g_url_request_job_tracker.begin(); | 245 for (URLRequestJobTracker::JobIterator i = g_url_request_job_tracker.begin(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 if (!file_util::PathExists(path)) { | 277 if (!file_util::PathExists(path)) { |
| 245 // TODO(tc): http://b/1094718 Bad things happen if we can't write to the | 278 // TODO(tc): http://b/1094718 Bad things happen if we can't write to the |
| 246 // profile directory. We should eventually be able to run in this | 279 // profile directory. We should eventually be able to run in this |
| 247 // situation. | 280 // situation. |
| 248 if (!file_util::CreateDirectory(path)) | 281 if (!file_util::CreateDirectory(path)) |
| 249 return NULL; | 282 return NULL; |
| 250 } | 283 } |
| 251 | 284 |
| 252 return Profile::CreateProfile(path); | 285 return Profile::CreateProfile(path); |
| 253 } | 286 } |
| OLD | NEW |