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 #include "chrome/browser/omnibox_search_hint.h" | 5 #include "chrome/browser/omnibox_search_hint.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | |
| 7 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 8 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 9 #include "base/task.h" | 10 #include "base/task.h" |
| 10 // TODO(avi): remove when conversions not needed any more | 11 // TODO(avi): remove when conversions not needed any more |
| 11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/autocomplete/autocomplete.h" | 13 #include "chrome/browser/autocomplete/autocomplete.h" |
| 13 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 14 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
| 14 #include "chrome/browser/autocomplete/autocomplete_match.h" | 15 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 15 #include "chrome/browser/infobars/infobar_tab_helper.h" | 16 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 16 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 // The omnibox hint that shows us. | 73 // The omnibox hint that shows us. |
| 73 OmniboxSearchHint* omnibox_hint_; | 74 OmniboxSearchHint* omnibox_hint_; |
| 74 | 75 |
| 75 // Whether the user clicked one of the buttons. | 76 // Whether the user clicked one of the buttons. |
| 76 bool action_taken_; | 77 bool action_taken_; |
| 77 | 78 |
| 78 // Whether the info-bar should be dismissed on the next navigation. | 79 // Whether the info-bar should be dismissed on the next navigation. |
| 79 bool should_expire_; | 80 bool should_expire_; |
| 80 | 81 |
| 81 // Used to delay the expiration of the info-bar. | 82 // Used to delay the expiration of the info-bar. |
| 82 ScopedRunnableMethodFactory<HintInfoBar> method_factory_; | 83 base::WeakPtrFactory<HintInfoBar> weak_factory_; |
| 83 | 84 |
| 84 DISALLOW_COPY_AND_ASSIGN(HintInfoBar); | 85 DISALLOW_COPY_AND_ASSIGN(HintInfoBar); |
| 85 }; | 86 }; |
| 86 | 87 |
| 87 HintInfoBar::HintInfoBar(OmniboxSearchHint* omnibox_hint) | 88 HintInfoBar::HintInfoBar(OmniboxSearchHint* omnibox_hint) |
| 88 : ConfirmInfoBarDelegate(omnibox_hint->tab()->infobar_tab_helper()), | 89 : ConfirmInfoBarDelegate(omnibox_hint->tab()->infobar_tab_helper()), |
| 89 omnibox_hint_(omnibox_hint), | 90 omnibox_hint_(omnibox_hint), |
| 90 action_taken_(false), | 91 action_taken_(false), |
| 91 should_expire_(false), | 92 should_expire_(false), |
| 92 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 93 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 93 // We want the info-bar to stick-around for few seconds and then be hidden | 94 // We want the info-bar to stick-around for few seconds and then be hidden |
| 94 // on the next navigation after that. | 95 // on the next navigation after that. |
| 95 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 96 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
|
James Hawkins
2011/11/19 03:31:12
nit: Start of parameter lines must start on the sa
groby-ooo-7-16
2011/11/21 22:54:48
Done.
| |
| 96 method_factory_.NewRunnableMethod(&HintInfoBar::AllowExpiry), | 97 base::Bind(&HintInfoBar::AllowExpiry, weak_factory_.GetWeakPtr()), |
| 97 8000); // 8 seconds. | 98 8000); // 8 seconds. |
| 98 } | 99 } |
| 99 | 100 |
| 100 HintInfoBar::~HintInfoBar() { | 101 HintInfoBar::~HintInfoBar() { |
| 101 if (!action_taken_) | 102 if (!action_taken_) |
| 102 UMA_HISTOGRAM_COUNTS("OmniboxSearchHint.Ignored", 1); | 103 UMA_HISTOGRAM_COUNTS("OmniboxSearchHint.Ignored", 1); |
| 103 } | 104 } |
| 104 | 105 |
| 105 bool HintInfoBar::ShouldExpire( | 106 bool HintInfoBar::ShouldExpire( |
| 106 const content::LoadCommittedDetails& details) const { | 107 const content::LoadCommittedDetails& details) const { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 } | 228 } |
| 228 | 229 |
| 229 // static | 230 // static |
| 230 bool OmniboxSearchHint::IsEnabled(Profile* profile) { | 231 bool OmniboxSearchHint::IsEnabled(Profile* profile) { |
| 231 // The infobar can only be shown if the correct switch has been provided and | 232 // The infobar can only be shown if the correct switch has been provided and |
| 232 // the user did not dismiss the infobar before. | 233 // the user did not dismiss the infobar before. |
| 233 return profile->GetPrefs()->GetBoolean(prefs::kShowOmniboxSearchHint) && | 234 return profile->GetPrefs()->GetBoolean(prefs::kShowOmniboxSearchHint) && |
| 234 CommandLine::ForCurrentProcess()->HasSwitch( | 235 CommandLine::ForCurrentProcess()->HasSwitch( |
| 235 switches::kSearchInOmniboxHint); | 236 switches::kSearchInOmniboxHint); |
| 236 } | 237 } |
| OLD | NEW |