Home | History | Annotate | Download | only in supervised
      1 // Copyright 2014 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_SUPERVISED_SUPERVISED_USER_CREATION_SCREEN_H_
      6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SUPERVISED_SUPERVISED_USER_CREATION_SCREEN_H_
      7 
      8 #include <string>
      9 
     10 #include "base/basictypes.h"
     11 #include "base/compiler_specific.h"
     12 #include "chrome/browser/chromeos/camera_presence_notifier.h"
     13 #include "chrome/browser/chromeos/login/screens/wizard_screen.h"
     14 #include "chrome/browser/chromeos/login/supervised/supervised_user_creation_controller.h"
     15 #include "chrome/browser/image_decoder.h"
     16 #include "chrome/browser/supervised_user/supervised_user_sync_service.h"
     17 #include "chrome/browser/ui/webui/chromeos/login/supervised_user_creation_screen_handler.h"
     18 #include "chromeos/network/portal_detector/network_portal_detector.h"
     19 #include "ui/gfx/image/image_skia.h"
     20 
     21 class Profile;
     22 
     23 namespace chromeos {
     24 
     25 class NetworkState;
     26 class ScreenManager;
     27 
     28 // Class that controls screen showing ui for supervised user creation.
     29 class SupervisedUserCreationScreen
     30     : public WizardScreen,
     31       public SupervisedUserCreationScreenHandler::Delegate,
     32       public SupervisedUserCreationController::StatusConsumer,
     33       public SupervisedUserSyncServiceObserver,
     34       public ImageDecoder::Delegate,
     35       public NetworkPortalDetector::Observer,
     36       public CameraPresenceNotifier::Observer {
     37  public:
     38   SupervisedUserCreationScreen(
     39       ScreenObserver* observer,
     40       SupervisedUserCreationScreenHandler* actor);
     41   virtual ~SupervisedUserCreationScreen();
     42 
     43   static SupervisedUserCreationScreen* Get(ScreenManager* manager);
     44 
     45   // Makes screen to show message about inconsistency in manager login flow
     46   // (e.g. password change detected, invalid OAuth token, etc).
     47   // Called when manager user is successfully authenticated, so ui elements
     48   // should result in forced logout.
     49   void ShowManagerInconsistentStateErrorScreen();
     50 
     51   // Called when authentication fails for manager with provided password.
     52   // Displays wrong password message on manager selection screen.
     53   void OnManagerLoginFailure();
     54 
     55   // Called when manager is successfully authenticated and account is in
     56   // consistent state.
     57   void OnManagerFullyAuthenticated(Profile* manager_profile);
     58 
     59   // Called when manager is successfully authenticated against cryptohome, but
     60   // OAUTH token validation hasn't completed yet.
     61   // Results in spinner indicating that creation is in process.
     62   void OnManagerCryptohomeAuthenticated();
     63 
     64   // Shows initial screen where managed user name/password are defined and
     65   // manager is selected.
     66   void ShowInitialScreen();
     67 
     68   // CameraPresenceNotifier::Observer implementation:
     69   virtual void OnCameraPresenceCheckDone(bool is_camera_present) OVERRIDE;
     70 
     71   // SupervisedUserSyncServiceObserver implementation
     72   virtual void OnSupervisedUserAcknowledged(
     73       const std::string& supervised_user_id) OVERRIDE {}
     74   virtual void OnSupervisedUsersSyncingStopped() OVERRIDE {}
     75   virtual void OnSupervisedUsersChanged() OVERRIDE;
     76 
     77   // WizardScreen implementation:
     78   virtual void PrepareToShow() OVERRIDE;
     79   virtual void Show() OVERRIDE;
     80   virtual void Hide() OVERRIDE;
     81   virtual std::string GetName() const OVERRIDE;
     82 
     83   // SupervisedUserCreationScreenHandler::Delegate implementation:
     84   virtual void OnActorDestroyed(SupervisedUserCreationScreenHandler* actor)
     85       OVERRIDE;
     86   virtual void CreateSupervisedUser(
     87       const base::string16& display_name,
     88       const std::string& supervised_user_password) OVERRIDE;
     89   virtual void ImportSupervisedUser(const std::string& user_id) OVERRIDE;
     90   virtual void ImportSupervisedUserWithPassword(
     91       const std::string& user_id,
     92       const std::string& password) OVERRIDE;
     93   virtual void AuthenticateManager(
     94       const std::string& manager_id,
     95       const std::string& manager_password) OVERRIDE;
     96   virtual void AbortFlow() OVERRIDE;
     97   virtual void FinishFlow() OVERRIDE;
     98   virtual bool FindUserByDisplayName(const base::string16& display_name,
     99                                      std::string *out_id) const OVERRIDE;
    100   virtual void OnPageSelected(const std::string& page) OVERRIDE;
    101 
    102   // SupervisedUserController::StatusConsumer overrides.
    103   virtual void OnCreationError(SupervisedUserCreationController::ErrorCode code)
    104       OVERRIDE;
    105   virtual void OnCreationTimeout() OVERRIDE;
    106   virtual void OnCreationSuccess() OVERRIDE;
    107   virtual void OnLongCreationWarning() OVERRIDE;
    108 
    109   // NetworkPortalDetector::Observer implementation:
    110   virtual void OnPortalDetectionCompleted(
    111           const NetworkState* network,
    112           const NetworkPortalDetector::CaptivePortalState& state) OVERRIDE;
    113 
    114   // TODO(antrim) : this is an explicit code duplications with UserImageScreen.
    115   // It should be removed by issue 251179.
    116 
    117   // SupervisedUserCreationScreenHandler::Delegate (image) implementation:
    118   virtual void OnPhotoTaken(const std::string& raw_data) OVERRIDE;
    119   virtual void OnImageSelected(const std::string& image_url,
    120                                const std::string& image_type) OVERRIDE;
    121   virtual void OnImageAccepted() OVERRIDE;
    122   // ImageDecoder::Delegate overrides:
    123   virtual void OnImageDecoded(const ImageDecoder* decoder,
    124                               const SkBitmap& decoded_image) OVERRIDE;
    125   virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE;
    126 
    127  private:
    128   void ApplyPicture();
    129   void OnGetSupervisedUsers(const base::DictionaryValue* users);
    130 
    131   SupervisedUserCreationScreenHandler* actor_;
    132 
    133   scoped_ptr<SupervisedUserCreationController> controller_;
    134   scoped_ptr<base::DictionaryValue> existing_users_;
    135 
    136   bool on_error_screen_;
    137   bool manager_signin_in_progress_;
    138   std::string last_page_;
    139 
    140   SupervisedUserSyncService* sync_service_;
    141 
    142   gfx::ImageSkia user_photo_;
    143   scoped_refptr<ImageDecoder> image_decoder_;
    144   bool apply_photo_after_decoding_;
    145   int selected_image_;
    146 
    147   base::WeakPtrFactory<SupervisedUserCreationScreen> weak_factory_;
    148 
    149   DISALLOW_COPY_AND_ASSIGN(SupervisedUserCreationScreen);
    150 };
    151 
    152 }  // namespace chromeos
    153 
    154 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_SUPERVISED_SUPERVISED_USER_CREATION_SCREEN_H_
    155 
    156