diff options
author | davemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-30 21:18:51 +0000 |
---|---|---|
committer | davemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-30 21:18:51 +0000 |
commit | 9acc48601ea4aff4e5ec977c0dd089e887ba5ffd (patch) | |
tree | 9c0ef6715ab756b6c8eafb5f4385eaab73a3a8ab /chrome/browser/profile_manager.cc | |
parent | 8d7690b29c0572c62bbe72817ac3b5195bf38e42 (diff) | |
download | chromium_src-9acc48601ea4aff4e5ec977c0dd089e887ba5ffd.zip chromium_src-9acc48601ea4aff4e5ec977c0dd089e887ba5ffd.tar.gz chromium_src-9acc48601ea4aff4e5ec977c0dd089e887ba5ffd.tar.bz2 |
Add -profile command line switch
Review URL: http://codereview.chromium.org/384062
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33335 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/profile_manager.cc')
-rw-r--r-- | chrome/browser/profile_manager.cc | 159 |
1 files changed, 27 insertions, 132 deletions
diff --git a/chrome/browser/profile_manager.cc b/chrome/browser/profile_manager.cc index 9b66e39..f8cb344 100644 --- a/chrome/browser/profile_manager.cc +++ b/chrome/browser/profile_manager.cc @@ -7,6 +7,7 @@ #include "chrome/browser/profile_manager.h" #include "app/l10n_util.h" +#include "base/command_line.h" #include "base/file_util.h" #include "base/path_service.h" #include "base/string_util.h" @@ -18,6 +19,7 @@ #include "chrome/browser/net/url_request_context_getter.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" +#include "chrome/common/chrome_switches.h" #include "chrome/common/logging_chrome.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" @@ -28,13 +30,6 @@ #include "net/url_request/url_request_job_tracker.h" // static -void ProfileManager::RegisterUserPrefs(PrefService* prefs) { - prefs->RegisterStringPref(prefs::kProfileName, L""); - prefs->RegisterStringPref(prefs::kProfileNickname, L""); - prefs->RegisterStringPref(prefs::kProfileID, L""); -} - -// static void ProfileManager::ShutdownSessionServices() { ProfileManager* pm = g_browser_process->profile_manager(); for (ProfileManager::const_iterator i = pm->begin(); i != pm->end(); ++i) @@ -65,12 +60,19 @@ ProfileManager::~ProfileManager() { FilePath ProfileManager::GetDefaultProfileDir( const FilePath& user_data_dir) { FilePath default_profile_dir(user_data_dir); + std::wstring profile = chrome::kNotSignedInProfile; +#if defined(OS_CHROMEOS) + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + if (command_line.HasSwitch(switches::kProfile)) { + profile = command_line.GetSwitchValue(switches::kProfile); + } +#endif default_profile_dir = default_profile_dir.Append( - FilePath::FromWStringHack(chrome::kNotSignedInProfile)); + FilePath::FromWStringHack(profile)); return default_profile_dir; } -FilePath ProfileManager::GetDefaultProfilePath( +FilePath ProfileManager::GetProfilePrefsPath( const FilePath &profile_dir) { FilePath default_prefs_path(profile_dir); default_prefs_path = default_prefs_path.Append(chrome::kPreferencesFilename); @@ -78,36 +80,28 @@ FilePath ProfileManager::GetDefaultProfilePath( } Profile* ProfileManager::GetDefaultProfile(const FilePath& user_data_dir) { - // Initialize profile, creating default if necessary - FilePath default_profile_dir = GetDefaultProfileDir(user_data_dir); + return GetProfile(GetDefaultProfileDir(user_data_dir)); +} + +Profile* ProfileManager::GetProfile(const FilePath& profile_dir) { // If the profile is already loaded (e.g., chrome.exe launched twice), just // return it. - Profile* profile = GetProfileByPath(default_profile_dir); + Profile* profile = GetProfileByPath(profile_dir); if (NULL != profile) return profile; - if (!ProfileManager::IsProfile(default_profile_dir)) { + if (!ProfileManager::IsProfile(profile_dir)) { // If the profile directory doesn't exist, create it. - profile = ProfileManager::CreateProfile(default_profile_dir, - L"", // No name. - L"", // No nickname. - chrome::kNotSignedInID); + profile = ProfileManager::CreateProfile(profile_dir); if (!profile) return NULL; bool result = AddProfile(profile); DCHECK(result); } else { // The profile already exists on disk, just load it. - profile = AddProfileByPath(default_profile_dir); + profile = AddProfileByPath(profile_dir); if (!profile) return NULL; - - if (profile->GetID() != chrome::kNotSignedInID) { - // Something must've gone wrong with the profile section of the - // Preferences file, fix it. - profile->SetID(chrome::kNotSignedInID); - profile->SetName(chrome::kNotSignedInProfile); - } } DCHECK(profile); return profile; @@ -126,37 +120,6 @@ Profile* ProfileManager::AddProfileByPath(const FilePath& path) { } } -void ProfileManager::NewWindowWithProfile(Profile* profile) { - DCHECK(profile); - Browser* browser = Browser::Create(profile); - browser->AddTabWithURL(GURL(), GURL(), PageTransition::TYPED, true, -1, - false, NULL); - browser->window()->Show(); -} - -Profile* ProfileManager::AddProfileByID(const std::wstring& id) { - AvailableProfile* available = GetAvailableProfileByID(id); - if (!available) - return NULL; - - FilePath path; - PathService::Get(chrome::DIR_USER_DATA, &path); - path = path.Append(available->directory()); - - return AddProfileByPath(path); -} - -AvailableProfile* ProfileManager::GetAvailableProfileByID( - const std::wstring& id) { - for (AvailableProfileVector::const_iterator i(available_profiles_.begin()); - i != available_profiles_.end(); ++i) { - if ((*i)->id() == id) - return *i; - } - - return NULL; -} - bool ProfileManager::AddProfile(Profile* profile) { DCHECK(profile); @@ -168,37 +131,15 @@ bool ProfileManager::AddProfile(Profile* profile) { ") as an already-loaded profile."; return false; } - if (GetProfileByID(profile->GetID())) { - NOTREACHED() << "Attempted to add profile with the same ID (" << - profile->GetID() << ") as an already-loaded profile."; - return false; - } profiles_.insert(profiles_.end(), profile); + profile->InitExtensions(); + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + if (!command_line.HasSwitch(switches::kDisableWebResources)) + profile->InitWebResources(); return true; } -void ProfileManager::RemoveProfile(Profile* profile) { - for (iterator i(begin()); i != end(); ++i) { - if ((*i) == profile) { - profiles_.erase(i); - return; - } - } -} - -void ProfileManager::RemoveProfileByPath(const FilePath& path) { - for (iterator i(begin()); i != end(); ++i) { - if ((*i)->GetPath() == path) { - delete *i; - profiles_.erase(i); - return; - } - } - - NOTREACHED() << "Attempted to remove non-loaded profile: " << path.value(); -} - Profile* ProfileManager::GetProfileByPath(const FilePath& path) const { for (const_iterator i(begin()); i != end(); ++i) { if ((*i)->GetPath() == path) @@ -208,15 +149,6 @@ Profile* ProfileManager::GetProfileByPath(const FilePath& path) const { return NULL; } -Profile* ProfileManager::GetProfileByID(const std::wstring& id) const { - for (const_iterator i(begin()); i != end(); ++i) { - if ((*i)->GetID() == id) - return *i; - } - - return NULL; -} - void ProfileManager::OnSuspend() { DCHECK(CalledOnValidThread()); @@ -257,39 +189,16 @@ void ProfileManager::ResumeProfile(Profile* profile) { // static bool ProfileManager::IsProfile(const FilePath& path) { - FilePath prefs_path = GetDefaultProfilePath(path); - + FilePath prefs_path = GetProfilePrefsPath(path); FilePath history_path = path; history_path = history_path.Append(chrome::kHistoryFilename); return file_util::PathExists(prefs_path) && - file_util::PathExists(history_path); -} - -// static -bool ProfileManager::CopyProfileData(const FilePath& source_path, - const FilePath& destination_path) { - // create destination directory if necessary - if (!file_util::PathExists(destination_path)) { - bool result = file_util::CreateDirectory(destination_path); - if (!result) { - DLOG(WARNING) << "Unable to create destination directory " << - destination_path.value(); - return false; - } - } - - // copy files in directory - return file_util::CopyDirectory(source_path, destination_path, false); + file_util::PathExists(history_path); } // static -Profile* ProfileManager::CreateProfile(const FilePath& path, - const std::wstring& name, - const std::wstring& nickname, - const std::wstring& id) { - DCHECK_LE(nickname.length(), name.length()); - +Profile* ProfileManager::CreateProfile(const FilePath& path) { if (IsProfile(path)) { DCHECK(false) << "Attempted to create a profile with the path:\n" << path.value() << "\n but that path already contains a profile"; @@ -303,19 +212,5 @@ Profile* ProfileManager::CreateProfile(const FilePath& path, return NULL; } - Profile* profile = Profile::CreateProfile(path); - PrefService* prefs = profile->GetPrefs(); - DCHECK(prefs); - prefs->SetString(prefs::kProfileName, name); - prefs->SetString(prefs::kProfileNickname, nickname); - prefs->SetString(prefs::kProfileID, id); - - return profile; -} - -// static -std::wstring ProfileManager::CanonicalizeID(const std::wstring& id) { - std::wstring no_whitespace; - TrimWhitespace(id, TRIM_ALL, &no_whitespace); - return StringToLowerASCII(no_whitespace); + return Profile::CreateProfile(path); } |