Home | History | Annotate | Download | only in login
      1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_DISPLAY_H_
      6 #define CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_DISPLAY_H_
      7 #pragma once
      8 
      9 #include <string>
     10 #include <vector>
     11 
     12 #include "base/string16.h"
     13 #include "chrome/browser/chromeos/login/help_app_launcher.h"
     14 #include "chrome/browser/chromeos/login/user_manager.h"
     15 #include "ui/gfx/native_widget_types.h"
     16 #include "ui/gfx/rect.h"
     17 
     18 namespace chromeos {
     19 
     20 // Delegate to be used while user removing.
     21 class RemoveUserDelegate {
     22  public:
     23   // Called right before actual user removal process is initiated.
     24   virtual void OnBeforeUserRemoved(const std::string& username) = 0;
     25 
     26   // Called right after user removal process has been initiated.
     27   virtual void OnUserRemoved(const std::string& username) = 0;
     28 };
     29 
     30 // TODO(nkostylev): Extract interface, create a BaseLoginDisplay class.
     31 // An abstract class that defines login UI implementation.
     32 class LoginDisplay : public RemoveUserDelegate {
     33  public:
     34   class Delegate {
     35    public:
     36     // Create new Google account.
     37     virtual void CreateAccount() = 0;
     38 
     39     // Returns name of the currently connected network.
     40     virtual string16 GetConnectedNetworkName() = 0;
     41 
     42     // Users decides to sign in into captive portal.
     43     virtual void FixCaptivePortal() = 0;
     44 
     45     // Sign in using |username| and |password| specified.
     46     // Used for both known and new users.
     47     virtual void Login(const std::string& username,
     48                        const std::string& password) = 0;
     49 
     50     // Sign in into Guest session.
     51     virtual void LoginAsGuest() = 0;
     52 
     53     // Called when existing user pod is selected in the UI.
     54     virtual void OnUserSelected(const std::string& username) = 0;
     55 
     56     // Called when the user requests enterprise enrollment.
     57     virtual void OnStartEnterpriseEnrollment() = 0;
     58 
     59    protected:
     60     virtual ~Delegate();
     61   };
     62 
     63   // |background_bounds| determines the bounds of login UI background.
     64   LoginDisplay(Delegate* delegate, const gfx::Rect& background_bounds);
     65   virtual ~LoginDisplay();
     66 
     67   // Call for destroying a pointer of type LoginDisplay, since some subclasses
     68   // are Singletons
     69   virtual void Destroy();
     70 
     71   // Initializes login UI with the user pods based on list of known users and
     72   // guest, new user pods if those are enabled.
     73   virtual void Init(const std::vector<UserManager::User>& users,
     74                     bool show_guest,
     75                     bool show_new_user) = 0;
     76 
     77 
     78   // Called when user image has been changed.
     79   // |user| contains updated user.
     80   virtual void OnUserImageChanged(UserManager::User* user) = 0;
     81 
     82   // After this call login display should be ready to be smoothly destroyed
     83   // (e.g. hide throbber, etc.).
     84   virtual void OnFadeOut() = 0;
     85 
     86   // Changes enabled state of the UI.
     87   virtual void SetUIEnabled(bool is_enabled) = 0;
     88 
     89   // Displays error with |error_msg_id| specified.
     90   // |login_attempts| shows number of login attempts made by current user.
     91   // |help_topic_id| is additional help topic that is presented as link.
     92   virtual void ShowError(int error_msg_id,
     93                          int login_attempts,
     94                          HelpAppLauncher::HelpTopic help_topic_id) = 0;
     95 
     96   gfx::Rect background_bounds() const { return background_bounds_; }
     97   void set_background_bounds(const gfx::Rect background_bounds){
     98     background_bounds_ = background_bounds;
     99   }
    100 
    101   Delegate* delegate() { return delegate_; }
    102   void set_delegate(Delegate* delegate) { delegate_ = delegate; }
    103 
    104   gfx::NativeWindow parent_window() const { return parent_window_; }
    105   void set_parent_window(gfx::NativeWindow window) { parent_window_ = window; }
    106 
    107   int width() const { return background_bounds_.width(); }
    108 
    109  protected:
    110   // Login UI delegate (controller).
    111   Delegate* delegate_;
    112 
    113   // Parent window, might be used to create dialog windows.
    114   gfx::NativeWindow parent_window_;
    115 
    116   // Bounds of the login UI background.
    117   gfx::Rect background_bounds_;
    118 
    119   DISALLOW_COPY_AND_ASSIGN(LoginDisplay);
    120 };
    121 
    122 }  // namespace chromeos
    123 
    124 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_DISPLAY_H_
    125