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

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

Issue 153353006: Opt out of download feedback from settings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: First version for review Created 6 years, 10 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_feedback_dialog_view.h" 5 #include "chrome/browser/ui/views/download/download_feedback_dialog_view.h"
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/supports_user_data.h" 8 #include "base/supports_user_data.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/views/constrained_window_views.h" 10 #include "chrome/browser/ui/views/constrained_window_views.h"
11 #include "grit/generated_resources.h" 11 #include "grit/generated_resources.h"
12 #include "ui/base/l10n/l10n_util.h" 12 #include "ui/base/l10n/l10n_util.h"
13 #include "ui/views/controls/message_box_view.h" 13 #include "ui/views/controls/message_box_view.h"
14 #include "ui/views/widget/widget.h" 14 #include "ui/views/widget/widget.h"
15 15
16 using safe_browsing::DownloadFeedbackService;
17
16 namespace { 18 namespace {
17 19
18 const void* kDialogStatusKey = &kDialogStatusKey; 20 const void* kDialogStatusKey = &kDialogStatusKey;
19 21
20 class DialogStatusData : public base::SupportsUserData::Data { 22 class DialogStatusData : public base::SupportsUserData::Data {
21 public: 23 public:
22 DialogStatusData() : currently_shown_(false) {} 24 DialogStatusData() : currently_shown_(false) {}
23 virtual ~DialogStatusData() {} 25 virtual ~DialogStatusData() {}
24 bool currently_shown() const { return currently_shown_; } 26 bool currently_shown() const { return currently_shown_; }
25 void set_currently_shown(bool shown) { currently_shown_ = shown; } 27 void set_currently_shown(bool shown) { currently_shown_ = shown; }
26 private: 28 private:
27 bool currently_shown_; 29 bool currently_shown_;
28 }; 30 };
29 31
30 } // namespace 32 } // namespace
31 33
32 // static 34 // static
33 void DownloadFeedbackDialogView::Show( 35 void DownloadFeedbackDialogView::Show(
34 gfx::NativeWindow parent_window, 36 gfx::NativeWindow parent_window,
35 Profile* profile, 37 Profile* profile,
36 const base::Callback<void(DownloadReportingStatus)>& callback) { 38 const base::Callback<
39 void(DownloadFeedbackService::DownloadReportingStatus)>& callback) {
37 // This dialog should only be shown if it hasn't been shown before. 40 // This dialog should only be shown if it hasn't been shown before.
38 DCHECK(profile->GetPrefs()->GetInteger( 41 DCHECK_EQ(DownloadFeedbackService::kDialogNotYetShown,
39 prefs::kSafeBrowsingDownloadReportingEnabled) == kDialogNotYetShown); 42 profile->GetPrefs()->GetInteger(
43 prefs::kSafeBrowsingDownloadReportingEnabled));
40 44
41 // Only one dialog should be shown at a time, so check to see if another one 45 // Only one dialog should be shown at a time, so check to see if another one
42 // is open. If another one is open, treat this parallel call as if reporting 46 // is open. If another one is open, treat this parallel call as if reporting
43 // is disabled (to be conservative). 47 // is disabled (to be conservative).
44 DialogStatusData* data = 48 DialogStatusData* data =
45 static_cast<DialogStatusData*>(profile->GetUserData(kDialogStatusKey)); 49 static_cast<DialogStatusData*>(profile->GetUserData(kDialogStatusKey));
46 if (data == NULL) { 50 if (data == NULL) {
47 data = new DialogStatusData(); 51 data = new DialogStatusData();
48 profile->SetUserData(kDialogStatusKey, data); 52 profile->SetUserData(kDialogStatusKey, data);
49 } 53 }
50 if (data->currently_shown() == false) { 54 if (data->currently_shown() == false) {
51 data->set_currently_shown(true); 55 data->set_currently_shown(true);
52 DownloadFeedbackDialogView* window = 56 DownloadFeedbackDialogView* window =
53 new DownloadFeedbackDialogView(profile, callback); 57 new DownloadFeedbackDialogView(profile, callback);
54 CreateBrowserModalDialogViews(window, parent_window)->Show(); 58 CreateBrowserModalDialogViews(window, parent_window)->Show();
55 } else { 59 } else {
56 callback.Run(kDownloadReportingDisabled); 60 callback.Run(DownloadFeedbackService::kDownloadReportingDisabled);
57 } 61 }
58 } 62 }
59 63
60 void DownloadFeedbackDialogView::ReleaseDialogStatusHold() { 64 void DownloadFeedbackDialogView::ReleaseDialogStatusHold() {
61 DialogStatusData* data = 65 DialogStatusData* data =
62 static_cast<DialogStatusData*>(profile_->GetUserData(kDialogStatusKey)); 66 static_cast<DialogStatusData*>(profile_->GetUserData(kDialogStatusKey));
63 DCHECK(data); 67 DCHECK(data);
64 data->set_currently_shown(false); 68 data->set_currently_shown(false);
65 } 69 }
66 70
67 DownloadFeedbackDialogView::DownloadFeedbackDialogView( 71 DownloadFeedbackDialogView::DownloadFeedbackDialogView(
68 Profile* profile, 72 Profile* profile,
69 const base::Callback<void(DownloadReportingStatus)>& callback) 73 const base::Callback<void(
74 DownloadFeedbackService::DownloadReportingStatus)>& callback)
70 : profile_(profile), 75 : profile_(profile),
71 callback_(callback), 76 callback_(callback),
72 explanation_box_view_(new views::MessageBoxView( 77 explanation_box_view_(new views::MessageBoxView(
73 views::MessageBoxView::InitParams(l10n_util::GetStringUTF16( 78 views::MessageBoxView::InitParams(l10n_util::GetStringUTF16(
74 IDS_FEEDBACK_SERVICE_DIALOG_EXPLANATION)))), 79 IDS_FEEDBACK_SERVICE_DIALOG_EXPLANATION)))),
75 title_text_(l10n_util::GetStringUTF16(IDS_FEEDBACK_SERVICE_DIALOG_TITLE)), 80 title_text_(l10n_util::GetStringUTF16(IDS_FEEDBACK_SERVICE_DIALOG_TITLE)),
76 ok_button_text_(l10n_util::GetStringUTF16( 81 ok_button_text_(l10n_util::GetStringUTF16(
77 IDS_FEEDBACK_SERVICE_DIALOG_OK_BUTTON_LABEL)), 82 IDS_FEEDBACK_SERVICE_DIALOG_OK_BUTTON_LABEL)),
78 cancel_button_text_(l10n_util::GetStringUTF16( 83 cancel_button_text_(l10n_util::GetStringUTF16(
79 IDS_FEEDBACK_SERVICE_DIALOG_CANCEL_BUTTON_LABEL)) { 84 IDS_FEEDBACK_SERVICE_DIALOG_CANCEL_BUTTON_LABEL)) {
80 } 85 }
81 86
82 DownloadFeedbackDialogView::~DownloadFeedbackDialogView() {} 87 DownloadFeedbackDialogView::~DownloadFeedbackDialogView() {}
83 88
84 int DownloadFeedbackDialogView::GetDefaultDialogButton() const { 89 int DownloadFeedbackDialogView::GetDefaultDialogButton() const {
85 return ui::DIALOG_BUTTON_CANCEL; 90 return ui::DIALOG_BUTTON_CANCEL;
86 } 91 }
87 92
88 base::string16 DownloadFeedbackDialogView::GetDialogButtonLabel( 93 base::string16 DownloadFeedbackDialogView::GetDialogButtonLabel(
89 ui::DialogButton button) const { 94 ui::DialogButton button) const {
90 return (button == ui::DIALOG_BUTTON_OK) ? 95 return (button == ui::DIALOG_BUTTON_OK) ?
91 ok_button_text_ : cancel_button_text_; 96 ok_button_text_ : cancel_button_text_;
92 } 97 }
93 98
94 bool DownloadFeedbackDialogView::Cancel() { 99 bool DownloadFeedbackDialogView::Cancel() {
95 profile_->GetPrefs()->SetInteger( 100 profile_->GetPrefs()->SetInteger(
96 prefs::kSafeBrowsingDownloadReportingEnabled, kDownloadReportingDisabled); 101 prefs::kSafeBrowsingDownloadReportingEnabled,
102 DownloadFeedbackService::kDownloadReportingDisabled);
97 ReleaseDialogStatusHold(); 103 ReleaseDialogStatusHold();
98 callback_.Run(kDownloadReportingDisabled); 104 callback_.Run(DownloadFeedbackService::kDownloadReportingDisabled);
99 return true; 105 return true;
100 } 106 }
101 107
102 bool DownloadFeedbackDialogView::Accept() { 108 bool DownloadFeedbackDialogView::Accept() {
103 profile_->GetPrefs()->SetInteger( 109 profile_->GetPrefs()->SetInteger(
104 prefs::kSafeBrowsingDownloadReportingEnabled, kDownloadReportingEnabled); 110 prefs::kSafeBrowsingDownloadReportingEnabled,
111 DownloadFeedbackService::kDownloadReportingEnabled);
105 ReleaseDialogStatusHold(); 112 ReleaseDialogStatusHold();
106 callback_.Run(kDownloadReportingEnabled); 113 callback_.Run(DownloadFeedbackService::kDownloadReportingEnabled);
107 return true; 114 return true;
108 } 115 }
109 116
110 ui::ModalType DownloadFeedbackDialogView::GetModalType() const { 117 ui::ModalType DownloadFeedbackDialogView::GetModalType() const {
111 return ui::MODAL_TYPE_WINDOW; 118 return ui::MODAL_TYPE_WINDOW;
112 } 119 }
113 120
114 base::string16 DownloadFeedbackDialogView::GetWindowTitle() const { 121 base::string16 DownloadFeedbackDialogView::GetWindowTitle() const {
115 return title_text_; 122 return title_text_;
116 } 123 }
117 124
118 void DownloadFeedbackDialogView::DeleteDelegate() { 125 void DownloadFeedbackDialogView::DeleteDelegate() {
119 delete this; 126 delete this;
120 } 127 }
121 128
122 views::Widget* DownloadFeedbackDialogView::GetWidget() { 129 views::Widget* DownloadFeedbackDialogView::GetWidget() {
123 return explanation_box_view_->GetWidget(); 130 return explanation_box_view_->GetWidget();
124 } 131 }
125 132
126 const views::Widget* DownloadFeedbackDialogView::GetWidget() const { 133 const views::Widget* DownloadFeedbackDialogView::GetWidget() const {
127 return explanation_box_view_->GetWidget(); 134 return explanation_box_view_->GetWidget();
128 } 135 }
129 136
130 views::View* DownloadFeedbackDialogView::GetContentsView() { 137 views::View* DownloadFeedbackDialogView::GetContentsView() {
131 return explanation_box_view_; 138 return explanation_box_view_;
132 } 139 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698