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