• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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_PASSWORD_CHANGED_VIEW_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_PASSWORD_CHANGED_VIEW_H_
7 #pragma once
8 
9 #include <string>
10 
11 #include "views/controls/button/button.h"
12 #include "views/controls/textfield/textfield_controller.h"
13 #include "views/view.h"
14 #include "views/window/dialog_delegate.h"
15 
16 namespace views {
17 class Button;
18 class Label;
19 class RadioButton;
20 class Textfield;
21 }  // namespace views
22 
23 namespace chromeos {
24 
25 // A dialog box that is shown when password change was detected.
26 // User is presented with an option to sync all settings or
27 // enter old password and sync only delta.
28 class PasswordChangedView : public views::View,
29                             public views::DialogDelegate,
30                             public views::ButtonListener,
31                             public views::TextfieldController {
32  public:
33   // Delegate class to get notifications from the view.
34   class Delegate {
35   public:
~Delegate()36     virtual ~Delegate() {}
37 
38     // User provided |old_password|, decrypt homedir and sync only delta.
39     virtual void RecoverEncryptedData(const std::string& old_password) = 0;
40 
41     // Ignores password change and forces full sync.
42     virtual void ResyncEncryptedData() = 0;
43   };
44 
45   PasswordChangedView(Delegate* delegate, bool full_sync_disabled);
~PasswordChangedView()46   virtual ~PasswordChangedView() {}
47 
48   // views::DialogDelegate:
49   virtual bool Accept();
50   virtual int GetDialogButtons() const;
51 
52   // views::WindowDelegate:
53   virtual View* GetInitiallyFocusedView();
IsModal()54   virtual bool IsModal() const { return true; }
GetContentsView()55   virtual views::View* GetContentsView() { return this; }
56 
57   // views::View:
58   virtual std::wstring GetWindowTitle() const;
59 
60   // views::ButtonListener:
61   virtual void ButtonPressed(views::Button* sender,
62                              const views::Event& event);
63 
64   // views::TextfieldController:
HandleKeyEvent(views::Textfield * sender,const views::KeyEvent & keystroke)65   virtual bool HandleKeyEvent(views::Textfield* sender,
66                               const views::KeyEvent& keystroke) {
67     return false;
68   }
ContentsChanged(views::Textfield * sender,const string16 & new_contents)69   virtual void ContentsChanged(views::Textfield* sender,
70                                const string16& new_contents) {}
71 
72  protected:
73   // views::View:
74   virtual gfx::Size GetPreferredSize();
75   virtual void ViewHierarchyChanged(bool is_add,
76                                     views::View* parent,
77                                     views::View* child);
78 
79  private:
80   // Called when dialog is accepted.
81   bool ExitDialog();
82 
83   // Initialize view layout.
84   void Init();
85 
86   // Screen controls.
87   views::Label* title_label_;
88   views::Label* description_label_;
89   views::RadioButton* full_sync_radio_;
90   views::RadioButton* delta_sync_radio_;
91   views::Textfield* old_password_field_;
92 
93   // Notifications receiver.
94   Delegate* delegate_;
95 
96   // Whether full sync option is disabled.
97   bool full_sync_disabled_;
98 
99   DISALLOW_COPY_AND_ASSIGN(PasswordChangedView);
100 };
101 
102 }  // namespace chromeos
103 
104 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_PASSWORD_CHANGED_VIEW_H_
105