summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/browser_main.cc91
-rw-r--r--chrome/browser/browser_prefs.cc14
-rw-r--r--chrome/browser/browser_prefs.h4
-rw-r--r--chrome/browser/first_run_win.cc2
-rw-r--r--chrome/browser/metrics/metrics_service.cc25
-rw-r--r--chrome/browser/metrics/metrics_service.h4
-rw-r--r--chrome/browser/plugin_process_host.cc3
-rw-r--r--chrome/browser/process_singleton_linux.cc14
-rw-r--r--chrome/browser/profile.cc43
-rw-r--r--chrome/browser/profile.h10
-rw-r--r--chrome/browser/profile_manager.cc159
-rw-r--r--chrome/browser/profile_manager.h82
-rw-r--r--chrome/browser/profile_manager_unittest.cc34
-rw-r--r--chrome/browser/renderer_host/browser_render_process_host.cc12
-rw-r--r--chrome/common/chrome_plugin_util.cc8
-rw-r--r--chrome/common/chrome_switches.cc5
-rw-r--r--chrome/common/chrome_switches.h1
-rw-r--r--chrome/common/pref_names.cc10
-rw-r--r--chrome/common/pref_names.h3
-rw-r--r--chrome/test/live_sync/live_bookmarks_sync_test.cc2
-rw-r--r--net/base/file_stream_posix.cc3
21 files changed, 158 insertions, 371 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index 28ba351..2b9d0ad 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -567,49 +567,8 @@ int BrowserMain(const MainFunctionParams& parameters) {
// Initialize the shared instance of user data manager.
scoped_ptr<UserDataManager> user_data_manager(UserDataManager::Create());
- // Try to create/load the profile.
- ProfileManager* profile_manager = browser_process->profile_manager();
- Profile* profile = profile_manager->GetDefaultProfile(user_data_dir);
-#if defined(OS_WIN)
- if (!profile) {
- // Ideally, we should be able to run w/o access to disk. For now, we
- // prompt the user to pick a different user-data-dir and restart chrome
- // with the new dir.
- // http://code.google.com/p/chromium/issues/detail?id=11510
- user_data_dir = UserDataDirDialog::RunUserDataDirDialog(user_data_dir);
- if (!parameters.ui_task && browser_shutdown::delete_resources_on_shutdown) {
- // Only delete the resources if we're not running tests. If we're running
- // tests the resources need to be reused as many places in the UI cache
- // SkBitmaps from the ResourceBundle.
- ResourceBundle::CleanupSharedInstance();
- }
-
- if (!user_data_dir.empty()) {
- // Because of the way CommandLine parses, it's sufficient to append a new
- // --user-data-dir switch. The last flag of the same name wins.
- // TODO(tc): It would be nice to remove the flag we don't want, but that
- // sounds risky if we parse differently than CommandLineToArgvW.
- CommandLine new_command_line = parsed_command_line;
- new_command_line.AppendSwitchWithValue(switches::kUserDataDir,
- user_data_dir.ToWStringHack());
- base::LaunchApp(new_command_line, false, false, NULL);
- }
-
- return ResultCodes::NORMAL_EXIT;
- }
-#else
- // TODO(port): fix this. See comments near the definition of
- // user_data_dir. It is better to CHECK-fail here than it is to
- // silently exit because of missing code in the above test.
- CHECK(profile) << "Cannot get default profile.";
-#endif
-
- PrefService* user_prefs = profile->GetPrefs();
- DCHECK(user_prefs);
-
- // Now that local state and user prefs have been loaded, make the two pref
- // services aware of all our preferences.
- browser::RegisterAllPrefs(user_prefs, local_state);
+ // Initialize the prefs of the local state.
+ browser::RegisterLocalState(local_state);
// Now that all preferences have been registered, set the install date
// for the uninstall metrics if this is our first run. This only actually
@@ -654,6 +613,46 @@ int BrowserMain(const MainFunctionParams& parameters) {
}
}
+ // Try to create/load the profile.
+ ProfileManager* profile_manager = browser_process->profile_manager();
+ Profile* profile = profile_manager->GetDefaultProfile(user_data_dir);
+#if defined(OS_WIN)
+ if (!profile) {
+ // Ideally, we should be able to run w/o access to disk. For now, we
+ // prompt the user to pick a different user-data-dir and restart chrome
+ // with the new dir.
+ // http://code.google.com/p/chromium/issues/detail?id=11510
+ user_data_dir = UserDataDirDialog::RunUserDataDirDialog(user_data_dir);
+ if (!parameters.ui_task && browser_shutdown::delete_resources_on_shutdown) {
+ // Only delete the resources if we're not running tests. If we're running
+ // tests the resources need to be reused as many places in the UI cache
+ // SkBitmaps from the ResourceBundle.
+ ResourceBundle::CleanupSharedInstance();
+ }
+
+ if (!user_data_dir.empty()) {
+ // Because of the way CommandLine parses, it's sufficient to append a new
+ // --user-data-dir switch. The last flag of the same name wins.
+ // TODO(tc): It would be nice to remove the flag we don't want, but that
+ // sounds risky if we parse differently than CommandLineToArgvW.
+ CommandLine new_command_line = parsed_command_line;
+ new_command_line.AppendSwitchWithValue(switches::kUserDataDir,
+ user_data_dir.ToWStringHack());
+ base::LaunchApp(new_command_line, false, false, NULL);
+ }
+
+ return ResultCodes::NORMAL_EXIT;
+ }
+#else
+ // TODO(port): fix this. See comments near the definition of
+ // user_data_dir. It is better to CHECK-fail here than it is to
+ // silently exit because of missing code in the above test.
+ CHECK(profile) << "Cannot get default profile.";
+#endif
+
+ PrefService* user_prefs = profile->GetPrefs();
+ DCHECK(user_prefs);
+
// Importing other browser settings is done in a browser-like process
// that exits when this task has finished.
#if defined(OS_WIN)
@@ -872,12 +871,6 @@ int BrowserMain(const MainFunctionParams& parameters) {
HandleTestParameters(parsed_command_line);
Platform::RecordBreakpadStatusUMA(metrics);
- // Start up the extensions service. This should happen before Start().
- profile->InitExtensions();
- // Start up the web resource service. This starts loading data after a
- // short delay so as not to interfere with startup time.
- if (!parsed_command_line.HasSwitch(switches::kDisableWebResources))
- profile->InitWebResources();
#if defined(OS_CHROMEOS)
chromeos::ExternalCookieHandler::GetCookies(parsed_command_line, profile);
diff --git a/chrome/browser/browser_prefs.cc b/chrome/browser/browser_prefs.cc
index 8020c4f..f96b39e 100644
--- a/chrome/browser/browser_prefs.cc
+++ b/chrome/browser/browser_prefs.cc
@@ -45,9 +45,18 @@
#include "chrome/browser/gtk/browser_window_gtk.h"
#endif
+#if defined(OS_CHROMEOS)
+#include "chrome/browser/chromeos/preferences.h"
+#endif
+
namespace browser {
void RegisterAllPrefs(PrefService* user_prefs, PrefService* local_state) {
+ RegisterLocalState(local_state);
+ RegisterUserPrefs(user_prefs);
+}
+
+void RegisterLocalState(PrefService* local_state) {
// Prefs in Local State
Browser::RegisterPrefs(local_state);
WebCacheManager::RegisterPrefs(local_state);
@@ -67,7 +76,9 @@ void RegisterAllPrefs(PrefService* user_prefs, PrefService* local_state) {
#if defined(OS_WIN) || defined(OS_LINUX)
TaskManager::RegisterPrefs(local_state);
#endif
+}
+void RegisterUserPrefs(PrefService* user_prefs) {
// User prefs
SessionStartupPref::RegisterUserPrefs(user_prefs);
Browser::RegisterUserPrefs(user_prefs);
@@ -87,6 +98,9 @@ void RegisterAllPrefs(PrefService* user_prefs, PrefService* local_state) {
#if defined(TOOLKIT_GTK)
BrowserWindowGtk::RegisterUserPrefs(user_prefs);
#endif
+#if defined(OS_CHROMEOS)
+ chromeos::Preferences::RegisterUserPrefs(user_prefs);
+#endif
}
} // namespace browser
diff --git a/chrome/browser/browser_prefs.h b/chrome/browser/browser_prefs.h
index 1926829..ccdd5fc 100644
--- a/chrome/browser/browser_prefs.h
+++ b/chrome/browser/browser_prefs.h
@@ -11,7 +11,9 @@ namespace browser {
// Makes the PrefService objects aware of all the prefs.
void RegisterAllPrefs(PrefService* user_prefs, PrefService* local_state);
+void RegisterLocalState(PrefService* local_state);
+void RegisterUserPrefs(PrefService* user_prefs);
-}
+} // namespace browser
#endif // CHROME_BROWSER_BROWSER_PREFS_H__
diff --git a/chrome/browser/first_run_win.cc b/chrome/browser/first_run_win.cc
index ef1256a..ef71e98 100644
--- a/chrome/browser/first_run_win.cc
+++ b/chrome/browser/first_run_win.cc
@@ -92,7 +92,7 @@ FilePath GetDefaultPrefFilePath(bool create_profile_dir,
return FilePath();
}
}
- return ProfileManager::GetDefaultProfilePath(default_pref_dir);
+ return ProfileManager::GetProfilePrefsPath(default_pref_dir);
}
bool InvokeGoogleUpdateForRename() {
diff --git a/chrome/browser/metrics/metrics_service.cc b/chrome/browser/metrics/metrics_service.cc
index 9eaa09d..5839171 100644
--- a/chrome/browser/metrics/metrics_service.cc
+++ b/chrome/browser/metrics/metrics_service.cc
@@ -1894,31 +1894,6 @@ void MetricsService::RecordHistogram(const Histogram& histogram) {
}
}
-void MetricsService::AddProfileMetric(Profile* profile,
- const std::wstring& key,
- int value) {
- // Restriction of types is needed for writing values. See
- // MetricsLog::WriteProfileMetrics.
- DCHECK(profile && !key.empty());
- PrefService* prefs = g_browser_process->local_state();
- DCHECK(prefs);
-
- // Key is stored in prefs, which interpret '.'s as paths. As such, key
- // shouldn't have any '.'s in it.
- DCHECK(key.find(L'.') == std::wstring::npos);
- // The id is most likely an email address. We shouldn't send it to the server.
- const std::wstring id_hash =
- UTF8ToWide(MetricsLog::CreateBase64Hash(WideToUTF8(profile->GetID())));
- DCHECK(id_hash.find('.') == std::string::npos);
-
- DictionaryValue* prof_prefs = prefs->GetMutableDictionary(
- prefs::kProfileMetrics);
- DCHECK(prof_prefs);
- const std::wstring pref_key = std::wstring(prefs::kProfilePrefix) + id_hash +
- L"." + key;
- prof_prefs->SetInteger(pref_key.c_str(), value);
-}
-
static bool IsSingleThreaded() {
static PlatformThreadId thread_id = 0;
if (!thread_id)
diff --git a/chrome/browser/metrics/metrics_service.h b/chrome/browser/metrics/metrics_service.h
index 9fa21fc..2386827 100644
--- a/chrome/browser/metrics/metrics_service.h
+++ b/chrome/browser/metrics/metrics_service.h
@@ -389,10 +389,6 @@ class MetricsService : public NotificationObserver,
const NotificationSource& source,
const NotificationDetails& details);
- // Adds a profile metric with the specified key/value pair.
- void AddProfileMetric(Profile* profile, const std::wstring& key,
- int value);
-
// Checks whether a notification can be logged.
bool CanLogNotification(NotificationType type,
const NotificationSource& source,
diff --git a/chrome/browser/plugin_process_host.cc b/chrome/browser/plugin_process_host.cc
index 3739c3f..ab17bb0 100644
--- a/chrome/browser/plugin_process_host.cc
+++ b/chrome/browser/plugin_process_host.cc
@@ -373,6 +373,9 @@ bool PluginProcessHost::Init(const WebPluginInfo& info,
switches::kMemoryProfiling,
switches::kUseLowFragHeapCrt,
switches::kEnableStatsTable,
+#if defined(OS_CHROMEOS)
+ switches::kProfile,
+#endif
};
const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
diff --git a/chrome/browser/process_singleton_linux.cc b/chrome/browser/process_singleton_linux.cc
index 046d7f9..ae507fa 100644
--- a/chrome/browser/process_singleton_linux.cc
+++ b/chrome/browser/process_singleton_linux.cc
@@ -507,7 +507,21 @@ void ProcessSingleton::LinuxWatcher::HandleMessage(
FilePath user_data_dir;
PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
ProfileManager* profile_manager = g_browser_process->profile_manager();
+
+#if defined(OS_CHROMEOS)
+ Profile* profile;
+ if (parsed_command_line.HasSwitch(switches::kProfile)) {
+ std::wstring profile_dir =
+ parsed_command_line.GetSwitchValue(switches::kProfile);
+ profile = profile_manager->GetProfile(
+ user_data_dir.Append(FilePath::FromWStringHack(profile_dir)));
+ } else {
+ profile = profile_manager->GetDefaultProfile(user_data_dir);
+ }
+#else
Profile* profile = profile_manager->GetDefaultProfile(user_data_dir);
+#endif
+
if (!profile) {
// We should only be able to get here if the profile already exists and
// has been created.
diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc
index 7f6c3f0..2db89ac 100644
--- a/chrome/browser/profile.cc
+++ b/chrome/browser/profile.cc
@@ -14,6 +14,7 @@
#include "chrome/browser/autofill/personal_data_manager.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/browser_list.h"
+#include "chrome/browser/browser_prefs.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_theme_provider.h"
#include "chrome/browser/chrome_thread.h"
@@ -63,10 +64,6 @@
#include "chrome/browser/gtk/gtk_theme_provider.h"
#endif
-#if defined(OS_CHROMEOS)
-#include "chrome/browser/chromeos/preferences.h"
-#endif
-
using base::Time;
using base::TimeDelta;
@@ -423,22 +420,6 @@ class OffTheRecordProfileImpl : public Profile,
return false;
}
- virtual std::wstring GetName() {
- return profile_->GetName();
- }
-
- virtual void SetName(const std::wstring& name) {
- profile_->SetName(name);
- }
-
- virtual std::wstring GetID() {
- return profile_->GetID();
- }
-
- virtual void SetID(const std::wstring& id) {
- profile_->SetID(id);
- }
-
virtual bool DidLastSessionExitCleanly() {
return profile_->DidLastSessionExitCleanly();
}
@@ -861,13 +842,7 @@ PrefService* ProfileImpl::GetPrefs() {
// The Profile class and ProfileManager class may read some prefs so
// register known prefs as soon as possible.
Profile::RegisterUserPrefs(prefs_.get());
- ProfileManager::RegisterUserPrefs(prefs_.get());
-#if defined(OS_CHROMEOS)
- // Register Touchpad prefs here instead of in browser_prefs because these
- // prefs are used in the constructor of ProfileImpl which happens before
- // browser_prefs' RegisterAllPrefs is called.
- chromeos::Preferences::RegisterUserPrefs(prefs_.get());
-#endif
+ browser::RegisterUserPrefs(prefs_.get());
// The last session exited cleanly if there is no pref for
// kSessionExitedCleanly or the value for kSessionExitedCleanly is true.
@@ -1160,20 +1135,6 @@ bool ProfileImpl::HasSessionService() const {
return (session_service_.get() != NULL);
}
-std::wstring ProfileImpl::GetName() {
- return GetPrefs()->GetString(prefs::kProfileName);
-}
-void ProfileImpl::SetName(const std::wstring& name) {
- GetPrefs()->SetString(prefs::kProfileName, name);
-}
-
-std::wstring ProfileImpl::GetID() {
- return GetPrefs()->GetString(prefs::kProfileID);
-}
-void ProfileImpl::SetID(const std::wstring& id) {
- GetPrefs()->SetString(prefs::kProfileID, id);
-}
-
bool ProfileImpl::DidLastSessionExitCleanly() {
// last_session_exited_cleanly_ is set when the preferences are loaded. Force
// it to be set by asking for the prefs.
diff --git a/chrome/browser/profile.h b/chrome/browser/profile.h
index 8b0eaae..1f3c4a3 100644
--- a/chrome/browser/profile.h
+++ b/chrome/browser/profile.h
@@ -307,12 +307,6 @@ class Profile {
// Returns true if this profile has a session service.
virtual bool HasSessionService() const = 0;
- // Convenience functions to get & set the name and ID of the profile.
- virtual std::wstring GetName() = 0;
- virtual void SetName(const std::wstring& name) = 0;
- virtual std::wstring GetID() = 0;
- virtual void SetID(const std::wstring& id) = 0;
-
// Returns true if the last time this profile was open it was exited cleanly.
virtual bool DidLastSessionExitCleanly() = 0;
@@ -442,10 +436,6 @@ class ProfileImpl : public Profile,
virtual SessionService* GetSessionService();
virtual void ShutdownSessionService();
virtual bool HasSessionService() const;
- virtual std::wstring GetName();
- virtual void SetName(const std::wstring& name);
- virtual std::wstring GetID();
- virtual void SetID(const std::wstring& id);
virtual bool DidLastSessionExitCleanly();
virtual BookmarkModel* GetBookmarkModel();
virtual bool IsSameProfile(Profile* profile);
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);
}
diff --git a/chrome/browser/profile_manager.h b/chrome/browser/profile_manager.h
index b52c7db..b27f47c 100644
--- a/chrome/browser/profile_manager.h
+++ b/chrome/browser/profile_manager.h
@@ -68,49 +68,19 @@ class ProfileManager : public NonThreadSafe,
ProfileManager();
virtual ~ProfileManager();
- // ProfileManager prefs are loaded as soon as the profile is created.
- static void RegisterUserPrefs(PrefService* prefs);
-
// Invokes ShutdownSessionService() on all profiles.
static void ShutdownSessionServices();
// Returns the default profile. This adds the profile to the
// ProfileManager if it doesn't already exist. This method returns NULL if
// the profile doesn't exist and we can't create it.
+ // The profile used can be overridden by using --profile on
Profile* GetDefaultProfile(const FilePath& user_data_dir);
- // If a profile with the given path is currently managed by this object,
- // return a pointer to the corresponding Profile object;
- // otherwise return NULL.
- Profile* GetProfileByPath(const FilePath& path) const;
-
- // If a profile with the given ID is currently managed by this object,
- // return a pointer to the corresponding Profile object;
- // otherwise returns NULL.
- Profile* GetProfileByID(const std::wstring& id) const;
-
- // Adds a profile to the set of currently-loaded profiles. Returns a
- // pointer to a Profile object corresponding to the given path.
- Profile* AddProfileByPath(const FilePath& path);
-
- // Adds a profile to the set of currently-loaded profiles. Returns a
- // pointer to a Profile object corresponding to the given profile ID.
- // If no profile with the given ID is known, returns NULL.
- Profile* AddProfileByID(const std::wstring& id);
-
- // Adds a pre-existing Profile object to the set managed by this
- // ProfileManager. This ProfileManager takes ownership of the Profile.
- // The Profile should not already be managed by this ProfileManager.
- // Returns true if the profile was added, false otherwise.
- bool AddProfile(Profile* profile);
-
- // Removes a profile from the set of currently-loaded profiles. The path must
- // be exactly the same (including case) as when GetProfileByPath was called.
- void RemoveProfileByPath(const FilePath& path);
-
- // Removes a profile from the set of currently-loaded profiles.
- // (Does not delete the profile object.)
- void RemoveProfile(Profile* profile);
+ // Returns a profile for a specific profile directory within the user data
+ // dir. This will return an existing profile it had already been created,
+ // otherwise it will create and manage it.
+ Profile* GetProfile(const FilePath& profile_dir);
// These allow iteration through the current list of profiles.
typedef std::vector<Profile*> ProfileVector;
@@ -123,12 +93,6 @@ class ProfileManager : public NonThreadSafe,
const_iterator end() const { return profiles_.end(); }
typedef std::vector<AvailableProfile*> AvailableProfileVector;
- const AvailableProfileVector& available_profiles() const {
- return available_profiles_;
- }
-
- // Creates a new window with the given profile.
- void NewWindowWithProfile(Profile* profile);
// PowerObserver notifications
void OnSuspend();
@@ -139,36 +103,34 @@ class ProfileManager : public NonThreadSafe,
// Returns the path to the profile directory based on the user data directory.
static FilePath GetDefaultProfileDir(const FilePath& user_data_dir);
- // Returns the path to the profile given the user profile directory.
- static FilePath GetDefaultProfilePath(const FilePath& profile_dir);
+// Returns the path to the preferences file given the user profile directory.
+ static FilePath GetProfilePrefsPath(const FilePath& profile_dir);
// Tries to determine whether the given path represents a profile
// directory, and returns true if it thinks it does.
static bool IsProfile(const FilePath& path);
- // Tries to copy profile data from the source path to the destination path,
- // returning true if successful.
- static bool CopyProfileData(const FilePath& source_path,
- const FilePath& destination_path);
+ // If a profile with the given path is currently managed by this object,
+ // return a pointer to the corresponding Profile object;
+ // otherwise return NULL.
+ Profile* GetProfileByPath(const FilePath& path) const;
- // Creates a new profile at the specified path with the given name and ID.
- // |name| is the full-length human-readable name for the profile
- // |nickname| is a shorter name for the profile--can be empty string
+ // Creates a new profile at the specified path.
// This method should always return a valid Profile (i.e., should never
// return NULL).
- static Profile* CreateProfile(const FilePath& path,
- const std::wstring& name,
- const std::wstring& nickname,
- const std::wstring& id);
+ static Profile* CreateProfile(const FilePath& path);
+
+ // Adds a profile to the set of currently-loaded profiles. Returns a
+ // pointer to a Profile object corresponding to the given path.
+ Profile* AddProfileByPath(const FilePath& path);
- // Returns the canonical form of the given ID string.
- static std::wstring CanonicalizeID(const std::wstring& id);
+ // Adds a pre-existing Profile object to the set managed by this
+ // ProfileManager. This ProfileManager takes ownership of the Profile.
+ // The Profile should not already be managed by this ProfileManager.
+ // Returns true if the profile was added, false otherwise.
+ bool AddProfile(Profile* profile);
private:
- // Returns the AvailableProfile entry associated with the given ID,
- // or NULL if no match is found.
- AvailableProfile* GetAvailableProfileByID(const std::wstring& id);
-
// Hooks to suspend/resume per-profile network traffic.
// These must be called on the IO thread.
static void SuspendProfile(Profile*);
diff --git a/chrome/browser/profile_manager_unittest.cc b/chrome/browser/profile_manager_unittest.cc
index b4f328ed..e38e68f 100644
--- a/chrome/browser/profile_manager_unittest.cc
+++ b/chrome/browser/profile_manager_unittest.cc
@@ -35,22 +35,6 @@ class ProfileManagerTest : public testing::Test {
FilePath test_dir_;
};
-TEST_F(ProfileManagerTest, CopyProfileData) {
- FilePath source_path;
- PathService::Get(chrome::DIR_TEST_DATA, &source_path);
- source_path = source_path.Append(FILE_PATH_LITERAL("profiles"));
-
- ASSERT_FALSE(ProfileManager::IsProfile(source_path));
- source_path = source_path.Append(FILE_PATH_LITERAL("sample"));
- ASSERT_TRUE(ProfileManager::IsProfile(source_path));
-
- FilePath dest_path = test_dir_;
- dest_path = dest_path.Append(FILE_PATH_LITERAL("profile_copy"));
- ASSERT_FALSE(ProfileManager::IsProfile(dest_path));
- ASSERT_TRUE(ProfileManager::CopyProfileData(source_path, dest_path));
- ASSERT_TRUE(ProfileManager::IsProfile(dest_path));
-}
-
TEST_F(ProfileManagerTest, CreateProfile) {
FilePath source_path;
PathService::Get(chrome::DIR_TEST_DATA, &source_path);
@@ -63,13 +47,9 @@ TEST_F(ProfileManagerTest, CreateProfile) {
scoped_ptr<Profile> profile;
// Successfully create a profile.
- profile.reset(ProfileManager::CreateProfile(dest_path, L"New Profile", L"",
- L"new-profile"));
+ profile.reset(ProfileManager::CreateProfile(dest_path));
ASSERT_TRUE(profile.get());
- PrefService* prefs = profile->GetPrefs();
- ASSERT_EQ(L"New Profile", prefs->GetString(prefs::kProfileName));
- ASSERT_EQ(L"new-profile", prefs->GetString(prefs::kProfileID));
profile.reset();
#ifdef NDEBUG
@@ -77,12 +57,8 @@ TEST_F(ProfileManagerTest, CreateProfile) {
// these cases would trigger DCHECKs.
// The profile already exists when we call CreateProfile. Just load it.
- profile.reset(ProfileManager::CreateProfile(dest_path, L"New Profile", L"",
- L"new-profile"));
+ profile.reset(ProfileManager::CreateProfile(dest_path));
ASSERT_TRUE(profile.get());
- prefs = profile->GetPrefs();
- ASSERT_EQ(L"New Profile", prefs->GetString(prefs::kProfileName));
- ASSERT_EQ(L"new-profile", prefs->GetString(prefs::kProfileID));
#endif
}
@@ -104,12 +80,10 @@ TEST_F(ProfileManagerTest, DISABLED_CreateAndUseTwoProfiles) {
scoped_ptr<Profile> profile2;
// Successfully create the profiles.
- profile1.reset(ProfileManager::CreateProfile(dest_path1, L"New Profile 1",
- L"", L"new-profile-1"));
+ profile1.reset(ProfileManager::CreateProfile(dest_path1));
ASSERT_TRUE(profile1.get());
- profile2.reset(ProfileManager::CreateProfile(dest_path2, L"New Profile 2",
- L"", L"new-profile-2"));
+ profile2.reset(ProfileManager::CreateProfile(dest_path2));
ASSERT_TRUE(profile2.get());
// Force lazy-init of some profile services to simulate use.
diff --git a/chrome/browser/renderer_host/browser_render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc
index db701ab..9726e6e 100644
--- a/chrome/browser/renderer_host/browser_render_process_host.cc
+++ b/chrome/browser/renderer_host/browser_render_process_host.cc
@@ -463,10 +463,16 @@ void BrowserRenderProcessHost::AppendRendererCommandLine(
ChildProcessHost::SetCrashReporterCommandLine(command_line);
- const std::string& profile_path =
+ const std::string user_data_dir =
browser_command_line.GetSwitchValueASCII(switches::kUserDataDir);
- if (!profile_path.empty())
- command_line->AppendSwitchWithValue(switches::kUserDataDir, profile_path);
+ if (!user_data_dir.empty())
+ command_line->AppendSwitchWithValue(switches::kUserDataDir, user_data_dir);
+#if defined(OS_CHROMEOS)
+ const std::string& profile =
+ browser_command_line.GetSwitchValueASCII(switches::kProfile);
+ if (!profile.empty())
+ command_line->AppendSwitchWithValue(switches::kProfile, profile);
+#endif
}
void BrowserRenderProcessHost::PropogateBrowserCommandLineToRenderer(
diff --git a/chrome/common/chrome_plugin_util.cc b/chrome/common/chrome_plugin_util.cc
index 4643a87..e3b0f40 100644
--- a/chrome/common/chrome_plugin_util.cc
+++ b/chrome/common/chrome_plugin_util.cc
@@ -138,6 +138,14 @@ CPError CPB_GetCommandLineArgumentsCommon(const char* url,
}
}
+#if defined (OS_CHROMEOS)
+ std::wstring profile = cmd.GetSwitchValue(switches::kProfile);
+ if (!profile.empty()) {
+ arguments_w += std::wstring(L"--") + ASCIIToWide(switches::kProfile) +
+ L"=\"" + profile + L"\" ";
+ }
+#endif
+
// Use '--app=url' instead of just 'url' to launch the browser with minimal
// chrome.
// Note: Do not change this flag! Old Gears shortcuts will break if you do!
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index 9b310bc..07efb297 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -443,6 +443,11 @@ const char kProcessPerSite[] = "process-per-site";
// script connections to each other).
const char kProcessPerTab[] = "process-per-tab";
+#if defined(OS_CHROMEOS)
+// Overrides the Default profile.
+const char kProfile[] = "profile";
+#endif
+
// Causes the process to run as a profile import subprocess.
const char kProfileImportProcess[] = "profile-import";
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index 2162976..e21d56fe 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -188,6 +188,7 @@ extern const char kZygoteProcess[];
extern const char kCookiePipe[];
extern const char kEnableGView[];
extern const char kTestLoadLibcros[];
+extern const char kProfile[];
#endif
#if defined(OS_LINUX)
diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc
index 702ddc2..40b5e0b 100644
--- a/chrome/common/pref_names.cc
+++ b/chrome/common/pref_names.cc
@@ -15,16 +15,6 @@ const wchar_t kHomePageIsNewTabPage[] = L"homepage_is_newtabpage";
// This is the URL of the page to load when opening new tabs.
const wchar_t kHomePage[] = L"homepage";
-// This is the human-readable name of the current profile.
-const wchar_t kProfileName[] = L"profile.name";
-
-// This is the abbreviated human-readable name of the current profile
-const wchar_t kProfileNickname[] = L"profile.nickname";
-
-// This is a short, preferably human-readable ID for the current profile.
-// Its value should be unique within the current user data directory.
-const wchar_t kProfileID[] = L"profile.id";
-
// Used to determine if the last session exited cleanly. Set to false when
// first opened, and to true when closing. On startup if the value is false,
// it means the profile didn't exit cleanly.
diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h
index 0a5f182..4b107e7 100644
--- a/chrome/common/pref_names.h
+++ b/chrome/common/pref_names.h
@@ -14,9 +14,6 @@ namespace prefs {
// Profile prefs
extern const wchar_t kHomePageIsNewTabPage[];
extern const wchar_t kHomePage[];
-extern const wchar_t kProfileName[];
-extern const wchar_t kProfileNickname[];
-extern const wchar_t kProfileID[];
extern const wchar_t kSessionExitedCleanly[];
extern const wchar_t kRestoreOnStartup[];
extern const wchar_t kURLsToRestoreOnStartup[];
diff --git a/chrome/test/live_sync/live_bookmarks_sync_test.cc b/chrome/test/live_sync/live_bookmarks_sync_test.cc
index 0fb4276..8d16edc 100644
--- a/chrome/test/live_sync/live_bookmarks_sync_test.cc
+++ b/chrome/test/live_sync/live_bookmarks_sync_test.cc
@@ -77,7 +77,7 @@ Profile* LiveBookmarksSyncTest::MakeProfile(const std::wstring& name) {
FilePath path;
PathService::Get(chrome::DIR_USER_DATA, &path);
path.Append(FilePath::FromWStringHack(name));
- return ProfileManager::CreateProfile(path, name, L"", L"");
+ return ProfileManager::CreateProfile(path);
}
void LiveBookmarksSyncTest::SetUpInProcessBrowserTestFixture() {
diff --git a/net/base/file_stream_posix.cc b/net/base/file_stream_posix.cc
index aac0be2..f039996 100644
--- a/net/base/file_stream_posix.cc
+++ b/net/base/file_stream_posix.cc
@@ -331,7 +331,8 @@ int FileStream::Open(const FilePath& path, int open_flags) {
open_flags_ = open_flags;
file_ = base::CreatePlatformFile(path.ToWStringHack(), open_flags_, NULL);
if (file_ == base::kInvalidPlatformFileValue) {
- LOG(WARNING) << "Failed to open file: " << errno;
+ LOG(WARNING) << "Failed to open file: " << errno
+ << " (" << path.ToWStringHack() << ")";
return MapErrorCode(errno);
}