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

Unified Diff: chrome/browser/profiles/profile_manager.cc

Issue 9087009: Restore all profiles which were active when restoring the last open pages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code review. Created 8 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/profiles/profile_manager.h ('k') | chrome/browser/profiles/profile_manager_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/profiles/profile_manager.cc
diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profiles/profile_manager.cc
index b1943b6160a14e24b420557dfc6ac136f40632bc..ed8dfac87b40404cb8b8035758f920ca4a257836 100644
--- a/chrome/browser/profiles/profile_manager.cc
+++ b/chrome/browser/profiles/profile_manager.cc
@@ -181,10 +181,18 @@ Profile* ProfileManager::GetLastUsedProfile() {
return profile_manager->GetLastUsedProfile(profile_manager->user_data_dir_);
}
+// static
+std::vector<Profile*> ProfileManager::GetLastOpenedProfiles() {
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ return profile_manager->GetLastOpenedProfiles(
+ profile_manager->user_data_dir_);
+}
+
ProfileManager::ProfileManager(const FilePath& user_data_dir)
: user_data_dir_(user_data_dir),
logged_in_(false),
- will_import_(false) {
+ will_import_(false),
+ shutdown_started_(false) {
BrowserList::AddObserver(this);
#if defined(OS_CHROMEOS)
registrar_.Add(
@@ -192,6 +200,18 @@ ProfileManager::ProfileManager(const FilePath& user_data_dir)
chrome::NOTIFICATION_LOGIN_USER_CHANGED,
content::NotificationService::AllSources());
#endif
+ registrar_.Add(
+ this,
+ chrome::NOTIFICATION_BROWSER_OPENED,
+ content::NotificationService::AllSources());
+ registrar_.Add(
+ this,
+ chrome::NOTIFICATION_BROWSER_CLOSED,
+ content::NotificationService::AllSources());
+ registrar_.Add(
+ this,
+ content::NOTIFICATION_APP_EXITING,
+ content::NotificationService::AllSources());
}
ProfileManager::~ProfileManager() {
@@ -255,6 +275,30 @@ Profile* ProfileManager::GetLastUsedProfile(const FilePath& user_data_dir) {
return GetProfile(last_used_profile_dir);
}
+std::vector<Profile*> ProfileManager::GetLastOpenedProfiles(
+ const FilePath& user_data_dir) {
+ PrefService* local_state = g_browser_process->local_state();
+ DCHECK(local_state);
+
+ std::vector<Profile*> to_return;
+ if (local_state->HasPrefPath(prefs::kProfilesLastActive)) {
+ const ListValue* profile_list =
+ local_state->GetList(prefs::kProfilesLastActive);
+ if (profile_list) {
+ ListValue::const_iterator it;
+ std::string profile;
+ for (it = profile_list->begin(); it != profile_list->end(); ++it) {
+ if (!(*it)->GetAsString(&profile) || profile.empty()) {
+ LOG(WARNING) << "Invalid entry in " << prefs::kProfilesLastActive;
+ continue;
+ }
+ to_return.push_back(GetProfile(user_data_dir.AppendASCII(profile)));
+ }
+ }
+ }
+ return to_return;
+}
+
Profile* ProfileManager::GetDefaultProfile(const FilePath& user_data_dir) {
FilePath default_profile_dir(user_data_dir);
default_profile_dir = default_profile_dir.Append(GetInitialProfileDir());
@@ -413,8 +457,62 @@ void ProfileManager::Observe(
CHECK(chromeos::CrosLibrary::Get()->GetCryptohomeLibrary()->IsMounted());
}
logged_in_ = true;
+ return;
}
#endif
+ if (shutdown_started_)
+ return;
+
+ bool update_active_profiles = false;
+ switch (type) {
+ case content::NOTIFICATION_APP_EXITING: {
+ // Ignore any browsers closing from now on.
+ shutdown_started_ = true;
+ break;
+ }
+ case chrome::NOTIFICATION_BROWSER_OPENED: {
+ Browser* browser = content::Source<Browser>(source).ptr();
+ DCHECK(browser);
+ Profile* profile = browser->profile();
+ DCHECK(profile);
+ if (++browser_counts_[profile] == 1) {
+ active_profiles_.push_back(profile);
+ update_active_profiles = true;
+ }
+ break;
+ }
+ case chrome::NOTIFICATION_BROWSER_CLOSED: {
+ Browser* browser = content::Source<Browser>(source).ptr();
+ DCHECK(browser);
+ Profile* profile = browser->profile();
+ DCHECK(profile);
+ if (--browser_counts_[profile] == 0) {
+ active_profiles_.erase(
+ std::remove(active_profiles_.begin(), active_profiles_.end(),
+ profile),
+ active_profiles_.end());
+ update_active_profiles = true;
+ }
+ break;
+ }
+ default: {
+ NOTREACHED();
+ break;
+ }
+ }
+ if (update_active_profiles) {
+ PrefService* local_state = g_browser_process->local_state();
+ DCHECK(local_state);
+ ListPrefUpdate update(local_state, prefs::kProfilesLastActive);
+ ListValue* profile_list = update.Get();
+
+ profile_list->Clear();
+ std::vector<Profile*>::const_iterator it;
+ for (it = active_profiles_.begin(); it != active_profiles_.end(); ++it) {
+ profile_list->Append(
+ new StringValue((*it)->GetPath().BaseName().MaybeAsASCII()));
+ }
+ }
}
void ProfileManager::SetWillImport() {
@@ -553,6 +651,7 @@ void ProfileManager::CreateMultiProfileAsync() {
void ProfileManager::RegisterPrefs(PrefService* prefs) {
prefs->RegisterStringPref(prefs::kProfileLastUsed, "");
prefs->RegisterIntegerPref(prefs::kProfilesNumCreated, 1);
+ prefs->RegisterListPref(prefs::kProfilesLastActive);
}
size_t ProfileManager::GetNumberOfProfiles() {
« no previous file with comments | « chrome/browser/profiles/profile_manager.h ('k') | chrome/browser/profiles/profile_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698