Home | History | Annotate | Download | only in ui
      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_UI_AUTO_LOGIN_INFOBAR_DELEGATE_H_
      6 #define CHROME_BROWSER_UI_AUTO_LOGIN_INFOBAR_DELEGATE_H_
      7 
      8 #include <string>
      9 #include "chrome/browser/infobars/confirm_infobar_delegate.h"
     10 #include "components/auto_login_parser/auto_login_parser.h"
     11 #include "content/public/browser/notification_observer.h"
     12 #include "content/public/browser/notification_registrar.h"
     13 
     14 class PrefService;
     15 class TokenService;
     16 
     17 namespace content {
     18 class NavigationController;
     19 }
     20 
     21 // This is the actual infobar displayed to prompt the user to auto-login.
     22 class AutoLoginInfoBarDelegate : public ConfirmInfoBarDelegate,
     23                                  public content::NotificationObserver {
     24  public:
     25   struct Params {
     26     // Information from a parsed header.
     27     auto_login_parser::HeaderData header;
     28 
     29     // Username to display in the infobar indicating user to be logged in as.
     30     // This is initially fetched from sign-in on non-Android platforms. Note
     31     // that on Android this field is not used.
     32     std::string username;
     33   };
     34 
     35   // Creates an autologin infobar delegate and adds it to |infobar_service|.
     36   static void Create(InfoBarService* infobar_service, const Params& params);
     37 
     38  protected:
     39   AutoLoginInfoBarDelegate(InfoBarService* owner, const Params& params);
     40   virtual ~AutoLoginInfoBarDelegate();
     41 
     42  private:
     43   // Enum values used for UMA histograms.
     44   enum Actions {
     45     SHOWN,       // The infobar was shown to the user.
     46     ACCEPTED,    // The user pressed the accept button.
     47     REJECTED,    // The user pressed the reject button.
     48     DISMISSED,   // The user pressed the close button.
     49     IGNORED,     // The user ignored the infobar.
     50     LEARN_MORE,  // The user clicked on the learn more link.
     51     HISTOGRAM_BOUNDING_VALUE
     52   };
     53 
     54   // ConfirmInfoBarDelegate:
     55   virtual void InfoBarDismissed() OVERRIDE;
     56   virtual int GetIconID() const OVERRIDE;
     57   virtual Type GetInfoBarType() const OVERRIDE;
     58   virtual AutoLoginInfoBarDelegate* AsAutoLoginInfoBarDelegate() OVERRIDE;
     59   virtual string16 GetMessageText() const OVERRIDE;
     60   virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
     61   virtual bool Accept() OVERRIDE;
     62   virtual bool Cancel() OVERRIDE;
     63 
     64   // content::NotificationObserver:
     65   virtual void Observe(int type,
     66                        const content::NotificationSource& source,
     67                        const content::NotificationDetails& details) OVERRIDE;
     68 
     69   void RecordHistogramAction(Actions action);
     70 
     71   const Params params_;
     72 
     73   // Whether any UI controls in the infobar were pressed or not.
     74   bool button_pressed_;
     75 
     76   // For listening to the user signing out.
     77   content::NotificationRegistrar registrar_;
     78 
     79   DISALLOW_COPY_AND_ASSIGN(AutoLoginInfoBarDelegate);
     80 };
     81 
     82 #endif  // CHROME_BROWSER_UI_AUTO_LOGIN_INFOBAR_DELEGATE_H_
     83