OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/webui/settings/settings_clear_browsing_data_handler.
h" | 5 #include "chrome/browser/ui/webui/settings/settings_clear_browsing_data_handler.
h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "components/browsing_data_ui/history_notice_utils.h" | 22 #include "components/browsing_data_ui/history_notice_utils.h" |
23 #include "components/prefs/pref_service.h" | 23 #include "components/prefs/pref_service.h" |
24 #include "content/public/browser/web_ui.h" | 24 #include "content/public/browser/web_ui.h" |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 const int kMaxTimesHistoryNoticeShown = 1; | 28 const int kMaxTimesHistoryNoticeShown = 1; |
29 | 29 |
30 // TODO(msramek): Get the list of deletion preferences from the JS side. | 30 // TODO(msramek): Get the list of deletion preferences from the JS side. |
31 const char* kCounterPrefs[] = { | 31 const char* kCounterPrefs[] = { |
32 prefs::kDeleteBrowsingHistory, | 32 browsing_data::prefs::kDeleteBrowsingHistory, |
33 prefs::kDeleteCache, | 33 browsing_data::prefs::kDeleteCache, |
34 prefs::kDeleteDownloadHistory, | 34 browsing_data::prefs::kDeleteDownloadHistory, |
35 prefs::kDeleteFormData, | 35 browsing_data::prefs::kDeleteFormData, |
36 prefs::kDeleteHostedAppsData, | 36 browsing_data::prefs::kDeleteHostedAppsData, |
37 prefs::kDeleteMediaLicenses, | 37 browsing_data::prefs::kDeleteMediaLicenses, |
38 prefs::kDeletePasswords, | 38 browsing_data::prefs::kDeletePasswords, |
39 }; | 39 }; |
40 | 40 |
41 } // namespace | 41 } // namespace |
42 | 42 |
43 namespace settings { | 43 namespace settings { |
44 | 44 |
45 ClearBrowsingDataHandler::ClearBrowsingDataHandler(content::WebUI* webui) | 45 ClearBrowsingDataHandler::ClearBrowsingDataHandler(content::WebUI* webui) |
46 : profile_(Profile::FromWebUI(webui)), | 46 : profile_(Profile::FromWebUI(webui)), |
47 sync_service_(ProfileSyncServiceFactory::GetForProfile(profile_)), | 47 sync_service_(ProfileSyncServiceFactory::GetForProfile(profile_)), |
48 sync_service_observer_(this), | 48 sync_service_observer_(this), |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 95 |
96 PrefService* prefs = profile_->GetPrefs(); | 96 PrefService* prefs = profile_->GetPrefs(); |
97 | 97 |
98 int site_data_mask = BrowsingDataRemover::REMOVE_SITE_DATA; | 98 int site_data_mask = BrowsingDataRemover::REMOVE_SITE_DATA; |
99 // Don't try to clear LSO data if it's not supported. | 99 // Don't try to clear LSO data if it's not supported. |
100 if (!prefs->GetBoolean(prefs::kClearPluginLSODataEnabled)) | 100 if (!prefs->GetBoolean(prefs::kClearPluginLSODataEnabled)) |
101 site_data_mask &= ~BrowsingDataRemover::REMOVE_PLUGIN_DATA; | 101 site_data_mask &= ~BrowsingDataRemover::REMOVE_PLUGIN_DATA; |
102 | 102 |
103 int remove_mask = 0; | 103 int remove_mask = 0; |
104 if (prefs->GetBoolean(prefs::kAllowDeletingBrowserHistory)) { | 104 if (prefs->GetBoolean(prefs::kAllowDeletingBrowserHistory)) { |
105 if (prefs->GetBoolean(prefs::kDeleteBrowsingHistory)) | 105 if (prefs->GetBoolean(browsing_data::prefs::kDeleteBrowsingHistory)) |
106 remove_mask |= BrowsingDataRemover::REMOVE_HISTORY; | 106 remove_mask |= BrowsingDataRemover::REMOVE_HISTORY; |
107 if (prefs->GetBoolean(prefs::kDeleteDownloadHistory)) | 107 if (prefs->GetBoolean(browsing_data::prefs::kDeleteDownloadHistory)) |
108 remove_mask |= BrowsingDataRemover::REMOVE_DOWNLOADS; | 108 remove_mask |= BrowsingDataRemover::REMOVE_DOWNLOADS; |
109 } | 109 } |
110 | 110 |
111 if (prefs->GetBoolean(prefs::kDeleteCache)) | 111 if (prefs->GetBoolean(browsing_data::prefs::kDeleteCache)) |
112 remove_mask |= BrowsingDataRemover::REMOVE_CACHE; | 112 remove_mask |= BrowsingDataRemover::REMOVE_CACHE; |
113 | 113 |
114 int origin_mask = 0; | 114 int origin_mask = 0; |
115 if (prefs->GetBoolean(prefs::kDeleteCookies)) { | 115 if (prefs->GetBoolean(browsing_data::prefs::kDeleteCookies)) { |
116 remove_mask |= site_data_mask; | 116 remove_mask |= site_data_mask; |
117 origin_mask |= BrowsingDataHelper::UNPROTECTED_WEB; | 117 origin_mask |= BrowsingDataHelper::UNPROTECTED_WEB; |
118 } | 118 } |
119 | 119 |
120 if (prefs->GetBoolean(prefs::kDeletePasswords)) | 120 if (prefs->GetBoolean(browsing_data::prefs::kDeletePasswords)) |
121 remove_mask |= BrowsingDataRemover::REMOVE_PASSWORDS; | 121 remove_mask |= BrowsingDataRemover::REMOVE_PASSWORDS; |
122 | 122 |
123 if (prefs->GetBoolean(prefs::kDeleteFormData)) | 123 if (prefs->GetBoolean(browsing_data::prefs::kDeleteFormData)) |
124 remove_mask |= BrowsingDataRemover::REMOVE_FORM_DATA; | 124 remove_mask |= BrowsingDataRemover::REMOVE_FORM_DATA; |
125 | 125 |
126 if (prefs->GetBoolean(prefs::kDeleteMediaLicenses)) | 126 if (prefs->GetBoolean(browsing_data::prefs::kDeleteMediaLicenses)) |
127 remove_mask |= BrowsingDataRemover::REMOVE_MEDIA_LICENSES; | 127 remove_mask |= BrowsingDataRemover::REMOVE_MEDIA_LICENSES; |
128 | 128 |
129 if (prefs->GetBoolean(prefs::kDeleteHostedAppsData)) { | 129 if (prefs->GetBoolean(browsing_data::prefs::kDeleteHostedAppsData)) { |
130 remove_mask |= site_data_mask; | 130 remove_mask |= site_data_mask; |
131 origin_mask |= BrowsingDataHelper::PROTECTED_WEB; | 131 origin_mask |= BrowsingDataHelper::PROTECTED_WEB; |
132 } | 132 } |
133 | 133 |
134 // Record the deletion of cookies and cache. | 134 // Record the deletion of cookies and cache. |
135 BrowsingDataRemover::CookieOrCacheDeletionChoice choice = | 135 BrowsingDataRemover::CookieOrCacheDeletionChoice choice = |
136 BrowsingDataRemover::NEITHER_COOKIES_NOR_CACHE; | 136 BrowsingDataRemover::NEITHER_COOKIES_NOR_CACHE; |
137 if (prefs->GetBoolean(prefs::kDeleteCookies)) { | 137 if (prefs->GetBoolean(browsing_data::prefs::kDeleteCookies)) { |
138 choice = prefs->GetBoolean(prefs::kDeleteCache) | 138 choice = prefs->GetBoolean(browsing_data::prefs::kDeleteCache) |
139 ? BrowsingDataRemover::BOTH_COOKIES_AND_CACHE | 139 ? BrowsingDataRemover::BOTH_COOKIES_AND_CACHE |
140 : BrowsingDataRemover::ONLY_COOKIES; | 140 : BrowsingDataRemover::ONLY_COOKIES; |
141 } else if (prefs->GetBoolean(prefs::kDeleteCache)) { | 141 } else if (prefs->GetBoolean(browsing_data::prefs::kDeleteCache)) { |
142 choice = BrowsingDataRemover::ONLY_CACHE; | 142 choice = BrowsingDataRemover::ONLY_CACHE; |
143 } | 143 } |
144 | 144 |
145 UMA_HISTOGRAM_ENUMERATION( | 145 UMA_HISTOGRAM_ENUMERATION( |
146 "History.ClearBrowsingData.UserDeletedCookieOrCacheFromDialog", choice, | 146 "History.ClearBrowsingData.UserDeletedCookieOrCacheFromDialog", choice, |
147 BrowsingDataRemover::MAX_CHOICE_VALUE); | 147 BrowsingDataRemover::MAX_CHOICE_VALUE); |
148 | 148 |
149 // Record the circumstances under which passwords are deleted. | 149 // Record the circumstances under which passwords are deleted. |
150 if (prefs->GetBoolean(prefs::kDeletePasswords)) { | 150 if (prefs->GetBoolean(browsing_data::prefs::kDeletePasswords)) { |
151 static const char* other_types[] = { | 151 static const char* other_types[] = { |
152 prefs::kDeleteBrowsingHistory, | 152 browsing_data::prefs::kDeleteBrowsingHistory, |
153 prefs::kDeleteDownloadHistory, | 153 browsing_data::prefs::kDeleteDownloadHistory, |
154 prefs::kDeleteCache, | 154 browsing_data::prefs::kDeleteCache, |
155 prefs::kDeleteCookies, | 155 browsing_data::prefs::kDeleteCookies, |
156 prefs::kDeleteFormData, | 156 browsing_data::prefs::kDeleteFormData, |
157 prefs::kDeleteHostedAppsData, | 157 browsing_data::prefs::kDeleteHostedAppsData, |
158 prefs::kDeleteMediaLicenses, | 158 browsing_data::prefs::kDeleteMediaLicenses, |
159 }; | 159 }; |
160 static size_t num_other_types = arraysize(other_types); | 160 static size_t num_other_types = arraysize(other_types); |
161 int checked_other_types = std::count_if( | 161 int checked_other_types = std::count_if( |
162 other_types, other_types + num_other_types, | 162 other_types, other_types + num_other_types, |
163 [prefs](const std::string& pref) { return prefs->GetBoolean(pref); }); | 163 [prefs](const std::string& pref) { return prefs->GetBoolean(pref); }); |
164 UMA_HISTOGRAM_SPARSE_SLOWLY( | 164 UMA_HISTOGRAM_SPARSE_SLOWLY( |
165 "History.ClearBrowsingData.PasswordsDeletion.AdditionalDatatypesCount", | 165 "History.ClearBrowsingData.PasswordsDeletion.AdditionalDatatypesCount", |
166 checked_other_types); | 166 checked_other_types); |
167 } | 167 } |
168 | 168 |
(...skipping 15 matching lines...) Expand all Loading... |
184 prefs->GetInteger(prefs::kClearBrowsingDataHistoryNoticeShownTimes); | 184 prefs->GetInteger(prefs::kClearBrowsingDataHistoryNoticeShownTimes); |
185 | 185 |
186 // When the deletion is complete, we might show an additional dialog with | 186 // When the deletion is complete, we might show an additional dialog with |
187 // a notice about other forms of browsing history. This is the case if | 187 // a notice about other forms of browsing history. This is the case if |
188 const bool show_notice = | 188 const bool show_notice = |
189 // 1. The dialog is relevant for the user. | 189 // 1. The dialog is relevant for the user. |
190 show_history_deletion_dialog_ && | 190 show_history_deletion_dialog_ && |
191 // 2. The notice has been shown less than |kMaxTimesHistoryNoticeShown|. | 191 // 2. The notice has been shown less than |kMaxTimesHistoryNoticeShown|. |
192 notice_shown_times < kMaxTimesHistoryNoticeShown && | 192 notice_shown_times < kMaxTimesHistoryNoticeShown && |
193 // 3. The selected data types contained browsing history. | 193 // 3. The selected data types contained browsing history. |
194 prefs->GetBoolean(prefs::kDeleteBrowsingHistory); | 194 prefs->GetBoolean(browsing_data::prefs::kDeleteBrowsingHistory); |
195 | 195 |
196 if (show_notice) { | 196 if (show_notice) { |
197 // Increment the preference. | 197 // Increment the preference. |
198 prefs->SetInteger(prefs::kClearBrowsingDataHistoryNoticeShownTimes, | 198 prefs->SetInteger(prefs::kClearBrowsingDataHistoryNoticeShownTimes, |
199 notice_shown_times + 1); | 199 notice_shown_times + 1); |
200 } | 200 } |
201 | 201 |
202 UMA_HISTOGRAM_BOOLEAN( | 202 UMA_HISTOGRAM_BOOLEAN( |
203 "History.ClearBrowsingData.ShownHistoryNoticeAfterClearing", show_notice); | 203 "History.ClearBrowsingData.ShownHistoryNoticeAfterClearing", show_notice); |
204 | 204 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 void ClearBrowsingDataHandler::UpdateCounterText( | 286 void ClearBrowsingDataHandler::UpdateCounterText( |
287 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { | 287 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { |
288 CallJavascriptFunction( | 288 CallJavascriptFunction( |
289 "cr.webUIListenerCallback", | 289 "cr.webUIListenerCallback", |
290 base::StringValue("update-counter-text"), | 290 base::StringValue("update-counter-text"), |
291 base::StringValue(result->source()->GetPrefName()), | 291 base::StringValue(result->source()->GetPrefName()), |
292 base::StringValue(GetCounterTextFromResult(result.get()))); | 292 base::StringValue(GetCounterTextFromResult(result.get()))); |
293 } | 293 } |
294 | 294 |
295 } // namespace settings | 295 } // namespace settings |
OLD | NEW |