Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_AUTOFILL_AUTOFILL_CC_INFOBAR_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_AUTOFILL_AUTOFILL_CC_INFOBAR_DELEGATE_H_ |
| 6 #define CHROME_BROWSER_AUTOFILL_AUTOFILL_CC_INFOBAR_DELEGATE_H_ | 6 #define CHROME_BROWSER_AUTOFILL_AUTOFILL_CC_INFOBAR_DELEGATE_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/callback.h" | |
| 9 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
| 10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/string16.h" | 12 #include "base/string16.h" |
| 12 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" | 13 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" |
| 13 #include "chrome/browser/autofill/autofill_metrics.h" | 14 #include "chrome/browser/autofill/autofill_metrics.h" |
| 14 #include "ui/base/window_open_disposition.h" | 15 #include "ui/base/window_open_disposition.h" |
| 15 | 16 |
| 16 class CreditCard; | 17 class CreditCard; |
| 17 class PersonalDataManager; | 18 class PersonalDataManager; |
| 18 | 19 |
| 19 namespace content { | 20 namespace content { |
| 20 struct LoadCommittedDetails; | 21 struct LoadCommittedDetails; |
| 21 } | 22 } |
| 22 | 23 |
| 23 // An InfoBar delegate that enables the user to allow or deny storing credit | 24 // An InfoBar delegate that enables the user to allow or deny storing credit |
| 24 // card information gathered from a form submission. | 25 // card information gathered from a form submission. |
| 25 class AutofillCCInfoBarDelegate : public ConfirmInfoBarDelegate { | 26 class AutofillCCInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 26 public: | 27 public: |
| 27 // Creates an autofill credit card delegate and adds it to |infobar_service|. | 28 // Creates an AutofillCCInfoBarDelegate and adds it to |infobar_service|. |
| 28 static void Create(InfoBarService* infobar_service, | 29 static void Create(InfoBarService* infobar_service, |
| 29 const CreditCard* credit_card, | 30 const AutofillMetrics* metric_logger, |
| 30 PersonalDataManager* personal_data, | 31 const base::Closure& import_callback); |
|
Ilya Sherman
2013/03/06 09:13:24
nit: import_callback -> save_card_callback or some
kaiwang
2013/03/06 18:25:04
Done.
| |
| 31 const AutofillMetrics* metric_logger); | |
| 32 | 32 |
| 33 #if defined(UNIT_TEST) | 33 static scoped_ptr<ConfirmInfoBarDelegate> CreateForTesting( |
| 34 static scoped_ptr<ConfirmInfoBarDelegate> Create( | 34 const AutofillMetrics* metric_logger, |
| 35 const CreditCard* credit_card, | 35 const base::Closure& import_callback); |
| 36 PersonalDataManager* personal_data, | |
| 37 const AutofillMetrics* metric_logger) { | |
| 38 return scoped_ptr<ConfirmInfoBarDelegate>(new AutofillCCInfoBarDelegate( | |
| 39 NULL, credit_card, personal_data, metric_logger)); | |
| 40 } | |
| 41 #endif | |
| 42 | 36 |
| 43 private: | 37 private: |
| 44 AutofillCCInfoBarDelegate(InfoBarService* infobar_service, | 38 AutofillCCInfoBarDelegate(InfoBarService* infobar_service, |
| 45 const CreditCard* credit_card, | 39 const AutofillMetrics* metric_logger, |
| 46 PersonalDataManager* personal_data, | 40 const base::Closure& import_callback); |
| 47 const AutofillMetrics* metric_logger); | |
| 48 virtual ~AutofillCCInfoBarDelegate(); | 41 virtual ~AutofillCCInfoBarDelegate(); |
| 49 | 42 |
| 50 void LogUserAction(AutofillMetrics::InfoBarMetric user_action); | 43 void LogUserAction(AutofillMetrics::InfoBarMetric user_action); |
| 51 | 44 |
| 52 // ConfirmInfoBarDelegate: | 45 // ConfirmInfoBarDelegate: |
| 53 virtual void InfoBarDismissed() OVERRIDE; | 46 virtual void InfoBarDismissed() OVERRIDE; |
| 54 virtual gfx::Image* GetIcon() const OVERRIDE; | 47 virtual gfx::Image* GetIcon() const OVERRIDE; |
| 55 virtual Type GetInfoBarType() const OVERRIDE; | 48 virtual Type GetInfoBarType() const OVERRIDE; |
| 56 virtual bool ShouldExpireInternal( | 49 virtual bool ShouldExpireInternal( |
| 57 const content::LoadCommittedDetails& details) const OVERRIDE; | 50 const content::LoadCommittedDetails& details) const OVERRIDE; |
| 58 virtual string16 GetMessageText() const OVERRIDE; | 51 virtual string16 GetMessageText() const OVERRIDE; |
| 59 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 52 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
| 60 virtual bool Accept() OVERRIDE; | 53 virtual bool Accept() OVERRIDE; |
| 61 virtual bool Cancel() OVERRIDE; | 54 virtual bool Cancel() OVERRIDE; |
| 62 virtual string16 GetLinkText() const OVERRIDE; | 55 virtual string16 GetLinkText() const OVERRIDE; |
| 63 virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; | 56 virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; |
| 64 | 57 |
| 65 // The credit card that should be saved if the user accepts the infobar. | |
| 66 scoped_ptr<const CreditCard> credit_card_; | |
| 67 | |
| 68 // The personal data manager to which the credit card should be saved. | |
| 69 // Weak reference. | |
| 70 PersonalDataManager* personal_data_; | |
| 71 | |
| 72 // For logging UMA metrics. | 58 // For logging UMA metrics. |
| 73 // Weak reference. Owned by the AutofillManager that initiated this infobar. | 59 // Weak reference. Owned by the AutofillManager that initiated this infobar. |
| 74 const AutofillMetrics* metric_logger_; | 60 const AutofillMetrics* metric_logger_; |
| 75 | 61 |
| 62 // The callback to do credit card importing. | |
|
Ilya Sherman
2013/03/06 09:13:24
nit: "The callback to save the credit card if the
kaiwang
2013/03/06 18:25:04
Done.
| |
| 63 base::Closure import_callback_; | |
| 64 | |
| 76 // Did the user ever explicitly accept or dismiss this infobar? | 65 // Did the user ever explicitly accept or dismiss this infobar? |
| 77 bool had_user_interaction_; | 66 bool had_user_interaction_; |
| 78 | 67 |
| 79 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, CreditCardInfoBar); | 68 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, CreditCardInfoBar); |
| 80 | 69 |
| 81 DISALLOW_COPY_AND_ASSIGN(AutofillCCInfoBarDelegate); | 70 DISALLOW_COPY_AND_ASSIGN(AutofillCCInfoBarDelegate); |
| 82 }; | 71 }; |
| 83 | 72 |
| 84 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_CC_INFOBAR_DELEGATE_H_ | 73 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_CC_INFOBAR_DELEGATE_H_ |
| OLD | NEW |