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 "base/sequenced_task_runner.h" | 7 #include "base/sequenced_task_runner.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "content/browser/browser_main_loop.h" | 9 #include "content/browser/browser_main_loop.h" |
10 #include "content/browser/fileapi/browser_file_system_helper.h" | 10 #include "content/browser/fileapi/browser_file_system_helper.h" |
11 #include "content/browser/gpu/shader_disk_cache.h" | 11 #include "content/browser/gpu/shader_disk_cache.h" |
12 #include "content/public/browser/browser_context.h" | 12 #include "content/public/browser/browser_context.h" |
13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 14 #include "content/public/browser/cookie_store_map.h" |
14 #include "content/public/browser/dom_storage_context.h" | 15 #include "content/public/browser/dom_storage_context.h" |
15 #include "content/public/browser/indexed_db_context.h" | 16 #include "content/public/browser/indexed_db_context.h" |
| 17 #include "content/public/common/url_constants.h" |
16 #include "net/base/completion_callback.h" | 18 #include "net/base/completion_callback.h" |
17 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
18 #include "net/cookies/cookie_monster.h" | 20 #include "net/cookies/cookie_monster.h" |
19 #include "net/url_request/url_request_context.h" | 21 #include "net/url_request/url_request_context.h" |
20 #include "net/url_request/url_request_context_getter.h" | 22 #include "net/url_request/url_request_context_getter.h" |
21 #include "webkit/browser/database/database_tracker.h" | 23 #include "webkit/browser/database/database_tracker.h" |
22 #include "webkit/browser/quota/quota_manager.h" | 24 #include "webkit/browser/quota/quota_manager.h" |
23 #include "webkit/common/dom_storage/dom_storage_types.h" | 25 #include "webkit/common/dom_storage/dom_storage_types.h" |
24 | 26 |
25 namespace content { | 27 namespace content { |
(...skipping 17 matching lines...) Expand all Loading... |
43 origin != origins.end(); ++origin) { | 45 origin != origins.end(); ++origin) { |
44 quota_manager->DeleteOriginData(*origin, quota_storage_type, | 46 quota_manager->DeleteOriginData(*origin, quota_storage_type, |
45 quota::QuotaClient::kAllClientsMask, | 47 quota::QuotaClient::kAllClientsMask, |
46 base::Bind(&DoNothingStatusCallback)); | 48 base::Bind(&DoNothingStatusCallback)); |
47 } | 49 } |
48 } | 50 } |
49 | 51 |
50 void ClearOriginOnIOThread( | 52 void ClearOriginOnIOThread( |
51 uint32 storage_mask, | 53 uint32 storage_mask, |
52 const GURL& storage_origin, | 54 const GURL& storage_origin, |
53 const scoped_refptr<net::URLRequestContextGetter>& request_context, | 55 const scoped_refptr<net::CookieStore>& cookie_store, |
54 const scoped_refptr<quota::QuotaManager>& quota_manager) { | 56 const scoped_refptr<quota::QuotaManager>& quota_manager) { |
55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
56 | 58 |
57 if (storage_mask & StoragePartition::kCookies) { | 59 if (storage_mask & StoragePartition::kCookies && cookie_store.get()) { |
58 // Handle the cookies. | 60 // Handle the cookies. |
59 net::CookieMonster* cookie_monster = | 61 net::CookieMonster* cookie_monster = cookie_store->GetCookieMonster(); |
60 request_context->GetURLRequestContext()->cookie_store()-> | 62 if (cookie_monster) { |
61 GetCookieMonster(); | |
62 if (cookie_monster) | |
63 cookie_monster->DeleteAllForHostAsync( | 63 cookie_monster->DeleteAllForHostAsync( |
64 storage_origin, net::CookieMonster::DeleteCallback()); | 64 storage_origin, net::CookieMonster::DeleteCallback()); |
| 65 } |
65 } | 66 } |
66 | 67 |
67 // Handle all HTML5 storage other than DOMStorageContext. | 68 // Handle all HTML5 storage other than DOMStorageContext. |
68 std::set<GURL> origins; | 69 std::set<GURL> origins; |
69 origins.insert(storage_origin); | 70 origins.insert(storage_origin); |
70 if (storage_mask & StoragePartition::kQuotaManagedTemporaryStorage) { | 71 if (storage_mask & StoragePartition::kQuotaManagedTemporaryStorage) { |
71 ClearQuotaManagedOriginsOnIOThread(quota_manager, | 72 ClearQuotaManagedOriginsOnIOThread(quota_manager, |
72 origins, | 73 origins, |
73 quota::kStorageTypeTemporary); | 74 quota::kStorageTypeTemporary); |
74 } | 75 } |
75 if (storage_mask & StoragePartition::kQuotaManagedPersistentStorage) { | 76 if (storage_mask & StoragePartition::kQuotaManagedPersistentStorage) { |
76 ClearQuotaManagedOriginsOnIOThread(quota_manager, | 77 ClearQuotaManagedOriginsOnIOThread(quota_manager, |
77 origins, | 78 origins, |
78 quota::kStorageTypePersistent); | 79 quota::kStorageTypePersistent); |
79 } | 80 } |
80 if (storage_mask & StoragePartition::kQuotaManagedSyncableStorage) { | 81 if (storage_mask & StoragePartition::kQuotaManagedSyncableStorage) { |
81 ClearQuotaManagedOriginsOnIOThread(quota_manager, | 82 ClearQuotaManagedOriginsOnIOThread(quota_manager, |
82 origins, | 83 origins, |
83 quota::kStorageTypeSyncable); | 84 quota::kStorageTypeSyncable); |
84 } | 85 } |
85 } | 86 } |
86 | 87 |
87 void ClearAllDataOnIOThread( | 88 void ClearAllDataOnIOThread( |
88 uint32 storage_mask, | 89 uint32 storage_mask, |
89 const scoped_refptr<net::URLRequestContextGetter>& request_context, | 90 const scoped_refptr<quota::QuotaManager>& quota_manager, |
90 const scoped_refptr<quota::QuotaManager>& quota_manager) { | 91 const scoped_refptr<net::CookieStore>& cookie_store) { |
91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
92 | 93 |
93 if (storage_mask & StoragePartition::kCookies) { | 94 if (storage_mask & StoragePartition::kCookies && cookie_store.get()) { |
94 // Handle the cookies. | 95 // Handle the cookies. |
95 net::CookieMonster* cookie_monster = | 96 net::CookieMonster* cookie_monster = cookie_store->GetCookieMonster(); |
96 request_context->GetURLRequestContext()->cookie_store()-> | |
97 GetCookieMonster(); | |
98 if (cookie_monster) | 97 if (cookie_monster) |
99 cookie_monster->DeleteAllAsync(net::CookieMonster::DeleteCallback()); | 98 cookie_monster->DeleteAllAsync(net::CookieMonster::DeleteCallback()); |
100 } | 99 } |
101 | 100 |
102 // Handle all HTML5 storage other than DOMStorageContext. | 101 // Handle all HTML5 storage other than DOMStorageContext. |
103 if (storage_mask & StoragePartition::kQuotaManagedTemporaryStorage) { | 102 if (storage_mask & StoragePartition::kQuotaManagedTemporaryStorage) { |
104 quota_manager->GetOriginsModifiedSince( | 103 quota_manager->GetOriginsModifiedSince( |
105 quota::kStorageTypeTemporary, base::Time(), | 104 quota::kStorageTypeTemporary, base::Time(), |
106 base::Bind(&ClearQuotaManagedOriginsOnIOThread, quota_manager)); | 105 base::Bind(&ClearQuotaManagedOriginsOnIOThread, quota_manager)); |
107 } | 106 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 } // namespace | 152 } // namespace |
154 | 153 |
155 StoragePartitionImpl::StoragePartitionImpl( | 154 StoragePartitionImpl::StoragePartitionImpl( |
156 const base::FilePath& partition_path, | 155 const base::FilePath& partition_path, |
157 quota::QuotaManager* quota_manager, | 156 quota::QuotaManager* quota_manager, |
158 ChromeAppCacheService* appcache_service, | 157 ChromeAppCacheService* appcache_service, |
159 fileapi::FileSystemContext* filesystem_context, | 158 fileapi::FileSystemContext* filesystem_context, |
160 webkit_database::DatabaseTracker* database_tracker, | 159 webkit_database::DatabaseTracker* database_tracker, |
161 DOMStorageContextImpl* dom_storage_context, | 160 DOMStorageContextImpl* dom_storage_context, |
162 IndexedDBContextImpl* indexed_db_context, | 161 IndexedDBContextImpl* indexed_db_context, |
| 162 scoped_ptr<CookieStoreMap> cookie_store_map, |
163 scoped_ptr<WebRTCIdentityStore> webrtc_identity_store) | 163 scoped_ptr<WebRTCIdentityStore> webrtc_identity_store) |
164 : partition_path_(partition_path), | 164 : partition_path_(partition_path), |
165 quota_manager_(quota_manager), | 165 quota_manager_(quota_manager), |
166 appcache_service_(appcache_service), | 166 appcache_service_(appcache_service), |
167 filesystem_context_(filesystem_context), | 167 filesystem_context_(filesystem_context), |
168 database_tracker_(database_tracker), | 168 database_tracker_(database_tracker), |
169 dom_storage_context_(dom_storage_context), | 169 dom_storage_context_(dom_storage_context), |
170 indexed_db_context_(indexed_db_context), | 170 indexed_db_context_(indexed_db_context), |
171 webrtc_identity_store_(webrtc_identity_store.Pass()) {} | 171 cookie_store_map_(cookie_store_map.Pass()), |
| 172 webrtc_identity_store_(webrtc_identity_store.Pass()) { |
| 173 } |
172 | 174 |
173 StoragePartitionImpl::~StoragePartitionImpl() { | 175 StoragePartitionImpl::~StoragePartitionImpl() { |
174 // These message loop checks are just to avoid leaks in unittests. | 176 // These message loop checks are just to avoid leaks in unittests. |
175 if (GetDatabaseTracker() && | 177 if (GetDatabaseTracker() && |
176 BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) { | 178 BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) { |
177 BrowserThread::PostTask( | 179 BrowserThread::PostTask( |
178 BrowserThread::FILE, FROM_HERE, | 180 BrowserThread::FILE, FROM_HERE, |
179 base::Bind(&webkit_database::DatabaseTracker::Shutdown, | 181 base::Bind(&webkit_database::DatabaseTracker::Shutdown, |
180 GetDatabaseTracker())); | 182 GetDatabaseTracker())); |
181 } | 183 } |
182 | 184 |
183 if (GetDOMStorageContext()) | 185 if (GetDOMStorageContext()) |
184 GetDOMStorageContext()->Shutdown(); | 186 GetDOMStorageContext()->Shutdown(); |
185 } | 187 } |
186 | 188 |
187 // TODO(ajwong): Break the direct dependency on |context|. We only | 189 // TODO(ajwong): Break the direct dependency on |context|. We only |
188 // need 3 pieces of info from it. | 190 // need 3 pieces of info from it. |
189 StoragePartitionImpl* StoragePartitionImpl::Create( | 191 StoragePartitionImpl* StoragePartitionImpl::Create( |
190 BrowserContext* context, | 192 BrowserContext* context, |
191 bool in_memory, | 193 bool in_memory, |
192 const base::FilePath& partition_path) { | 194 const base::FilePath& partition_path, |
| 195 scoped_ptr<CookieStoreMap> cookie_store_map) { |
193 // Ensure that these methods are called on the UI thread, except for | 196 // Ensure that these methods are called on the UI thread, except for |
194 // unittests where a UI thread might not have been created. | 197 // unittests where a UI thread might not have been created. |
195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
196 !BrowserThread::IsMessageLoopValid(BrowserThread::UI)); | 199 !BrowserThread::IsMessageLoopValid(BrowserThread::UI)); |
197 | 200 |
198 // All of the clients have to be created and registered with the | 201 // All of the clients have to be created and registered with the |
199 // QuotaManager prior to the QuotaManger being used. We do them | 202 // QuotaManager prior to the QuotaManger being used. We do them |
200 // all together here prior to handing out a reference to anything | 203 // all together here prior to handing out a reference to anything |
201 // that utilizes the QuotaManager. | 204 // that utilizes the QuotaManager. |
202 scoped_refptr<quota::QuotaManager> quota_manager = new quota::QuotaManager( | 205 scoped_refptr<quota::QuotaManager> quota_manager = new quota::QuotaManager( |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 scoped_ptr<WebRTCIdentityStore> webrtc_identity_store( | 249 scoped_ptr<WebRTCIdentityStore> webrtc_identity_store( |
247 new WebRTCIdentityStore()); | 250 new WebRTCIdentityStore()); |
248 | 251 |
249 return new StoragePartitionImpl(partition_path, | 252 return new StoragePartitionImpl(partition_path, |
250 quota_manager.get(), | 253 quota_manager.get(), |
251 appcache_service.get(), | 254 appcache_service.get(), |
252 filesystem_context.get(), | 255 filesystem_context.get(), |
253 database_tracker.get(), | 256 database_tracker.get(), |
254 dom_storage_context.get(), | 257 dom_storage_context.get(), |
255 indexed_db_context.get(), | 258 indexed_db_context.get(), |
| 259 cookie_store_map.Pass(), |
256 webrtc_identity_store.Pass()); | 260 webrtc_identity_store.Pass()); |
257 } | 261 } |
258 | 262 |
259 base::FilePath StoragePartitionImpl::GetPath() { | 263 base::FilePath StoragePartitionImpl::GetPath() { |
260 return partition_path_; | 264 return partition_path_; |
261 } | 265 } |
262 | 266 |
263 net::URLRequestContextGetter* StoragePartitionImpl::GetURLRequestContext() { | 267 net::URLRequestContextGetter* StoragePartitionImpl::GetURLRequestContext() { |
264 return url_request_context_.get(); | 268 return url_request_context_.get(); |
265 } | 269 } |
(...skipping 20 matching lines...) Expand all Loading... |
286 } | 290 } |
287 | 291 |
288 DOMStorageContextImpl* StoragePartitionImpl::GetDOMStorageContext() { | 292 DOMStorageContextImpl* StoragePartitionImpl::GetDOMStorageContext() { |
289 return dom_storage_context_.get(); | 293 return dom_storage_context_.get(); |
290 } | 294 } |
291 | 295 |
292 IndexedDBContextImpl* StoragePartitionImpl::GetIndexedDBContext() { | 296 IndexedDBContextImpl* StoragePartitionImpl::GetIndexedDBContext() { |
293 return indexed_db_context_.get(); | 297 return indexed_db_context_.get(); |
294 } | 298 } |
295 | 299 |
| 300 const CookieStoreMap& StoragePartitionImpl::GetCookieStoreMap() { |
| 301 return *cookie_store_map_; |
| 302 } |
| 303 |
296 void StoragePartitionImpl::AsyncClearDataForOrigin( | 304 void StoragePartitionImpl::AsyncClearDataForOrigin( |
297 uint32 storage_mask, | 305 uint32 storage_mask, |
298 const GURL& storage_origin, | 306 const GURL& storage_origin) { |
299 net::URLRequestContextGetter* request_context_getter) { | |
300 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
301 | 308 |
302 BrowserThread::PostTask( | 309 BrowserThread::PostTask( |
303 BrowserThread::IO, FROM_HERE, | 310 BrowserThread::IO, FROM_HERE, |
304 base::Bind(&ClearOriginOnIOThread, | 311 base::Bind(&ClearOriginOnIOThread, storage_mask, storage_origin, |
305 storage_mask, | 312 make_scoped_refptr(GetCookieStoreMap().GetForScheme( |
306 storage_origin, | 313 storage_origin.scheme())), |
307 make_scoped_refptr(request_context_getter), | |
308 quota_manager_)); | 314 quota_manager_)); |
309 | 315 |
310 if (storage_mask & kLocalDomStorage) | 316 if (storage_mask & kLocalDomStorage) |
311 GetDOMStorageContext()->DeleteLocalStorage(storage_origin); | 317 GetDOMStorageContext()->DeleteLocalStorage(storage_origin); |
312 } | 318 } |
313 | 319 |
314 void StoragePartitionImpl::AsyncClearData(uint32 storage_mask) { | 320 void StoragePartitionImpl::AsyncClearData(uint32 storage_mask) { |
315 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 321 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
316 | 322 |
317 // We ignore the media request context because it shares the same cookie store | 323 // We ignore the media request context because it shares the same cookie |
318 // as the main request context. | 324 // store as the main request context. |
| 325 // |
| 326 // TODO(ajwong): Do we need to remove data for all things in the map? This is |
| 327 // different from old behavior. |
319 BrowserThread::PostTask( | 328 BrowserThread::PostTask( |
320 BrowserThread::IO, FROM_HERE, | 329 BrowserThread::IO, FROM_HERE, |
321 base::Bind(&ClearAllDataOnIOThread, | 330 base::Bind(&ClearAllDataOnIOThread, |
322 storage_mask, | 331 storage_mask, |
323 url_request_context_, | 332 quota_manager_, |
324 quota_manager_)); | 333 make_scoped_refptr( |
| 334 GetCookieStoreMap().GetForScheme(chrome::kHttpScheme)))); |
325 | 335 |
326 if (storage_mask & kLocalDomStorage) { | 336 if (storage_mask & kLocalDomStorage) { |
327 dom_storage_context_->GetLocalStorageUsage( | 337 dom_storage_context_->GetLocalStorageUsage( |
328 base::Bind(&OnLocalStorageUsageInfo, dom_storage_context_)); | 338 base::Bind(&OnLocalStorageUsageInfo, dom_storage_context_)); |
329 } | 339 } |
330 | 340 |
331 if (storage_mask & kSessionDomStorage) { | 341 if (storage_mask & kSessionDomStorage) { |
332 dom_storage_context_->GetSessionStorageUsage( | 342 dom_storage_context_->GetSessionStorageUsage( |
333 base::Bind(&OnSessionStorageUsageInfo, dom_storage_context_)); | 343 base::Bind(&OnSessionStorageUsageInfo, dom_storage_context_)); |
334 } | 344 } |
(...skipping 21 matching lines...) Expand all Loading... |
356 net::URLRequestContextGetter* url_request_context) { | 366 net::URLRequestContextGetter* url_request_context) { |
357 url_request_context_ = url_request_context; | 367 url_request_context_ = url_request_context; |
358 } | 368 } |
359 | 369 |
360 void StoragePartitionImpl::SetMediaURLRequestContext( | 370 void StoragePartitionImpl::SetMediaURLRequestContext( |
361 net::URLRequestContextGetter* media_url_request_context) { | 371 net::URLRequestContextGetter* media_url_request_context) { |
362 media_url_request_context_ = media_url_request_context; | 372 media_url_request_context_ = media_url_request_context; |
363 } | 373 } |
364 | 374 |
365 } // namespace content | 375 } // namespace content |
OLD | NEW |