Upstream version 7.35.139.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / login / managed / locally_managed_user_creation_screen.h
1 // Copyright (c) 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_CHROMEOS_LOGIN_MANAGED_LOCALLY_MANAGED_USER_CREATION_SCREEN_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_MANAGED_LOCALLY_MANAGED_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/managed/managed_user_creation_controller.h"
14 #include "chrome/browser/chromeos/login/screens/wizard_screen.h"
15 #include "chrome/browser/chromeos/net/network_portal_detector.h"
16 #include "chrome/browser/image_decoder.h"
17 #include "chrome/browser/ui/webui/chromeos/login/locally_managed_user_creation_screen_handler.h"
18 #include "ui/gfx/image/image_skia.h"
19
20 class Profile;
21
22 namespace chromeos {
23
24 class NetworkState;
25
26 // Class that controls screen showing ui for locally managed user creation.
27 class LocallyManagedUserCreationScreen
28     : public WizardScreen,
29       public LocallyManagedUserCreationScreenHandler::Delegate,
30       public ManagedUserCreationController::StatusConsumer,
31       public ImageDecoder::Delegate,
32       public NetworkPortalDetector::Observer,
33       public CameraPresenceNotifier::Observer {
34  public:
35   LocallyManagedUserCreationScreen(
36       ScreenObserver* observer,
37       LocallyManagedUserCreationScreenHandler* actor);
38   virtual ~LocallyManagedUserCreationScreen();
39
40   // Makes screen to show message about inconsistency in manager login flow
41   // (e.g. password change detected, invalid OAuth token, etc).
42   // Called when manager user is successfully authenticated, so ui elements
43   // should result in forced logout.
44   void ShowManagerInconsistentStateErrorScreen();
45
46   // Called when authentication fails for manager with provided password.
47   // Displays wrong password message on manager selection screen.
48   void OnManagerLoginFailure();
49
50   // Called when manager is successfully authenticated and account is in
51   // consistent state.
52   void OnManagerFullyAuthenticated(Profile* manager_profile);
53
54   // Called when manager is successfully authenticated against cryptohome, but
55   // OAUTH token validation hasn't completed yet.
56   // Results in spinner indicating that creation is in process.
57   void OnManagerCryptohomeAuthenticated();
58
59   // Shows initial screen where managed user name/password are defined and
60   // manager is selected.
61   void ShowInitialScreen();
62
63   // CameraPresenceNotifier::Observer implementation:
64   virtual void OnCameraPresenceCheckDone(bool is_camera_present) OVERRIDE;
65
66   // WizardScreen implementation:
67   virtual void PrepareToShow() OVERRIDE;
68   virtual void Show() OVERRIDE;
69   virtual void Hide() OVERRIDE;
70   virtual std::string GetName() const OVERRIDE;
71
72   // LocallyManagedUserCreationScreenHandler::Delegate implementation:
73   virtual void OnActorDestroyed(LocallyManagedUserCreationScreenHandler* actor)
74       OVERRIDE;
75   virtual void CreateManagedUser(
76       const base::string16& display_name,
77       const std::string& managed_user_password) OVERRIDE;
78   virtual void ImportManagedUser(const std::string& user_id) OVERRIDE;
79   virtual void ImportManagedUserWithPassword(
80       const std::string& user_id,
81       const std::string& password) OVERRIDE;
82   virtual void AuthenticateManager(
83       const std::string& manager_id,
84       const std::string& manager_password) OVERRIDE;
85   virtual void AbortFlow() OVERRIDE;
86   virtual void FinishFlow() OVERRIDE;
87   virtual bool FindUserByDisplayName(const base::string16& display_name,
88                                      std::string *out_id) const OVERRIDE;
89   virtual void OnPageSelected(const std::string& page) OVERRIDE;
90
91   // LocallyManagedUserController::StatusConsumer overrides.
92   virtual void OnCreationError(ManagedUserCreationController::ErrorCode code)
93       OVERRIDE;
94   virtual void OnCreationTimeout() OVERRIDE;
95   virtual void OnCreationSuccess() OVERRIDE;
96   virtual void OnLongCreationWarning() OVERRIDE;
97
98   // NetworkPortalDetector::Observer implementation:
99   virtual void OnPortalDetectionCompleted(
100           const NetworkState* network,
101           const NetworkPortalDetector::CaptivePortalState& state) OVERRIDE;
102
103   // TODO(antrim) : this is an explicit code duplications with UserImageScreen.
104   // It should be removed by issue 251179.
105
106   // LocallyManagedUserCreationScreenHandler::Delegate (image) implementation:
107   virtual void OnPhotoTaken(const std::string& raw_data) OVERRIDE;
108   virtual void OnImageSelected(const std::string& image_url,
109                                const std::string& image_type) OVERRIDE;
110   virtual void OnImageAccepted() OVERRIDE;
111   // ImageDecoder::Delegate overrides:
112   virtual void OnImageDecoded(const ImageDecoder* decoder,
113                               const SkBitmap& decoded_image) OVERRIDE;
114   virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE;
115
116  private:
117   void ApplyPicture();
118   void OnGetManagedUsers(const base::DictionaryValue* users);
119
120   base::WeakPtrFactory<LocallyManagedUserCreationScreen> weak_factory_;
121   LocallyManagedUserCreationScreenHandler* actor_;
122
123   scoped_ptr<ManagedUserCreationController> controller_;
124   scoped_ptr<base::DictionaryValue> existing_users_;
125
126   bool on_error_screen_;
127   std::string last_page_;
128
129   gfx::ImageSkia user_photo_;
130   scoped_refptr<ImageDecoder> image_decoder_;
131   bool apply_photo_after_decoding_;
132   int selected_image_;
133
134   DISALLOW_COPY_AND_ASSIGN(LocallyManagedUserCreationScreen);
135 };
136
137 }  // namespace chromeos
138
139 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_MANAGED_LOCALLY_MANAGED_USER_CREATION_SCREEN_H_
140