| 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 #include "chrome/browser/omnibox_search_hint.h" | 5 #include "chrome/browser/omnibox_search_hint.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/task.h" | 9 #include "base/task.h" |
| 10 // TODO(avi): remove when conversions not needed any more | 10 // TODO(avi): remove when conversions not needed any more |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 public: | 49 public: |
| 50 explicit HintInfoBar(OmniboxSearchHint* omnibox_hint); | 50 explicit HintInfoBar(OmniboxSearchHint* omnibox_hint); |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 virtual ~HintInfoBar(); | 53 virtual ~HintInfoBar(); |
| 54 | 54 |
| 55 void AllowExpiry() { should_expire_ = true; } | 55 void AllowExpiry() { should_expire_ = true; } |
| 56 | 56 |
| 57 // ConfirmInfoBarDelegate: | 57 // ConfirmInfoBarDelegate: |
| 58 virtual bool ShouldExpire( | 58 virtual bool ShouldExpire( |
| 59 const NavigationController::LoadCommittedDetails& details) const; | 59 const NavigationController::LoadCommittedDetails& details) const OVERRIDE; |
| 60 virtual void InfoBarDismissed(); | 60 virtual void InfoBarDismissed() OVERRIDE; |
| 61 virtual void InfoBarClosed(); | 61 virtual gfx::Image* GetIcon() const OVERRIDE; |
| 62 virtual gfx::Image* GetIcon() const; | 62 virtual Type GetInfoBarType() const OVERRIDE; |
| 63 virtual Type GetInfoBarType() const; | 63 virtual string16 GetMessageText() const OVERRIDE; |
| 64 virtual string16 GetMessageText() const; | 64 virtual int GetButtons() const OVERRIDE; |
| 65 virtual int GetButtons() const; | 65 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
| 66 virtual string16 GetButtonLabel(InfoBarButton button) const; | 66 virtual bool Accept() OVERRIDE; |
| 67 virtual bool Accept(); | |
| 68 | 67 |
| 69 // The omnibox hint that shows us. | 68 // The omnibox hint that shows us. |
| 70 OmniboxSearchHint* omnibox_hint_; | 69 OmniboxSearchHint* omnibox_hint_; |
| 71 | 70 |
| 72 // Whether the user clicked one of the buttons. | 71 // Whether the user clicked one of the buttons. |
| 73 bool action_taken_; | 72 bool action_taken_; |
| 74 | 73 |
| 75 // Whether the info-bar should be dismissed on the next navigation. | 74 // Whether the info-bar should be dismissed on the next navigation. |
| 76 bool should_expire_; | 75 bool should_expire_; |
| 77 | 76 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 88 should_expire_(false), | 87 should_expire_(false), |
| 89 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 88 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
| 90 // We want the info-bar to stick-around for few seconds and then be hidden | 89 // We want the info-bar to stick-around for few seconds and then be hidden |
| 91 // on the next navigation after that. | 90 // on the next navigation after that. |
| 92 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 91 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 93 method_factory_.NewRunnableMethod(&HintInfoBar::AllowExpiry), | 92 method_factory_.NewRunnableMethod(&HintInfoBar::AllowExpiry), |
| 94 8000); // 8 seconds. | 93 8000); // 8 seconds. |
| 95 } | 94 } |
| 96 | 95 |
| 97 HintInfoBar::~HintInfoBar() { | 96 HintInfoBar::~HintInfoBar() { |
| 97 if (!action_taken_) |
| 98 UMA_HISTOGRAM_COUNTS("OmniboxSearchHint.Ignored", 1); |
| 98 } | 99 } |
| 99 | 100 |
| 100 bool HintInfoBar::ShouldExpire( | 101 bool HintInfoBar::ShouldExpire( |
| 101 const NavigationController::LoadCommittedDetails& details) const { | 102 const NavigationController::LoadCommittedDetails& details) const { |
| 102 return should_expire_; | 103 return should_expire_; |
| 103 } | 104 } |
| 104 | 105 |
| 105 void HintInfoBar::InfoBarDismissed() { | 106 void HintInfoBar::InfoBarDismissed() { |
| 106 action_taken_ = true; | 107 action_taken_ = true; |
| 107 UMA_HISTOGRAM_COUNTS("OmniboxSearchHint.Closed", 1); | 108 UMA_HISTOGRAM_COUNTS("OmniboxSearchHint.Closed", 1); |
| 108 // User closed the infobar, let's not bug him again with this in the future. | 109 // User closed the infobar, let's not bug him again with this in the future. |
| 109 omnibox_hint_->DisableHint(); | 110 omnibox_hint_->DisableHint(); |
| 110 } | 111 } |
| 111 | 112 |
| 112 void HintInfoBar::InfoBarClosed() { | |
| 113 if (!action_taken_) | |
| 114 UMA_HISTOGRAM_COUNTS("OmniboxSearchHint.Ignored", 1); | |
| 115 delete this; | |
| 116 } | |
| 117 | |
| 118 gfx::Image* HintInfoBar::GetIcon() const { | 113 gfx::Image* HintInfoBar::GetIcon() const { |
| 119 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 114 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
| 120 IDR_INFOBAR_QUESTION_MARK); | 115 IDR_INFOBAR_QUESTION_MARK); |
| 121 } | 116 } |
| 122 | 117 |
| 123 InfoBarDelegate::Type HintInfoBar::GetInfoBarType() const { | 118 InfoBarDelegate::Type HintInfoBar::GetInfoBarType() const { |
| 124 return PAGE_ACTION_TYPE; | 119 return PAGE_ACTION_TYPE; |
| 125 } | 120 } |
| 126 | 121 |
| 127 string16 HintInfoBar::GetMessageText() const { | 122 string16 HintInfoBar::GetMessageText() const { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 } | 223 } |
| 229 | 224 |
| 230 // static | 225 // static |
| 231 bool OmniboxSearchHint::IsEnabled(Profile* profile) { | 226 bool OmniboxSearchHint::IsEnabled(Profile* profile) { |
| 232 // The infobar can only be shown if the correct switch has been provided and | 227 // The infobar can only be shown if the correct switch has been provided and |
| 233 // the user did not dismiss the infobar before. | 228 // the user did not dismiss the infobar before. |
| 234 return profile->GetPrefs()->GetBoolean(prefs::kShowOmniboxSearchHint) && | 229 return profile->GetPrefs()->GetBoolean(prefs::kShowOmniboxSearchHint) && |
| 235 CommandLine::ForCurrentProcess()->HasSwitch( | 230 CommandLine::ForCurrentProcess()->HasSwitch( |
| 236 switches::kSearchInOmniboxHint); | 231 switches::kSearchInOmniboxHint); |
| 237 } | 232 } |
| OLD | NEW |