OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browsing_data/browsing_data_remover_impl.h" | 5 #include "chrome/browser/browsing_data/browsing_data_remover_impl.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 callback.Run(); | 53 callback.Run(); |
54 } | 54 } |
55 | 55 |
56 // Another convenience method to turn a callback without arguments into one that | 56 // Another convenience method to turn a callback without arguments into one that |
57 // accepts (and ignores) a single argument. | 57 // accepts (and ignores) a single argument. |
58 template <typename T> | 58 template <typename T> |
59 base::Callback<void(T)> IgnoreArgument(const base::Closure& callback) { | 59 base::Callback<void(T)> IgnoreArgument(const base::Closure& callback) { |
60 return base::Bind(&IgnoreArgumentHelper<T>, callback); | 60 return base::Bind(&IgnoreArgumentHelper<T>, callback); |
61 } | 61 } |
62 | 62 |
63 bool DoesOriginMatchMaskAndUrls( | |
64 const base::WeakPtr<BrowsingDataRemoverImpl>& remover_weak_ptr, | |
65 int origin_type_mask, | |
66 const base::Callback<bool(const GURL&)>& predicate, | |
67 const GURL& origin, | |
68 storage::SpecialStoragePolicy* special_storage_policy) { | |
69 // If BrowsingDataRemoverImpl is null, it is not possible to determine which | |
70 // origins should have their data deleted, and so we do not delete | |
71 // anything. This is not a problem, because this can only happen shortly | |
72 // before shutdown and thus the deletion would likely not be able to | |
73 // finish anyway. | |
74 if (!remover_weak_ptr) | |
75 return false; | |
76 | |
77 return predicate.Run(origin) && | |
78 remover_weak_ptr->DoesOriginMatchMask(origin_type_mask, origin, | |
79 special_storage_policy); | |
80 } | |
81 | |
82 void ClearHttpAuthCacheOnIOThread( | 63 void ClearHttpAuthCacheOnIOThread( |
83 scoped_refptr<net::URLRequestContextGetter> context_getter, | 64 scoped_refptr<net::URLRequestContextGetter> context_getter, |
84 base::Time delete_begin) { | 65 base::Time delete_begin) { |
85 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 66 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
86 | 67 |
87 net::HttpNetworkSession* http_session = context_getter->GetURLRequestContext() | 68 net::HttpNetworkSession* http_session = context_getter->GetURLRequestContext() |
88 ->http_transaction_factory() | 69 ->http_transaction_factory() |
89 ->GetSession(); | 70 ->GetSession(); |
90 DCHECK(http_session); | 71 DCHECK(http_session); |
91 http_session->http_auth_cache()->ClearEntriesAddedWithin(base::Time::Now() - | 72 http_session->http_auth_cache()->ClearEntriesAddedWithin(base::Time::Now() - |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 weak_ptr_factory_.GetWeakPtr()); | 128 weak_ptr_factory_.GetWeakPtr()); |
148 } | 129 } |
149 | 130 |
150 void BrowsingDataRemoverImpl::SubTask::CompletionCallback() { | 131 void BrowsingDataRemoverImpl::SubTask::CompletionCallback() { |
151 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 132 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
152 DCHECK(is_pending_); | 133 DCHECK(is_pending_); |
153 is_pending_ = false; | 134 is_pending_ = false; |
154 forward_callback_.Run(); | 135 forward_callback_.Run(); |
155 } | 136 } |
156 | 137 |
| 138 BrowsingDataRemoverImpl::OriginMaskAndURLMatcher::OriginMaskAndURLMatcher() {} |
| 139 BrowsingDataRemoverImpl::OriginMaskAndURLMatcher::~OriginMaskAndURLMatcher() {} |
| 140 |
| 141 bool BrowsingDataRemoverImpl::OriginMaskAndURLMatcher:: |
| 142 DoesOriginMatchMaskAndURLs( |
| 143 int origin_type_mask, |
| 144 const base::Callback<bool(const GURL&)>& predicate, |
| 145 const GURL& origin, |
| 146 storage::SpecialStoragePolicy* policy) const { |
| 147 if (!predicate.is_null() && !predicate.Run(origin)) |
| 148 return false; |
| 149 |
| 150 const std::vector<std::string>& schemes = url::GetWebStorageSchemes(); |
| 151 bool is_web_scheme = |
| 152 (std::find(schemes.begin(), schemes.end(), origin.GetOrigin().scheme()) != |
| 153 schemes.end()); |
| 154 |
| 155 // If a websafe origin is unprotected, it matches iff UNPROTECTED_WEB. |
| 156 if ((!policy || !policy->IsStorageProtected(origin.GetOrigin())) && |
| 157 is_web_scheme && (origin_type_mask & ORIGIN_TYPE_UNPROTECTED_WEB)) { |
| 158 return true; |
| 159 } |
| 160 origin_type_mask &= ~ORIGIN_TYPE_UNPROTECTED_WEB; |
| 161 |
| 162 // Hosted applications (protected and websafe origins) iff PROTECTED_WEB. |
| 163 if (policy && policy->IsStorageProtected(origin.GetOrigin()) && |
| 164 is_web_scheme && (origin_type_mask & ORIGIN_TYPE_PROTECTED_WEB)) { |
| 165 return true; |
| 166 } |
| 167 origin_type_mask &= ~ORIGIN_TYPE_PROTECTED_WEB; |
| 168 |
| 169 DCHECK(embedder_matcher_ || !origin_type_mask) |
| 170 << "The mask contains embedder-defined origin types, but there is no " |
| 171 << "embedder delegate matcher to process them."; |
| 172 |
| 173 if (embedder_matcher_) |
| 174 return embedder_matcher_.Run(origin_type_mask, origin, policy); |
| 175 |
| 176 return false; |
| 177 } |
| 178 |
157 BrowsingDataRemoverImpl::BrowsingDataRemoverImpl( | 179 BrowsingDataRemoverImpl::BrowsingDataRemoverImpl( |
158 content::BrowserContext* browser_context) | 180 content::BrowserContext* browser_context) |
159 : browser_context_(browser_context), | 181 : browser_context_(browser_context), |
160 remove_mask_(-1), | 182 remove_mask_(-1), |
161 origin_type_mask_(-1), | 183 origin_type_mask_(-1), |
162 is_removing_(false), | 184 is_removing_(false), |
163 sub_task_forward_callback_( | 185 sub_task_forward_callback_( |
164 base::Bind(&BrowsingDataRemoverImpl::NotifyIfDone, | 186 base::Bind(&BrowsingDataRemoverImpl::NotifyIfDone, |
165 base::Unretained(this))), | 187 base::Unretained(this))), |
166 synchronous_clear_operations_(sub_task_forward_callback_), | 188 synchronous_clear_operations_(sub_task_forward_callback_), |
167 clear_embedder_data_(sub_task_forward_callback_), | 189 clear_embedder_data_(sub_task_forward_callback_), |
168 clear_cache_(sub_task_forward_callback_), | 190 clear_cache_(sub_task_forward_callback_), |
169 clear_channel_ids_(sub_task_forward_callback_), | 191 clear_channel_ids_(sub_task_forward_callback_), |
170 clear_http_auth_cache_(sub_task_forward_callback_), | 192 clear_http_auth_cache_(sub_task_forward_callback_), |
171 clear_storage_partition_data_(sub_task_forward_callback_), | 193 clear_storage_partition_data_(sub_task_forward_callback_), |
| 194 origin_mask_and_url_matcher_(new OriginMaskAndURLMatcher()), |
172 weak_ptr_factory_(this) { | 195 weak_ptr_factory_(this) { |
173 DCHECK(browser_context_); | 196 DCHECK(browser_context_); |
174 } | 197 } |
175 | 198 |
176 BrowsingDataRemoverImpl::~BrowsingDataRemoverImpl() { | 199 BrowsingDataRemoverImpl::~BrowsingDataRemoverImpl() { |
177 if (!task_queue_.empty()) { | 200 if (!task_queue_.empty()) { |
178 VLOG(1) << "BrowsingDataRemoverImpl shuts down with " << task_queue_.size() | 201 VLOG(1) << "BrowsingDataRemoverImpl shuts down with " << task_queue_.size() |
179 << " pending tasks"; | 202 << " pending tasks"; |
180 } | 203 } |
181 | 204 |
(...skipping 13 matching lines...) Expand all Loading... |
195 } | 218 } |
196 | 219 |
197 void BrowsingDataRemoverImpl::SetRemoving(bool is_removing) { | 220 void BrowsingDataRemoverImpl::SetRemoving(bool is_removing) { |
198 DCHECK_NE(is_removing_, is_removing); | 221 DCHECK_NE(is_removing_, is_removing); |
199 is_removing_ = is_removing; | 222 is_removing_ = is_removing; |
200 } | 223 } |
201 | 224 |
202 void BrowsingDataRemoverImpl::SetEmbedderDelegate( | 225 void BrowsingDataRemoverImpl::SetEmbedderDelegate( |
203 std::unique_ptr<BrowsingDataRemoverDelegate> embedder_delegate) { | 226 std::unique_ptr<BrowsingDataRemoverDelegate> embedder_delegate) { |
204 embedder_delegate_ = std::move(embedder_delegate); | 227 embedder_delegate_ = std::move(embedder_delegate); |
| 228 |
| 229 if (embedder_delegate_) { |
| 230 origin_mask_and_url_matcher_->set_embedder_matcher( |
| 231 embedder_delegate_->GetMaskMatcherFunction()); |
| 232 } |
205 } | 233 } |
206 | 234 |
207 BrowsingDataRemoverDelegate* | 235 BrowsingDataRemoverDelegate* |
208 BrowsingDataRemoverImpl::GetEmbedderDelegate() const { | 236 BrowsingDataRemoverImpl::GetEmbedderDelegate() const { |
209 return embedder_delegate_.get(); | 237 return embedder_delegate_.get(); |
210 } | 238 } |
211 | 239 |
212 bool BrowsingDataRemoverImpl::DoesOriginMatchMask( | 240 bool BrowsingDataRemoverImpl::DoesOriginMatchMask( |
213 int origin_type_mask, | 241 int origin_type_mask, |
214 const GURL& origin, | 242 const GURL& origin, |
215 storage::SpecialStoragePolicy* policy) const { | 243 storage::SpecialStoragePolicy* policy) const { |
216 const std::vector<std::string>& schemes = url::GetWebStorageSchemes(); | 244 return origin_mask_and_url_matcher_->DoesOriginMatchMaskAndURLs( |
217 bool is_web_scheme = | 245 origin_type_mask, base::Callback<bool(const GURL&)>(), origin, policy); |
218 (std::find(schemes.begin(), schemes.end(), origin.GetOrigin().scheme()) != | |
219 schemes.end()); | |
220 | |
221 // If a websafe origin is unprotected, it matches iff UNPROTECTED_WEB. | |
222 if ((!policy || !policy->IsStorageProtected(origin.GetOrigin())) && | |
223 is_web_scheme && (origin_type_mask & ORIGIN_TYPE_UNPROTECTED_WEB)) { | |
224 return true; | |
225 } | |
226 origin_type_mask &= ~ORIGIN_TYPE_UNPROTECTED_WEB; | |
227 | |
228 // Hosted applications (protected and websafe origins) iff PROTECTED_WEB. | |
229 if (policy && policy->IsStorageProtected(origin.GetOrigin()) && | |
230 is_web_scheme && (origin_type_mask & ORIGIN_TYPE_PROTECTED_WEB)) { | |
231 return true; | |
232 } | |
233 origin_type_mask &= ~ORIGIN_TYPE_PROTECTED_WEB; | |
234 | |
235 DCHECK(embedder_delegate_ || !origin_type_mask) | |
236 << "The mask contains embedder-defined origin types, but there is no " | |
237 << "embedder delegate to process them."; | |
238 | |
239 if (embedder_delegate_) { | |
240 return embedder_delegate_->DoesOriginMatchEmbedderMask(origin_type_mask, | |
241 origin, policy); | |
242 } | |
243 | |
244 return false; | |
245 } | 246 } |
246 | 247 |
247 void BrowsingDataRemoverImpl::Remove(const base::Time& delete_begin, | 248 void BrowsingDataRemoverImpl::Remove(const base::Time& delete_begin, |
248 const base::Time& delete_end, | 249 const base::Time& delete_end, |
249 int remove_mask, | 250 int remove_mask, |
250 int origin_type_mask) { | 251 int origin_type_mask) { |
251 RemoveInternal(delete_begin, delete_end, remove_mask, origin_type_mask, | 252 RemoveInternal(delete_begin, delete_end, remove_mask, origin_type_mask, |
252 std::unique_ptr<BrowsingDataFilterBuilder>(), nullptr); | 253 std::unique_ptr<BrowsingDataFilterBuilder>(), nullptr); |
253 } | 254 } |
254 | 255 |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 // partition, create a cookie matcher function. | 497 // partition, create a cookie matcher function. |
497 content::StoragePartition::CookieMatcherFunction cookie_matcher; | 498 content::StoragePartition::CookieMatcherFunction cookie_matcher; |
498 if (!filter_builder.IsEmptyBlacklist() && | 499 if (!filter_builder.IsEmptyBlacklist() && |
499 (storage_partition_remove_mask & | 500 (storage_partition_remove_mask & |
500 content::StoragePartition::REMOVE_DATA_MASK_COOKIES)) { | 501 content::StoragePartition::REMOVE_DATA_MASK_COOKIES)) { |
501 cookie_matcher = filter_builder.BuildCookieFilter(); | 502 cookie_matcher = filter_builder.BuildCookieFilter(); |
502 } | 503 } |
503 | 504 |
504 storage_partition->ClearData( | 505 storage_partition->ClearData( |
505 storage_partition_remove_mask, quota_storage_remove_mask, | 506 storage_partition_remove_mask, quota_storage_remove_mask, |
506 base::Bind(&DoesOriginMatchMaskAndUrls, weak_ptr_factory_.GetWeakPtr(), | 507 base::Bind(&OriginMaskAndURLMatcher::DoesOriginMatchMaskAndURLs, |
507 origin_type_mask_, filter), | 508 origin_mask_and_url_matcher_, origin_type_mask_, filter), |
508 cookie_matcher, delete_begin_, delete_end_, | 509 cookie_matcher, delete_begin_, delete_end_, |
509 clear_storage_partition_data_.GetCompletionCallback()); | 510 clear_storage_partition_data_.GetCompletionCallback()); |
510 } | 511 } |
511 | 512 |
512 ////////////////////////////////////////////////////////////////////////////// | 513 ////////////////////////////////////////////////////////////////////////////// |
513 // CACHE | 514 // CACHE |
514 if (remove_mask & DATA_TYPE_CACHE) { | 515 if (remove_mask & DATA_TYPE_CACHE) { |
515 base::RecordAction(UserMetricsAction("ClearBrowsingData_Cache")); | 516 base::RecordAction(UserMetricsAction("ClearBrowsingData_Cache")); |
516 | 517 |
517 // TODO(msramek): Clear the cache of all renderers. | 518 // TODO(msramek): Clear the cache of all renderers. |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 | 662 |
662 if (completion_inhibitor_) { | 663 if (completion_inhibitor_) { |
663 completion_inhibitor_->OnBrowsingDataRemoverWouldComplete( | 664 completion_inhibitor_->OnBrowsingDataRemoverWouldComplete( |
664 this, base::Bind(&BrowsingDataRemoverImpl::Notify, | 665 this, base::Bind(&BrowsingDataRemoverImpl::Notify, |
665 weak_ptr_factory_.GetWeakPtr())); | 666 weak_ptr_factory_.GetWeakPtr())); |
666 return; | 667 return; |
667 } | 668 } |
668 | 669 |
669 Notify(); | 670 Notify(); |
670 } | 671 } |
OLD | NEW |