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