summaryrefslogtreecommitdiffstats
path: root/chrome/browser/profiles
diff options
context:
space:
mode:
authorjwd@chromium.org <jwd@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-17 04:33:40 +0000
committerjwd@chromium.org <jwd@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-17 04:33:40 +0000
commit4251165a510cacb88fd7ab028d3e902fcbf78195 (patch)
tree16b63403919ce96e7ca2cb2605a56416082d9f46 /chrome/browser/profiles
parentca2704c8bb6f89adf2fd5686aba000700247b603 (diff)
downloadchromium_src-4251165a510cacb88fd7ab028d3e902fcbf78195.zip
chromium_src-4251165a510cacb88fd7ab028d3e902fcbf78195.tar.gz
chromium_src-4251165a510cacb88fd7ab028d3e902fcbf78195.tar.bz2
Adding a first prototype of guest mode.
This currently doesn't support the guest contract (fresh profile each session). That will come in a future CL. Screenshot of UI available at https://docs.google.com/file/d/0B2G_JZ2jrki9VFdQem1GRkp2RWM/edit?usp=sharing BUG=103846 TEST=Launch chrome with the flag enable-desktop-guest-mode. The avatar menu should be shown even when there is only one profile, there should be a guest link in the menu and it should launch a new window with no avatar menu. Launching that window will also cause a directory called "Guest Profile" to be created in the user data dir. Review URL: https://chromiumcodereview.appspot.com/11877033 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@211931 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/profiles')
-rw-r--r--chrome/browser/profiles/avatar_menu_model.cc21
-rw-r--r--chrome/browser/profiles/avatar_menu_model.h2
-rw-r--r--chrome/browser/profiles/off_the_record_profile_impl.cc2
-rw-r--r--chrome/browser/profiles/off_the_record_profile_impl.h2
-rw-r--r--chrome/browser/profiles/profile.cc3
-rw-r--r--chrome/browser/profiles/profile.h2
-rw-r--r--chrome/browser/profiles/profile_impl.cc2
-rw-r--r--chrome/browser/profiles/profile_impl.h2
-rw-r--r--chrome/browser/profiles/profile_manager.cc53
-rw-r--r--chrome/browser/profiles/profile_manager.h6
-rw-r--r--chrome/browser/profiles/profile_manager_unittest.cc7
11 files changed, 78 insertions, 24 deletions
diff --git a/chrome/browser/profiles/avatar_menu_model.cc b/chrome/browser/profiles/avatar_menu_model.cc
index f05dd2f..4a86e7f 100644
--- a/chrome/browser/profiles/avatar_menu_model.cc
+++ b/chrome/browser/profiles/avatar_menu_model.cc
@@ -192,6 +192,18 @@ base::FilePath AvatarMenuModel::GetProfilePath(size_t index) {
return profile_info_->GetPathOfProfileAtIndex(item.model_index);
}
+// static
+void AvatarMenuModel::SwitchToGuestProfileWindow(Browser* browser) {
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ profile_manager->CreateProfileAsync(ProfileManager::GetGuestProfilePath(),
+ base::Bind(&OnProfileCreated,
+ false,
+ browser->host_desktop_type()),
+ string16(),
+ string16(),
+ false);
+}
+
size_t AvatarMenuModel::GetNumberOfItems() {
return items_.size();
}
@@ -272,9 +284,12 @@ bool AvatarMenuModel::ShouldShowAvatarMenu() {
DCHECK(ProfileManager::IsMultipleProfilesEnabled());
return true;
}
- return ProfileManager::IsMultipleProfilesEnabled() &&
- g_browser_process->profile_manager() &&
- g_browser_process->profile_manager()->GetNumberOfProfiles() > 1;
+ if (ProfileManager::IsMultipleProfilesEnabled()) {
+ return ProfileManager::IsNewProfileManagementEnabled() ||
+ (g_browser_process->profile_manager() &&
+ g_browser_process->profile_manager()->GetNumberOfProfiles() > 1);
+ }
+ return false;
}
void AvatarMenuModel::RebuildMenu() {
diff --git a/chrome/browser/profiles/avatar_menu_model.h b/chrome/browser/profiles/avatar_menu_model.h
index 0ab6818..95668b4 100644
--- a/chrome/browser/profiles/avatar_menu_model.h
+++ b/chrome/browser/profiles/avatar_menu_model.h
@@ -74,6 +74,8 @@ class AvatarMenuModel : public content::NotificationObserver {
void EditProfile(size_t index);
// Creates a new profile.
void AddNewProfile(ProfileMetrics::ProfileAdd type);
+ // Creates a new guest user window.
+ static void SwitchToGuestProfileWindow(Browser* browser);
// Gets the path associated with the profile at |index|.
base::FilePath GetProfilePath(size_t index);
diff --git a/chrome/browser/profiles/off_the_record_profile_impl.cc b/chrome/browser/profiles/off_the_record_profile_impl.cc
index 52fda4c..cf95b53 100644
--- a/chrome/browser/profiles/off_the_record_profile_impl.cc
+++ b/chrome/browser/profiles/off_the_record_profile_impl.cc
@@ -189,7 +189,7 @@ std::string OffTheRecordProfileImpl::GetProfileName() {
return std::string();
}
-base::FilePath OffTheRecordProfileImpl::GetPath() {
+base::FilePath OffTheRecordProfileImpl::GetPath() const {
return profile_->GetPath();
}
diff --git a/chrome/browser/profiles/off_the_record_profile_impl.h b/chrome/browser/profiles/off_the_record_profile_impl.h
index 1a7b946..6559269c 100644
--- a/chrome/browser/profiles/off_the_record_profile_impl.h
+++ b/chrome/browser/profiles/off_the_record_profile_impl.h
@@ -83,7 +83,7 @@ class OffTheRecordProfileImpl : public Profile {
virtual GURL GetHomePage() OVERRIDE;
// content::BrowserContext implementation:
- virtual base::FilePath GetPath() OVERRIDE;
+ virtual base::FilePath GetPath() const OVERRIDE;
virtual scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner() OVERRIDE;
virtual bool IsOffTheRecord() const OVERRIDE;
virtual content::DownloadManagerDelegate*
diff --git a/chrome/browser/profiles/profile.cc b/chrome/browser/profiles/profile.cc
index cea0f90..93415c7 100644
--- a/chrome/browser/profiles/profile.cc
+++ b/chrome/browser/profiles/profile.cc
@@ -10,6 +10,7 @@
#include "build/build_config.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/first_run/first_run.h"
+#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/sync/sync_prefs.h"
@@ -168,7 +169,7 @@ bool Profile::IsGuestSession() const {
chromeos::switches::kGuestSession);
return is_guest_session;
#else
- return false;
+ return GetPath() == ProfileManager::GetGuestProfilePath();
#endif
}
diff --git a/chrome/browser/profiles/profile.h b/chrome/browser/profiles/profile.h
index 61ef0ca..19a232a9 100644
--- a/chrome/browser/profiles/profile.h
+++ b/chrome/browser/profiles/profile.h
@@ -325,7 +325,7 @@ class Profile : public content::BrowserContext {
std::string GetDebugName();
// Returns whether it is a guest session.
- bool IsGuestSession() const;
+ virtual bool IsGuestSession() const;
// Did the user restore the last session? This is set by SessionRestore.
void set_restored_last_session(bool restored_last_session) {
diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc
index 5bf3a34..d363656a 100644
--- a/chrome/browser/profiles/profile_impl.cc
+++ b/chrome/browser/profiles/profile_impl.cc
@@ -663,7 +663,7 @@ std::string ProfileImpl::GetProfileName() {
return GetPrefs()->GetString(prefs::kGoogleServicesUsername);
}
-base::FilePath ProfileImpl::GetPath() {
+base::FilePath ProfileImpl::GetPath() const {
return path_;
}
diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h
index d7520a7..d2c7396 100644
--- a/chrome/browser/profiles/profile_impl.h
+++ b/chrome/browser/profiles/profile_impl.h
@@ -61,7 +61,7 @@ class ProfileImpl : public Profile {
static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
// content::BrowserContext implementation:
- virtual base::FilePath GetPath() OVERRIDE;
+ virtual base::FilePath GetPath() const OVERRIDE;
virtual content::DownloadManagerDelegate*
GetDownloadManagerDelegate() OVERRIDE;
virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profiles/profile_manager.cc
index 6811e87..d0079b7 100644
--- a/chrome/browser/profiles/profile_manager.cc
+++ b/chrome/browser/profiles/profile_manager.cc
@@ -929,6 +929,16 @@ base::FilePath ProfileManager::CreateMultiProfileAsync(
}
// static
+base::FilePath ProfileManager::GetGuestProfilePath() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+
+ base::FilePath guest_path = profile_manager->user_data_dir();
+ return guest_path.Append(chrome::kGuestProfileDir);
+}
+
+// static
void ProfileManager::RegisterPrefs(PrefRegistrySimple* registry) {
registry->RegisterStringPref(prefs::kProfileLastUsed, std::string());
registry->RegisterIntegerPref(prefs::kProfilesNumCreated, 1);
@@ -965,6 +975,8 @@ ProfileShortcutManager* ProfileManager::profile_shortcut_manager() {
}
void ProfileManager::AddProfileToCache(Profile* profile) {
+ if (profile->IsGuestSession())
+ return;
ProfileInfoCache& cache = GetProfileInfoCache();
if (profile->GetPath().DirName() != cache.GetUserDataDir())
return;
@@ -998,25 +1010,30 @@ void ProfileManager::InitProfileUserPrefs(Profile* profile) {
if (profile->GetPath().DirName() != cache.GetUserDataDir())
return;
+ bool is_managed = false;
size_t avatar_index;
std::string profile_name;
- bool is_managed = false;
- size_t profile_cache_index =
- cache.GetIndexOfProfileWithPath(profile->GetPath());
- // If the cache has an entry for this profile, use the cache data.
- if (profile_cache_index != std::string::npos) {
- avatar_index =
- cache.GetAvatarIconIndexOfProfileAtIndex(profile_cache_index);
- profile_name =
- UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_cache_index));
- is_managed = cache.ProfileIsManagedAtIndex(profile_cache_index);
- } else if (profile->GetPath() ==
- GetDefaultProfileDir(cache.GetUserDataDir())) {
+ if (profile->IsGuestSession()) {
+ profile_name = l10n_util::GetStringUTF8(IDS_PROFILES_GUEST_PROFILE_NAME);
avatar_index = 0;
- profile_name = l10n_util::GetStringUTF8(IDS_DEFAULT_PROFILE_NAME);
} else {
- avatar_index = cache.ChooseAvatarIconIndexForNewProfile();
- profile_name = UTF16ToUTF8(cache.ChooseNameForNewProfile(avatar_index));
+ size_t profile_cache_index =
+ cache.GetIndexOfProfileWithPath(profile->GetPath());
+ // If the cache has an entry for this profile, use the cache data.
+ if (profile_cache_index != std::string::npos) {
+ avatar_index =
+ cache.GetAvatarIconIndexOfProfileAtIndex(profile_cache_index);
+ profile_name =
+ UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_cache_index));
+ is_managed = cache.ProfileIsManagedAtIndex(profile_cache_index);
+ } else if (profile->GetPath() ==
+ GetDefaultProfileDir(cache.GetUserDataDir())) {
+ avatar_index = 0;
+ profile_name = l10n_util::GetStringUTF8(IDS_DEFAULT_PROFILE_NAME);
+ } else {
+ avatar_index = cache.ChooseAvatarIconIndexForNewProfile();
+ profile_name = UTF16ToUTF8(cache.ChooseNameForNewProfile(avatar_index));
+ }
}
if (!profile->GetPrefs()->HasPrefPath(prefs::kProfileAvatarIndex))
@@ -1164,6 +1181,12 @@ bool ProfileManager::IsMultipleProfilesEnabled() {
return true;
}
+// static
+bool ProfileManager::IsNewProfileManagementEnabled() {
+ return CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kNewProfileManagement);
+}
+
void ProfileManager::AutoloadProfiles() {
// If running in the background is disabled for the browser, do not autoload
// any profiles.
diff --git a/chrome/browser/profiles/profile_manager.h b/chrome/browser/profiles/profile_manager.h
index 1b2ba42..c26bd56 100644
--- a/chrome/browser/profiles/profile_manager.h
+++ b/chrome/browser/profiles/profile_manager.h
@@ -202,6 +202,9 @@ class ProfileManager : public base::NonThreadSafe,
const CreateCallback& callback,
bool is_managed);
+ // Returns the full path to be used for guest profiles.
+ static base::FilePath GetGuestProfilePath();
+
// Register multi-profile related preferences in Local State.
static void RegisterPrefs(PrefRegistrySimple* registry);
@@ -222,6 +225,9 @@ class ProfileManager : public base::NonThreadSafe,
// Checks if multiple profiles is enabled.
static bool IsMultipleProfilesEnabled();
+ // Checks if new profile management is enabled.
+ static bool IsNewProfileManagementEnabled();
+
// Autoloads profiles if they are running background apps.
void AutoloadProfiles();
diff --git a/chrome/browser/profiles/profile_manager_unittest.cc b/chrome/browser/profiles/profile_manager_unittest.cc
index 3ceedcb..86f9f57 100644
--- a/chrome/browser/profiles/profile_manager_unittest.cc
+++ b/chrome/browser/profiles/profile_manager_unittest.cc
@@ -302,6 +302,13 @@ TEST_F(ProfileManagerTest, CreateProfilesAsync) {
message_loop_.RunUntilIdle();
}
+TEST_F(ProfileManagerTest, GetGuestProfilePath) {
+ base::FilePath guest_path = ProfileManager::GetGuestProfilePath();
+ base::FilePath expected_path = temp_dir_.path();
+ expected_path = expected_path.Append(chrome::kGuestProfileDir);
+ EXPECT_EQ(expected_path, guest_path);
+}
+
TEST_F(ProfileManagerTest, AutoloadProfilesWithBackgroundApps) {
ProfileManager* profile_manager = g_browser_process->profile_manager();
ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();