diff options
-rw-r--r-- | chrome/browser/extensions/extension_managed_mode_api.cc | 2 | ||||
-rw-r--r-- | chrome/browser/managed_mode.cc | 39 | ||||
-rw-r--r-- | chrome/browser/managed_mode.h | 8 |
3 files changed, 43 insertions, 6 deletions
diff --git a/chrome/browser/extensions/extension_managed_mode_api.cc b/chrome/browser/extensions/extension_managed_mode_api.cc index d0258ef..1471743 100644 --- a/chrome/browser/extensions/extension_managed_mode_api.cc +++ b/chrome/browser/extensions/extension_managed_mode_api.cc @@ -39,7 +39,7 @@ bool EnterManagedModeFunction::RunImpl() { // TODO(pamg): WIP. Show modal password dialog and save hashed password. Set // |confirmed| to false if user cancels dialog. - confirmed = ManagedMode::EnterManagedMode(); + confirmed = ManagedMode::EnterManagedMode(profile()); } scoped_ptr<DictionaryValue> result(new DictionaryValue); diff --git a/chrome/browser/managed_mode.cc b/chrome/browser/managed_mode.cc index cd9d14d..cef0d9e 100644 --- a/chrome/browser/managed_mode.cc +++ b/chrome/browser/managed_mode.cc @@ -7,6 +7,8 @@ #include "base/command_line.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/prefs/pref_service.h" +#include "chrome/browser/profiles/profile_manager.h" +#include "chrome/browser/ui/browser_list.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" @@ -30,14 +32,43 @@ bool ManagedMode::IsInManagedMode() { } // static -bool ManagedMode::EnterManagedMode() { - SetInManagedMode(true); - return true; +bool ManagedMode::EnterManagedMode(Profile* profile) { + bool confirmed = PlatformConfirmEnter(); + if (confirmed) { + // Close all other profiles. + // TODO(bauerb): This may not close all windows, for example if there is an + // onbeforeunload handler. We should cancel entering managed mode in that + // case. + std::vector<Profile*> profiles = + g_browser_process->profile_manager()->GetLoadedProfiles(); + for (std::vector<Profile*>::iterator it = profiles.begin(); + it != profiles.end(); ++it) { + if (*it != profile) + BrowserList::CloseAllBrowsersWithProfile(*it); + } + + SetInManagedMode(true); + } + return confirmed; } // static void ManagedMode::LeaveManagedMode() { - SetInManagedMode(false); + bool confirmed = PlatformConfirmLeave(); + if (confirmed) + SetInManagedMode(false); +} + +// static +bool ManagedMode::PlatformConfirmEnter() { + // TODO(bauerb): Show platform-specific confirmation dialog. + return true; +} + +// static +bool ManagedMode::PlatformConfirmLeave() { + // TODO(bauerb): Show platform-specific confirmation dialog. + return true; } // static diff --git a/chrome/browser/managed_mode.h b/chrome/browser/managed_mode.h index 93cc9ad..11466bf 100644 --- a/chrome/browser/managed_mode.h +++ b/chrome/browser/managed_mode.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_MANAGED_MODE_H_ class PrefService; +class Profile; class ManagedMode { public: @@ -13,10 +14,15 @@ class ManagedMode { static bool IsInManagedMode(); // Returns true iff managed mode was entered sucessfully. - static bool EnterManagedMode(); + static bool EnterManagedMode(Profile* profile); static void LeaveManagedMode(); private: + // Platform-specific methods that confirm whether we can enter or leave + // managed mode. + static bool PlatformConfirmEnter(); + static bool PlatformConfirmLeave(); + static void SetInManagedMode(bool in_managed_mode); }; |