Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: chrome/browser/ui/views/download/download_item_view.cc

Issue 402293002: Experience sampling instrumentation for dangerous downloads warnings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sampling-api
Patch Set: rebase-update Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/views/download/download_item_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/views/download/download_item_view.h" 5 #include "chrome/browser/ui/views/download/download_item_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/i18n/break_iterator.h" 13 #include "base/i18n/break_iterator.h"
14 #include "base/i18n/rtl.h" 14 #include "base/i18n/rtl.h"
15 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
16 #include "base/prefs/pref_service.h" 16 #include "base/prefs/pref_service.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
19 #include "base/strings/sys_string_conversions.h" 19 #include "base/strings/sys_string_conversions.h"
20 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
21 #include "chrome/browser/browser_process.h" 21 #include "chrome/browser/browser_process.h"
22 #include "chrome/browser/download/chrome_download_manager_delegate.h" 22 #include "chrome/browser/download/chrome_download_manager_delegate.h"
23 #include "chrome/browser/download/download_item_model.h" 23 #include "chrome/browser/download/download_item_model.h"
24 #include "chrome/browser/download/download_stats.h" 24 #include "chrome/browser/download/download_stats.h"
25 #include "chrome/browser/download/drag_download_item.h" 25 #include "chrome/browser/download/drag_download_item.h"
26 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s ampling.h"
26 #include "chrome/browser/profiles/profile.h" 27 #include "chrome/browser/profiles/profile.h"
27 #include "chrome/browser/safe_browsing/download_feedback_service.h" 28 #include "chrome/browser/safe_browsing/download_feedback_service.h"
28 #include "chrome/browser/safe_browsing/download_protection_service.h" 29 #include "chrome/browser/safe_browsing/download_protection_service.h"
29 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 30 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
30 #include "chrome/browser/themes/theme_properties.h" 31 #include "chrome/browser/themes/theme_properties.h"
31 #include "chrome/browser/ui/views/download/download_feedback_dialog_view.h" 32 #include "chrome/browser/ui/views/download/download_feedback_dialog_view.h"
32 #include "chrome/browser/ui/views/download/download_shelf_context_menu_view.h" 33 #include "chrome/browser/ui/views/download/download_shelf_context_menu_view.h"
33 #include "chrome/browser/ui/views/download/download_shelf_view.h" 34 #include "chrome/browser/ui/views/download/download_shelf_view.h"
34 #include "chrome/browser/ui/views/frame/browser_view.h" 35 #include "chrome/browser/ui/views/frame/browser_view.h"
35 #include "content/public/browser/download_danger_type.h" 36 #include "content/public/browser/download_danger_type.h"
(...skipping 11 matching lines...) Expand all
47 #include "ui/gfx/image/image.h" 48 #include "ui/gfx/image/image.h"
48 #include "ui/gfx/text_elider.h" 49 #include "ui/gfx/text_elider.h"
49 #include "ui/gfx/text_utils.h" 50 #include "ui/gfx/text_utils.h"
50 #include "ui/views/controls/button/label_button.h" 51 #include "ui/views/controls/button/label_button.h"
51 #include "ui/views/controls/label.h" 52 #include "ui/views/controls/label.h"
52 #include "ui/views/mouse_constants.h" 53 #include "ui/views/mouse_constants.h"
53 #include "ui/views/widget/root_view.h" 54 #include "ui/views/widget/root_view.h"
54 #include "ui/views/widget/widget.h" 55 #include "ui/views/widget/widget.h"
55 56
56 using content::DownloadItem; 57 using content::DownloadItem;
58 using extensions::SamplingEvent;
57 59
58 // TODO(paulg): These may need to be adjusted when download progress 60 // TODO(paulg): These may need to be adjusted when download progress
59 // animation is added, and also possibly to take into account 61 // animation is added, and also possibly to take into account
60 // different screen resolutions. 62 // different screen resolutions.
61 static const int kTextWidth = 140; // Pixels 63 static const int kTextWidth = 140; // Pixels
62 static const int kDangerousTextWidth = 200; // Pixels 64 static const int kDangerousTextWidth = 200; // Pixels
63 static const int kVerticalPadding = 3; // Pixels 65 static const int kVerticalPadding = 3; // Pixels
64 static const int kVerticalTextPadding = 2; // Pixels 66 static const int kVerticalTextPadding = 2; // Pixels
65 static const int kTooltipMaxWidth = 800; // Pixels 67 static const int kTooltipMaxWidth = 800; // Pixels
66 68
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 225
224 SetAccessibilityFocusable(true); 226 SetAccessibilityFocusable(true);
225 227
226 OnDownloadUpdated(download()); 228 OnDownloadUpdated(download());
227 UpdateDropDownButtonPosition(); 229 UpdateDropDownButtonPosition();
228 } 230 }
229 231
230 DownloadItemView::~DownloadItemView() { 232 DownloadItemView::~DownloadItemView() {
231 StopDownloadProgress(); 233 StopDownloadProgress();
232 download()->RemoveObserver(this); 234 download()->RemoveObserver(this);
235
236 // Experience Sampling: If view was removed and was dangerous, then the user
237 // dismissed the download.
238 if (mode_ == DANGEROUS_MODE || mode_ == MALICIOUS_MODE)
239 sampling_event_->CreateUserDecisionEvent("deny");
felt 2014/07/25 17:36:49 Can you update the comment to say something like:
Chris Thompson 2014/08/11 19:35:15 Done.
233 } 240 }
234 241
235 // Progress animation handlers. 242 // Progress animation handlers.
236 243
237 void DownloadItemView::UpdateDownloadProgress() { 244 void DownloadItemView::UpdateDownloadProgress() {
238 progress_angle_ = 245 progress_angle_ =
239 (progress_angle_ + DownloadShelf::kUnknownIncrementDegrees) % 246 (progress_angle_ + DownloadShelf::kUnknownIncrementDegrees) %
240 DownloadShelf::kMaxDegrees; 247 DownloadShelf::kMaxDegrees;
241 SchedulePaint(); 248 SchedulePaint();
242 } 249 }
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 1127
1121 void DownloadItemView::ClearWarningDialog() { 1128 void DownloadItemView::ClearWarningDialog() {
1122 DCHECK(download()->GetDangerType() == 1129 DCHECK(download()->GetDangerType() ==
1123 content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED); 1130 content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED);
1124 DCHECK(mode_ == DANGEROUS_MODE || mode_ == MALICIOUS_MODE); 1131 DCHECK(mode_ == DANGEROUS_MODE || mode_ == MALICIOUS_MODE);
1125 1132
1126 mode_ = NORMAL_MODE; 1133 mode_ = NORMAL_MODE;
1127 body_state_ = NORMAL; 1134 body_state_ = NORMAL;
1128 drop_down_state_ = NORMAL; 1135 drop_down_state_ = NORMAL;
1129 1136
1137 // ExperienceSampling: User proceeded through the warning.
1138 sampling_event_->CreateUserDecisionEvent("proceed");
felt 2014/07/25 21:23:21 P.S. remember that you defined constants for "proc
Chris Thompson 2014/08/11 19:35:15 Done.
1139
1130 // Remove the views used by the warning dialog. 1140 // Remove the views used by the warning dialog.
1131 if (save_button_) { 1141 if (save_button_) {
1132 RemoveChildView(save_button_); 1142 RemoveChildView(save_button_);
1133 delete save_button_; 1143 delete save_button_;
1134 save_button_ = NULL; 1144 save_button_ = NULL;
1135 } 1145 }
1136 RemoveChildView(discard_button_); 1146 RemoveChildView(discard_button_);
1137 delete discard_button_; 1147 delete discard_button_;
1138 discard_button_ = NULL; 1148 discard_button_ = NULL;
1139 RemoveChildView(dangerous_download_label_); 1149 RemoveChildView(dangerous_download_label_);
(...skipping 23 matching lines...) Expand all
1163 content::DownloadDangerType danger_type = download()->GetDangerType(); 1173 content::DownloadDangerType danger_type = download()->GetDangerType();
1164 RecordDangerousDownloadWarningShown(danger_type); 1174 RecordDangerousDownloadWarningShown(danger_type);
1165 #if defined(FULL_SAFE_BROWSING) 1175 #if defined(FULL_SAFE_BROWSING)
1166 if (model_.ShouldAllowDownloadFeedback()) { 1176 if (model_.ShouldAllowDownloadFeedback()) {
1167 safe_browsing::DownloadFeedbackService::RecordEligibleDownloadShown( 1177 safe_browsing::DownloadFeedbackService::RecordEligibleDownloadShown(
1168 danger_type); 1178 danger_type);
1169 } 1179 }
1170 #endif 1180 #endif
1171 mode_ = model_.MightBeMalicious() ? MALICIOUS_MODE : DANGEROUS_MODE; 1181 mode_ = model_.MightBeMalicious() ? MALICIOUS_MODE : DANGEROUS_MODE;
1172 1182
1183 // ExperienceSampling: Dangerous or malicious download warning is being shown
1184 // to the user, so we start a new SamplingEvent and track it.
1185 std::string event_name = model_.MightBeMalicious() ?
1186 "download_warning_malicious"
1187 : "download_warning_dangerous";
1188 sampling_event_.reset(new SamplingEvent(
1189 event_name,
1190 download()->GetURL(),
1191 download()->GetReferrerUrl(),
1192 download()->GetBrowserContext()));
1193
1173 body_state_ = NORMAL; 1194 body_state_ = NORMAL;
1174 drop_down_state_ = NORMAL; 1195 drop_down_state_ = NORMAL;
1175 if (mode_ == DANGEROUS_MODE) { 1196 if (mode_ == DANGEROUS_MODE) {
1176 save_button_ = new views::LabelButton( 1197 save_button_ = new views::LabelButton(
1177 this, model_.GetWarningConfirmButtonText()); 1198 this, model_.GetWarningConfirmButtonText());
1178 save_button_->SetStyle(views::Button::STYLE_BUTTON); 1199 save_button_->SetStyle(views::Button::STYLE_BUTTON);
1179 AddChildView(save_button_); 1200 AddChildView(save_button_);
1180 } 1201 }
1181 int discard_button_message = model_.IsMalicious() ? 1202 int discard_button_message = model_.IsMalicious() ?
1182 IDS_DISMISS_DOWNLOAD : IDS_DISCARD_DOWNLOAD; 1203 IDS_DISMISS_DOWNLOAD : IDS_DISCARD_DOWNLOAD;
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
1356 void DownloadItemView::AnimateStateTransition(State from, State to, 1377 void DownloadItemView::AnimateStateTransition(State from, State to,
1357 gfx::SlideAnimation* animation) { 1378 gfx::SlideAnimation* animation) {
1358 if (from == NORMAL && to == HOT) { 1379 if (from == NORMAL && to == HOT) {
1359 animation->Show(); 1380 animation->Show();
1360 } else if (from == HOT && to == NORMAL) { 1381 } else if (from == HOT && to == NORMAL) {
1361 animation->Hide(); 1382 animation->Hide();
1362 } else if (from != to) { 1383 } else if (from != to) {
1363 animation->Reset((to == HOT) ? 1.0 : 0.0); 1384 animation->Reset((to == HOT) ? 1.0 : 0.0);
1364 } 1385 }
1365 } 1386 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/download/download_item_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698