a00226908af9c053588cf6576e7056de91d44ba1
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / login / screens / user_image_screen.h
1 // Copyright (c) 2012 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_SCREENS_USER_IMAGE_SCREEN_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_USER_IMAGE_SCREEN_H_
7
8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/chromeos/login/screens/user_image_screen_actor.h"
11 #include "chrome/browser/chromeos/login/screens/wizard_screen.h"
12 #include "chrome/browser/chromeos/login/user.h"
13 #include "chrome/browser/chromeos/login/user_image_sync_observer.h"
14 #include "chrome/browser/image_decoder.h"
15 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_registrar.h"
17
18 namespace base {
19 class Timer;
20 class Value;
21 };
22
23 namespace policy {
24 class PolicyChangeRegistrar;
25 }
26
27 namespace chromeos {
28
29 class UserImageScreen: public WizardScreen,
30                        public UserImageScreenActor::Delegate,
31                        public ImageDecoder::Delegate,
32                        public content::NotificationObserver,
33                        public UserImageSyncObserver::Observer {
34  public:
35   UserImageScreen(ScreenObserver* screen_observer,
36                   UserImageScreenActor* actor);
37   virtual ~UserImageScreen();
38
39   // Indicates whether profile picture is enabled for given user.
40   void SetProfilePictureEnabled(bool support_profile_picture);
41   // Sets |user_id| of user that would have picture updated.
42   void SetUserID(const std::string& user_id);
43
44   // WizardScreen implementation:
45   virtual void PrepareToShow() OVERRIDE;
46   virtual void Show() OVERRIDE;
47   virtual void Hide() OVERRIDE;
48   virtual std::string GetName() const OVERRIDE;
49
50   // UserImageScreenActor::Delegate implementation:
51   virtual void OnScreenReady() OVERRIDE;
52   virtual void OnPhotoTaken(const std::string& raw_data) OVERRIDE;
53   virtual void OnImageSelected(const std::string& image_url,
54                                const std::string& image_type,
55                                bool is_user_selection) OVERRIDE;
56   virtual void OnImageAccepted() OVERRIDE;
57   virtual void OnActorDestroyed(UserImageScreenActor* actor) OVERRIDE;
58
59   virtual bool profile_picture_absent() OVERRIDE;
60   virtual int selected_image() OVERRIDE;
61   virtual std::string profile_picture_data_url() OVERRIDE;
62
63   // content::NotificationObserver implementation:
64   virtual void Observe(int type,
65                        const content::NotificationSource& source,
66                        const content::NotificationDetails& details) OVERRIDE;
67
68   // ImageDecoder::Delegate implementation:
69   virtual void OnImageDecoded(const ImageDecoder* decoder,
70                               const SkBitmap& decoded_image) OVERRIDE;
71   virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE;
72   virtual void OnCameraPresenceCheckDone(bool is_camera_present) OVERRIDE;
73
74   // UserImageSyncObserver::Observer implementation:
75   virtual void OnInitialSync(bool local_image_updated) OVERRIDE;
76
77   bool user_selected_image() const { return user_has_selected_image_; }
78
79  private:
80   // Called when whaiting for sync timed out.
81   void OnSyncTimeout();
82
83   bool IsWaitingForSync() const;
84
85   // Called when the policy::key::kUserAvatarImage policy changes while the
86   // screen is being shown. If the policy is set, closes the screen because the
87   // user is not allowed to override a policy-set image.
88   void OnUserImagePolicyChanged(const base::Value* previous,
89                                 const base::Value* current);
90
91   // Returns current user.
92   const User* GetUser();
93
94   // Returns UserImageManager for the current user.
95   UserImageManager* GetUserImageManager();
96
97   // Returns UserImageSyncObserver for the current user.
98   UserImageSyncObserver* GetSyncObserver();
99
100   // Called when it's decided not to skip the screen.
101   void HideCurtain();
102
103   // Closes the screen.
104   void ExitScreen();
105
106   content::NotificationRegistrar notification_registrar_;
107
108   scoped_ptr<policy::PolicyChangeRegistrar> policy_registrar_;
109
110   UserImageScreenActor* actor_;
111
112   // Last ImageDecoder instance used to decode an image blob received by
113   // HandlePhotoTaken.
114   scoped_refptr<ImageDecoder> image_decoder_;
115
116   // Last user photo, if taken.
117   gfx::ImageSkia user_photo_;
118
119   // If |true|, decoded photo should be immediately accepeted (i.e., both
120   // HandleTakePhoto and HandleImageAccepted have already been called but we're
121   // still waiting for  photo image decoding to finish.
122   bool accept_photo_after_decoding_;
123
124   // Index of the selected user image.
125   int selected_image_;
126
127   bool profile_picture_enabled_;
128
129   // Encoded profile picture.
130   std::string profile_picture_data_url_;
131
132   // True if user has no custom profile picture.
133   bool profile_picture_absent_;
134
135   std::string user_id_;
136
137   // Timer used for waiting for user image sync.
138   scoped_ptr<base::Timer> sync_timer_;
139
140   // If screen ready to be shown.
141   bool is_screen_ready_;
142
143   // True if user has explicitly selected some image.
144   bool user_has_selected_image_;
145
146   DISALLOW_COPY_AND_ASSIGN(UserImageScreen);
147 };
148
149 }  // namespace chromeos
150
151 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_USER_IMAGE_SCREEN_H_