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 24 matching lines...) Expand all Loading... | |
35 | 35 |
36 } | 36 } |
37 | 37 |
38 namespace settings { | 38 namespace settings { |
39 | 39 |
40 ClearBrowsingDataHandler::ClearBrowsingDataHandler(content::WebUI* webui) | 40 ClearBrowsingDataHandler::ClearBrowsingDataHandler(content::WebUI* webui) |
41 : profile_(Profile::FromWebUI(webui)), | 41 : profile_(Profile::FromWebUI(webui)), |
42 sync_service_(ProfileSyncServiceFactory::GetForProfile(profile_)), | 42 sync_service_(ProfileSyncServiceFactory::GetForProfile(profile_)), |
43 sync_service_observer_(this), | 43 sync_service_observer_(this), |
44 remover_(nullptr), | 44 remover_(nullptr), |
45 remover_observer_(this), | |
45 show_history_footer_(false), | 46 show_history_footer_(false), |
46 show_history_deletion_dialog_(false), | 47 show_history_deletion_dialog_(false), |
47 weak_ptr_factory_(this) {} | 48 weak_ptr_factory_(this) {} |
48 | 49 |
49 ClearBrowsingDataHandler::~ClearBrowsingDataHandler() { | 50 ClearBrowsingDataHandler::~ClearBrowsingDataHandler() { |
50 if (remover_) | |
51 remover_->RemoveObserver(this); | |
52 } | 51 } |
53 | 52 |
54 void ClearBrowsingDataHandler::RegisterMessages() { | 53 void ClearBrowsingDataHandler::RegisterMessages() { |
55 web_ui()->RegisterMessageCallback( | 54 web_ui()->RegisterMessageCallback( |
56 "clearBrowsingData", | 55 "clearBrowsingData", |
57 base::Bind(&ClearBrowsingDataHandler::HandleClearBrowsingData, | 56 base::Bind(&ClearBrowsingDataHandler::HandleClearBrowsingData, |
58 base::Unretained(this))); | 57 base::Unretained(this))); |
59 | 58 |
60 web_ui()->RegisterMessageCallback( | 59 web_ui()->RegisterMessageCallback( |
61 "initializeClearBrowsingData", | 60 "initializeClearBrowsingData", |
62 base::Bind(&ClearBrowsingDataHandler::HandleInitialize, | 61 base::Bind(&ClearBrowsingDataHandler::HandleInitialize, |
63 base::Unretained(this))); | 62 base::Unretained(this))); |
64 } | 63 } |
65 | 64 |
66 void ClearBrowsingDataHandler::OnJavascriptAllowed() { | 65 void ClearBrowsingDataHandler::OnJavascriptAllowed() { |
67 PrefService* prefs = profile_->GetPrefs(); | 66 PrefService* prefs = profile_->GetPrefs(); |
68 profile_pref_registrar_.Init(prefs); | 67 profile_pref_registrar_.Init(prefs); |
69 profile_pref_registrar_.Add( | 68 profile_pref_registrar_.Add( |
70 prefs::kAllowDeletingBrowserHistory, | 69 prefs::kAllowDeletingBrowserHistory, |
71 base::Bind(&ClearBrowsingDataHandler::OnBrowsingHistoryPrefChanged, | 70 base::Bind(&ClearBrowsingDataHandler::OnBrowsingHistoryPrefChanged, |
72 base::Unretained(this))); | 71 base::Unretained(this))); |
73 | 72 |
74 if (sync_service_) | 73 if (sync_service_) |
75 sync_service_observer_.Add(sync_service_); | 74 sync_service_observer_.Add(sync_service_); |
75 | |
76 if (!remover_) { | |
Dan Beam
2016/07/08 19:27:44
no curlies
| |
77 remover_ = BrowsingDataRemoverFactory::GetForBrowserContext(profile_); | |
78 } | |
79 | |
80 remover_observer_.Add(remover_); | |
76 } | 81 } |
77 | 82 |
78 void ClearBrowsingDataHandler::OnJavascriptDisallowed() { | 83 void ClearBrowsingDataHandler::OnJavascriptDisallowed() { |
84 remover_observer_.RemoveAll(); | |
79 profile_pref_registrar_.RemoveAll(); | 85 profile_pref_registrar_.RemoveAll(); |
80 sync_service_observer_.RemoveAll(); | 86 sync_service_observer_.RemoveAll(); |
81 } | 87 } |
82 | 88 |
83 void ClearBrowsingDataHandler::HandleClearBrowsingData( | 89 void ClearBrowsingDataHandler::HandleClearBrowsingData( |
84 const base::ListValue* args) { | 90 const base::ListValue* args) { |
85 // We should never be called when the previous clearing has not yet finished. | 91 // We should never be called when the previous clearing has not yet finished. |
86 CHECK(!remover_); | 92 CHECK(!remover_->is_removing()); |
87 CHECK_EQ(1U, args->GetSize()); | 93 CHECK_EQ(1U, args->GetSize()); |
88 CHECK(webui_callback_id_.empty()); | 94 CHECK(webui_callback_id_.empty()); |
89 CHECK(args->GetString(0, &webui_callback_id_)); | 95 CHECK(args->GetString(0, &webui_callback_id_)); |
90 | 96 |
91 PrefService* prefs = profile_->GetPrefs(); | 97 PrefService* prefs = profile_->GetPrefs(); |
92 | 98 |
93 int site_data_mask = BrowsingDataRemover::REMOVE_SITE_DATA; | 99 int site_data_mask = BrowsingDataRemover::REMOVE_SITE_DATA; |
94 // Don't try to clear LSO data if it's not supported. | 100 // Don't try to clear LSO data if it's not supported. |
95 if (!prefs->GetBoolean(prefs::kClearPluginLSODataEnabled)) | 101 if (!prefs->GetBoolean(prefs::kClearPluginLSODataEnabled)) |
96 site_data_mask &= ~BrowsingDataRemover::REMOVE_PLUGIN_DATA; | 102 site_data_mask &= ~BrowsingDataRemover::REMOVE_PLUGIN_DATA; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 int checked_other_types = std::count_if( | 162 int checked_other_types = std::count_if( |
157 other_types, other_types + num_other_types, | 163 other_types, other_types + num_other_types, |
158 [prefs](const std::string& pref) { return prefs->GetBoolean(pref); }); | 164 [prefs](const std::string& pref) { return prefs->GetBoolean(pref); }); |
159 UMA_HISTOGRAM_SPARSE_SLOWLY( | 165 UMA_HISTOGRAM_SPARSE_SLOWLY( |
160 "History.ClearBrowsingData.PasswordsDeletion.AdditionalDatatypesCount", | 166 "History.ClearBrowsingData.PasswordsDeletion.AdditionalDatatypesCount", |
161 checked_other_types); | 167 checked_other_types); |
162 } | 168 } |
163 | 169 |
164 int period_selected = | 170 int period_selected = |
165 prefs->GetInteger(browsing_data::prefs::kDeleteTimePeriod); | 171 prefs->GetInteger(browsing_data::prefs::kDeleteTimePeriod); |
166 remover_ = BrowsingDataRemoverFactory::GetForBrowserContext(profile_); | |
167 remover_->AddObserver(this); | |
168 remover_->Remove(BrowsingDataRemover::Period( | 172 remover_->Remove(BrowsingDataRemover::Period( |
169 static_cast<browsing_data::TimePeriod>(period_selected)), | 173 static_cast<browsing_data::TimePeriod>(period_selected)), |
170 remove_mask, origin_mask); | 174 remove_mask, origin_mask); |
171 } | 175 } |
172 | 176 |
177 void ClearBrowsingDataHandler::OnBrowsingDataRemoving(bool is_removing) { | |
178 CallJavascriptFunction("cr.webUIListenerCallback", | |
179 base::StringValue("browsing-data-removing"), | |
180 base::FundamentalValue(is_removing)); | |
181 } | |
182 | |
173 void ClearBrowsingDataHandler::OnBrowsingDataRemoverDone() { | 183 void ClearBrowsingDataHandler::OnBrowsingDataRemoverDone() { |
174 remover_->RemoveObserver(this); | |
175 remover_ = nullptr; | |
176 | |
177 PrefService* prefs = profile_->GetPrefs(); | 184 PrefService* prefs = profile_->GetPrefs(); |
178 int notice_shown_times = | 185 int notice_shown_times = |
179 prefs->GetInteger(prefs::kClearBrowsingDataHistoryNoticeShownTimes); | 186 prefs->GetInteger(prefs::kClearBrowsingDataHistoryNoticeShownTimes); |
180 | 187 |
181 // When the deletion is complete, we might show an additional dialog with | 188 // When the deletion is complete, we might show an additional dialog with |
182 // a notice about other forms of browsing history. This is the case if | 189 // a notice about other forms of browsing history. This is the case if |
183 const bool show_notice = | 190 const bool show_notice = |
184 // 1. The dialog is relevant for the user. | 191 // 1. The dialog is relevant for the user. |
185 show_history_deletion_dialog_ && | 192 show_history_deletion_dialog_ && |
186 // 2. The notice has been shown less than |kMaxTimesHistoryNoticeShown|. | 193 // 2. The notice has been shown less than |kMaxTimesHistoryNoticeShown|. |
(...skipping 20 matching lines...) Expand all Loading... | |
207 CallJavascriptFunction( | 214 CallJavascriptFunction( |
208 "cr.webUIListenerCallback", | 215 "cr.webUIListenerCallback", |
209 base::StringValue("browsing-history-pref-changed"), | 216 base::StringValue("browsing-history-pref-changed"), |
210 base::FundamentalValue( | 217 base::FundamentalValue( |
211 profile_->GetPrefs()->GetBoolean( | 218 profile_->GetPrefs()->GetBoolean( |
212 prefs::kAllowDeletingBrowserHistory))); | 219 prefs::kAllowDeletingBrowserHistory))); |
213 } | 220 } |
214 | 221 |
215 void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) { | 222 void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) { |
216 AllowJavascript(); | 223 AllowJavascript(); |
224 const base::Value* callback_id; | |
225 CHECK(args->Get(0, &callback_id)); | |
217 | 226 |
218 // TODO(msramek): Simplify this using a factory. | 227 // TODO(msramek): Simplify this using a factory. |
219 AddCounter(base::WrapUnique(new AutofillCounter(profile_))); | 228 AddCounter(base::WrapUnique(new AutofillCounter(profile_))); |
220 AddCounter(base::WrapUnique(new CacheCounter(profile_))); | 229 AddCounter(base::WrapUnique(new CacheCounter(profile_))); |
221 AddCounter(base::WrapUnique(new DownloadsCounter(profile_))); | 230 AddCounter(base::WrapUnique(new DownloadsCounter(profile_))); |
222 AddCounter(base::WrapUnique(new HistoryCounter(profile_))); | 231 AddCounter(base::WrapUnique(new HistoryCounter(profile_))); |
223 AddCounter(base::WrapUnique(new HostedAppsCounter(profile_))); | 232 AddCounter(base::WrapUnique(new HostedAppsCounter(profile_))); |
224 AddCounter(base::WrapUnique(new PasswordsCounter(profile_))); | 233 AddCounter(base::WrapUnique(new PasswordsCounter(profile_))); |
225 AddCounter(base::WrapUnique(new MediaLicensesCounter(profile_))); | 234 AddCounter(base::WrapUnique(new MediaLicensesCounter(profile_))); |
226 | 235 |
227 OnStateChanged(); | 236 OnStateChanged(); |
228 RefreshHistoryNotice(); | 237 RefreshHistoryNotice(); |
238 OnBrowsingDataRemoving(remover_->is_removing()); | |
239 | |
240 ResolveJavascriptCallback(*callback_id, *base::Value::CreateNullValue()); | |
229 } | 241 } |
230 | 242 |
231 void ClearBrowsingDataHandler::OnStateChanged() { | 243 void ClearBrowsingDataHandler::OnStateChanged() { |
232 CallJavascriptFunction( | 244 CallJavascriptFunction( |
233 "cr.webUIListenerCallback", | 245 "cr.webUIListenerCallback", |
234 base::StringValue("update-footer"), | 246 base::StringValue("update-footer"), |
235 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()), | 247 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()), |
236 base::FundamentalValue(show_history_footer_)); | 248 base::FundamentalValue(show_history_footer_)); |
237 } | 249 } |
238 | 250 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
285 void ClearBrowsingDataHandler::UpdateCounterText( | 297 void ClearBrowsingDataHandler::UpdateCounterText( |
286 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { | 298 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { |
287 CallJavascriptFunction( | 299 CallJavascriptFunction( |
288 "cr.webUIListenerCallback", | 300 "cr.webUIListenerCallback", |
289 base::StringValue("update-counter-text"), | 301 base::StringValue("update-counter-text"), |
290 base::StringValue(result->source()->GetPrefName()), | 302 base::StringValue(result->source()->GetPrefName()), |
291 base::StringValue(GetCounterTextFromResult(result.get()))); | 303 base::StringValue(GetCounterTextFromResult(result.get()))); |
292 } | 304 } |
293 | 305 |
294 } // namespace settings | 306 } // namespace settings |
OLD | NEW |