Home | History | Annotate | Download | only in login
      1 // Copyright 2013 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_UI_WEBUI_CHROMEOS_LOGIN_GAIA_SCREEN_HANDLER_H_
      6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_GAIA_SCREEN_HANDLER_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/command_line.h"
     10 #include "base/memory/ref_counted.h"
     11 #include "chrome/browser/ui/webui/chromeos/login/network_state_informer.h"
     12 #include "net/base/net_errors.h"
     13 
     14 namespace chromeos {
     15 
     16 class SigninScreenHandler;
     17 
     18 // A class that's used to specify the way how Gaia should be loaded.
     19 struct GaiaContext {
     20   GaiaContext();
     21 
     22   // Forces Gaia to reload.
     23   bool force_reload;
     24 
     25   // Whether local verison of Gaia is used.
     26   bool is_local;
     27 
     28   // True if password was changed for the current user.
     29   bool password_changed;
     30 
     31   // True if user pods can be displyed.
     32   bool show_users;
     33 
     34   // Whether Gaia should be loaded in offline mode.
     35   bool use_offline;
     36 
     37   // True if user list is non-empty.
     38   bool has_users;
     39 
     40   // Email of current user.
     41   std::string email;
     42 };
     43 
     44 // A class that handles WebUI hooks in Gaia screen.
     45 class GaiaScreenHandler : public BaseScreenHandler {
     46  public:
     47   enum FrameState {
     48     FRAME_STATE_UNKNOWN = 0,
     49     FRAME_STATE_LOADING,
     50     FRAME_STATE_LOADED,
     51     FRAME_STATE_ERROR
     52   };
     53 
     54   explicit GaiaScreenHandler(
     55       const scoped_refptr<NetworkStateInformer>& network_state_informer);
     56   virtual ~GaiaScreenHandler();
     57 
     58   void LoadGaia(const GaiaContext& context);
     59   void UpdateGaia(const GaiaContext& context);
     60   void ReloadGaia();
     61 
     62   FrameState frame_state() const { return frame_state_; }
     63   net::Error frame_error() const { return frame_error_; }
     64 
     65  private:
     66   // TODO (ygorshenin@): remove this dependency.
     67   friend class SigninScreenHandler;
     68 
     69   // BaseScreenHandler implementation:
     70   virtual void DeclareLocalizedValues(LocalizedValuesBuilder* builder) OVERRIDE;
     71   virtual void Initialize() OVERRIDE;
     72 
     73   // WebUIMessageHandler implementation:
     74   virtual void RegisterMessages() OVERRIDE;
     75 
     76   // WebUI message handlers.
     77   void HandleFrameLoadingCompleted(int status);
     78 
     79   // TODO (ygorshenin@): GaiaScreenHandler should implement
     80   // NetworkStateInformer::Observer.
     81   void UpdateState(ErrorScreenActor::ErrorReason reason);
     82 
     83   // TODO (ygorshenin@): remove this dependency.
     84   void SetSigninScreenHandler(SigninScreenHandler* handler);
     85 
     86   // Current state of Gaia frame.
     87   FrameState frame_state_;
     88 
     89   // Latest Gaia frame error.
     90   net::Error frame_error_;
     91 
     92   // Network state informer used to keep signin screen up.
     93   scoped_refptr<NetworkStateInformer> network_state_informer_;
     94 
     95   // Non-owning ptr to SigninScreenHandler instance. Should not be used
     96   // in dtor.
     97   // TODO (ygorshenin@): GaiaScreenHandler shouldn't communicate with
     98   // signin_screen_handler directly.
     99   SigninScreenHandler* signin_screen_handler_;
    100 
    101   DISALLOW_COPY_AND_ASSIGN(GaiaScreenHandler);
    102 };
    103 
    104 }  // namespace chromeos
    105 
    106 #endif  // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_GAIA_SCREEN_HANDLER_H_
    107