Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / login / session / user_session_manager.h
index e32e0cd..8a27904 100644 (file)
@@ -8,23 +8,35 @@
 #include <string>
 
 #include "base/basictypes.h"
+#include "base/callback.h"
+#include "base/memory/scoped_ptr.h"
 #include "base/memory/singleton.h"
 #include "base/memory/weak_ptr.h"
 #include "base/observer_list.h"
 #include "chrome/browser/chromeos/base/locale_util.h"
 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h"
 #include "chromeos/dbus/session_manager_client.h"
+#include "chromeos/ime/input_method_manager.h"
 #include "chromeos/login/auth/authenticator.h"
 #include "chromeos/login/auth/user_context.h"
 #include "components/user_manager/user.h"
+#include "components/user_manager/user_manager.h"
 #include "net/base/network_change_notifier.h"
 
 class PrefRegistrySimple;
 class PrefService;
 class Profile;
 
+namespace user_manager {
+
+class User;
+
+}  // namespace user_manager
+
 namespace chromeos {
 
+class EasyUnlockKeyManager;
+
 class UserSessionManagerDelegate {
  public:
   // Called after profile is loaded and prepared for the session.
@@ -58,7 +70,8 @@ class UserSessionManager
     : public OAuth2LoginManager::Observer,
       public net::NetworkChangeNotifier::ConnectionTypeObserver,
       public base::SupportsWeakPtr<UserSessionManager>,
-      public UserSessionManagerDelegate {
+      public UserSessionManagerDelegate,
+      public user_manager::UserManager::UserSessionStateObserver {
  public:
   // Returns UserSessionManager instance.
   static UserSessionManager* GetInstance();
@@ -91,10 +104,14 @@ class UserSessionManager
   // and notifies observers.
   void RestoreActiveSessions();
 
-  // Returns true iff browser has been restarted after crash and UserManager
-  // finished restoring user sessions.
+  // Returns true iff browser has been restarted after crash and
+  // UserSessionManager finished restoring user sessions.
   bool UserSessionsRestored() const;
 
+  // Returns true iff browser has been restarted after crash and
+  // user sessions restoration is in progress.
+  bool UserSessionsRestoreInProgress() const;
+
   // Initialize RLZ.
   void InitRlz(Profile* profile);
 
@@ -112,10 +129,9 @@ class UserSessionManager
 
   // Invoked when the user is logging in for the first time, or is logging in to
   // an ephemeral session type, such as guest or a public session.
-  static void SetFirstLoginPrefs(
-      PrefService* prefs,
-      const std::string& public_session_locale,
-      const std::string& public_session_input_method);
+  void SetFirstLoginPrefs(Profile* profile,
+                          const std::string& public_session_locale,
+                          const std::string& public_session_input_method);
 
   // Gets/sets Chrome OAuth client id and secret for kiosk app mode. The default
   // values can be overridden with kiosk auth file.
@@ -128,14 +144,30 @@ class UserSessionManager
 
   // Changes browser locale (selects best suitable locale from different
   // user settings). Returns true if callback will be called.
-  // Returns true if callback will be called.
   bool RespectLocalePreference(
       Profile* profile,
       const user_manager::User* user,
       scoped_ptr<locale_util::SwitchLanguageCallback> callback) const;
 
-  void AddSessionStateObserver(UserSessionStateObserver* observer);
-  void RemoveSessionStateObserver(UserSessionStateObserver* observer);
+  // Returns true if Easy unlock keys needs to be updated.
+  bool NeedsToUpdateEasyUnlockKeys() const;
+
+  // Returns true if there are pending Easy unlock key operations and
+  // |callback| will be invoked when it is done.
+  bool CheckEasyUnlockKeyOps(const base::Closure& callback);
+
+  void AddSessionStateObserver(chromeos::UserSessionStateObserver* observer);
+  void RemoveSessionStateObserver(chromeos::UserSessionStateObserver* observer);
+
+  virtual void ActiveUserChanged(
+      const user_manager::User* active_user) OVERRIDE;
+
+  // Returns default IME state for user session.
+  scoped_refptr<input_method::InputMethodManager::State> GetDefaultIMEState(
+      Profile* profile);
+
+  // Note this could return NULL if not enabled.
+  EasyUnlockKeyManager* GetEasyUnlockKeyManager();
 
  private:
   friend struct DefaultSingletonTraits<UserSessionManager>;
@@ -220,6 +252,12 @@ class UserSessionManager
   // Notifies observers that user pending sessions restore has finished.
   void NotifyPendingUserSessionsRestoreFinished();
 
+  // Update Easy unlock cryptohome keys using the pairing data in user prefs.
+  void UpdateEasyUnlockKeys(Profile* user_profile);
+
+  // Callback invoked when Easy unlock key operations are finished.
+  void OnEasyUnlockKeyOpsFinished(bool success);
+
   UserSessionManagerDelegate* delegate_;
 
   // Authentication/user context.
@@ -232,15 +270,18 @@ class UserSessionManager
 
   // Active user session restoration related members.
 
-  // True is user sessions has been restored after crash.
+  // True if user sessions has been restored after crash.
   // On a normal boot then login into user sessions this will be false.
   bool user_sessions_restored_;
 
+  // True if user sessions restoration after crash is in progress.
+  bool user_sessions_restore_in_progress_;
+
   // User sessions that have to be restored after browser crash.
   // [user_id] > [user_id_hash]
   SessionManagerClient::ActiveSessionsMap pending_user_sessions_;
 
-  ObserverList<UserSessionStateObserver> session_state_observer_list_;
+  ObserverList<chromeos::UserSessionStateObserver> session_state_observer_list_;
 
   // OAuth2 session related members.
 
@@ -262,6 +303,15 @@ class UserSessionManager
   std::string chrome_client_id_;
   std::string chrome_client_secret_;
 
+  // Per-user-session Input Methods states.
+  std::map<Profile*, scoped_refptr<input_method::InputMethodManager::State> >
+      default_ime_states_;
+
+  // Manages Easy unlock cryptohome keys.
+  scoped_ptr<EasyUnlockKeyManager> easy_unlock_key_manager_;
+  bool running_easy_unlock_key_ops_;
+  base::Closure easy_unlock_key_ops_finished_callback_;
+
   DISALLOW_COPY_AND_ASSIGN(UserSessionManager);
 };