Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/android/search_geolocation_disclosure_infobar_delegate. h" | 5 #include "chrome/browser/android/search_geolocation_disclosure_infobar_delegate. h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/metrics/histogram_macros.h" | |
| 8 #include "chrome/browser/android/android_theme_resources.h" | 9 #include "chrome/browser/android/android_theme_resources.h" |
| 9 #include "chrome/browser/infobars/infobar_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/ui/android/infobars/search_geolocation_disclosure_infob ar.h" | 12 #include "chrome/browser/ui/android/infobars/search_geolocation_disclosure_infob ar.h" |
| 12 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 13 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
| 14 #include "components/prefs/pref_service.h" | 15 #include "components/prefs/pref_service.h" |
| 15 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 17 | 18 |
| 19 // This enum is used in histograms, and is thus append only. Do not remove or | |
| 20 // re-order items. | |
| 21 enum class SearchGeolocationDisclosureInfoBarDelegate::DisclosureResult { | |
| 22 IGNORED = 0, | |
| 23 SETTINGS_CLICKED, | |
| 24 DISMISSED, | |
| 25 LAST = DISMISSED | |
|
gone
2016/11/30 18:28:45
Curious about this since I've seen it twice now: i
| |
| 26 }; | |
| 27 | |
| 18 SearchGeolocationDisclosureInfoBarDelegate:: | 28 SearchGeolocationDisclosureInfoBarDelegate:: |
| 19 ~SearchGeolocationDisclosureInfoBarDelegate() {} | 29 ~SearchGeolocationDisclosureInfoBarDelegate() { |
| 30 UMA_HISTOGRAM_ENUMERATION( | |
| 31 "GeolocationDisclosure.DisclosureResult", | |
| 32 static_cast<base::HistogramBase::Sample>(result_), | |
| 33 static_cast<base::HistogramBase::Sample>(DisclosureResult::LAST) + 1); | |
| 34 UMA_HISTOGRAM_MEDIUM_TIMES("GeolocationDisclosure.InfoBarVisibleTime", | |
| 35 base::Time::Now() - creation_time_); | |
| 36 } | |
| 20 | 37 |
| 21 // static | 38 // static |
| 22 void SearchGeolocationDisclosureInfoBarDelegate::Create( | 39 void SearchGeolocationDisclosureInfoBarDelegate::Create( |
| 23 content::WebContents* web_contents, const GURL& search_url) { | 40 content::WebContents* web_contents, |
| 41 const GURL& search_url) { | |
| 24 InfoBarService* infobar_service = | 42 InfoBarService* infobar_service = |
| 25 InfoBarService::FromWebContents(web_contents); | 43 InfoBarService::FromWebContents(web_contents); |
| 26 // Add the new delegate. | 44 // Add the new delegate. |
| 27 infobar_service->AddInfoBar( | 45 infobar_service->AddInfoBar( |
| 28 base::MakeUnique<SearchGeolocationDisclosureInfoBar>( | 46 base::MakeUnique<SearchGeolocationDisclosureInfoBar>( |
| 29 base::WrapUnique(new SearchGeolocationDisclosureInfoBarDelegate( | 47 base::WrapUnique(new SearchGeolocationDisclosureInfoBarDelegate( |
| 30 web_contents, search_url)))); | 48 web_contents, search_url)))); |
| 31 } | 49 } |
| 32 | 50 |
| 33 // static | 51 // static |
| 34 bool SearchGeolocationDisclosureInfoBarDelegate:: | 52 bool SearchGeolocationDisclosureInfoBarDelegate:: |
| 35 IsSearchGeolocationDisclosureOpen(content::WebContents* web_contents) { | 53 IsSearchGeolocationDisclosureOpen(content::WebContents* web_contents) { |
| 36 InfoBarService* infobar_service = | 54 InfoBarService* infobar_service = |
| 37 InfoBarService::FromWebContents(web_contents); | 55 InfoBarService::FromWebContents(web_contents); |
| 38 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { | 56 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { |
| 39 infobars::InfoBar* existing_infobar = infobar_service->infobar_at(i); | 57 infobars::InfoBar* existing_infobar = infobar_service->infobar_at(i); |
| 40 if (existing_infobar->delegate()->GetIdentifier() == | 58 if (existing_infobar->delegate()->GetIdentifier() == |
| 41 infobars::InfoBarDelegate:: | 59 infobars::InfoBarDelegate:: |
| 42 SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_DELEGATE) { | 60 SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_DELEGATE) { |
| 43 return true; | 61 return true; |
| 44 } | 62 } |
| 45 } | 63 } |
| 46 | 64 |
| 47 return false; | 65 return false; |
| 48 } | 66 } |
| 49 | 67 |
| 68 void SearchGeolocationDisclosureInfoBarDelegate::RecordSettingsClicked() { | |
| 69 result_ = DisclosureResult::SETTINGS_CLICKED; | |
| 70 // This counts as a dismissed so the dialog isn't shown again. | |
| 71 pref_service_->SetBoolean(prefs::kSearchGeolocationDisclosureDismissed, true); | |
| 72 } | |
| 73 | |
| 50 SearchGeolocationDisclosureInfoBarDelegate:: | 74 SearchGeolocationDisclosureInfoBarDelegate:: |
| 51 SearchGeolocationDisclosureInfoBarDelegate( | 75 SearchGeolocationDisclosureInfoBarDelegate( |
| 52 content::WebContents* web_contents, | 76 content::WebContents* web_contents, |
| 53 const GURL& search_url) | 77 const GURL& search_url) |
| 54 : infobars::InfoBarDelegate(), search_url_(search_url) { | 78 : infobars::InfoBarDelegate(), |
| 79 search_url_(search_url), | |
| 80 result_(DisclosureResult::IGNORED), | |
| 81 creation_time_(base::Time::Now()) { | |
| 55 pref_service_ = Profile::FromBrowserContext(web_contents->GetBrowserContext()) | 82 pref_service_ = Profile::FromBrowserContext(web_contents->GetBrowserContext()) |
| 56 ->GetPrefs(); | 83 ->GetPrefs(); |
| 57 base::string16 link = l10n_util::GetStringUTF16( | 84 base::string16 link = l10n_util::GetStringUTF16( |
| 58 IDS_SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_SETTINGS_LINK_TEXT); | 85 IDS_SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_SETTINGS_LINK_TEXT); |
| 59 size_t offset; | 86 size_t offset; |
| 60 message_text_ = l10n_util::GetStringFUTF16( | 87 message_text_ = l10n_util::GetStringFUTF16( |
| 61 IDS_SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_TEXT, link, &offset); | 88 IDS_SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_TEXT, link, &offset); |
| 62 inline_link_range_ = gfx::Range(offset, offset + link.length()); | 89 inline_link_range_ = gfx::Range(offset, offset + link.length()); |
| 63 } | 90 } |
| 64 | 91 |
| 65 void SearchGeolocationDisclosureInfoBarDelegate::InfoBarDismissed() { | 92 void SearchGeolocationDisclosureInfoBarDelegate::InfoBarDismissed() { |
| 93 result_ = DisclosureResult::DISMISSED; | |
| 66 pref_service_->SetBoolean(prefs::kSearchGeolocationDisclosureDismissed, true); | 94 pref_service_->SetBoolean(prefs::kSearchGeolocationDisclosureDismissed, true); |
| 67 } | 95 } |
| 68 | 96 |
| 69 infobars::InfoBarDelegate::Type | 97 infobars::InfoBarDelegate::Type |
| 70 SearchGeolocationDisclosureInfoBarDelegate::GetInfoBarType() const { | 98 SearchGeolocationDisclosureInfoBarDelegate::GetInfoBarType() const { |
| 71 return PAGE_ACTION_TYPE; | 99 return PAGE_ACTION_TYPE; |
| 72 } | 100 } |
| 73 | 101 |
| 74 infobars::InfoBarDelegate::InfoBarIdentifier | 102 infobars::InfoBarDelegate::InfoBarIdentifier |
| 75 SearchGeolocationDisclosureInfoBarDelegate::GetIdentifier() const { | 103 SearchGeolocationDisclosureInfoBarDelegate::GetIdentifier() const { |
| 76 return SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_DELEGATE; | 104 return SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_DELEGATE; |
| 77 } | 105 } |
| 78 | 106 |
| 79 int SearchGeolocationDisclosureInfoBarDelegate::GetIconId() const { | 107 int SearchGeolocationDisclosureInfoBarDelegate::GetIconId() const { |
| 80 return IDR_ANDROID_INFOBAR_GEOLOCATION; | 108 return IDR_ANDROID_INFOBAR_GEOLOCATION; |
| 81 } | 109 } |
| OLD | NEW |