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