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

Side by Side Diff: ios/chrome/browser/browsing_data/ios_chrome_browsing_data_remover.mm

Issue 1844243002: [CookieStore] Upgrading host-based deleting to predicate-based deleting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removed url-based deletion on ios Created 4 years, 8 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 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 "ios/chrome/browser/browsing_data/ios_chrome_browsing_data_remover.h" 5 #include "ios/chrome/browser/browsing_data/ios_chrome_browsing_data_remover.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
(...skipping 20 matching lines...) Expand all
31 #include "ios/chrome/browser/ios_chrome_io_thread.h" 31 #include "ios/chrome/browser/ios_chrome_io_thread.h"
32 #include "ios/chrome/browser/passwords/ios_chrome_password_store_factory.h" 32 #include "ios/chrome/browser/passwords/ios_chrome_password_store_factory.h"
33 #include "ios/chrome/browser/search_engines/template_url_service_factory.h" 33 #include "ios/chrome/browser/search_engines/template_url_service_factory.h"
34 #include "ios/chrome/browser/sessions/ios_chrome_tab_restore_service_factory.h" 34 #include "ios/chrome/browser/sessions/ios_chrome_tab_restore_service_factory.h"
35 #include "ios/chrome/browser/web_data_service_factory.h" 35 #include "ios/chrome/browser/web_data_service_factory.h"
36 #include "ios/net/http_cache_helper.h" 36 #include "ios/net/http_cache_helper.h"
37 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" 37 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
38 #include "ios/web/public/user_metrics.h" 38 #include "ios/web/public/user_metrics.h"
39 #include "ios/web/public/web_thread.h" 39 #include "ios/web/public/web_thread.h"
40 #include "net/base/net_errors.h" 40 #include "net/base/net_errors.h"
41 #include "net/cookies/canonical_cookie.h"
droger 2016/04/05 19:17:30 This may not be needed.
dmurph 2016/04/05 22:15:54 Done.
41 #include "net/cookies/cookie_store.h" 42 #include "net/cookies/cookie_store.h"
42 #include "net/http/transport_security_state.h" 43 #include "net/http/transport_security_state.h"
43 #include "net/ssl/channel_id_service.h" 44 #include "net/ssl/channel_id_service.h"
44 #include "net/ssl/channel_id_store.h" 45 #include "net/ssl/channel_id_store.h"
45 #include "net/url_request/url_request_context.h" 46 #include "net/url_request/url_request_context.h"
46 #include "net/url_request/url_request_context_getter.h" 47 #include "net/url_request/url_request_context_getter.h"
47 48
48 using base::UserMetricsAction; 49 using base::UserMetricsAction;
49 using web::WebThread; 50 using web::WebThread;
50 51
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 DCHECK(AllDone()); 120 DCHECK(AllDone());
120 } 121 }
121 122
122 // Static. 123 // Static.
123 void IOSChromeBrowsingDataRemover::set_removing(bool is_removing) { 124 void IOSChromeBrowsingDataRemover::set_removing(bool is_removing) {
124 DCHECK(is_removing_ != is_removing); 125 DCHECK(is_removing_ != is_removing);
125 is_removing_ = is_removing; 126 is_removing_ = is_removing;
126 } 127 }
127 128
128 void IOSChromeBrowsingDataRemover::Remove(int remove_mask) { 129 void IOSChromeBrowsingDataRemover::Remove(int remove_mask) {
129 RemoveImpl(remove_mask, GURL()); 130 RemoveImpl(remove_mask);
130 } 131 }
131 132
132 void IOSChromeBrowsingDataRemover::RemoveImpl(int remove_mask, 133 void IOSChromeBrowsingDataRemover::RemoveImpl(int remove_mask) {
133 const GURL& remove_url) {
134 DCHECK_CURRENTLY_ON(WebThread::UI); 134 DCHECK_CURRENTLY_ON(WebThread::UI);
135 set_removing(true); 135 set_removing(true);
136 remove_mask_ = remove_mask; 136 remove_mask_ = remove_mask;
137 137
138 // On other platforms, it is possible to specify different types of origins 138 // On other platforms, it is possible to specify different types of origins
139 // to clear data for (e.g., unprotected web vs. extensions). On iOS, this 139 // to clear data for (e.g., unprotected web vs. extensions). On iOS, this
140 // mask is always implicitly the unprotected web, which is the only type that 140 // mask is always implicitly the unprotected web, which is the only type that
141 // is relevant. This metric is left here for historical consistency. 141 // is relevant. This metric is left here for historical consistency.
142 web::RecordAction( 142 web::RecordAction(
143 UserMetricsAction("ClearBrowsingData_MaskContainsUnprotectedWeb")); 143 UserMetricsAction("ClearBrowsingData_MaskContainsUnprotectedWeb"));
144 144
145 if (remove_mask & REMOVE_HISTORY) { 145 if (remove_mask & REMOVE_HISTORY) {
146 history::HistoryService* history_service = 146 history::HistoryService* history_service =
147 ios::HistoryServiceFactory::GetForBrowserState( 147 ios::HistoryServiceFactory::GetForBrowserState(
148 browser_state_, ServiceAccessType::EXPLICIT_ACCESS); 148 browser_state_, ServiceAccessType::EXPLICIT_ACCESS);
149 if (history_service) { 149 if (history_service) {
150 std::set<GURL> restrict_urls; 150 std::set<GURL> restrict_urls;
151 if (!remove_url.is_empty())
152 restrict_urls.insert(remove_url);
153 web::RecordAction(UserMetricsAction("ClearBrowsingData_History")); 151 web::RecordAction(UserMetricsAction("ClearBrowsingData_History"));
154 waiting_for_clear_history_ = true; 152 waiting_for_clear_history_ = true;
155 153
156 history_service->ExpireLocalAndRemoteHistoryBetween( 154 history_service->ExpireLocalAndRemoteHistoryBetween(
157 ios::WebHistoryServiceFactory::GetForBrowserState(browser_state_), 155 ios::WebHistoryServiceFactory::GetForBrowserState(browser_state_),
158 restrict_urls, delete_begin_, delete_end_, 156 restrict_urls, delete_begin_, delete_end_,
159 base::Bind(&IOSChromeBrowsingDataRemover::OnHistoryDeletionDone, 157 base::Bind(&IOSChromeBrowsingDataRemover::OnHistoryDeletionDone,
160 base::Unretained(this)), 158 base::Unretained(this)),
161 &history_task_tracker_); 159 &history_task_tracker_);
162 } 160 }
(...skipping 21 matching lines...) Expand all
184 TemplateURLService* keywords_model = 182 TemplateURLService* keywords_model =
185 ios::TemplateURLServiceFactory::GetForBrowserState(browser_state_); 183 ios::TemplateURLServiceFactory::GetForBrowserState(browser_state_);
186 if (keywords_model && !keywords_model->loaded()) { 184 if (keywords_model && !keywords_model->loaded()) {
187 template_url_sub_ = keywords_model->RegisterOnLoadedCallback( 185 template_url_sub_ = keywords_model->RegisterOnLoadedCallback(
188 base::Bind(&IOSChromeBrowsingDataRemover::OnKeywordsLoaded, 186 base::Bind(&IOSChromeBrowsingDataRemover::OnKeywordsLoaded,
189 base::Unretained(this))); 187 base::Unretained(this)));
190 keywords_model->Load(); 188 keywords_model->Load();
191 waiting_for_clear_keyword_data_ = true; 189 waiting_for_clear_keyword_data_ = true;
192 } else if (keywords_model) { 190 } else if (keywords_model) {
193 keywords_model->RemoveAutoGeneratedForOriginBetween( 191 keywords_model->RemoveAutoGeneratedForOriginBetween(
194 remove_url, delete_begin_, delete_end_); 192 GURL(), delete_begin_, delete_end_);
195 } 193 }
196 } 194 }
197 195
198 // If the caller is removing history for all hosts, then clear ancillary 196 // If the caller is removing history for all hosts, then clear ancillary
199 // historical information. 197 // historical information.
200 if (remove_url.is_empty()) { 198 // We also delete the list of recently closed tabs. Since these expire,
201 // We also delete the list of recently closed tabs. Since these expire, 199 // they can't be more than a day old, so we can simply clear them all.
202 // they can't be more than a day old, so we can simply clear them all. 200 sessions::TabRestoreService* tab_service =
203 sessions::TabRestoreService* tab_service = 201 IOSChromeTabRestoreServiceFactory::GetForBrowserState(browser_state_);
204 IOSChromeTabRestoreServiceFactory::GetForBrowserState(browser_state_); 202 if (tab_service) {
205 if (tab_service) { 203 tab_service->ClearEntries();
206 tab_service->ClearEntries(); 204 tab_service->DeleteLastSession();
207 tab_service->DeleteLastSession();
208 }
209 } 205 }
210 206
211 // The saved Autofill profiles and credit cards can include the origin from 207 // The saved Autofill profiles and credit cards can include the origin from
212 // which these profiles and credit cards were learned. These are a form of 208 // which these profiles and credit cards were learned. These are a form of
213 // history, so clear them as well. 209 // history, so clear them as well.
214 scoped_refptr<autofill::AutofillWebDataService> web_data_service = 210 scoped_refptr<autofill::AutofillWebDataService> web_data_service =
215 ios::WebDataServiceFactory::GetAutofillWebDataForBrowserState( 211 ios::WebDataServiceFactory::GetAutofillWebDataForBrowserState(
216 browser_state_, ServiceAccessType::EXPLICIT_ACCESS); 212 browser_state_, ServiceAccessType::EXPLICIT_ACCESS);
217 if (web_data_service.get()) { 213 if (web_data_service.get()) {
218 waiting_for_clear_autofill_origin_urls_ = true; 214 waiting_for_clear_autofill_origin_urls_ = true;
(...skipping 23 matching lines...) Expand all
242 // any user action. 238 // any user action.
243 if (delete_begin_ == base::Time()) { 239 if (delete_begin_ == base::Time()) {
244 scoped_refptr<net::URLRequestContextGetter> safe_browsing_context = 240 scoped_refptr<net::URLRequestContextGetter> safe_browsing_context =
245 make_scoped_refptr(ios::GetChromeBrowserProvider() 241 make_scoped_refptr(ios::GetChromeBrowserProvider()
246 ->GetSafeBrowsingURLRequestContext()); 242 ->GetSafeBrowsingURLRequestContext());
247 if (safe_browsing_context) { 243 if (safe_browsing_context) {
248 ++waiting_for_clear_cookies_count_; 244 ++waiting_for_clear_cookies_count_;
249 WebThread::PostTask( 245 WebThread::PostTask(
250 WebThread::IO, FROM_HERE, 246 WebThread::IO, FROM_HERE,
251 base::Bind(&IOSChromeBrowsingDataRemover::ClearCookiesOnIOThread, 247 base::Bind(&IOSChromeBrowsingDataRemover::ClearCookiesOnIOThread,
252 base::Unretained(this), safe_browsing_context, GURL())); 248 base::Unretained(this), safe_browsing_context));
253 } 249 }
254 } 250 }
255 251
256 ++waiting_for_clear_cookies_count_; 252 ++waiting_for_clear_cookies_count_;
257 WebThread::PostTask( 253 WebThread::PostTask(
258 WebThread::IO, FROM_HERE, 254 WebThread::IO, FROM_HERE,
259 base::Bind(&IOSChromeBrowsingDataRemover::ClearCookiesOnIOThread, 255 base::Bind(&IOSChromeBrowsingDataRemover::ClearCookiesOnIOThread,
260 base::Unretained(this), main_context_getter_, remove_url)); 256 base::Unretained(this), main_context_getter_));
261 257
262 // TODO(mkwst): If we're not removing passwords, then clear the 'zero-click' 258 // TODO(mkwst): If we're not removing passwords, then clear the 'zero-click'
263 // flag for all credentials in the password store. 259 // flag for all credentials in the password store.
264 } 260 }
265 261
266 if (remove_mask & REMOVE_CHANNEL_IDS) { 262 if (remove_mask & REMOVE_CHANNEL_IDS) {
267 web::RecordAction(UserMetricsAction("ClearBrowsingData_ChannelIDs")); 263 web::RecordAction(UserMetricsAction("ClearBrowsingData_ChannelIDs"));
268 if (main_context_getter_) { 264 if (main_context_getter_) {
269 waiting_for_clear_channel_ids_ = true; 265 waiting_for_clear_channel_ids_ = true;
270 WebThread::PostTask( 266 WebThread::PostTask(
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 base::Unretained(this), num_deleted)); 460 base::Unretained(this), num_deleted));
465 return; 461 return;
466 } 462 }
467 463
468 DCHECK_GT(waiting_for_clear_cookies_count_, 0); 464 DCHECK_GT(waiting_for_clear_cookies_count_, 0);
469 --waiting_for_clear_cookies_count_; 465 --waiting_for_clear_cookies_count_;
470 NotifyAndDeleteIfDone(); 466 NotifyAndDeleteIfDone();
471 } 467 }
472 468
473 void IOSChromeBrowsingDataRemover::ClearCookiesOnIOThread( 469 void IOSChromeBrowsingDataRemover::ClearCookiesOnIOThread(
474 const scoped_refptr<net::URLRequestContextGetter>& rq_context, 470 const scoped_refptr<net::URLRequestContextGetter>& rq_context) {
475 const GURL& storage_url) {
476 DCHECK_CURRENTLY_ON(WebThread::IO); 471 DCHECK_CURRENTLY_ON(WebThread::IO);
477 net::CookieStore* cookie_store = 472 net::CookieStore* cookie_store =
478 rq_context->GetURLRequestContext()->cookie_store(); 473 rq_context->GetURLRequestContext()->cookie_store();
479 if (storage_url.is_empty()) { 474 cookie_store->DeleteAllCreatedBetweenAsync(
480 cookie_store->DeleteAllCreatedBetweenAsync( 475 delete_begin_, delete_end_,
481 delete_begin_, delete_end_, 476 base::Bind(&IOSChromeBrowsingDataRemover::OnClearedCookies,
482 base::Bind(&IOSChromeBrowsingDataRemover::OnClearedCookies, 477 base::Unretained(this)));
483 base::Unretained(this)));
484 } else {
485 cookie_store->DeleteAllCreatedBetweenForHostAsync(
486 delete_begin_, delete_end_, storage_url,
487 base::Bind(&IOSChromeBrowsingDataRemover::OnClearedCookies,
488 base::Unretained(this)));
489 }
490 } 478 }
491 479
492 void IOSChromeBrowsingDataRemover::ClearChannelIDsOnIOThread( 480 void IOSChromeBrowsingDataRemover::ClearChannelIDsOnIOThread(
493 const scoped_refptr<net::URLRequestContextGetter>& rq_context) { 481 const scoped_refptr<net::URLRequestContextGetter>& rq_context) {
494 DCHECK_CURRENTLY_ON(WebThread::IO); 482 DCHECK_CURRENTLY_ON(WebThread::IO);
495 net::ChannelIDService* channel_id_service = 483 net::ChannelIDService* channel_id_service =
496 rq_context->GetURLRequestContext()->channel_id_service(); 484 rq_context->GetURLRequestContext()->channel_id_service();
497 channel_id_service->GetChannelIDStore()->DeleteAllCreatedBetween( 485 channel_id_service->GetChannelIDStore()->DeleteAllCreatedBetween(
498 delete_begin_, delete_end_, 486 delete_begin_, delete_end_,
499 base::Bind(&IOSChromeBrowsingDataRemover::OnClearedChannelIDsOnIOThread, 487 base::Bind(&IOSChromeBrowsingDataRemover::OnClearedChannelIDsOnIOThread,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 waiting_for_clear_autofill_origin_urls_ = false; 520 waiting_for_clear_autofill_origin_urls_ = false;
533 NotifyAndDeleteIfDone(); 521 NotifyAndDeleteIfDone();
534 } 522 }
535 523
536 // static 524 // static
537 IOSChromeBrowsingDataRemover::CallbackSubscription 525 IOSChromeBrowsingDataRemover::CallbackSubscription
538 IOSChromeBrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback( 526 IOSChromeBrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback(
539 const IOSChromeBrowsingDataRemover::Callback& callback) { 527 const IOSChromeBrowsingDataRemover::Callback& callback) {
540 return GetOnBrowsingDataRemovedCallbacks()->Add(callback); 528 return GetOnBrowsingDataRemovedCallbacks()->Add(callback);
541 } 529 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698