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 "content/browser/storage_partition_impl.h" | 5 #include "content/browser/storage_partition_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
| 12 #include "base/bind.h" |
12 #include "base/location.h" | 13 #include "base/location.h" |
13 #include "base/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
14 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
16 #include "content/browser/browser_main_loop.h" | 17 #include "content/browser/browser_main_loop.h" |
17 #include "content/browser/fileapi/browser_file_system_helper.h" | 18 #include "content/browser/fileapi/browser_file_system_helper.h" |
18 #include "content/browser/geofencing/geofencing_manager.h" | 19 #include "content/browser/geofencing/geofencing_manager.h" |
19 #include "content/browser/gpu/shader_disk_cache.h" | 20 #include "content/browser/gpu/shader_disk_cache.h" |
20 #include "content/browser/host_zoom_map_impl.h" | 21 #include "content/browser/host_zoom_map_impl.h" |
21 #include "content/browser/notifications/platform_notification_context_impl.h" | 22 #include "content/browser/notifications/platform_notification_context_impl.h" |
22 #include "content/common/dom_storage/dom_storage_types.h" | 23 #include "content/common/dom_storage/dom_storage_types.h" |
23 #include "content/public/browser/browser_context.h" | 24 #include "content/public/browser/browser_context.h" |
24 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
25 #include "content/public/browser/dom_storage_context.h" | 26 #include "content/public/browser/dom_storage_context.h" |
26 #include "content/public/browser/indexed_db_context.h" | 27 #include "content/public/browser/indexed_db_context.h" |
27 #include "content/public/browser/local_storage_usage_info.h" | 28 #include "content/public/browser/local_storage_usage_info.h" |
28 #include "content/public/browser/session_storage_usage_info.h" | 29 #include "content/public/browser/session_storage_usage_info.h" |
29 #include "net/base/completion_callback.h" | 30 #include "net/base/completion_callback.h" |
30 #include "net/base/net_errors.h" | 31 #include "net/base/net_errors.h" |
| 32 #include "net/cookies/canonical_cookie.h" |
31 #include "net/cookies/cookie_monster.h" | 33 #include "net/cookies/cookie_monster.h" |
32 #include "net/url_request/url_request_context.h" | 34 #include "net/url_request/url_request_context.h" |
33 #include "net/url_request/url_request_context_getter.h" | 35 #include "net/url_request/url_request_context_getter.h" |
34 #include "storage/browser/database/database_tracker.h" | 36 #include "storage/browser/database/database_tracker.h" |
35 #include "storage/browser/quota/quota_manager.h" | 37 #include "storage/browser/quota/quota_manager.h" |
36 | 38 |
37 namespace content { | 39 namespace content { |
38 | 40 |
39 namespace { | 41 namespace { |
40 | 42 |
| 43 bool DoesCookieMatchHost(const std::string& host, |
| 44 const net::CanonicalCookie& cookie) { |
| 45 return cookie.IsHostCookie() && cookie.IsDomainMatch(host); |
| 46 } |
| 47 |
41 void OnClearedCookies(const base::Closure& callback, int num_deleted) { | 48 void OnClearedCookies(const base::Closure& callback, int num_deleted) { |
42 // The final callback needs to happen from UI thread. | 49 // The final callback needs to happen from UI thread. |
43 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 50 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
44 BrowserThread::PostTask( | 51 BrowserThread::PostTask( |
45 BrowserThread::UI, FROM_HERE, | 52 BrowserThread::UI, FROM_HERE, |
46 base::Bind(&OnClearedCookies, callback, num_deleted)); | 53 base::Bind(&OnClearedCookies, callback, num_deleted)); |
47 return; | 54 return; |
48 } | 55 } |
49 | 56 |
50 callback.Run(); | 57 callback.Run(); |
51 } | 58 } |
52 | 59 |
53 void ClearCookiesOnIOThread( | 60 void ClearCookiesOnIOThread( |
54 const scoped_refptr<net::URLRequestContextGetter>& rq_context, | 61 const scoped_refptr<net::URLRequestContextGetter>& rq_context, |
55 const base::Time begin, | 62 const base::Time begin, |
56 const base::Time end, | 63 const base::Time end, |
57 const GURL& storage_origin, | 64 const GURL& storage_origin, |
58 const base::Closure& callback) { | 65 const base::Closure& callback) { |
59 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 66 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
60 net::CookieStore* cookie_store = rq_context-> | 67 net::CookieStore* cookie_store = rq_context-> |
61 GetURLRequestContext()->cookie_store(); | 68 GetURLRequestContext()->cookie_store(); |
62 if (storage_origin.is_empty()) { | 69 if (storage_origin.is_empty()) { |
63 cookie_store->DeleteAllCreatedBetweenAsync( | 70 cookie_store->DeleteAllCreatedBetweenAsync( |
64 begin, | 71 begin, |
65 end, | 72 end, |
66 base::Bind(&OnClearedCookies, callback)); | 73 base::Bind(&OnClearedCookies, callback)); |
67 } else { | 74 } else { |
68 cookie_store->DeleteAllCreatedBetweenForHostAsync( | 75 // TODO(mkwst): It's not clear whether removing host cookies is the correct |
69 begin, | 76 // behavior. We might want to remove all domain-matching cookies instead. |
70 end, | 77 // Also, this code path may be dead anyways. |
71 storage_origin, base::Bind(&OnClearedCookies, callback)); | 78 cookie_store->DeleteAllCreatedBetweenWithPredicateAsync( |
| 79 begin, end, |
| 80 StoragePartitionImpl::CreatePredicateForHostCookies(storage_origin), |
| 81 base::Bind(&OnClearedCookies, callback)); |
72 } | 82 } |
73 } | 83 } |
74 | 84 |
75 void CheckQuotaManagedDataDeletionStatus(size_t* deletion_task_count, | 85 void CheckQuotaManagedDataDeletionStatus(size_t* deletion_task_count, |
76 const base::Closure& callback) { | 86 const base::Closure& callback) { |
77 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 87 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
78 if (*deletion_task_count == 0) { | 88 if (*deletion_task_count == 0) { |
79 delete deletion_task_count; | 89 delete deletion_task_count; |
80 callback.Run(); | 90 callback.Run(); |
81 } | 91 } |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 if (remove_mask & StoragePartition::REMOVE_DATA_MASK_INDEXEDDB) | 224 if (remove_mask & StoragePartition::REMOVE_DATA_MASK_INDEXEDDB) |
215 quota_client_mask |= storage::QuotaClient::kIndexedDatabase; | 225 quota_client_mask |= storage::QuotaClient::kIndexedDatabase; |
216 if (remove_mask & StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS) | 226 if (remove_mask & StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS) |
217 quota_client_mask |= storage::QuotaClient::kServiceWorker; | 227 quota_client_mask |= storage::QuotaClient::kServiceWorker; |
218 if (remove_mask & StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE) | 228 if (remove_mask & StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE) |
219 quota_client_mask |= storage::QuotaClient::kServiceWorkerCache; | 229 quota_client_mask |= storage::QuotaClient::kServiceWorkerCache; |
220 | 230 |
221 return quota_client_mask; | 231 return quota_client_mask; |
222 } | 232 } |
223 | 233 |
| 234 // static |
| 235 net::CookieStore::CookiePredicate |
| 236 StoragePartitionImpl::CreatePredicateForHostCookies(const GURL& url) { |
| 237 return base::Bind(&DoesCookieMatchHost, url.host()); |
| 238 } |
| 239 |
224 // Helper for deleting quota managed data from a partition. | 240 // Helper for deleting quota managed data from a partition. |
225 // | 241 // |
226 // Most of the operations in this class are done on IO thread. | 242 // Most of the operations in this class are done on IO thread. |
227 struct StoragePartitionImpl::QuotaManagedDataDeletionHelper { | 243 struct StoragePartitionImpl::QuotaManagedDataDeletionHelper { |
228 QuotaManagedDataDeletionHelper(uint32_t remove_mask, | 244 QuotaManagedDataDeletionHelper(uint32_t remove_mask, |
229 uint32_t quota_storage_remove_mask, | 245 uint32_t quota_storage_remove_mask, |
230 const GURL& storage_origin, | 246 const GURL& storage_origin, |
231 const base::Closure& callback) | 247 const base::Closure& callback) |
232 : remove_mask(remove_mask), | 248 : remove_mask(remove_mask), |
233 quota_storage_remove_mask(quota_storage_remove_mask), | 249 quota_storage_remove_mask(quota_storage_remove_mask), |
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
901 net::URLRequestContextGetter* url_request_context) { | 917 net::URLRequestContextGetter* url_request_context) { |
902 url_request_context_ = url_request_context; | 918 url_request_context_ = url_request_context; |
903 } | 919 } |
904 | 920 |
905 void StoragePartitionImpl::SetMediaURLRequestContext( | 921 void StoragePartitionImpl::SetMediaURLRequestContext( |
906 net::URLRequestContextGetter* media_url_request_context) { | 922 net::URLRequestContextGetter* media_url_request_context) { |
907 media_url_request_context_ = media_url_request_context; | 923 media_url_request_context_ = media_url_request_context; |
908 } | 924 } |
909 | 925 |
910 } // namespace content | 926 } // namespace content |
OLD | NEW |