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