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/previews/previews_infobar_delegate.h" | 5 #include "chrome/browser/previews/previews_infobar_delegate.h" |
6 | 6 |
| 7 #include "base/metrics/histogram_macros.h" |
7 #include "chrome/browser/android/android_theme_resources.h" | 8 #include "chrome/browser/android/android_theme_resources.h" |
8 #include "chrome/browser/infobars/infobar_service.h" | 9 #include "chrome/browser/infobars/infobar_service.h" |
9 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" | 10 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" |
10 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact
ory.h" | 11 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact
ory.h" |
11 #include "chrome/browser/previews/previews_infobar_tab_helper.h" | 12 #include "chrome/browser/previews/previews_infobar_tab_helper.h" |
12 #include "chrome/grit/generated_resources.h" | 13 #include "chrome/grit/generated_resources.h" |
13 #include "components/infobars/core/infobar.h" | 14 #include "components/infobars/core/infobar.h" |
14 #include "content/public/browser/render_frame_host.h" | 15 #include "content/public/browser/render_frame_host.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 namespace { |
| 20 |
| 21 // Key of the UMA Previews.InfoBarAction.LoFi histogram. |
| 22 const char kUMAPreviewsInfoBarActionLoFi[] = "Previews.InfoBarAction.LoFi"; |
| 23 |
| 24 // Key of the UMA Previews.InfoBarAction.Offline histogram. |
| 25 const char kUMAPreviewsInfoBarActionOffline[] = |
| 26 "Previews.InfoBarAction.Offline"; |
| 27 |
| 28 // Key of the UMA Previews.InfoBarAction.LitePage histogram. |
| 29 const char kUMAPreviewsInfoBarActionLitePage[] = |
| 30 "Previews.InfoBarAction.LitePage"; |
| 31 |
| 32 // Actions on the previews infobar. This enum must remain synchronized with the |
| 33 // enum of the same name in metrics/histograms/histograms.xml. |
| 34 enum PreviewsInfoBarAction { |
| 35 INFOBAR_SHOWN = 0, |
| 36 INFOBAR_LOAD_ORIGINAL_CLICKED = 1, |
| 37 INFOBAR_DISMISSED_BY_USER = 2, |
| 38 INFOBAR_DISMISSED_BY_NAVIGATION = 3, |
| 39 INFOBAR_INDEX_BOUNDARY |
| 40 }; |
| 41 |
| 42 void RecordPreviewsInfoBarAction( |
| 43 PreviewsInfoBarDelegate::PreviewsInfoBarType infobar_type, |
| 44 PreviewsInfoBarAction action) { |
| 45 if (infobar_type == PreviewsInfoBarDelegate::LOFI) { |
| 46 UMA_HISTOGRAM_ENUMERATION(kUMAPreviewsInfoBarActionLoFi, action, |
| 47 INFOBAR_INDEX_BOUNDARY); |
| 48 } else if (infobar_type == PreviewsInfoBarDelegate::LITE_PAGE) { |
| 49 UMA_HISTOGRAM_ENUMERATION(kUMAPreviewsInfoBarActionLitePage, action, |
| 50 INFOBAR_INDEX_BOUNDARY); |
| 51 } else if (infobar_type == PreviewsInfoBarDelegate::OFFLINE) { |
| 52 UMA_HISTOGRAM_ENUMERATION(kUMAPreviewsInfoBarActionOffline, action, |
| 53 INFOBAR_INDEX_BOUNDARY); |
| 54 } |
| 55 } |
| 56 |
| 57 } // namespace |
| 58 |
18 PreviewsInfoBarDelegate::~PreviewsInfoBarDelegate() {} | 59 PreviewsInfoBarDelegate::~PreviewsInfoBarDelegate() {} |
19 | 60 |
20 // static | 61 // static |
21 void PreviewsInfoBarDelegate::Create(content::WebContents* web_contents, | 62 void PreviewsInfoBarDelegate::Create(content::WebContents* web_contents, |
22 PreviewsInfoBarType infobar_type) { | 63 PreviewsInfoBarType infobar_type) { |
23 PreviewsInfoBarTabHelper* infobar_tab_helper = | 64 PreviewsInfoBarTabHelper* infobar_tab_helper = |
24 PreviewsInfoBarTabHelper::FromWebContents(web_contents); | 65 PreviewsInfoBarTabHelper::FromWebContents(web_contents); |
25 if (infobar_tab_helper->displayed_preview_infobar()) | 66 if (infobar_tab_helper->displayed_preview_infobar()) |
26 return; | 67 return; |
27 | 68 |
28 InfoBarService* infobar_service = | 69 InfoBarService* infobar_service = |
29 InfoBarService::FromWebContents(web_contents); | 70 InfoBarService::FromWebContents(web_contents); |
30 | 71 |
31 infobars::InfoBar* infobar = | 72 infobars::InfoBar* infobar = |
32 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( | 73 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( |
33 std::unique_ptr<ConfirmInfoBarDelegate>( | 74 std::unique_ptr<ConfirmInfoBarDelegate>( |
34 new PreviewsInfoBarDelegate(web_contents, infobar_type)))); | 75 new PreviewsInfoBarDelegate(web_contents, infobar_type)))); |
35 | 76 |
36 if (infobar && (infobar_type == LITE_PAGE || infobar_type == LOFI)) { | 77 if (infobar && (infobar_type == LITE_PAGE || infobar_type == LOFI)) { |
37 auto* data_reduction_proxy_settings = | 78 auto* data_reduction_proxy_settings = |
38 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 79 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
39 web_contents->GetBrowserContext()); | 80 web_contents->GetBrowserContext()); |
40 data_reduction_proxy_settings->IncrementLoFiUIShown(); | 81 data_reduction_proxy_settings->IncrementLoFiUIShown(); |
41 } | 82 } |
42 | 83 |
| 84 RecordPreviewsInfoBarAction(infobar_type, INFOBAR_SHOWN); |
43 infobar_tab_helper->set_displayed_preview_infobar(true); | 85 infobar_tab_helper->set_displayed_preview_infobar(true); |
44 } | 86 } |
45 | 87 |
46 PreviewsInfoBarDelegate::PreviewsInfoBarDelegate( | 88 PreviewsInfoBarDelegate::PreviewsInfoBarDelegate( |
47 content::WebContents* web_contents, | 89 content::WebContents* web_contents, |
48 PreviewsInfoBarType infobar_type) | 90 PreviewsInfoBarType infobar_type) |
49 : ConfirmInfoBarDelegate(), | 91 : ConfirmInfoBarDelegate(), |
50 infobar_type_(infobar_type) {} | 92 infobar_type_(infobar_type) {} |
51 | 93 |
52 infobars::InfoBarDelegate::InfoBarIdentifier | 94 infobars::InfoBarDelegate::InfoBarIdentifier |
53 PreviewsInfoBarDelegate::GetIdentifier() const { | 95 PreviewsInfoBarDelegate::GetIdentifier() const { |
54 return DATA_REDUCTION_PROXY_PREVIEW_INFOBAR_DELEGATE; | 96 return DATA_REDUCTION_PROXY_PREVIEW_INFOBAR_DELEGATE; |
55 } | 97 } |
56 | 98 |
57 int PreviewsInfoBarDelegate::GetIconId() const { | 99 int PreviewsInfoBarDelegate::GetIconId() const { |
58 #if defined(OS_ANDROID) | 100 #if defined(OS_ANDROID) |
59 return IDR_ANDROID_INFOBAR_PREVIEWS; | 101 return IDR_ANDROID_INFOBAR_PREVIEWS; |
60 #else | 102 #else |
61 return kNoIconID; | 103 return kNoIconID; |
62 #endif | 104 #endif |
63 } | 105 } |
64 | 106 |
65 bool PreviewsInfoBarDelegate::ShouldExpire( | 107 bool PreviewsInfoBarDelegate::ShouldExpire( |
66 const NavigationDetails& details) const { | 108 const NavigationDetails& details) const { |
67 // TODO(megjablon): Record UMA data. | 109 RecordPreviewsInfoBarAction(infobar_type_, INFOBAR_DISMISSED_BY_NAVIGATION); |
68 return InfoBarDelegate::ShouldExpire(details); | 110 return InfoBarDelegate::ShouldExpire(details); |
69 } | 111 } |
70 | 112 |
| 113 void PreviewsInfoBarDelegate::InfoBarDismissed() { |
| 114 RecordPreviewsInfoBarAction(infobar_type_, INFOBAR_DISMISSED_BY_USER); |
| 115 } |
| 116 |
71 base::string16 PreviewsInfoBarDelegate::GetMessageText() const { | 117 base::string16 PreviewsInfoBarDelegate::GetMessageText() const { |
72 return l10n_util::GetStringUTF16((infobar_type_ == OFFLINE) | 118 return l10n_util::GetStringUTF16((infobar_type_ == OFFLINE) |
73 ? IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE | 119 ? IDS_PREVIEWS_INFOBAR_FASTER_PAGE_TITLE |
74 : IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE); | 120 : IDS_PREVIEWS_INFOBAR_SAVED_DATA_TITLE); |
75 } | 121 } |
76 | 122 |
77 int PreviewsInfoBarDelegate::GetButtons() const { | 123 int PreviewsInfoBarDelegate::GetButtons() const { |
78 return BUTTON_NONE; | 124 return BUTTON_NONE; |
79 } | 125 } |
80 | 126 |
81 base::string16 PreviewsInfoBarDelegate::GetLinkText() const { | 127 base::string16 PreviewsInfoBarDelegate::GetLinkText() const { |
82 return l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK); | 128 return l10n_util::GetStringUTF16(IDS_PREVIEWS_INFOBAR_LINK); |
83 } | 129 } |
84 | 130 |
85 bool PreviewsInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { | 131 bool PreviewsInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { |
86 // TODO(megjablon): Record UMA data. | 132 RecordPreviewsInfoBarAction(infobar_type_, INFOBAR_LOAD_ORIGINAL_CLICKED); |
| 133 |
87 if (infobar_type_ == LITE_PAGE || infobar_type_ == LOFI) { | 134 if (infobar_type_ == LITE_PAGE || infobar_type_ == LOFI) { |
88 auto* web_contents = | 135 auto* web_contents = |
89 InfoBarService::WebContentsFromInfoBar(infobar()); | 136 InfoBarService::WebContentsFromInfoBar(infobar()); |
90 | 137 |
91 if (infobar_type_ == LITE_PAGE) | 138 if (infobar_type_ == LITE_PAGE) |
92 web_contents->GetController().ReloadDisableLoFi(true); | 139 web_contents->GetController().ReloadDisableLoFi(true); |
93 else if (infobar_type_ == LOFI) | 140 else if (infobar_type_ == LOFI) |
94 web_contents->ReloadLoFiImages(); | 141 web_contents->ReloadLoFiImages(); |
95 | 142 |
96 auto* data_reduction_proxy_settings = | 143 auto* data_reduction_proxy_settings = |
97 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 144 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
98 web_contents->GetBrowserContext()); | 145 web_contents->GetBrowserContext()); |
99 data_reduction_proxy_settings->IncrementLoFiUserRequestsForImages(); | 146 data_reduction_proxy_settings->IncrementLoFiUserRequestsForImages(); |
100 } | 147 } |
101 | 148 |
102 return true; | 149 return true; |
103 } | 150 } |
OLD | NEW |