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" |
11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
12 #include "base/metrics/sparse_histogram.h" | 12 #include "base/metrics/sparse_histogram.h" |
13 #include "chrome/browser/browsing_data/browsing_data_counter_factory.h" | 13 #include "chrome/browser/browsing_data/browsing_data_counter_factory.h" |
14 #include "chrome/browser/browsing_data/browsing_data_counter_utils.h" | 14 #include "chrome/browser/browsing_data/browsing_data_counter_utils.h" |
15 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 15 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
16 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" | |
17 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h" | 16 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h" |
18 #include "chrome/browser/history/web_history_service_factory.h" | 17 #include "chrome/browser/history/web_history_service_factory.h" |
19 #include "chrome/browser/sync/profile_sync_service_factory.h" | 18 #include "chrome/browser/sync/profile_sync_service_factory.h" |
20 #include "chrome/common/channel_info.h" | 19 #include "chrome/common/channel_info.h" |
21 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
22 #include "components/browsing_data/core/history_notice_utils.h" | 21 #include "components/browsing_data/core/history_notice_utils.h" |
23 #include "components/browsing_data/core/pref_names.h" | 22 #include "components/browsing_data/core/pref_names.h" |
24 #include "components/prefs/pref_service.h" | 23 #include "components/prefs/pref_service.h" |
25 #include "content/public/browser/web_ui.h" | 24 #include "content/public/browser/web_ui.h" |
26 | 25 |
(...skipping 12 matching lines...) Expand all Loading... |
39 browsing_data::prefs::kDeletePasswords, | 38 browsing_data::prefs::kDeletePasswords, |
40 }; | 39 }; |
41 | 40 |
42 } // namespace | 41 } // namespace |
43 | 42 |
44 namespace settings { | 43 namespace settings { |
45 | 44 |
46 // TaskObserver ---------------------------------------------------------------- | 45 // TaskObserver ---------------------------------------------------------------- |
47 | 46 |
48 class ClearBrowsingDataHandler::TaskObserver | 47 class ClearBrowsingDataHandler::TaskObserver |
49 : public BrowsingDataRemover::Observer { | 48 : public content::BrowsingDataRemover::Observer { |
50 public: | 49 public: |
51 TaskObserver(BrowsingDataRemover* remover, const base::Closure& callback); | 50 TaskObserver(content::BrowsingDataRemover* remover, |
| 51 const base::Closure& callback); |
52 ~TaskObserver() override; | 52 ~TaskObserver() override; |
53 | 53 |
54 void OnBrowsingDataRemoverDone() override; | 54 void OnBrowsingDataRemoverDone() override; |
55 | 55 |
56 private: | 56 private: |
57 base::Closure callback_; | 57 base::Closure callback_; |
58 ScopedObserver<BrowsingDataRemover, BrowsingDataRemover::Observer> | 58 ScopedObserver<content::BrowsingDataRemover, |
| 59 content::BrowsingDataRemover::Observer> |
59 remover_observer_; | 60 remover_observer_; |
60 | 61 |
61 DISALLOW_COPY_AND_ASSIGN(TaskObserver); | 62 DISALLOW_COPY_AND_ASSIGN(TaskObserver); |
62 }; | 63 }; |
63 | 64 |
64 ClearBrowsingDataHandler::TaskObserver::TaskObserver( | 65 ClearBrowsingDataHandler::TaskObserver::TaskObserver( |
65 BrowsingDataRemover* remover, const base::Closure& callback) | 66 content::BrowsingDataRemover* remover, |
66 : callback_(callback), | 67 const base::Closure& callback) |
67 remover_observer_(this) { | 68 : callback_(callback), remover_observer_(this) { |
68 remover_observer_.Add(remover); | 69 remover_observer_.Add(remover); |
69 } | 70 } |
70 | 71 |
71 ClearBrowsingDataHandler::TaskObserver::~TaskObserver() {} | 72 ClearBrowsingDataHandler::TaskObserver::~TaskObserver() {} |
72 | 73 |
73 void ClearBrowsingDataHandler::TaskObserver::OnBrowsingDataRemoverDone() { | 74 void ClearBrowsingDataHandler::TaskObserver::OnBrowsingDataRemoverDone() { |
74 remover_observer_.RemoveAll(); | 75 remover_observer_.RemoveAll(); |
75 callback_.Run(); | 76 callback_.Run(); |
76 } | 77 } |
77 | 78 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 int site_data_mask = ChromeBrowsingDataRemoverDelegate::DATA_TYPE_SITE_DATA; | 127 int site_data_mask = ChromeBrowsingDataRemoverDelegate::DATA_TYPE_SITE_DATA; |
127 // Don't try to clear LSO data if it's not supported. | 128 // Don't try to clear LSO data if it's not supported. |
128 if (!prefs->GetBoolean(prefs::kClearPluginLSODataEnabled)) | 129 if (!prefs->GetBoolean(prefs::kClearPluginLSODataEnabled)) |
129 site_data_mask &= ~ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PLUGIN_DATA; | 130 site_data_mask &= ~ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PLUGIN_DATA; |
130 | 131 |
131 int remove_mask = 0; | 132 int remove_mask = 0; |
132 if (prefs->GetBoolean(prefs::kAllowDeletingBrowserHistory)) { | 133 if (prefs->GetBoolean(prefs::kAllowDeletingBrowserHistory)) { |
133 if (prefs->GetBoolean(browsing_data::prefs::kDeleteBrowsingHistory)) | 134 if (prefs->GetBoolean(browsing_data::prefs::kDeleteBrowsingHistory)) |
134 remove_mask |= ChromeBrowsingDataRemoverDelegate::DATA_TYPE_HISTORY; | 135 remove_mask |= ChromeBrowsingDataRemoverDelegate::DATA_TYPE_HISTORY; |
135 if (prefs->GetBoolean(browsing_data::prefs::kDeleteDownloadHistory)) | 136 if (prefs->GetBoolean(browsing_data::prefs::kDeleteDownloadHistory)) |
136 remove_mask |= BrowsingDataRemover::DATA_TYPE_DOWNLOADS; | 137 remove_mask |= content::BrowsingDataRemover::DATA_TYPE_DOWNLOADS; |
137 } | 138 } |
138 | 139 |
139 if (prefs->GetBoolean(browsing_data::prefs::kDeleteCache)) | 140 if (prefs->GetBoolean(browsing_data::prefs::kDeleteCache)) |
140 remove_mask |= BrowsingDataRemover::DATA_TYPE_CACHE; | 141 remove_mask |= content::BrowsingDataRemover::DATA_TYPE_CACHE; |
141 | 142 |
142 int origin_mask = 0; | 143 int origin_mask = 0; |
143 if (prefs->GetBoolean(browsing_data::prefs::kDeleteCookies)) { | 144 if (prefs->GetBoolean(browsing_data::prefs::kDeleteCookies)) { |
144 remove_mask |= site_data_mask; | 145 remove_mask |= site_data_mask; |
145 origin_mask |= BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB; | 146 origin_mask |= content::BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB; |
146 } | 147 } |
147 | 148 |
148 if (prefs->GetBoolean(browsing_data::prefs::kDeletePasswords)) | 149 if (prefs->GetBoolean(browsing_data::prefs::kDeletePasswords)) |
149 remove_mask |= ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PASSWORDS; | 150 remove_mask |= ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PASSWORDS; |
150 | 151 |
151 if (prefs->GetBoolean(browsing_data::prefs::kDeleteFormData)) | 152 if (prefs->GetBoolean(browsing_data::prefs::kDeleteFormData)) |
152 remove_mask |= ChromeBrowsingDataRemoverDelegate::DATA_TYPE_FORM_DATA; | 153 remove_mask |= ChromeBrowsingDataRemoverDelegate::DATA_TYPE_FORM_DATA; |
153 | 154 |
154 if (prefs->GetBoolean(browsing_data::prefs::kDeleteMediaLicenses)) | 155 if (prefs->GetBoolean(browsing_data::prefs::kDeleteMediaLicenses)) |
155 remove_mask |= BrowsingDataRemover::DATA_TYPE_MEDIA_LICENSES; | 156 remove_mask |= content::BrowsingDataRemover::DATA_TYPE_MEDIA_LICENSES; |
156 | 157 |
157 if (prefs->GetBoolean(browsing_data::prefs::kDeleteHostedAppsData)) { | 158 if (prefs->GetBoolean(browsing_data::prefs::kDeleteHostedAppsData)) { |
158 remove_mask |= site_data_mask; | 159 remove_mask |= site_data_mask; |
159 origin_mask |= BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB; | 160 origin_mask |= content::BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB; |
160 } | 161 } |
161 | 162 |
162 // Record the deletion of cookies and cache. | 163 // Record the deletion of cookies and cache. |
163 BrowsingDataRemover::CookieOrCacheDeletionChoice choice = | 164 content::BrowsingDataRemover::CookieOrCacheDeletionChoice choice = |
164 BrowsingDataRemover::NEITHER_COOKIES_NOR_CACHE; | 165 content::BrowsingDataRemover::NEITHER_COOKIES_NOR_CACHE; |
165 if (prefs->GetBoolean(browsing_data::prefs::kDeleteCookies)) { | 166 if (prefs->GetBoolean(browsing_data::prefs::kDeleteCookies)) { |
166 choice = prefs->GetBoolean(browsing_data::prefs::kDeleteCache) | 167 choice = prefs->GetBoolean(browsing_data::prefs::kDeleteCache) |
167 ? BrowsingDataRemover::BOTH_COOKIES_AND_CACHE | 168 ? content::BrowsingDataRemover::BOTH_COOKIES_AND_CACHE |
168 : BrowsingDataRemover::ONLY_COOKIES; | 169 : content::BrowsingDataRemover::ONLY_COOKIES; |
169 } else if (prefs->GetBoolean(browsing_data::prefs::kDeleteCache)) { | 170 } else if (prefs->GetBoolean(browsing_data::prefs::kDeleteCache)) { |
170 choice = BrowsingDataRemover::ONLY_CACHE; | 171 choice = content::BrowsingDataRemover::ONLY_CACHE; |
171 } | 172 } |
172 | 173 |
173 UMA_HISTOGRAM_ENUMERATION( | 174 UMA_HISTOGRAM_ENUMERATION( |
174 "History.ClearBrowsingData.UserDeletedCookieOrCacheFromDialog", choice, | 175 "History.ClearBrowsingData.UserDeletedCookieOrCacheFromDialog", choice, |
175 BrowsingDataRemover::MAX_CHOICE_VALUE); | 176 content::BrowsingDataRemover::MAX_CHOICE_VALUE); |
176 | 177 |
177 // Record the circumstances under which passwords are deleted. | 178 // Record the circumstances under which passwords are deleted. |
178 if (prefs->GetBoolean(browsing_data::prefs::kDeletePasswords)) { | 179 if (prefs->GetBoolean(browsing_data::prefs::kDeletePasswords)) { |
179 static const char* other_types[] = { | 180 static const char* other_types[] = { |
180 browsing_data::prefs::kDeleteBrowsingHistory, | 181 browsing_data::prefs::kDeleteBrowsingHistory, |
181 browsing_data::prefs::kDeleteDownloadHistory, | 182 browsing_data::prefs::kDeleteDownloadHistory, |
182 browsing_data::prefs::kDeleteCache, | 183 browsing_data::prefs::kDeleteCache, |
183 browsing_data::prefs::kDeleteCookies, | 184 browsing_data::prefs::kDeleteCookies, |
184 browsing_data::prefs::kDeleteFormData, | 185 browsing_data::prefs::kDeleteFormData, |
185 browsing_data::prefs::kDeleteHostedAppsData, | 186 browsing_data::prefs::kDeleteHostedAppsData, |
186 browsing_data::prefs::kDeleteMediaLicenses, | 187 browsing_data::prefs::kDeleteMediaLicenses, |
187 }; | 188 }; |
188 static size_t num_other_types = arraysize(other_types); | 189 static size_t num_other_types = arraysize(other_types); |
189 int checked_other_types = std::count_if( | 190 int checked_other_types = std::count_if( |
190 other_types, other_types + num_other_types, | 191 other_types, other_types + num_other_types, |
191 [prefs](const std::string& pref) { return prefs->GetBoolean(pref); }); | 192 [prefs](const std::string& pref) { return prefs->GetBoolean(pref); }); |
192 UMA_HISTOGRAM_SPARSE_SLOWLY( | 193 UMA_HISTOGRAM_SPARSE_SLOWLY( |
193 "History.ClearBrowsingData.PasswordsDeletion.AdditionalDatatypesCount", | 194 "History.ClearBrowsingData.PasswordsDeletion.AdditionalDatatypesCount", |
194 checked_other_types); | 195 checked_other_types); |
195 } | 196 } |
196 | 197 |
197 int period_selected = | 198 int period_selected = |
198 prefs->GetInteger(browsing_data::prefs::kDeleteTimePeriod); | 199 prefs->GetInteger(browsing_data::prefs::kDeleteTimePeriod); |
199 | 200 |
200 std::string webui_callback_id; | 201 std::string webui_callback_id; |
201 CHECK_EQ(1U, args->GetSize()); | 202 CHECK_EQ(1U, args->GetSize()); |
202 CHECK(args->GetString(0, &webui_callback_id)); | 203 CHECK(args->GetString(0, &webui_callback_id)); |
203 | 204 |
204 BrowsingDataRemover* remover = | 205 content::BrowsingDataRemover* remover = |
205 BrowsingDataRemoverFactory::GetForBrowserContext(profile_); | 206 content::BrowserContext::GetBrowsingDataRemover(profile_); |
206 task_observer_ = base::MakeUnique<TaskObserver>( | 207 task_observer_ = base::MakeUnique<TaskObserver>( |
207 remover, | 208 remover, |
208 base::Bind(&ClearBrowsingDataHandler::OnClearingTaskFinished, | 209 base::Bind(&ClearBrowsingDataHandler::OnClearingTaskFinished, |
209 base::Unretained(this), webui_callback_id)); | 210 base::Unretained(this), webui_callback_id)); |
210 browsing_data::TimePeriod time_period = | 211 browsing_data::TimePeriod time_period = |
211 static_cast<browsing_data::TimePeriod>(period_selected); | 212 static_cast<browsing_data::TimePeriod>(period_selected); |
212 browsing_data::RecordDeletionForPeriod(time_period); | 213 browsing_data::RecordDeletionForPeriod(time_period); |
213 remover->RemoveAndReply( | 214 remover->RemoveAndReply( |
214 browsing_data::CalculateBeginDeleteTime(time_period), | 215 browsing_data::CalculateBeginDeleteTime(time_period), |
215 browsing_data::CalculateEndDeleteTime(time_period), | 216 browsing_data::CalculateEndDeleteTime(time_period), |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 | 325 |
325 void ClearBrowsingDataHandler::UpdateCounterText( | 326 void ClearBrowsingDataHandler::UpdateCounterText( |
326 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { | 327 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { |
327 CallJavascriptFunction( | 328 CallJavascriptFunction( |
328 "cr.webUIListenerCallback", base::Value("update-counter-text"), | 329 "cr.webUIListenerCallback", base::Value("update-counter-text"), |
329 base::Value(result->source()->GetPrefName()), | 330 base::Value(result->source()->GetPrefName()), |
330 base::Value(GetChromeCounterTextFromResult(result.get()))); | 331 base::Value(GetChromeCounterTextFromResult(result.get()))); |
331 } | 332 } |
332 | 333 |
333 } // namespace settings | 334 } // namespace settings |
OLD | NEW |